MongoDB副本集部署

mongodb 副本集搭建



环境
192.168.1.191   master
192.168.1.192   slave,arbiter
OS: ubuntu14.04
mongodb: mongodb-linux-x86_64-ubuntu1404-v3.2-latest.tgz

tar xf mongodb-linux-x86_64-ubuntu1404-v3.2-latest.tgz -C /usr/local/
mv /usr/local/mongodb-linux-x86_64-ubuntu1404-v3.2 /usr/local/mongodb
编写配置文件
###master
dbpath=/mongodata/
logpath=/mongodata/log/master.log
pidfilepath=/mongodata/master.pid  
directoryperdb=true
logappend=true  
replSet=buka  
bind_ip=192.168.1.191
port=27017
oplogSize=10000  
fork=true
noprealloc=true

###slave
dbpath=/mongodata/slave
logpath=/mongodata/log/slaver.log
pidfilepath=/mongodata/slaver.pid  
directoryperdb=true
logappend=true
replSet=buka
bind_ip=192.168.1.192
port=27017
oplogSize=10000
fork=true
noprealloc=true


###arbiter
dbpath=/mongodata/arbiter
logpath=/mongodata/log/arbiterr.log
pidfilepath=/mongodata/arbiterr.pid
directoryperdb=true
logappend=true
replSet=buka
bind_ip=192.168.1.192
port=27018
oplogSize=10000
fork=true
noprealloc=true

##创建目录,建议和安装目录分开
    mkdir /mongodata
    mkdir /mongodata/log

    ##slave和arbiter
    mkdir /mongodata/slave
    mkdir /mongodata/arbiter
    mkdir /mongodata/log

##启动
    cd /usr/local/mongo
    cp bin/mongo /usr/bin/
    cp bin/mongod /usr/bin/

    mongod -f master.conf
    mongod -f slave.conf
    mongod -f arbiter.conf

##配置主,备,仲裁节点
    mongo 192.168.1.191            
    cfg={_id:"buka",members:[{_id:0,host:'192.168.1.191:27017',priority:2},{_id:1,host:'192.168.1.192:27017',priority:1},{_id:2,host:'192.168.1.192:27018',arbiterOnly:true}]};
    rs.initiate(cfg)
    rs.status()

##在master节点创建admin db和用户
    mongo 192.168.1.191
    use admin
    db.createUser({user:"admin",pwd:"asd12345",roles:[{ role:"root",db:"admin"}]})
    db.auth('admin','asd12345')  #返回1代表认证成功


##配置节点间加密认证和auth
    在一个节点生成key文件,并拷贝到其它节点
    openssl rand -base64 100 > keyfile0
    chmod 600 keyfile0

##在各节点配置文件中加入下面两行
    auth=true
    keyFile=keyfile0

##重启各节点服务
    mongo 192.168.1.191
    use admin
    db.auth('admin','asd12345')

##创建一个库
    use test1
    db.createUser({user:"test1",pwd:"asd12345",roles:[{ role:"readWrite",db:"test1"}]})
##认证

    db.auth("test1","asd12345")   ##返回1代表认证成功

posted @ 2017-07-25 16:27  (KeeP)  阅读(257)  评论(0编辑  收藏  举报