部署规划
一、在三个节点上创建如下目录,做测试的话建议确保在/目录有15G左右的剩余空间
[root@orcl ~]# mkdir -p /var/config
[root@orcl ~]# mkdir -p /var/sd1
[root@orcl ~]# mkdir -p /var/sd2
[root@orcl ~]# mkdir -p /var/sd3
二、查看配置文件
[root@orcl ~]# cat /etc/config.conf?
port=28000
dbpath=/var/config
logpath=/var/config/config.log
logappend=true
fork=true
configsvr=true
[root@orcl ~]# cat /etc/route.conf?
port=27017
configdb=192.168.1.30:28000,192.168.1.52:28000,192.168.1.108:28000
logpath=/var/log/mongos.log
logappend=true
fork=true
[root@orcl ~]# cat /etc/sd1.conf?
port = 27018
dbpath=/var/sd1
logpath =/var/sd1/shard1.log
logappend =true
shardsvr =true
replSet =set1
fork =true
[root@orcl ~]# cat /etc/sd2.conf ?
port = 27019
dbpath=/var/sd2
logpath =/var/sd2/shard2.log
logappend =true
shardsvr =true
replSet =set2
fork =true
[root@orcl ~]# cat /etc/sd3.conf ?
port = 27020
dbpath=/var/sd3
logpath =/var/sd3/shard1.log
logappend =true
shardsvr =true
replSet =set3
fork =true
三、在三个节点上同步时间
略
四、在三个节点上启动用config服务器
节点1
[root@orcl ~]# mongod -f /etc/config.conf?
about to fork child process, waiting until server is ready for connections.
forked process: 3472
child process started successfully, parent exiting
[root@orcl ~]# ps -ef |grep mongo
root ? ? ?3472 ? ? 1 ?1 19:15 ? ? ? ? ?00:00:01 mongod -f /etc/config.conf
root ? ? ?3499 ?2858 ?0 19:17 pts/0 ? ?00:00:00 grep mongo
[root@orcl ~]# netstat -anltp|grep 28000
tcp ? ? ? ?0 ? ? ?0 0.0.0.0:28000 ? ? ? ? ? ? ? 0.0.0.0:* ? ? ? ? ? ? ? ? ? LISTEN ? ? ?3472/mongod?
节点2
[root@localhost ~]# mongod -f /etc/config.conf
about to fork child process, waiting until server is ready for connections.
forked process: 2998
child process started successfully, parent exiting
[root@localhost ~]# ps -ef |grep mongo
root ? ? ?2998 ? ? 1 ?8 19:15 ? ? ? ? ?00:00:08 mongod -f /etc/config.conf
root ? ? ?3014 ?2546 ?0 19:17 pts/0 ? ?00:00:00 grep mongo
[root@localhost ~]# netstat -anltp|grep 28000
tcp ? ? ? ?0 ? ? ?0 0.0.0.0:28000 ? ? ? ? ? ? ? 0.0.0.0:* ? ? ? ? ? ? ? ? ? LISTEN ? ? ?2998/mongod ?
节点3
[root@db10g ~]# mongod -f /etc/config.conf
about to fork child process, waiting until server is ready for connections.
forked process: 4086
child process started successfully, parent exiting
[root@db10g ~]# ps -ef |grep mongo
root ? ? ?4086 ? ? 1 ?2 19:25 ? ? ? ? ?00:00:00 mongod -f /etc/config.conf
root ? ? ?4100 ?3786 ?0 19:25 pts/0 ? ?00:00:00 grep mongo
[root@db10g ~]# netstat -anltp|grep 28000
tcp ? ? ? ?0 ? ? ?0 0.0.0.0:28000 ? ? ? ? ? ? ? 0.0.0.0:* ? ? ? ? ? ? ? ? ? LISTEN ? ? ?4086/mongod ?
五、在三个节点上启动用路由服务器
节点1
[root@orcl ~]# ?mongos -f /etc/route.conf
about to fork child process, waiting until server is ready for connections.
forked process: 3575
child process started successfully, parent exiting
[root@orcl ~]# netstat -anltp|grep 2701
tcp ? ? ? ?0 ? ? ?0 0.0.0.0:27017 ? ? ? ? ? ? ? 0.0.0.0:* ? ? ? ? ? ? ? ? ? LISTEN ? ? ?3575/mongos ?
节点2
[root@localhost ~]# ?mongos -f /etc/route.conf
about to fork child process, waiting until server is ready for connections.
forked process: 3057
child process started successfully, parent exiting
[root@localhost ~]# netstat -anltp|grep 2701
tcp ? ? ? ?0 ? ? ?0 0.0.0.0:27017 ?
节点3
[root@db10g ~]# mongos -f /etc/route.conf
about to fork child process, waiting until server is ready for connections.
forked process: 4108
child process started successfully, parent exiting
[root@db10g ~]# netstat -anltp|grep 27017
tcp ? ? ? ?0 ? ? ?0 0.0.0.0:27017 ? ? ? ? ? ? ? 0.0.0.0:* ? ? ? ? ? ? ? ? ? LISTEN ? ? ?4108/mongos?
六、在三个节点启用shard
mongod -f /etc/sd1.conf
mongod -f /etc/sd2.conf
mongod -f /etc/sd3.conf
节点1
[ro