Mongodb3.3.6 CentOS7分區實驗環境搭建
一、拓撲圖
二、部署 1.Mongodb安裝
3台伺服器都安裝mongodb,安裝包拷到/usr/local/下,為了清晰展示,每個節點建立一個mongodb,共建立了4個,其中,master、slave、arbiter搭建副本級。
2、建立單個分區副本級
1)在每個目錄建立日誌目錄logs、資料目錄data/db、配置目錄conf
2)在每個conf目錄編寫設定檔mongd.conf
192.168.1.82
Master:
port=10002
dbpath=/usr/local/mongodb-3.3.6_master/data/db
logpath=/usr/local/mongodb-3.3.6_master/logs/mongod.log
fork=true
logappend=true
nohttpinterface=true
replSet=test1 #複本集名稱
pidfilepath=/var/run/mongo_master.pid
bind_ip=192.168.1.82
Slave:
port=10001
dbpath=/usr/local/mongodb-3.3.6_slave/data/db
logpath=/usr/local/mongodb-3.3.6_slave/logs/mongod.log
fork=true
logappend=true
nohttpinterface=true
replSet=test1
pidfilepath=/var/run/mongo_slave.pid
bind_ip=192.168.1.82
Arbiter:
port=10000
dbpath=/usr/local/mongodb-3.3.6_arbiter/data/db
logpath=/usr/local/mongodb-3.3.6_arbiter/logs/mongod.log
fork=true
logappend=true
replSet=test1
nohttpinterface=true
pidfilepath=/var/run/mongo_arbiter.pid
bind_ip=192.168.1.82
3)分別啟動mongodb
/usr/local/mongodb-3.3.6_master/bin/mongod-f ../conf/mongod.conf
/usr/local/mongodb-3.3.6_slave/bin/mongod-f ../conf/mongod.conf
/usr/local/mongodb-3.3.6_arbiter/bin/mongod-f ../conf/mongod.conf
4)配置副本級
進入master的mongo shell
#cd /usrl/local/mongodb-3.3.6_master/bin
#./mongo192.168.1.82:10002
切換到admin庫
>useadmin
>config={‘_id’:’test1’,‘members’:[ {‘_id’:0,’host’:'192.168.1.82:10002',’priority’:2},{‘_id’:1,’host’:'192.168.1.82:10001',’priority’:1},{‘_id’:2,’host’:'192.168.1.82:10000',’arbiterOnly’:true}]};
初始化副本
>rs.initiate(config)
查看叢集狀態
>rs.status()
test1:PRIMARY>rs.status()
{
"set" : "test1",
"date" :ISODate("2017-01-04T06:36:07.732Z"),
"myState" : 1,
"term" : NumberLong(9),
"heartbeatIntervalMillis" :NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" :Timestamp(1483511762, 1),
"t" : NumberLong(9)
},
"appliedOpTime" : {
"ts" :Timestamp(1483511762, 1),
"t" : NumberLong(9)
},
"durableOpTime" : {
"ts" :Timestamp(1483511762, 1),
"t" : NumberLong(9)
}
},
"members" : [
{
"_id" : 0,
"name" :"192.168.1.82:10002",
"health" : 1,
"state" : 1,
"stateStr" :"PRIMARY",
"uptime" : 448,
"optime" : {
"ts" :Timestamp(1483511762, 1),
"t" :NumberLong(9)
},
"optimeDate" :ISODate("2017-01-04T06:36:02Z"),
"electionTime" :Timestamp(1483511352, 1),
"electionDate" :ISODate("2017-01-04T06:29:12Z"),
"configVersion" : 3,
"self" : true
},
{