CentOS 6.8 Deployment of mongodb3.6.2 master-Slave

Source: Internet
Author: User
Tags auth mongodb version

CentOS 6.8 Deployment of mongodb3.6.2 master-Slave

Environment:

Master: 172.17.165.245

From: 172.17.165.230

MongoDB version: mongodb3.6.2

Download the program

[email protected] opt]# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.6.2.tgz[[email protected] opt]# tar -zxvf mongodb-linux-x86_64-rhel62-3.6.2.tgz  -C /usr/local/[[email protected] local]# mv mongodb-linux-x86_64-rhel62-3.6.2/  mongodb[[email protected] mongodb]# mkdir -p /data/mongodb[[email protected] mongodb]# mkdir logs[[email protected] mongodb]# cd logs/[[email protected] logs]# touch mongodb.log [[email protected] logs]# mkdir -p /var/run/mongodb

modifying configuration file Parameters

master[[email protected] opt]# cat /usr/local/mongodb/mongdb.confport = 27017logpath = /usr/local/mongodb/logs/mongodb.logpidfilepath=/var/run/mongodb/mongodb.piddbpath=/data/mongodbmaster = true           #确定我是主服务器source = 172.17.165.230fork = truelogappend = true#auth = trueslave[[email protected] ~]# cat /usr/local/mongodb/mongodb.conf port = 27017    #端口号logpath = /usr/local/mongodb/logs/mongodb.log   #日志位置pidfilepath=/var/run/mongodb/mongodb.pid        #PID 位置dbpath=/data/mongodb                            #数据存放位置slave = true                                    #模式 确定我是从服务器source = 172.17.165.245                         #规定从属于哪个ip  注意:ip是主服务器的fork = true                                     #设置后台运行logappend = true                                #日志输出格式#auth = true                                    #开启认证

Setting environment variables

[[email protected] ~]# vim /etc/profileexport PATH=/usr/local/mongodb/bin:$PATH

Start the program

[[email protected] ~]# mongod --config /usr/local/mongodb/mongodb.conf about to fork child process, waiting until server is ready for connections.forked process: 32287child process started successfully, parent exiting说明程序已经正常启动

Common statements:

use admin创建关于用户db.createUser({user:"admin", pwd:"admin",roles:[{role:"root", db:"admin"}]})> rs.slaveOk()

Main Library INSERT statement

mongo 172.17.165.245:27017创建新库 插入数据> use new10         switched to db new10> db.new10.save({"name":22200})WriteResult({ "nInserted" : 1 })> db.new10.find(){ "_id" : ObjectId("5a7d7544ab1efad7a5581285"), "name" : 22200 }

Viewing from a library

[[email protected] mongodb]# mongo> use adminswitched to db admin> db.auth("admin","admin")1> > rs.slaveOk()> show dbsadmin         0.000GBconfig        0.000GBlocal         0.000GBmaster_slave  0.000GBnew1          0.000GBnew10         0.000GBteot          0.000GBtest          0.000GB> switched to db new10> db.new10.find(){ "_id" : ObjectId("5a7d7544ab1efad7a5581285"), "name" : 22200 }

The data above the main library has been viewed from the top of the library and the master has been built.

CentOS 6.8 Deployment of mongodb3.6.2 master-Slave

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.