<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Damilare Joseph</title>
    <description>The latest articles on Forem by Damilare Joseph (@dre4success).</description>
    <link>https://forem.com/dre4success</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F37322%2Fdd5e61bc-8c79-42e6-9b32-4e5d7cac4dbf.jpeg</url>
      <title>Forem: Damilare Joseph</title>
      <link>https://forem.com/dre4success</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/dre4success"/>
    <language>en</language>
    <item>
      <title>SSH to an EC2 instance from VS Code</title>
      <dc:creator>Damilare Joseph</dc:creator>
      <pubDate>Mon, 09 Mar 2020 17:25:50 +0000</pubDate>
      <link>https://forem.com/dre4success/ssh-to-an-ec2-instance-from-vs-code-2707</link>
      <guid>https://forem.com/dre4success/ssh-to-an-ec2-instance-from-vs-code-2707</guid>
      <description>&lt;p&gt;Requirements: &lt;/p&gt;

&lt;p&gt;1) You must have &lt;a href="https://code.visualstudio.com/"&gt;VSCode&lt;/a&gt; or &lt;a href="https://code.visualstudio.com/insiders/"&gt;VSCode Insider &lt;/a&gt; installed.&lt;/p&gt;

&lt;p&gt;2) A running &lt;a href="https://code.visualstudio.com/docs/remote/troubleshooting#_installing-a-supported-ssh-server"&gt;SSH server &lt;/a&gt; preferrable a linux server running on an EC2 instance.&lt;/p&gt;

&lt;p&gt;3) An &lt;a href="https://code.visualstudio.com/docs/remote/troubleshooting#_installing-a-supported-ssh-client"&gt; SSH Client &lt;/a&gt; on your local system.&lt;/p&gt;

&lt;p&gt;Steps to SSH on VSCode&lt;/p&gt;

&lt;p&gt;a) Install the &lt;a href="https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack"&gt;Remote extension pack&lt;/a&gt; on your vscode.&lt;/p&gt;

&lt;p&gt;b) In VSCode, press &lt;strong&gt;F1&lt;/strong&gt; to open the command palette, and type connect.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yir-rlIk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/u6d7yw8mqpdfptqbu763.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yir-rlIk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/u6d7yw8mqpdfptqbu763.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;c) Select Remote-SSH: Connect to Host. This will bring out options for you to add or configure SSH Hosts.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UDhbvJo4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/bqst7wqv4q75x9c2y6js.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UDhbvJo4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/bqst7wqv4q75x9c2y6js.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;d) Select configure SSH Hosts. This will give you options to create a config file. For mine I selected the first option /Users/username/.ssh/config.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HWPwbjrM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2ungbq3suq0h5i2uxjii.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HWPwbjrM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2ungbq3suq0h5i2uxjii.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will open a new file for you were you can create an ssh config.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VnLnHcxw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/bmvcrnsd68ndloton5zq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VnLnHcxw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/bmvcrnsd68ndloton5zq.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Host&lt;/strong&gt; is any name you want VSCode to use to recognize your file.&lt;br&gt;
The &lt;strong&gt;HostName&lt;/strong&gt; is the public dns of your EC2 instance or public ip address of your server.&lt;br&gt;
The &lt;strong&gt;User&lt;/strong&gt; is the username of your server.&lt;br&gt;
The &lt;strong&gt;IdentityFile&lt;/strong&gt; is the path to your ssh key which you got when you created your EC2 instance.&lt;/p&gt;

&lt;p&gt;Press &lt;strong&gt;F1&lt;/strong&gt; again to open the command palette. Select Remote-SSH and this time, you should see the &lt;strong&gt;Host&lt;/strong&gt; you just created. As you can see in the image below, mine is the &lt;strong&gt;personal&lt;/strong&gt; that appears.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2BjcKIbn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/9coq72krq3x4jzyq7jhg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2BjcKIbn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/9coq72krq3x4jzyq7jhg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select yours, and it will attempt connecting to it. When it has successfully connected, you will see something like this in the bottom left corner of your VSCode.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OdmVwW_X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xxbh52tzvnmjqdgjojd3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OdmVwW_X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xxbh52tzvnmjqdgjojd3.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Congrats!! 🥳  You have successfully connected your remote server to VSCode. Now you can start working on those files you want.&lt;/p&gt;

&lt;p&gt;If it didn't connect, don't despair, it will output some messages in the VSCode debug console. From there, you can see what's wrong.&lt;/p&gt;

&lt;p&gt;Please leave your questions and comments below. I will be happy to answer them.&lt;/p&gt;

