时间:2021-07-01 10:21:17 帮助过:43人阅读
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
Mongodb3.4.7搭建高可用集群(二)
标签:机器 des 端口 ini 初始化 conf member -- fork