服务器准备:
主节点192.168.100.106
从节点192.168.100.107
仲裁节点192.168.100.108
三台服务器:
关闭防火墙
service iptables stop
chkconfig iptables off
创建文件夹
mkdir -p /export/mongo/data/db
mkdir -p /export/mongo/log
mkdir -p /export/mongo/key
mkdir -p /export/mongo/run
mkdir -p /export/mongo/conf
上传mongodb-linux-x86_64-3.4.6.tgz并解压在/export/mongo目录下
tar -zxvf mongodb-linux-x86_64-3.4.6.tgz
mv mongodb-linux-x86_64-3.4.6 mongodb
cd /export/mongo/log
创建mongod.log文件
主节点:
vim /export/mongo/conf/mongo.conf
port =28007
fork =true
dbpath =/export/mongo/data/db
logpath =/export/mongo/log/mongod.log
pidfilepath=/export/mongo/run/28007.pid
logappend =true
shardsvr =true
replSet =shard1
bind_ip=主节点IP
oplogSize=10000
noprealloc=true
从节点:
vim /export/mongo/conf/mongo.conf
port =28008
fork =true
dbpath =/export/mongo/data/db
logpath =/export/mongo/log/mongod.log
pidfilepath=/export/mongo/run/28008.pid
logappend =true
shardsvr =true
replSet =shard1
bind_ip=从节点IP
oplogSize=10000
noprealloc=true
仲裁节点:
vim /export/mongo/conf/mongo.conf
port =28009
fork =true
dbpath =/export/mongo/data/db
logpath =/export/mongo/log/mongod.log
pidfilepath=/export/mongo/run/28009.pid
logappend =true
shardsvr =true
replSet =shard1
bind_ip=仲裁节点IP
oplogSize=10000
noprealloc=true
三台服务启动mongodb:
cd /export/mongo/mongodb/bin
./mongod -f /export/mongo/conf/mongo.conf
主节点:
cd /export/mongo/mongodb/bin
./mongo 主节点IP:28007
use admin
config={_id:'shard1',members:[{_id:0,host:'118.1.2.81:28007'},{_id:1,host:'118.1.2.82:28008'},{_id:2,host:'118.1.2.74:28009', arbiterOnly:true}]}
rs.initiate(config)
--查看副本集情况
rs.status()
测试写入数据:
use db_test
db.tb_test01.insert( {"name":"yiibai tutorials"})
db.tb_test01.find()