</description>
      <category>vscode</category>
      <category>ec2</category>
      <category>ssh</category>
      <category>aws</category>
    </item>
    <item>
      <title>Deploying a MongoDB replica set on AWS EC2 instance</title>
      <dc:creator>Damilare Joseph</dc:creator>
      <pubDate>Wed, 08 Jan 2020 20:25:29 +0000</pubDate>
      <link>https://forem.com/dre4success/deploying-a-mongodb-replica-set-on-aws-ec2-instance-2gec</link>
      <guid>https://forem.com/dre4success/deploying-a-mongodb-replica-set-on-aws-ec2-instance-2gec</guid>
      <description>&lt;p&gt;According to Mongodb's website, "A replica set in MongoDB is a group of &lt;br&gt;
&lt;a href="https://docs.mongodb.com/manual/reference/program/mongod/#bin.mongod"&gt;mongod&lt;/a&gt; processes that maintain the same data set. Replica sets provide redundancy and high availability, and are the basis for all production deployments." Meaning if you are using MongoDB as your data source and you are ready to deploy in production, you need a replica set for some system reliability. &lt;/p&gt;

&lt;p&gt;It is advised that each member of your replica set have their own standalone servers. &lt;/p&gt;

&lt;p&gt;For this tutorial, I will be setting up a replica set with an arbiter.&lt;br&gt;
For more on replication and replica set architecture, see &lt;a href="https://docs.mongodb.com/manual/replication/"&gt; Replica Set Architecture &lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STEP 1: Create 3 EC2 instance and Install MongoDB&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create 3 ec2 instance, they can be of any OS, just make sure you can install Mongodb on each of them.&lt;/p&gt;

&lt;p&gt;I will be using Red Hat Enterprise Linux 8 for the 3 instance.&lt;/p&gt;

&lt;p&gt;For MongoDB installation guide, checkout &lt;a href="https://docs.mongodb.com/manual/installation/"&gt;MongoDB Installation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Make sure the 3 instance created are in the same security group and the inbound rule allows them to talk with each other on port 27017.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STEP 2: Enable Access Control (Authentication and Authorization)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a Keyfile:
&lt;p&gt;With &lt;a href="https://docs.mongodb.com/manual/core/security-internal-authentication/#internal-auth-keyfile"&gt;keyfile&lt;/a&gt; authentication, each mongod instances in the replica set uses the contents of the keyfile as the shared password for authenticating other members in the deployment. Only mongod instances with the correct keyfile can join the replica set.&lt;/p&gt;
Run the following command to generate a keyfile
&lt;ol&gt;
&lt;li&gt;
  openssl rand -base64 756 &amp;gt; &lt;strong&gt;/opt/mongo/mongod-keyfile&lt;/strong&gt;

 &lt;/li&gt;
&lt;li&gt;

  chmod 400 &lt;strong&gt;/opt/mongo/mongod-keyfile&lt;/strong&gt;

 &lt;/li&gt;
&lt;li&gt;
&lt;i&gt; sudo chown mongodb:mongodb &lt;strong&gt;/opt/mongo/mongod-keyfile&lt;/strong&gt; &lt;/i&gt; &lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;p&gt;The above commands will generate a keyfile for you located in &lt;strong&gt;/opt/mongo/mongod-keyfile&lt;/strong&gt;. It will give read permissions to the owner and allow mongodb to be able to read it.&lt;/p&gt;
&lt;li&gt;Copy the Keyfile to other replica-set members:
&lt;p&gt;This means copying the keyfile generated to the other EC2-instances where your member replica-set members are located. You might have to run the second and third command above in the replica-set instances after copying them to enable read permission.&lt;/p&gt;
&lt;p&gt; To transfer files from one EC2 instance to another, you can follow this tutorial, &lt;a href="https://blog.e-zest.com/how-to-do-scp-from-one-ec2-instance-to-another-ec2-instance/"&gt;File Transfer between 2 EC2 Instance&lt;/a&gt; &lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;Update the configuration file:
&lt;ol&gt;
 &lt;li&gt;Open the file: &lt;i&gt;sudo nano /etc/mongod.conf&lt;/i&gt;
&lt;/li&gt;
 &lt;li&gt;Under &lt;strong&gt;bindIp&lt;/strong&gt; in &lt;strong&gt;net&lt;/strong&gt;, add the private address of the current machine along with the localhost because mongodb binds to the localhost by default&lt;/li&gt;
