一、安装环境
centos6.5
master:172.30.29.108
slave:172.30.29.107
二、master安装
1软件包安装
#yum install -y mongodb mongodb-server
#/etc/init.d/mongod start
#chkconfig mongod onf
2创建用户
#mongo
>use admin
>db.addUser("roor","master") #创建全局管理账户
>use local
>db.addUser("repl","repl") #创建主从复制账户
>exit
3修改配置文件
#vim /etc/mongodb.conf
port = 27017
fork = true
pidfilepath = /var/run/mongodb/mongodb.pid
logpath = /var/log/mongodb/mongodb.log
dbpath =/var/lib/mongodb
journal = true
logappend = true
auth = true
master = true
oplogSize = 10000 #单位为M,一般大小为硬盘大小5%
#/etc/init.d/mongod restart
三、slave安装
1软件包安装
#yum install -y mongodb mongodb-server
#/etc/init.d/mongod start
#chkconfig mongod onf
2创建用户
#mongo
>use admin
>db.addUser("roor","slave") #创建全局管理账户
>use local
>db.addUser("repl","repl") #创建主从复制账户
>exit
3修改配置文件
#vim /etc/mongodb.conf
port = 27017
fork = true
pidfilepath = /var/run/mongodb/mongodb.pid
logpath = /var/log/mongodb/mongodb.log
dbpath =/var/lib/mongodb
journal = true
logappend = true
auth = true
slave = true
source = 172.30.29.108
autoresync = true
oplogSize = 10000
#/etc/init.d/mongod restart
至此,主从服务安装完成,默认从服务器只有只读权限。
本文出自 “不莱梅乐队” 博客,谢绝转载!
原文地址:http://danhanwen.blog.51cto.com/8525423/1558093