How To Install Mongo

 admin

How to Install and Configure MongoDB on Ubuntu 16.04

MongoDB is a NoSQL database that offers a high performance, high availability, and automatic scaling enterprise database. MongoDB is a NoSQL database, so you can’t use SQL (Structured Query Language) to insert and retrieve data, and it does not store data in tables like MySQL or Postgres. Data is stored in a “document” structure in JSON format (in MongoDB called BSON). MongoDB was first introduced in 2009 and is currently developed by the company MongoDB Inc.

MongoDB only provides packages for 64-bit LTS (long-term support) Ubuntu releases. For example, 12.04 LTS (precise), 14.04 LTS (trusty), 16.04 LTS (xenial), and so on.” mongodb site.

Prerequisites

The installers for MongoDB are available in both the 32-bit and 64-bit format. The 32-bit installers are good for development and test environments. But for production environments you should use the 64-bit installers. Otherwise, you can be limited to the amount of data that can be stored within. I am trying to test out mongoDB and see if it is anything for me. I downloaded the 32bit windows version, but have no idea on how to continue from now on.

  • Ubuntu Server 16.04 – 64 bit
  • Root privileges

What we will do in this tutorial:

  1. Install MongoDB
  2. Configure MongoDB
  3. Conclusion

Install MongoDB on Ubuntu 16.04

Step 1 – Importing the Public Key

GPG keys of the software distributor are required by the Ubuntu package manager apt (Advanced Package Tool) to ensure package consistency and authenticity. Run this command to import MongoDB keys to your server.

sudo apt-key adv –keyserver hkp://keyserver.ubuntu.com:80 –recv EA312927

Step 2 – Create source list file MongoDB

Create a MongoDB list file in /etc/apt/sources.list.d/ with this command:

echo “deb http://repo.mongodb.org/apt/ubuntu “$(lsb_release -sc)”/mongodb-org/3.2 multiverse” sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list

Step 3 – Update the repository

update the repository with the apt command:

sudo apt-get update

Step 4 – Install MongoDB

Now you can install MongoDB by typing this command:

sudo apt-get install -y mongodb-org

We have to create a new mongodb systemd service file in the ‘/lib/systemd/system’ directory. Go to that directory and create the new mongodb service file ‘mongod.service’ with vim.

cd /lib/systemd/system/
vim mongod.service

Paste script below:

Save the file and exit.

Now update the systemd service with command below:

systemctl daemon-reload

Start mongodb and add it as service to be started at boot time:

systemctl start mongod
systemctl enable mongod

Now check that mongodb has been started on port 27017 with the netstat command.

netstat -plntu

Configure MongoDB username and password

When the MongoDB packages are installed you can configure username and password for the database server:

Step 1 – Open mongo shell

Before you set up a username and password for MongoDB, you need to open the mongodb shell on your server. You can login by typing:

mongo

If you get error Failed global initialization: BadValue Invalid or no user locale set. Please ensure LANG and/or LC_* environment variables are set correctly, try the command:

export LC_ALL=C
mongo

Step 2 – Switch to the database admin