&lt;li&gt;Under &lt;strong&gt;replication&lt;/strong&gt; add &lt;strong&gt;replSetName&lt;/strong&gt; with the name of your replica set&lt;/li&gt;
&lt;li&gt;Under &lt;strong&gt;security&lt;/strong&gt;, add &lt;strong&gt;&lt;i&gt;keyFile: 'path to keyfile you generated'&lt;/i&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Save the file and restart mongodb: &lt;i&gt;sudo systemctl restart mongod&lt;/i&gt;
&lt;/li&gt;

&lt;/ol&gt;
&lt;/li&gt; 
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;STEP 3: Create and connect your replicaset members&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Connect to the mongo shell(typing &lt;i&gt;mongo&lt;/i&gt; should get you there) in any of the servers you want to make the primary&lt;/li&gt;
&lt;li&gt;run &lt;strong&gt; rs.initiate()&lt;/strong&gt; to create your Primary. This sets the current instance as the primary replica&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create the user admin: This admin user must have privileges to create other users, such as a user with the &lt;strong&gt;userAdminAnyDatabase&lt;/strong&gt; role.&lt;/p&gt;
&lt;p&gt;run &lt;strong&gt;&lt;p&gt;&lt;i&gt;db.createUser({user: “admin”, pwd: “admin”, 
roles: [{role: “userAdminAnyDatabase”, db: “admin"}]})&lt;/i&gt;&lt;/p&gt;&lt;/strong&gt; to create an admin user for you. Use a strong username and password of your choice.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;exit the shell and authenticate as admin user: &lt;p&gt;&lt;strong&gt;&lt;i&gt;
mongo -u 'your-username' -p --authenticationDatabase admin&lt;/i&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It will prompt for your password, enter correct one.
&lt;/p&gt;


&lt;/li&gt;
&lt;li&gt;Create a cluster admin: Use the &lt;strong&gt;clusterAdmin&lt;/strong&gt; role. This grants access to replication operations such as configuring replica set.

&lt;p&gt;run &lt;strong&gt;&lt;p&gt;&lt;i&gt;db.createUser({user: “adminCluster”, pwd: “adminCluster”, 
roles: [{role: “clusterAdmin”, db: “admin"}]})&lt;/i&gt;&lt;/p&gt;&lt;/strong&gt;. Use a unique username and a strong password for this.
&lt;/p&gt;


&lt;/li&gt;
&lt;li&gt;Exit the shell and authenticate as the cluster admin to add more replica members. &lt;p&gt;&lt;strong&gt;&lt;i&gt;mongo -u 'your-cluster-admin-username' -p --authenticationDatabase admin&lt;/i&gt;&lt;/strong&gt;&lt;/p&gt;When it prompts for password, enter your cluster admin password.&lt;/li&gt;
&lt;li&gt;Add more cluster members by running &lt;p&gt;&lt;strong&gt;&lt;i&gt;rs.add( { host: "ipaddress/hostname-of-the-instance-you-want-to-add-as-member:27017" } )&lt;/i&gt;&lt;/strong&gt;&lt;/p&gt; &lt;/li&gt;
&lt;li&gt;Add an arbiter to your replica set: &lt;p&gt;&lt;strong&gt;&lt;i&gt;rs.addArb(‘ipaddress/hostname-of-the-instance-you-want-to-make-as-arbiter:27017’)&lt;/i&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Sidenotes:&lt;/strong&gt;&lt;br&gt;
You can create additional db users for your clients(backend applications, etc) to connect to. To do that, authenticate as admin and create a db user with the appropriate role you want.&lt;/p&gt;

&lt;p&gt;In adding a new member to the cluster,&lt;br&gt;
copy the &lt;strong&gt;keyfile&lt;/strong&gt; you generated to the new member’s server. uncomment security in the &lt;strong&gt;&lt;i&gt;/etc/mongod.conf&lt;/i&gt;&lt;/strong&gt; file and add &lt;strong&gt;&lt;i&gt;keyFile: 'file location'&lt;/i&gt;&lt;/strong&gt;&lt;br&gt;
uncomment &lt;strong&gt;replication&lt;/strong&gt; and add &lt;strong&gt;&lt;i&gt;replSetName&lt;/i&gt;&lt;/strong&gt; with the replica set’s name you want to add it to.&lt;br&gt;
save file and start mongod instance.&lt;br&gt;
Go to the primary of the replica set and add this new member to the replica set using rs.add( { host: "ipaddress/hostname-of-the-instance-you-want-to-add-as-member:27017" } )&lt;/p&gt;

</description>
      <category>mongodb</category>
      <category>aws</category>
      <category>ec2</category>
      <category>replicaset</category>
    </item>
  </channel>
</rss>
