1.安装

2.启动mongodb

3.添加mongodb自启动


mongo副本集

1.创建key文件
touch /var/lib/mongodb/key/key1
touch /var/lib/mongodb/key/key2
echo “12345678”>>/var/lib/mongodb/key/key1
echo “12345678”>>/var/lib/mongodb/key/key2
chmod 600 /var/lib/mongodb/key/key1
chmod 600 /var/lib/mongodb/key/key2
2.启动mongod
mongod –replSet rs1 –keyFile /var/lib/mongodb/key/key1 –dbpath=/var/lib/mongodb/data1/ –logpath=/var/log/mongodb/log1/ –port 27017 –fork
mongod –replSet rs1 –keyFile /var/lib/mongodb/key/key2 –dbpath=/var/lib/mongodb/data2/ –logpath=/var/log/mongodb/log2/ –port 27018 –fork

3.进入mongo,配置rs
config_rs1 =
{
“_id” : “rs1”,
“members” : [
{
“_id” : 0,
“host” : “localhost:27017”,
“priority” : 100
},
{
“_id” : 1,
“host” : “localhost:27018”,
“priority” : 100
}
]
}
rs.initiate(config_rs1)
rs.slaveOk()

Related Posts

发表评论