centos 6.8 部署mongodb3.6.2主從

來源:互聯網
上載者:User

標籤:cal   std   cot   app   說明   /etc   從庫   配置   iter   

centos 6.8 部署mongodb3.6.2主從

環境:

主:172.17.165.245

從:172.17.165.230

mongodb版本:mongodb3.6.2

下載程式

[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

修改設定檔參數

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                                    #開啟認證

設定環境變數

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

啟動程式

[[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說明程式已經正常啟動

常用語句:

use admin建立關於使用者db.createUser({user:"admin", pwd:"admin",roles:[{role:"root", db:"admin"}]})> rs.slaveOk()

主庫插入語句

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 }

從庫進行查看

[[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 }

從庫上面已經查看了主庫上面的資料 說明主從已經搭建完畢

centos 6.8 部署mongodb3.6.2主從

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.