官术网_书友最值得收藏!

Installing MongoDB

Until now, we have worked with the relational database server, MySQL. In this recipe, we will learn how to install and configure MongoDB, which is a not only SQL (NoSQL) document storage server.

Getting ready

You will need access to a root account or an account with sudo privileges.

How to do it…

To get the latest version of MongoDB, we need to add the MongoDB source to Ubuntu installation sources:

  1. First, import the MongoDB GPG public key:
    $ sudo apt-key adv \
    --keyserver hkp://keyserver.ubuntu.com:80 \
    --recv 7F0CEB10
    
  2. Create a list file and add an install source to it:
    $ echo “deb http://repo.mongodb.org/apt/ubuntu “$(lsb_release -sc)”/mongodb-org/3.0 multiverse” | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
    
  3. Update the apt repository sources and install the MongoDB server:
    $ sudo apt-get update
    $ sudo apt-get install -y mongodb-org
    
  4. After installation completes, check the status of the MongoDB server:
    $ sudo service mongod status
    
  5. Now you can start using the MongoDB server. To access the Mongo shell, use the following command:
    $ mongo
    

How it works…

We have installed the MongoDB server from the MongoDB official repository. The Ubuntu package repository includes the MongoDB package in it, but it is not up to date with the latest release of MongoDB. With GPG keys, Ubuntu ensures the authenticity of the packages being installed. After importing the GPG key, we have created a list file that contains the installation source of the MongoDB server.

After installation, the MongoDB service should start automatically. You can check logs at /var/log/mongodb/mongod.log.

See also

主站蜘蛛池模板: 孟津县| 遂宁市| 广平县| 三江| 蒙城县| 绥芬河市| 亳州市| 鹤壁市| 射阳县| 丽水市| 肥乡县| 陈巴尔虎旗| 改则县| 广宁县| 鄯善县| 巍山| 山阳县| 滦南县| 贵德县| 贞丰县| 微山县| 萨嘎县| 隆化县| 电白县| 玉山县| 凤城市| 沈丘县| 东兴市| 若羌县| 高邮市| 金塔县| 当阳市| 改则县| 新晃| 丹凤县| 前郭尔| 盖州市| 南宁市| 壶关县| 龙井市| 六枝特区|