标签:机器 des 端口 ini 初始化 conf member -- fork
部署Mongodb高可用集群
按照官方说明,至少需要3个config server,2个mongos,2个shard,每个shard至少2个副本,就是4个shard,共需要9个Mongodb实例。这里只虚拟出2个机器节点,将不同的Mongodb实例部署在不同的端口上模拟实现。
config server | leo.zhi.1:10010,leo.zhi.2:10010 |
mongos server | leo.zhi.1:10020,leo.zhi.2:10020 |
shard server | leo.zhi.1:10001,leo.zhi.2:10002 |
leo.zhi.1和leo.zhi.2上分别创建文件夹
[root@leo mongodb]# mkdir -p config/data [root@leo mongodb]# mkdir -p config/log [root@leo mongodb]# mkdir -p mongos/log [root@leo mongodb]# mkdir -p shard1/data [root@leo mongodb]# mkdir -p shard1/log [root@leo mongodb]# mkdir -p shard2/data [root@leo mongodb]# mkdir -p shard2/log
其中data目录存放数据,log目录存放日志
mongos服务不存放数据,所以不需要数据目录,只需要log目录
Mongodb配置文件(采用YAML格式书写)
systemLog:
destination: file
path: "/usr/local/mongodb/config/log/mongod.log"
logAppend: true
storage:
dbPath: "/usr/local/mongodb/config/data"
journal:
enabled: true
directoryPerDB: true
net:
port: 10010
processManagement:
fork: true
pidFilePath: "/usr/local/mongodb/config/mongod.pid"
sharding:
clusterRole: configsvr
replication:
replSetName: configReplSet
1. 在每台服务器上分别启Mongodb实例
[root@leo mongodb]# mongod --config config/mongod.conf about to fork child process, waiting until server is ready for connections. forked process: 3293 child process started successfully, parent exiting
2. 随便选个一个节点,登录mongo,初始化config server 的 replica set
[root@leo mongodb]# mongo --port 10010 > rs.initiate( { _id: "configReplSet", configsvr: true, members:[ {_id:0,host:"leo.zhi.1:10010"}, {_id:1,host:"leo.zhi.2:10010"}] } )
... configReplSet:OTHER> exit [root@leo mongodb]# mongo --port 10010 configReplSet:PRIMARY>
Mongodb配置文件(采用YAML格式书写)
systemLog:
destination: file
path: "/usr/local/mongodb/shard1/log/mongod.log"
logAppend: true
storage:
dbPath: "/usr/local/mongodb/shard1/data"
journal:
enabled: true
directoryPerDB: true
net:
port: 10001
processManagement:
fork: true
pidFilePath: "/usr/local/mongodb/shard1/mongod.pid"
sharding:
clusterRole: shardsvr
replication:
replSetName: shard1ReplSet
1. 在每个节点启动shard1
[root@leo mongodb]# mongod --config shard1/mongod.conf
2. 随便选个一个节点,登录mongo,初始化shard1 的 replica set
[root@leo mongodb]# mongo --port 10001 > rs.initiate( { _id: "shard1ReplSet", members:[ {_id:0,host:"leo.zhi.1:10001"}, {_id:1,host:"leo.zhi.2:10002"}] } ) ... shard1ReplSet:OTHER> exit [root@leo mongodb]# mongo --port 10001 shard1ReplSet:PRIMARY>
Mongodb配置文件(采用YAML格式书写)
systemLog:
destination: file
path: "/usr/local/mongodb/shard2/log/mongod.log"
logAppend: true
storage:
dbPath: "/usr/local/mongodb/shard2/data"
journal:
enabled: true
directoryPerDB: true
net:
port: 10002
processManagement:
fork: true
pidFilePath: "/usr/local/mongodb/shard2/mongod.pid"
sharding:
clusterRole: shardsvr
replication:
replSetName: shard2ReplSet
其余操作步骤同部署shard1
标签:机器 des 端口 ini 初始化 conf member -- fork
原文地址:http://www.cnblogs.com/seastar1989/p/7511356.html