Installing MongoDB on Linux

Source: Internet
Author: User

Installed version: 3.0.7

Installation machine: All machines

Installation process:

1. Use the Hadoop account to extract the/opt/hadoop/directory:

$ TAR-ZXVF mongodb-${version}.tar.gz-c/opt/hadoop/

2. Set up a soft link:

$ ln-s/opt/hadoop/mongodb-${version}/opt/hadoop/mongodb

3. Configure the environment variables and make them effective:

# Vim/etc/profile

Export Mongodb_home=/opt/hadoop/mongodb

Export Path=${mongodb_home}/bin: $PATH

# Source/etc/profile

4. Create the data-related directory under the/opt/hadoop/mongodb/directory (you must ensure that the directory is empty):

$ mkdir-p/opt/hadoop/mongodb/data/configsvr

$ mkdir-p/opt/hadoop/mongodb/data/rs0-0

$ mkdir-p/opt/hadoop/mongodb/data/rs1-0

5. Modify the configsvr.conf file in the Conf directory:

$ vim/opt/hadoop/mongodb/conf/configsvr.conf

Modify the following content

Path: "/opt/hadoop/mongodb/logs/configsvr.log"

Pidfilepath: "/opt/hadoop/mongodb/configsvr.pid"

DbPath: "/opt/hadoop/mongodb/data/configsvr"

6. Continue to modify the mongos.conf file:

$ vim/opt/hadoop/mongodb/conf/mongos.conf

Modify the following content

Path: "/opt/hadoop/mongodb/logs/mongos.log"

Pidfilepath: "/opt/hadoop/mongodb/mongos.pid"

7. Continue to modify the rs0.conf file:

$ vim/opt/hadoop/mongodb/conf/rs0.conf

Modify the following content

Path: "/opt/hadoop/mongodb/logs/rs0-0.log"

Pidfilepath: "/opt/hadoop/mongodb/rs0-0.pid"

DbPath: "/opt/hadoop/mongodb/data/rs0-0"

8. Continue to modify the rs1.conf file:

$ vim/opt/hadoop/mongodb/conf/rs1.conf

Modify the following content

Path: "/opt/hadoop/mongodb/logs/rs1-0.log"

Pidfilepath: "/opt/hadoop/mongodb/rs1-0.pid"

DbPath: "/opt/hadoop/mongodb/data/rs1-0"

9. Copy the MongoDB to the BASELINE02 machine on the BASELINE01 and modify the environment variables as per step 3:

$ scp-r/opt/hadoop/mongodb-${version} [email protected]2:/opt/hadoop

$ ln-s/opt/hadoop/mongodb-${version}/opt/hadoop/mongodb

10. Modify the folder name in the data directory:

$ mv/opt/hadoop/mongodb/data/rs0-0/opt/hadoop/mongodb/data/rs0-1

$ mv/opt/hadoop/mongodb/data/rs1-0/opt/hadoop/mongodb/data/rs1-1

11. Modify the Rs0.conf file on BASELINE02:

$ vim/opt/hadoop/mongodb/conf/rs0.conf

Modify the following content

Path: "/opt/hadoop/mongodb/logs/rs0-1.log"

Pidfilepath: "/opt/hadoop/mongodb/rs0-1.pid"

DbPath: "/opt/hadoop/mongodb/data/rs0-1"

12. Modify the rs1.conf file on BASELINE02:

$ vim/opt/hadoop/mongodb/conf/rs1.conf

Modify the following content

Path: "/opt/hadoop/mongodb/logs/rs1-1.log"

Pidfilepath: "/opt/hadoop/mongodb/rs1-1.pid"

DbPath: "/opt/hadoop/mongodb/data/rs1-1"

13. Copy the MongoDB to the BASELINE03 machine on the BASELINE01:

$ scp-r/opt/hadoop/mongodb-${version} hadoop@baseline03:/opt/hadoop

$ ln-s/opt/hadoop/mongodb-${version}/opt/hadoop/mongodb

14. Modify the folder name in the data directory:

$ mv/opt/hadoop/mongodb/data/rs0-0/opt/hadoop/mongodb/data/rs0-2

$ mv/opt/hadoop/mongodb/data/rs1-0/opt/hadoop/mongodb/data/rs1-2

15. Modify the rs0.conf file on baseline03:

$ vim/opt/hadoop/mongodb/conf/rs0.conf

Modify the following content

Path: "/opt/hadoop/mongodb/logs/rs0-2.log"

Pidfilepath: "/opt/hadoop/mongodb/rs0-2.pid"

DbPath: "/opt/hadoop/mongodb/data/rs0-2"

16. Modify the rs1.conf file on baseline03:

$ vim/opt/hadoop/mongodb/conf/rs1.conf

Modify the following content

Path: "/opt/hadoop/mongodb/logs/rs1-2.log"

Pidfilepath: "/opt/hadoop/mongodb/rs1-2.pid"

DbPath: "/opt/hadoop/mongodb/data/rs1-2"

17.RS0 configuration:

Three machines sequentially start the Mongod service:

$ Mongod--config/opt/hadoop/mongodb/conf/rs0.conf

18. Perform a connection to the Mongod instance on BASELINE01:

$ MONGO baseline01:27017

After the connection is successful, execute:

>rs0conf = {

_id: "Rs0",

Members: [

{

_id:0,

Host: "baseline01:27017"

}

]

}

>rs.initiate (rs0conf)

>rs.add ("baseline02:27017")

>rs.add ("baseline03:27017")

>rs.status ()//half minute after the execution of the command, if a master two from the Rs0 configuration is successful


RS1 configuration:

Three machines sequentially start the Mongod service:

$ Mongod--config/opt/hadoop/mongodb/conf/rs1.conf

To perform a connection to the Mongod instance on BASELINE01:

$ MONGO baseline01:27018

>rs1conf = {

_id: "Rs1",

Members: [

{

_id:0,

Host: "baseline01:27018"

}

]

}

>rs.initiate (rs1conf)

>rs.add ("baseline02:27018")

>rs.add ("baseline03:27018")

>rs.status ()//half minute after the execution of the command, if a master two from the Rs1 configuration is successful

19. Three machines start the configuration server separately:

$ Mongod--config/opt/hadoop/mongodb/conf/configsvr.conf

20. Three machines start the MONGOs route separately:

$ MONGOs--config/opt/hadoop/mongodb/conf/mongos.conf

21. Connect to the MONGOs on the BASELINE01:

$ MONGO baseline01:27000

22. Switch to the Admin database and add shards:

mongos> Use admin

Mongos>db.runcommand ({addshard: "rs0/baseline01:27017,baseline02:27017,baseline03:27017"})

Mongos>db.runcommand ({addshard: "rs1/baseline01:27018,baseline02:27018,baseline03:27018"})

23. View the Shard Status:

Mongos>db.runcommand ({listshards:1})

24. Start the Shard for the TestDB database:

Mongos>db.runcommand ({enablesharding: "TestDB"})

Mongos>db.runcommand ({shardcollection: "Testdb.test_table", Key:{id:1}})

25. Connect to the MONGOs on the BASELINE01:

$ MONGO baseline01:27000

26 Test Insert Data:

Mongos>use TestDB

Mongos>for (var i = 1; I <= 50000; i++) Db.test_table.insert ({"id": I, "name": "str" +i, "date": New Date ()})

Writeresult ({"ninserted": 1})

Mongos>db.test_table.stats ()

View shard Status, if there is data on Rs0 and RS1, indicating successful deployment

Installing MongoDB on Linux

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.