{"id":1067,"date":"2017-10-09T05:01:14","date_gmt":"2017-10-09T02:01:14","guid":{"rendered":"https:\/\/community.virtono.com\/?p=1067"},"modified":"2023-06-21T10:48:36","modified_gmt":"2023-06-21T07:48:36","slug":"how-to-install-mongodb-on-ubuntu-16-04","status":"publish","type":"post","link":"https:\/\/www.virtono.com\/community\/tutorial-how-to\/how-to-install-mongodb-on-ubuntu-16-04\/","title":{"rendered":"How to Install MongoDB on Ubuntu 16.04"},"content":{"rendered":"<p><b>Introduction<\/b><\/p>\n<p>MongoDB it is a document-oriented database. It is a free and open-source database. It does not rely on a traditional table-based relational database structure that\u2019s why it is classified as a NoSQL database. Instead it uses JSON-like documents with dynamic schemas. Before you add data to database MongoDB does not require a predefined schema cause it\u2019s not like other relational database.The schema can be altercated at any time<\/p>\n<p>In the following tutorial in one of its part we will use the MongoDB Repository to install the latest version of MongoDB. In part two now we have to start the authentication to secure it on the local system. At the end the final step, we\u2019ll show how to more securely allow remote connection if they\u2019re needed<\/p>\n<p>For more information on MongoDB please read this <a href=\"https:\/\/virtono.com\/community\/news-announcements\/mongodb-and-nosql-databases\/\" target=\"_blank\" rel=\"noopener\">article<\/a>.<\/p>\n<p><strong>You can follow up with the video below or just follow along with the article.<\/strong><\/p>\n<p><span class=\"embed-youtube\" style=\"text-align:center; display: block;\"><iframe loading=\"lazy\" class=\"youtube-player\" width=\"750\" height=\"422\" src=\"https:\/\/www.youtube.com\/embed\/_4eb3GBunDo?version=3&#038;rel=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;fs=1&#038;hl=en-US&#038;autohide=2&#038;wmode=transparent\" allowfullscreen=\"true\" style=\"border:0;\" sandbox=\"allow-scripts allow-same-origin allow-popups allow-presentation allow-popups-to-escape-sandbox\"><\/iframe><\/span><\/p>\n<p>Part One: Setting Up the Server<\/p>\n<p>Step 1 \u2014 Adding the MongoDB Repository<\/p>\n<p>MongoDB it\u2019s already included in Ubuntu package repositories, but the official MongoDB repository provides the most up-to-date version and is the recommended way of installing the software. In this step, we will add this official repository to our server.<\/p>\n<ul>\n<li>Ubuntu ensures the authenticity of software packages by verifying that they are signed with GPG keys, so we first have to import the key for the official MongoDB sudo apt-key adv &#8211;keyserver hkp:\/\/keyserver.ubuntu.com:80 &#8211;recv 0C49F3730359A14518585931BC711F9BA15703C6<\/li>\n<li><\/li>\n<\/ul>\n<p>The following output confirms that we&#8217;ve successfully imported the key:<\/p>\n<p>Output<\/p>\n<p>Executing: \/tmp\/tmp.IdwenTia0s\/gpg.1.sh &#8211;keyserver<\/p>\n<p>hkp:\/\/keyserver.ubuntu.com:80<\/p>\n<p>&#8211;recv<\/p>\n<p>0C49F3730359A14518585931BC711F9BA15703C6<\/p>\n<p>gpg: requesting key A15703C6 from hkp server keyserver.ubuntu.com<\/p>\n<p>gpg: key A15703C6: public key &#8220;MongoDB 3.4 Release Signing Key &lt;packaging@mongodb.com&gt;&#8221; imported<\/p>\n<p>gpg: Total number processed: 1<\/p>\n<p>gpg: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0imported: 1 \u00a0(RSA: 1)<\/p>\n<p>Next, we&#8217;ll add MongoDB repository details so\u00a0apt\u00a0will know where to download the packages. Issue the following command to create a list file for MongoDB.<\/p>\n<ul>\n<li>echo &#8220;deb [ arch=amd64,arm64 ] http:\/\/repo.mongodb.org\/apt\/ubuntu xenial\/mongodb-org\/3.4 multiverse&#8221; | sudo tee \/etc\/apt\/sources.list.d\/mongodb-org-3.4.list<\/li>\n<li><\/li>\n<\/ul>\n<p>Finally, we&#8217;ll update the packages list.<\/p>\n<ul>\n<li>sudo apt-get update<\/li>\n<li><\/li>\n<\/ul>\n<p>Now we&#8217;re ready to install MongoDB.<\/p>\n<p>Step 2 \u2014 Installing MongoDB<\/p>\n<p>We&#8217;ll install themongodb-org\u00a0meta-package, which includes the daemon, configuration and init scripts, shell, and management tools on the server.<\/p>\n<ul>\n<li>sudo apt-get install mongodb-org<\/li>\n<li><\/li>\n<\/ul>\n<p>Press enter or type\u00a0Y\u00a0to proceed when prompted. Once the installation is complete, we&#8217;ll start the Mongo daemon:<\/p>\n<ul>\n<li>sudo systemctl start mongod<\/li>\n<li><\/li>\n<\/ul>\n<p>Since\u00a0systemctl\u00a0doesn&#8217;t provide output, we&#8217;ll check the status to verify that the service has started properly.<\/p>\n<ul>\n<li>sudo systemctl status mongod<\/li>\n<li><\/li>\n<\/ul>\n<p>Output<\/p>\n<ul>\n<li>mongod.service &#8211; High-performance, schema-free document-oriented database<\/li>\n<\/ul>\n<p>Loaded: loaded (\/lib\/systemd\/system\/mongod.service; disabled; vendor preset: enabled)<\/p>\n<p>Active: active (running) since Fri 2017-02-17 18:57:26 UTC; 17min ago<\/p>\n<p>Docs: https:\/\/docs.mongodb.org\/manual<\/p>\n<p>Main PID: 2811 (mongod)<\/p>\n<p>Tasks: 17<\/p>\n<p>Memory: 56.8M<\/p>\n<p>CPU: 7.294s<\/p>\n<p>CGroup: \/system.slice\/mongod.service<\/p>\n<p>\u2514\u25002811 \/usr\/bin\/mongod &#8211;quiet &#8211;config \/etc\/mongod.conf<\/p>\n<p>Press\u00a0q\u00a0to exit. Now that we&#8217;ve manually started the daemon and verified that it\u2019s running, we&#8217;ll ensure that it restarts automatically at boot:<\/p>\n<ul>\n<li>sudo systemctl enable mongod<\/li>\n<li><\/li>\n<\/ul>\n<p>The following output confirms that the command was successful:<\/p>\n<p>Output<\/p>\n<p>Created symlink from \/etc\/systemd\/system\/multi-user.target.wants\/mongod.service<\/p>\n<p>to \/lib\/systemd\/system\/mongod.service.<\/p>\n<p>Next, we&#8217;ll take essential steps to secure our databases.<\/p>\n<p>Part Two: Securing MongoDB<\/p>\n<p>Earlier versions of MongoDB were vulnerable to automated exploits because by default no authentication was required to interact with the database. Any user could create and destroy databases, as well as read from and write to their contents by default. This was compounded because those earlier versions also configured the MongoDB daemon to listen on all interfaces by default, which meant that automated scripts could detect MongoDB instances that weren&#8217;t protected by a firewall and, if authentication hadn&#8217;t been enabled, gain complete access to MongoDB.<\/p>\n<p>The situation has been mitigated in the 3.x release as well as earlier versions provided by some package managers because the daemon is now bound to 127.0.0.1 so it will only accept connections on the Unix socket. It is not automatically open to the Internet.<\/p>\n<p>However, authentication is still disabled by default, so any users on the local system have complete access to the databases. To secure this we&#8217;ll create an administrative user, enable authentication and test.<\/p>\n<p>Step 1 \u2014 Adding an Administrative User<\/p>\n<p>To add our user, we&#8217;ll connect to the Mongo shell:<\/p>\n<ul>\n<li>mongo<\/li>\n<li><\/li>\n<\/ul>\n<p>The output when we use the Mongo shell warns us that access control is not enabled for the database and that read\/write access to data and configuration is unrestricted.<\/p>\n<p>Output<\/p>\n<p>MongoDB shell version v3.4.2<\/p>\n<p>connecting to: mongodb:\/\/127.0.0.1:27017<\/p>\n<p>MongoDB server version: 3.4.2<\/p>\n<p>Welcome to the MongoDB shell.<\/p>\n<p>For interactive help, type &#8220;help&#8221;.<\/p>\n<p>For more comprehensive documentation, see<\/p>\n<p>http:\/\/docs.mongodb.org\/<\/p>\n<p>Questions? Try the support group<\/p>\n<p>http:\/\/groups.google.com\/group\/mongodb-user<\/p>\n<p>Server has startup warnings:<\/p>\n<p>2017-02-21T19:10:42.446+0000 I STORAGE \u00a0[initandlisten]<\/p>\n<p>2017-02-21T19:10:42.446+0000 I STORAGE \u00a0[initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine<\/p>\n<p>2017-02-21T19:10:42.446+0000 I STORAGE \u00a0[initandlisten] ** \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0See http:\/\/dochub.mongodb.org\/core\/prodnotes-filesystem<\/p>\n<p>2017-02-21T19:10:42.534+0000 I CONTROL \u00a0[initandlisten]<\/p>\n<p>2017-02-21T19:10:42.534+0000 I CONTROL \u00a0[initandlisten] ** WARNING: Access control is not enabled for the database.<\/p>\n<p>2017-02-21T19:10:42.534+0000 I CONTROL \u00a0[initandlisten] ** \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Read and write access to data and configuration is unrestricted.<\/p>\n<p>2017-02-21T19:10:42.534+0000 I CONTROL \u00a0[initandlisten]<\/p>\n<p>&gt;<\/p>\n<p>We&#8217;re free to choose the name for the administrative user since the privilege level comes from the assignment of the role\u00a0userAdminAnyDatabase. The database,\u00a0admin\u00a0designates where the credentials are stored. You can learn more about authentication in the MongoDB Security\u00a0<a href=\"https:\/\/docs.mongodb.com\/manual\/core\/authentication\/\" target=\"_blank\" rel=\"noopener\">Authentication\u00a0<\/a>section.<\/p>\n<p>Set the username of your choice and be sure to pick your own secure password and substitute them in the command below:<\/p>\n<ul>\n<li>use admin<\/li>\n<li><\/li>\n<li>db.createUser(<\/li>\n<li><\/li>\n<li>\u00a0{<\/li>\n<li><\/li>\n<li>\u00a0\u00a0\u00a0user: &#8220;AdminSammy&#8221;,<\/li>\n<li><\/li>\n<li>\u00a0\u00a0\u00a0pwd: &#8220;AdminSammy&#8217;sSecurePassword&#8221;,<\/li>\n<li><\/li>\n<li>\u00a0\u00a0\u00a0roles: [ { role: &#8220;userAdminAnyDatabase&#8221;, db: &#8220;admin&#8221; } ]<\/li>\n<li><\/li>\n<li>\u00a0}<\/li>\n<li><\/li>\n<li>)<\/li>\n<li><\/li>\n<\/ul>\n<p>When we issue the\u00a0db.createUser\u00a0command, the shell will prepend three dots before each line until the command is complete. After that, we should receive feedback like the following when the user has been added.<\/p>\n<p>Output<\/p>\n<p>&gt; use admin<\/p>\n<p>switched to db admin<\/p>\n<p>&gt; db.createUser(<\/p>\n<p>&#8230; \u00a0\u00a0{<\/p>\n<p>&#8230; \u00a0\u00a0\u00a0\u00a0user: &#8220;AdminSammy&#8221;,<\/p>\n<p>&#8230; \u00a0\u00a0\u00a0\u00a0pwd: &#8220;AdminSammy&#8217;sSecurePassword&#8221;,<\/p>\n<p>&#8230; \u00a0\u00a0\u00a0\u00a0roles: [ { role: &#8220;userAdminAnyDatabase&#8221;, db: &#8220;admin&#8221; } ]<\/p>\n<p>&#8230; \u00a0\u00a0}<\/p>\n<p>&#8230; )<\/p>\n<p>Successfully added user: {<\/p>\n<p>&#8220;user&#8221; : &#8220;AdminSammy&#8221;,<\/p>\n<p>&#8220;roles&#8221; : [<\/p>\n<p>{<\/p>\n<p>&#8220;role&#8221; : &#8220;userAdminAnyDatabase&#8221;,<\/p>\n<p>&#8220;db&#8221; : &#8220;admin&#8221;<\/p>\n<p>}<\/p>\n<p>]<\/p>\n<p>}<\/p>\n<p>Type &#8216;exit&#8217; and press\u00a0ENTER\u00a0or use\u00a0CTRL+C\u00a0to leave the client.<\/p>\n<p>At this point, our user will be allowed to enter credentials, but they will not be\u00a0<b>required<\/b>\u00a0to do so until we enable authentication and restart the MongoDB daemon.<\/p>\n<p>Step 2 \u2014 Enabling Authentication<\/p>\n<p>Authentication is enabled in the\u00a0mongod.conf\u00a0file. Once we enable it and restart\u00a0mongod, users still will be able to connect to Mongo without authenticating, but they will be required to provide a username and password before they can interact.<\/p>\n<p>Let&#8217;s open the configuration file:<\/p>\n<ul>\n<li>sudo nano \/etc\/mongod.conf<\/li>\n<li><\/li>\n<\/ul>\n<p>In the\u00a0#security\u00a0section, we&#8217;ll remove the hash in front of\u00a0security\u00a0to enable the stanza. Then we&#8217;ll add the authorization setting. When we&#8217;re done, the lines should look like the excerpt below:<\/p>\n<p>mongodb.conf<\/p>\n<p>. . .<\/p>\n<p>security:<\/p>\n<p>authorization: &#8220;enabled&#8221;<\/p>\n<p>. . .<\/p>\n<p>Note that the \u201csecurity\u201d line has no spaces at the beginning, and the \u201cauthorization\u201d line must be indented with two spaces<\/p>\n<p>Once we&#8217;ve saved and exited the file, we&#8217;ll restart the daemon:<\/p>\n<ul>\n<li>sudo systemctl restart mongod<\/li>\n<li><\/li>\n<\/ul>\n<p>If we&#8217;ve made an error in the configuration, the dameon won&#8217;t start. Since\u00a0systemctl\u00a0doesn&#8217;t provide output, we&#8217;ll use its\u00a0status\u00a0option to be sure that it did:.<\/p>\n<ul>\n<li>sudo systemctl status mongod<\/li>\n<li><\/li>\n<\/ul>\n<p>If we see\u00a0Active: active (running)\u00a0in the output and it ends with something like the text below, we can be sure the\u00a0restart\u00a0command was successful:<\/p>\n<p>Output<\/p>\n<p>Jan 23 19:15:42 MongoHost systemd[1]: Started High-performance, schema-free document-oriented database.<\/p>\n<p>Having verified the daemon is up, let&#8217;s test authentication.<\/p>\n<p>Step 3 \u2014 Verifying that Unauthenticated Users are Restricted<\/p>\n<p>First, let&#8217;s connect without credentials to verify that our actions are restricted:<\/p>\n<ul>\n<li>mongo<\/li>\n<li><\/li>\n<\/ul>\n<p>Now that we&#8217;ve enabled authentication, all of the earlier warnings are resolved.<\/p>\n<p>Output<\/p>\n<p>MongoDB shell version v3.4.2<\/p>\n<p>connecting to: mongodb:\/\/127.0.0.1:27017<\/p>\n<p>MongoDB server version: 3.4.2<\/p>\n<p>We&#8217;re connected to the\u00a0test\u00a0database. We&#8217;ll test that our access is restricted with the\u00a0show dbscommand:<\/p>\n<ul>\n<li>show dbs<\/li>\n<li><\/li>\n<\/ul>\n<p>Output<\/p>\n<p>2017-02-21T19:20:42.919+0000 E QUERY \u00a0\u00a0\u00a0[thread1] Error: listDatabases failed:{<\/p>\n<p>&#8220;ok&#8221; : 0,<\/p>\n<p>&#8220;errmsg&#8221; : &#8220;not authorized on admin to execute command { listDatabases: 1.0 }&#8221;,<\/p>\n<p>&#8220;code&#8221; : 13,<\/p>\n<p>&#8220;codeName&#8221; : &#8220;Unauthorized&#8221;<\/p>\n<p>. . .<\/p>\n<p>We wouldn&#8217;t be able to create users or similarily privileged tasks without authenticating.<\/p>\n<p>Let&#8217;s exit the shell to proceed:<\/p>\n<ul>\n<li>exit<\/li>\n<li><\/li>\n<\/ul>\n<p>Next, we&#8217;ll make sure our Administrative user\u00a0<i>does<\/i>\u00a0have access.<\/p>\n<p>Step 4 \u2014 Verifying the Administrative User&#8217;s Access<\/p>\n<p>We&#8217;ll connect as our administrator with the\u00a0-u\u00a0option to supply a username and\u00a0-p\u00a0to be prompted for a password. We will also need to supply the database where we stored the user&#8217;s authentication credentials with the\u00a0&#8211;authenticationDatabase\u00a0option.<\/p>\n<ul>\n<li>mongo -u AdminSammy -p &#8211;authenticationDatabase admin<\/li>\n<li><\/li>\n<\/ul>\n<p>We&#8217;ll be prompted for the password, so supply it. Once we enter the correct password, we&#8217;ll be dropped into the shell, where we can issue the\u00a0show dbs\u00a0command:<\/p>\n<p>Output<\/p>\n<p>MongoDB shell version v3.4.2<\/p>\n<p>Enter password:<\/p>\n<p>connecting to: mongodb:\/\/127.0.0.1:27017<\/p>\n<p>MongoDB server version: 3.4.2<\/p>\n<p>&gt;<\/p>\n<p>Rather than being denied access, we should see the available databases:<\/p>\n<ul>\n<li>show dbs<\/li>\n<li><\/li>\n<\/ul>\n<p>Output<\/p>\n<p>admin \u00a00.000GB<\/p>\n<p>local \u00a00.000GB<\/p>\n<p>Type\u00a0exit\u00a0or press\u00a0CTRL+C\u00a0to exit.<\/p>\n<p>See the MongoDB documentation to learn more about\u00a0<a href=\"https:\/\/docs.mongodb.com\/manual\/core\/authentication\/\" target=\"_blank\" rel=\"noopener\">Authentication<\/a>,\u00a0<a href=\"https:\/\/docs.mongodb.com\/manual\/core\/authorization\/\" target=\"_blank\" rel=\"noopener\">Role-Based Access Control<\/a>, and\u00a0<a href=\"https:\/\/docs.mongodb.com\/manual\/tutorial\/manage-users-and-roles\/\" target=\"_blank\" rel=\"noopener\">Users and Roles<\/a>.<\/p>\n<p>Part Three: Configuring Remote Access (Optional)<\/p>\n<p>Before we start working with an installation that allows remote connections, ideally we&#8217;ll have MongoDB behind an external firewall, protected by a virtual private network (VPN), or restricted through a bastion host. As we work toward that, however, we can take the somewhat less-complicated step of enabling a firewall on the database server and restricting access to the specific host or hosts that need it.<\/p>\n<p>Step 1 \u2014 Enabling UFW<\/p>\n<p>We enabled UFW and allowed only SSH connections. Before we open a port for our client machine, let&#8217;s verify UFW&#8217;s status:<\/p>\n<ul>\n<li>sudo ufw status<\/li>\n<li><\/li>\n<\/ul>\n<p><b>Note:<\/b>\u00a0If the output indicates that the firewall is\u00a0inactive, activate it with:<\/p>\n<ul>\n<li>sudo ufw enable<\/li>\n<li><\/li>\n<\/ul>\n<p>Once it&#8217;s enabled, rerunning the status command,\u00a0sudo ufw status\u00a0will show the rules. If necessary, be sure to allow SSH.<\/p>\n<ul>\n<li>sudo ufw allow OpenSSH<\/li>\n<li><\/li>\n<\/ul>\n<p>Unless we made changes to the prerequisites, the output should show that only OpenSSH is allowed:<\/p>\n<p>Output<\/p>\n<p>Status: active<\/p>\n<p>To \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Action \u00a0\u00a0\u00a0\u00a0\u00a0From<\/p>\n<p>&#8212; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8212;&#8212; \u00a0\u00a0\u00a0\u00a0\u00a0&#8212;-<\/p>\n<p>OpenSSH \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ALLOW \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Anywhere<\/p>\n<p>OpenSSH (v6) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ALLOW \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Anywhere (v6)<\/p>\n<p>Next, we&#8217;ll allow access to the default MongoDB port, 27017, but restrict that access to a specific host. If you&#8217;ve changed the default port, be sure to update it in the command below.<\/p>\n<ul>\n<li>sudo ufw allow from client_ip_address to any port 27017<\/li>\n<li><\/li>\n<\/ul>\n<p>Re-run this command using the IP address for each additional client that needs access. To double-check the rule, we&#8217;ll run\u00a0ufw status\u00a0again:<\/p>\n<ul>\n<li>sudo ufw status<\/li>\n<li><\/li>\n<\/ul>\n<p>Output<\/p>\n<p>To \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Action \u00a0\u00a0\u00a0\u00a0\u00a0From<\/p>\n<p>&#8212; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8212;&#8212; \u00a0\u00a0\u00a0\u00a0\u00a0&#8212;-<\/p>\n<p>OpenSSH \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ALLOW \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Anywhere<\/p>\n<p>27017 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ALLOW \u00a0\u00a0\u00a0\u00a0\u00a0client_ip_address<\/p>\n<p>OpenSSH (v6) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ALLOW \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Anywhere (v6)<\/p>\n<p>With this firewall rule in place, we&#8217;re ready to configure MongoDB to listen on its public interface.<\/p>\n<p>Step 2 \u2014 Configuring a Public bindIP<\/p>\n<p>To allow remote connections, we will add our host&#8217;s publically-routable IP address to the\u00a0mongod.conf\u00a0file.<\/p>\n<ul>\n<li>sudo nano \/etc\/mongod.conf<\/li>\n<li><\/li>\n<\/ul>\n<p>In the\u00a0net\u00a0stanza, add the\u00a0MongoHost&#8217;s IP to the\u00a0bindIp\u00a0line:<\/p>\n<p>Excerpt of \/etc\/mongod.conf<\/p>\n<p>. . .<\/p>\n<p>net:<\/p>\n<p>port: 27017<\/p>\n<p>bindIp: 127.0.0.1,IP_of_MongoHost<\/p>\n<p>. . .<\/p>\n<p>We&#8217;ll save and exit the file, then restart the daemon:<\/p>\n<ul>\n<li>sudo systemctl restart mongod<\/li>\n<li><\/li>\n<\/ul>\n<p>As we did earlier, we&#8217;ll confirm restart was successful:<\/p>\n<ul>\n<li>sudo systemctl status mongodb<\/li>\n<li><\/li>\n<\/ul>\n<p>The output should contain\u00a0Active: active (running), and we can proceed to our final test. Mongo is now listening on its default port.<\/p>\n<p>Step 3 \u2014 Testing the Remote Connection<\/p>\n<p>We&#8217;ll test that Mongo is listening on its public interface by adding the\u00a0&#8211;host\u00a0flag with the IP address from the\u00a0mongodb.conf\u00a0file.<\/p>\n<ul>\n<li>mongo -u AdminSammy -p &#8211;authenticationDatabase admin &#8211;host IP_address_of_MongoHost<\/li>\n<li><\/li>\n<\/ul>\n<p>MongoDB shell version v3.4.2<\/p>\n<p>Enter password:<\/p>\n<p>connecting to: mongodb:\/\/107.170.233.82:27017\/<\/p>\n<p>MongoDB server version: 3.4.2<\/p>\n<p>Reaching the prompt confirms that the daemon is listening on its public IP. At this point, any transaction between a remote connection and the MongoDB host is unencrypted so the next step, before testing the firewall, should be to secure those transations. For help with this, see MongoDB&#8217;s Security documentation on\u00a0<a href=\"https:\/\/docs.mongodb.com\/manual\/core\/security-transport-encryption\/\" target=\"_blank\" rel=\"noopener\">Transport Encryption<\/a>.<\/p>\n<p>Conclusion<\/p>\n<p>In the following tutorial, in order to install the latest avaible version of MongoDB we\u2019ve added the MongoDB to our package list, we have also added an administrative user, and enabled authentication.<\/p>\n<p>It it also shown that how to configure MongoDB to accept remote connections.We should allow connections only from hosts that require access to prevent advertising the MongoDB.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction MongoDB it is a document-oriented database. It is a free and open-source database. It does not rely on a traditional table-based relational database structure that\u2019s why it is classified as a NoSQL database. Instead it uses JSON-like documents with dynamic schemas. Before you add data to database MongoDB does<\/p>\n","protected":false},"author":4,"featured_media":1128,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[3],"tags":[],"class_list":["post-1067","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorial-how-to"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/10\/mongodb-1.jpeg?fit=1040%2C560&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7ISfL-hd","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":1127,"url":"https:\/\/www.virtono.com\/community\/tutorial-how-to\/mongodb\/","url_meta":{"origin":1067,"position":0},"title":"MongoDB","author":"Shreyash Sharma","date":"October 17, 2017","format":false,"excerpt":"Series:\u00a0Introduction to the MEAN Stack Part 1: Definition of the MEAN stack Part 2:\u00a0Setup of the MEAN stack Part 3:\u00a0Node.js Part 4:\u00a0npm Part 5:\u00a0Connect Part 6:\u00a0Express Part 7:\u00a0MongoDB Part 8:\u00a0Mongoose Part 9:\u00a0REST Part 10:\u00a0Baucis Part 11:\u00a0Bower Part 12:\u00a0AngularJS Part 13:\u00a0Restangular So far our server has only returned static data: files\u2026","rel":"","context":"In &quot;Knowledgebase&quot;","block_context":{"text":"Knowledgebase","link":"https:\/\/www.virtono.com\/community\/category\/knowledgebase\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/10\/mongodb-1.jpeg?fit=1040%2C560&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/10\/mongodb-1.jpeg?fit=1040%2C560&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/10\/mongodb-1.jpeg?fit=1040%2C560&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/10\/mongodb-1.jpeg?fit=1040%2C560&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":965,"url":"https:\/\/www.virtono.com\/community\/tutorial-how-to\/how-to-install-mongodb-on-debian-8\/","url_meta":{"origin":1067,"position":1},"title":"How to Install MongoDB on Debian 8","author":"Daniel Draga","date":"June 11, 2017","format":false,"excerpt":"Introduction Part of the MEAN stack MongoDB is the new\u00a0NoSQL document database that is being implemented within modern web applications. So using MongoDB in your own application will give it the edge, you will be able to deal with a large amount of data. On top of all that you\u2026","rel":"","context":"In &quot;Tutorials&quot;","block_context":{"text":"Tutorials","link":"https:\/\/www.virtono.com\/community\/category\/tutorial-how-to\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/06\/mongodb-for-giant-ideas-bbab5c3cf8.png?fit=1024%2C512&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/06\/mongodb-for-giant-ideas-bbab5c3cf8.png?fit=1024%2C512&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/06\/mongodb-for-giant-ideas-bbab5c3cf8.png?fit=1024%2C512&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/06\/mongodb-for-giant-ideas-bbab5c3cf8.png?fit=1024%2C512&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":1068,"url":"https:\/\/www.virtono.com\/community\/knowledgebase\/mongodb-and-nosql-databases\/","url_meta":{"origin":1067,"position":2},"title":"MongoDB And NoSQL Databases","author":"Shreyash Sharma","date":"October 9, 2017","format":false,"excerpt":"Introduction MongoDB it is a document-oriented database. It is a free and open-source database. It does not rely on a traditional table-based relational database structure that\u2019s why it is classified as a NoSQL database. Instead it uses JSON-like documents with dynamic schemas. Before you add data to database MongoDB does\u2026","rel":"","context":"In &quot;Knowledgebase&quot;","block_context":{"text":"Knowledgebase","link":"https:\/\/www.virtono.com\/community\/category\/knowledgebase\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/10\/mongodb.jpeg?fit=1040%2C560&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/10\/mongodb.jpeg?fit=1040%2C560&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/10\/mongodb.jpeg?fit=1040%2C560&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/10\/mongodb.jpeg?fit=1040%2C560&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":3230,"url":"https:\/\/www.virtono.com\/community\/tutorial-how-to\/how-to-install-mongodb-on-ubuntu\/","url_meta":{"origin":1067,"position":3},"title":"How to install MongoDB on Ubuntu","author":"George B.","date":"April 13, 2023","format":false,"excerpt":"Welcome to this comprehensive guide on how to install MongoDB on Ubuntu! In the following steps, you will learn everything you need to know to set up MongoDB on your Ubuntu system. Whether you're a beginner or an experienced user, this guide will walk you through the installation process, providing\u2026","rel":"","context":"In &quot;Tutorials&quot;","block_context":{"text":"Tutorials","link":"https:\/\/www.virtono.com\/community\/category\/tutorial-how-to\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/04\/How-to-install-MongoDB-Ubuntu-22.png?fit=600%2C330&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/04\/How-to-install-MongoDB-Ubuntu-22.png?fit=600%2C330&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/04\/How-to-install-MongoDB-Ubuntu-22.png?fit=600%2C330&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":3687,"url":"https:\/\/www.virtono.com\/community\/tutorial-how-to\/how-to-deploy-mongodb-on-kubernetes\/","url_meta":{"origin":1067,"position":4},"title":"How to Deploy MongoDB on Kubernetes","author":"George B.","date":"July 29, 2023","format":false,"excerpt":"This tutorial will walk you through installing MongoDB on Kubernetes cluster. We'll assume that you've already got K3s and Helm set up on your machine. The deployment of applications like MongoDB on Kubernetes cluster is made easier by the Kubernetes package manager Helm. Before getting too technical, it's important to\u2026","rel":"","context":"In &quot;Tutorials&quot;","block_context":{"text":"Tutorials","link":"https:\/\/www.virtono.com\/community\/category\/tutorial-how-to\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/07\/How-to-Deploy-MongoDB-on-Kubernetes.png?fit=360%2C240&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1105,"url":"https:\/\/www.virtono.com\/community\/tutorial-how-to\/mongoose\/","url_meta":{"origin":1067,"position":5},"title":"Mongoose","author":"Shreyash Sharma","date":"October 12, 2017","format":false,"excerpt":"Series:\u00a0Introduction to the MEAN Stack Part 1: Definition of the MEAN stack Part 2:\u00a0Setup of the MEAN stack Part 3:\u00a0Node.js Part 4:\u00a0npm Part 5:\u00a0Connect Part 6:\u00a0Express Part 7:\u00a0MongoDB Part 8:\u00a0Mongoose Part 9:\u00a0REST Part 10:\u00a0Baucis Part 11:\u00a0Bower Part 12:\u00a0AngularJS Part 13:\u00a0Restangular Mongoose\u00a0is a framework which is based on the\u00a0native MongoDB driver\u00a0and\u2026","rel":"","context":"In &quot;Knowledgebase&quot;","block_context":{"text":"Knowledgebase","link":"https:\/\/www.virtono.com\/community\/category\/knowledgebase\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2017\/10\/mongoose.png?fit=370%2C200&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/posts\/1067","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/comments?post=1067"}],"version-history":[{"count":2,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/posts\/1067\/revisions"}],"predecessor-version":[{"id":3589,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/posts\/1067\/revisions\/3589"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/media\/1128"}],"wp:attachment":[{"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/media?parent=1067"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/categories?post=1067"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/tags?post=1067"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}