环境:
OS:CentOS 7
db:mongodb 2.6.5
-------------------------主库配置------------------------
1.安装数据库
省略
安装的时候建立如下目录
[root@pxc01 mongodb265]# mkdir data
[root@pxc01 mongodb265]# mkdir log
[root@pxc01 mongodb265]# mkdir key
[root@pxc01 mongodb265]# mkdir conf
3.主库的配置文件(mongo.cnf)
port = 10000
fork = true
dbpath = /opt/mongodb265/data
logpath = /opt/mongodb265/log/logs
logappend = true
shardsvr = true
quiet = true
keyFile=/opt/mongodb265/key/keyfile #添加keyfile
auth = true #打开认证
master = true #打开主库配置
4.添加keyfile
[root@pxc01 key]# cd /opt/mongodb265/key
[root@pxc01 key]# openssl rand -base64 741 >>keyfile
[root@pxc01 key]# chmod 700 keyfile
5.重启数据库
./mongod -f /opt/mongodb265/conf/mongo.cnf
----------------------从库配置---------------------------
1.安装数据库
与主库安装一致
2.从库配置文件
port = 10001
slave = true
fork = true
source = 192.168.56.91:10000
slavedelay = 10
autoresync = true
dbpath = /opt/mongodb265/data
logpath = /opt/mongodb265/log/logs
keyFile=/opt/mongodb265/key/keyfile
quiet = true
3.将主库的keyfile拷贝到从库的目录/opt/mongodb265/key/
[root@pxc01 key]# scp keyfile root@192.168.56.92:/opt/mongodb265/key/
传到从库后,然后在从库上执行
[root@pxc02 key]# chmod 700 keyfile
4.启动从库
./mongod -f /opt/mongodb265/conf/mongo.cnf
遇到的问题:
2018-03-15T21:23:37.061-0400 [replslave] warning: Failed to connect to 192.168.56.91:10000, reason: errno:113 No route to host
2018-03-15T21:23:37.062-0400 [replslave] repl: couldn't connect to server 192.168.56.91:10000 (192.168.56.91), connection attempt fa
iled
提示无法连接主库
主库防火墙状态
[root@pxc02 log]# firewall-cmd --state
running
主库和从库都关闭防火墙
systemctl stop firewalld.service ##停止firewall
systemctl disable firewalld.service ##禁止firewall开机启动
5.登录从库
[root@pxc02 bin]# ./mongo 192.168.56.92:10001
要进行验证才能访问数据库
> use admin
switched to db admin
> db.auth("root","123456");
-- The End --
阅读(3173) | 评论(0) | 转发(0) |