準備工作
軟體環境
OS:Oracle Linux 6.5
MongoDB:mongodb3.2.3
部署架構
類比有三台伺服器
10.1.5.123:28001 主節點
10.1.5.123:28002 從節點
10.1.5.123:28003 選舉節點
複製集架構:一主,一從,一選舉節點
下載安裝
下載地址:https://www.mongodb.org/downloads
mongodb-linux-x86_64-rhel62-3.2.3.tgz
部署步驟 1.建立目錄及使用者
[root@devtest mongodb]# mkdir conf data log
[root@devtest data]# mkdir 28001 28002 28003
--建立mongo使用者
[root@devtest conf]# groupadd mongod
[root@devtest conf]# useradd -g mongod mongod
2.建立設定檔
--配置三個執行個體的設定檔(修改相應的連接埠號碼即可)
--節點1
$ vi /home/mongod/mongodb3.2.3/conf/28001.conf
port=28001
bind_ip=10.1.5.123
logpath=/home/mongod/mongodb3.2.3/log/28001.log
dbpath=/home/mongod/mongodb3.2.3/data/28001/
logappend=true
pidfilepath=/home/mongod/mongodb3.2.3/data/28001/28001.pid
fork=true
oplogSize=1024
replSet=MyMongo
--節點2
$ vi /home/mongod/mongodb3.2.3/conf/28002.conf
port=28002
bind_ip=10.1.5.123
logpath=/home/mongod/mongodb3.2.3/log/28002.log
dbpath=/home/mongod/mongodb3.2.3/data/28002/
logappend=true
pidfilepath=/home/mongod/mongodb3.2.3/data/28002/28002.pid
fork=true
oplogSize=1024
replSet=MyMongo
--節點3
$ vi /home/mongod/mongodb3.2.3/conf/28003.conf
port=28003
bind_ip=10.1.5.123
logpath=/home/mongod/mongodb3.2.3/log/28003.log
dbpath=/home/mongod/mongodb3.2.3/data/28003/
logappend=true
pidfilepath=/home/mongod/mongodb3.2.3/data/28003/28003.pid
fork=true
oplogSize=1024
replSet=MyMongo
3.啟動mongo複製集
$ mongod -f /home/mongod/mongodb3.2.3/conf/28001.conf
$ mongod -f /home/mongod/mongodb3.2.3/conf/28002.conf
$ mongod -f /home/mongod/mongodb3.2.3/conf/28003.conf
4.初始化複製集
[mongod@devtest ~]$ mongo 10.1.5.123:28001/admin
MongoDB shell version: 3.2.3
connecting to: 10.1.5.123:28001/admin
Welcome to the MongoDB shell.
For interactive help, type"help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
> db
admin
> config = {
... "_id":"MyMongo",
... members:[
...{"_id":0,host:"10.1.5.123:28001"},
...{"_id":1,host:"10.1.5.123:28002"},
... {"_id":2,host:"10.1.5.123:28003"}]
... }
{
"id" : "MyMongo",
"members" : [
{
"_id" : 0,
"host" :"10.1.5.123:28001"
},
{
"_id" : 1,
"host" :"10.1.5.123:28002"
},
{
"_id" : 2,
"host" :"10.1.5.123:28003"
}
]
}
--查看複製整合員
> config.members
[
{
"_id" : 0,
"host" :"10.1.5.123:28001"
},
{
"_id" : 1,
"host" :"10.1.5.123:28002"
},
{
&nb