環(huán)境介紹:
成都創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),夾江企業(yè)網(wǎng)站建設(shè),夾江品牌網(wǎng)站建設(shè),網(wǎng)站定制,夾江網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營(yíng)銷,網(wǎng)絡(luò)優(yōu)化,夾江網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
192.168.1.250 主 port=27408
192.168.1.250 仲裁 port=27409
192.168.1.251 備 port=27408
[root@HE4 ~]# tar xvf MongoDB-linux-x86_64-2.6.10.tgz
[root@HE4 ~]# mkdir -p /export/mongodb
[root@HE4 ~]# mkdir -p /export/mongodb/bin
[root@HE4 ~]# mkdir -p /export/mongodb/conf
[root@HE4 ~]# mkdir -p /export/mongodb/log
[root@HE4 ~]# mkdir -p /export/mongodb/data
[root@HE4 bin]# cd /root/mongodb-linux-x86_64-2.6.10/bin
[root@HE4 bin]# cp /root/mongodb-linux-x86_64-2.6.10/bin/* /export/mongodb/bin/
[root@HE1 bin]# vi /export/mongodb/conf/mongod.conf
port=27408 dbpath=/export/mongodb/data logpath=/export/mongodb/log/mongod.log fork=true logappend=true keyFile=/export/mongodb/key/mongod nohttpinterface=true replSet=shard1 [root@HE1 bin]# vi /export/mongodb/conf/arbiter.conf port=27409 dbpath=/export/mongodb/arbiter logpath=/export/mongodb/log/arbiter.log fork=true logappend=true keyFile=/export/mongodb/key/arbiter nohttpinterface=true replSet=shard1
keyfile文件包括:
mongod,arbiter
創(chuàng)建一個(gè)生成keyfile的腳本
vi create_key.sh
cat /dev/urandom | LC_ALL=C tr -dc "[:alnum:]" | fold -w 10 |head -1 >/tmp/key.txt keystring=`cat /tmp/key.txt` echo $keystring >/export/mongodb/key/mongod echo $keystring >/export/mongodb/key/arbiter chmod 600 /export/mongodb/key/*
啟動(dòng)服務(wù)器在主
[root@HE3 ~]#/export/mongodb/bin/mongod -f /export/mongodb/conf/mongod.conf
[root@HE3 ~]# /export/mongodb/bin/mongod -f /export/mongodb/conf/arbiter.conf
在從
[root@HE4 ~]#/export/mongodb/bin/mongod -f /export/mongodb/conf/mongod.conf
>config={_id:'shard1',members:[{_id:0,host:'192.168.1.248:27408'},{_id:1,host:'192.168.1.249:27408'},{_id:2,host:'192.168.1.248:27409',arbiterOnly:true}]}
>rs.initiate(config)
初始化rs.initiate(config),config是之前定義的名
主備庫(kù)配置好后,備庫(kù)查詢
shard1:SECONDARY> use test switched to db test shard1:SECONDARY> db.t1.find() error: { "$err" : "not master and slaveOk=false", "code" : 13435 } shard1:SECONDARY> rs.slaveOk() shard1:SECONDARY> db.t1.find() { "_id" : ObjectId("5704c11d3e0651733bfdea23"), "x" : 1 }
rs.stauts()可以看狀態(tài),health:1代表健康,stateStr誰(shuí)是我們的仲裁
想讓主庫(kù)降級(jí)成從庫(kù),rs.stepDown()