mongo-1配置文件:
systemLog:
destination: file
logAppend: true
path: /opt/mongo-1/logs/mongodb.log
storage:
dbPath: /opt/mongo-1/data
journal:
enabled: true
processManagement:
fork: true # fork and run in background
pidFilePath: /opt/mongo-1/mongod.pid # location of pidfile
timeZoneInfo: /usr/share/zoneinfo
net:
port: 9797
bindIp: 0.0.0.0 # Listen to local interface only, comment to listen on all interfaces.
replication:
replSetName: rs0
mongo-2配置文件
systemLog:
destination: file
logAppend: true
path: /opt/mongo-2/logs/mongodb.log
storage:
dbPath: /opt/mongo-2/data
journal:
enabled: true
processManagement:
fork: true # fork and run in background
pidFilePath: /opt/mongo-2/mongod.pid # location of pidfile
timeZoneInfo: /usr/share/zoneinfo
net:
port: 9798
bindIp: 0.0.0.0 # Listen to local interface only, comment to listen on all interfaces.
replication:
replSetName: rs0
分别进入mongo-1 mongo-2的bin目录,然后运行:
./mongod -f 配置文件路径
成功则如图所示
image.png
然后随便进入一个节点运行
./mongo --port 端口号
然后在控制台输入:
rsconf = {
_id: "rs0",
members: [
{
_id: 0,
host: "47.99.216.139:9797"
},
{
_id: 1,
host: "47.99.216.139:9798"
}
]
};
随后运行
rs.initiate( rsconf )
使用rs.status()查看状态
image.png搭建成功
网友评论