### mongodb的主從配置(不帶auth認(rèn)證)
創(chuàng)新互聯(lián)建站是一家專注于成都做網(wǎng)站、網(wǎng)站制作、
成都外貿(mào)網(wǎng)站建設(shè)與策劃設(shè)計(jì),西充網(wǎng)站建設(shè)哪家好?
創(chuàng)新互聯(lián)建站做網(wǎng)站,專注于網(wǎng)站建設(shè)10余年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:西充等地區(qū)。西充做網(wǎng)站價(jià)格咨詢:13518219792
### 注意事項(xiàng):
- 服務(wù)器節(jié)點(diǎn)之前時(shí)間要同步
- 開啟防火墻的一定要允許通過相關(guān)端口
- 開啟selinux的也要進(jìn)行設(shè)置
- 建立雙擊互信模式最好不過
### master配置文件
[root@blog ~]# sed -e '/^#/d;/^$/d' /etc/mongodb.conf
bind_ip = 192.168.58.10
port = 27017
fork = true
pidfilepath = /var/run/mongodb/mongodb.pid
logpath = /var/log/mongodb/mongodb.log
dbpath =/mongo/data
journal = true
master = true
nohttpinterface = true
[root@blog ~]#
### slave配置文件
- slave = true
- source = 192.168.58.10:27017
[root@redis ~]# sed -e '/^#/d;/^$/d' /etc/mongodb.conf
bind_ip = 192.168.58.30
port = 27017
fork = true
pidfilepath = /var/run/mongodb/mongodb.pid
logpath = /var/log/mongodb/mongodb.log
dbpath =/var/lib/mongodb
journal = true
nohttpinterface = true
slave = true
source = 192.168.58.10:27017
[root@redis ~]#
### 重啟兩節(jié)點(diǎn)的mongodb服務(wù)進(jìn)行初始化操作并驗(yàn)證數(shù)據(jù)同步情況
[root@blog ~]#
[root@blog ~]# hostname
blog.unix178.com
[root@blog ~]# mongo
MongoDB shell version: 2.4.6
connecting to: test
> show dbs
admin0.203125GB
local10.0732421875GB
test0.203125GB
zhuima0.203125GB
>
[root@redis ~]# hostname
redis.unix178.com
[root@redis ~]# mongo
MongoDB shell version: 2.4.6
connecting to: test
> show dbs
admin0.203125GB
local0.078125GB
zhuima0.203125GB
>
### 查看同步情況
[root@blog ~]# mongo 192.168.58.30
MongoDB shell version: 2.4.6
connecting to: 192.168.58.30/test
> show dbs
admin0.203125GB
local0.078125GB
nick0.203125GB
test0.203125GB
zhuima0.203125GB
>
[root@redis ~]# mongo 192.168.58.10
MongoDB shell version: 2.4.6
connecting to: 192.168.58.10/test
> show dbs;
admin0.203125GB
local10.0732421875GB
nick0.203125GB
test0.203125GB
zhuima0.203125GB
>
### 添加新的數(shù)據(jù)進(jìn)行驗(yàn)證
[root@redis ~]# mongo 192.168.58.10
MongoDB shell version: 2.4.6
connecting to: 192.168.58.10/test
> show dbs;
admin0.203125GB
local10.0732421875GB
nick0.203125GB
test0.203125GB
zhuima0.203125GB
> use nick
switched to db nick
> use newdb
switched to db newdb
> db.newdb.insert({new:"yes",info:"nothing"})
> show collections
newdb
system.indexes
> db.newdb.find()
{ "_id" : ObjectId("53cbd4b35974b01658718b2d"), "new" : "yes", "info" : "nothing" }
>
[root@blog ~]# mongo 192.168.58.30
MongoDB shell version: 2.4.6
connecting to: 192.168.58.30/test
> show dbs
admin0.203125GB
local0.078125GB
nick0.203125GB
test0.203125GB
zhuima0.203125GB
> show dbs
admin0.203125GB
local0.078125GB
newdb0.203125GB
nick0.203125GB
test0.203125GB
zhuima0.203125GB
> use newdb
switched to db newdb
> show collections
newdb
system.indexes
> db.newdb.find()
{ "_id" : ObjectId("53cbd4b35974b01658718b2d"), "new" : "yes", "info" : "nothing" }
>
### 后記
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
網(wǎng)頁標(biāo)題:mongodb之master/slave模式-創(chuàng)新互聯(lián)
轉(zhuǎn)載來源:
http://weahome.cn/article/jgjos.html