Once you`re in the MongoDB shell, switch to the database named admin:

use admin

It seemed to work well, from what I've read here. Any updates on how that thickness held up Mainer? Grumman canoe serial number lookup. I found where Mainer used 3/8th thick 2.5 inch wide UHMW with elevator bolts.

Step 3 – Create the root user

Create the root user with this command :

db.createUser({user:”admin”, pwd:”admin123″, roles:[{role:”root”, db:”admin”}]})

Desc: Create user admin with password admin123 and have the permission/role as root and the database is admin.

Now type exit to exit from MongoDB shell.

Step 4 – Enable mongodb authentication

Edit the mongodb service file ‘/lib/systemd/system/mongod.service’ with your editor.

vim /lib/systemd/system/mongod.service

On the ‘ExecStart‘ line 9, add the new option ‘–auth‘.

ExecStart=/usr/bin/mongod –quiet –auth –config /etc/mongod.conf

Save and exit.

Reload the systemd service:

systemd daemon-reload

Step 5 – Restart MongoDB and try to connect

Now restart MongoDB and connect with the user created.

sudo service mongod restart

and connect to the mongodb shell with this command:

mongo -u admin -p admin123 –authenticationDatabase admin

and you will see the output like this:

Conclusion

A well-known NoSQL database that offers high performance, high availability, and automatic scaling is MongoDB. It is different from the RDBMS such as MySQL, PostgreSQL, and SQLite as it does not use SQL to set and retrieve data. MongoDB stores data in `documents` called BSON (binary representation of JSON with additional types of information). MongoDB is only available for 64-bit Long Term Support Ubuntu Release.

-->

MongoDB is a popular open-source, high-performance NoSQL database. This article guides you through installing and configuring MongoDB on a Windows Server 2016 virtual machine (VM) in Azure. You can also install MongoDB on a Linux VM in Azure.

Prerequisites

Before you install and configure MongoDB, you need to create a VM and, ideally, add a data disk to it. See the following articles to create a VM and add a data disk:

  • Create a Windows Server VM using the Azure portal or Azure PowerShell.
  • Attach a data disk to a Windows Server VM using the Azure portal or Azure PowerShell.

To begin installing and configuring MongoDB, log on to your Windows Server VM by using Remote Desktop.

Install MongoDB

Important

MongoDB security features, such as authentication and IP address binding, are not enabled by default. Security features should be enabled before deploying MongoDB to a production environment. For more information, see MongoDB Security and Authentication.

  1. After you've connected to your VM using Remote Desktop, open Internet Explorer from the taskbar.

  2. Select Use recommended security, privacy, and compatibility settings when Internet Explorer first opens, and click OK.

  3. Internet Explorer enhanced security configuration is enabled by default. Add the MongoDB website to the list of allowed sites:

    • Select the Tools icon in the upper-right corner.

    • In Internet Options, select the Security tab, and then select the Trusted Sites icon. Athelas font family free download.

    • Click the Sites button. Add https://*.mongodb.com to the list of trusted sites, and then close the dialog box.

  4. Browse to the MongoDB - Downloads page (https://www.mongodb.com/downloads).

  5. If needed, select the Community Server edition and then select the latest current stable release forWindows Server 2008 R2 64-bit and later. To download the installer, click DOWNLOAD (msi).

    Run the installer after the download is complete.

  6. Read and accept the license agreement. When you're prompted, select Complete install.

  7. If desired, you can choose to also install Compass, a graphical interface for MongoDB.

  8. On the final screen, click Install.

Configure the VM and MongoDB

How To Install Mongo Db On Ubuntu 16.04

  1. The path variables are not updated by the MongoDB installer. Without the MongoDB bin location in your path variable, you need to specify the full path each time you use a MongoDB executable. To add the location to your path variable:

    • Right-click the Start menu, and select System.

    • Click Advanced system settings, and then click Environment Variables.

    • Under System variables, select Path, and then click Edit.

      Add the path to your MongoDB bin folder. MongoDB is typically installed in C:Program FilesMongoDB. Verify the installation path on your VM. The following example adds the default MongoDB install location to the PATH variable:

      Note

      Be sure to add the leading semicolon (;) to indicate that you are adding a location to your PATH variable.

  2. Create MongoDB data and log directories on your data disk. From the Start menu, select Command Prompt. The following examples create the directories on drive F:

  3. Start a MongoDB instance with the following command, adjusting the path to your data and log directories accordingly:

    It may take several minutes for MongoDB to allocate the journal files and start listening for connections. All log messages are directed to the F:MongoLogsmongolog.log file as mongod.exe server starts and allocates journal files.

    Note

    The command prompt stays focused on this task while your MongoDB instance is running. Leave the command prompt window open to continue running MongoDB. Or, install MongoDB as service, as detailed in the next step.

  4. For a more robust MongoDB experience, install the mongod.exe as a service. Creating a service means you don't need to leave a command prompt running each time you want to use MongoDB. Create the service as follows, adjusting the path to your data and log directories accordingly:

    The preceding command creates a service named MongoDB, with a description of 'Mongo DB'. The following parameters are also specified:

    • The --dbpath option specifies the location of the data directory.
    • The --logpath option must be used to specify a log file, because the running service does not have a command window to display output.
    • The --logappend option specifies that a restart of the service causes output to append to the existing log file.

    To start the MongoDB service, run the following command:

    For more information about creating the MongoDB service, see Configure a Windows Service for MongoDB.

Install Mongodb Server

Test the MongoDB instance

With MongoDB running as a single instance or installed as a service, you can now start creating and using your databases. To start the MongoDB administrative shell, open another command prompt window from the Start menu, and enter the following command:

You can list the databases with the db command. Insert some data as follows:

Search for data as follows:

The output is similar to the following example:

Exit the mongo console as follows:

Configure firewall and Network Security Group rules

Now that MongoDB is installed and running, open a port in Windows Firewall so you can remotely connect to MongoDB. To create a new inbound rule to allow TCP port 27017, open an administrative PowerShell prompt and enter the following command:

You can also create the rule by using the Windows Firewall with Advanced Security graphical management tool. Create a new inbound rule to allow TCP port 27017.

If needed, create a Network Security Group rule to allow access to MongoDB from outside of the existing Azure virtual network subnet. You can create the Network Security Group rules by using the Azure portal or Azure PowerShell. As with the Windows Firewall rules, allow TCP port 27017 to the virtual network interface of your MongoDB VM.

Note

How To Install Mongodb On Windows

TCP port 27017 is the default port used by MongoDB. You can change this port by using the --port parameter when starting mongod.exe manually or from a service. If you change the port, make sure to update the Windows Firewall and Network Security Group rules in the preceding steps.

How To Install Mongoose

Next steps

How To Install Mongodb On Linux

In this tutorial, you learned how to install and configure MongoDB on your Windows VM. You can now access MongoDB on your Windows VM, by following the advanced topics in the MongoDB documentation.