mongodb配置---副本集
admin
2023-03-03 15:42:08
0

mongodb配置 192.11.11.11 为master节点
192.11.11.12 为仲裁节点
192.11.11.13 为备节点

1、下载tar包
https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.2.tgz

2、解压
rm -rf /neworiental/mongodb
tar -zxvf /neworiental/tools/mongodb-linux-x86_64-4.0.2.tgz -C /neworiental/
mv /neworiental/mongodb-linux-x86_64-4.0.2 /neworiental/mongodb

3、建立目录文件夹
mkdir -p /neworiental/mongodb/data/master
mkdir -p /neworiental/mongodb/data/slaver
mkdir -p /neworiental/mongodb/data/arbiter
mkdir -p /neworiental/mongodb/log
mkdir -p /neworiental/mongodb/master
mkdir -p /neworiental/mongodb/slaver
mkdir -p /neworiental/mongodb/arbiter
mkdir /neworiental/mongodb/keyFile/

4、配置文件
addr=/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"
cat < /neworiental/mongodb/master/master.conf
#master.conf
dbpath=/neworiental/mongodb/data/master
logpath=/neworiental/mongodb/log/master.log
pidfilepath=/neworiental/mongodb/master.pid
directoryperdb=true
logappend=true
replSet=preferential-mongo
bind_ip=$addr
port=27017
oplogSize=10000
fork=true
noprealloc=true
#auth=true
maxConns=200000
EOF

cat < /neworiental/mongodb/slaver/slaver.conf
#slaver.conf
dbpath=/neworiental/mongodb/data/slaver
logpath=/neworiental/mongodb/log/slaver.log
pidfilepath=/neworiental/mongodb/slaver.pid
directoryperdb=true
logappend=true
replSet=preferential-mongo
bind_ip=$addr
port=27017
oplogSize=10000
fork=true
noprealloc=true
#auth=true
maxConns=200000
EOF

cat < /neworiental/mongodb/arbiter/arbiter.conf
#arbiter.conf
dbpath=/neworiental/mongodb/data/arbiter
logpath=/neworiental/mongodb/log/arbiter.log
pidfilepath=/neworiental/mongodb/arbiter.pid
directoryperdb=true
logappend=true
replSet=preferential-mongo
bind_ip=$addr
port=27017
oplogSize=10000
fork=true
noprealloc=true
#auth=true
maxConns=200000
EOF

6、分别在master、slaver、arbiter运行相应命令,启动mongodb
/neworiental/mongodb/bin/mongod -f /neworiental/mongodb/master/master.conf #master
/neworiental/mongodb/bin/mongod -f /neworiental/mongodb/slaver/slaver.conf #slaver
/neworiental/mongodb/bin/mongod -f /neworiental/mongodb/arbiter/arbiter.conf #arbiter

7、配置主,备,仲裁节点
/neworiental/mongodb/bin/mongo 172.22.31.83:27017 #ip和port是某个节点的地址

use admin

cfg={ _id:"preferential-mongo", members:[
{_id:0,host:'192.11.11.11:27017',priority:2},
{_id:1,host:'192.11.11.13:27017',priority:1},
{_id:2,host:'192.11.11.12:27017',arbiterOnly:true}] };

rs.initiate(cfg) #使配置生效

#如果要添加节点

rs.add( { host: "ip:27017", priority: 0, votes: 0 }) # 添加节点

rs.status() #查看状态,是否生效

出现:"stateStr" : "RECOVERING" 表示 没有生效

#创建密码验证

use admin
db.createUser( { user:"preferential", pwd:"preferential",
roles:[{role:"readWriteAnyDatabase",db:"admin"},
{role:"dbAdminAnyDatabase",db:"admin"},
{role:"userAdminAnyDatabase",db:"admin"}] } ) #创建数据库密码

相关内容

热门资讯

年龄相差40多岁,韩执政党党首... 当地时间5月3日,韩国执政党共同民主党党首郑清来携“备战”国会议员补选的前青瓦台人工智能未来规划首席...
人民之心·总书记谈政绩观④|一... 统筹:李琳 杨格策划:叶莉子设计:杨晨悦校对:陈学德素材来源:《人民日报》、新华网
英方裁定2名中国公民有罪,外交... 澎湃新闻记者 杨文钦 朱郑勇5月8日,外交部发言人林剑主持例行记者会。英国广播公司(BBC)记者提问...
特朗普威胁欧盟:7月4日之前履... 【文/观察者网 陈思佳】去年7月,美国和欧盟在英国达成一项贸易协议,但欧盟目前仍未批准协议,引起美国...
四川“人工智能+”一号创新工程... “三步走” ●到2027年,实现人工智能与重点领域广泛深度融合 ●到2030年,加快建成具有全国影响...
移动云总经理孙少陵:夯实算力网... 【移动云总经理孙少陵:夯实算力网络底座 实现智算全域互联】财联社5月8日电,中国移动2026移动云大...
苹果带摄像头AirPods已进... PChome 5月8日消息,彭博社记者马克·古尔曼爆料称,苹果最新打造的带摄像头AirPods已进入...
原创 马... 希冯·齐利斯,埃隆·马斯克四个孩子的母亲,周三在法庭上公开了她与这位科技亿万富翁之间复杂且曾一度保密...
农田边毒水直流,比排污更刺眼的... 5月7日,总台《焦点访谈》曝光了徐州贾汪区农谷大道路边沟存在水体污染问题。全长12公里的路边沟满是污...
28岁女子坠亡,施工方谎报 近日,深圳龙岗区应急管理局公布了《龙岗龙城香港中文大学(深圳)医学院项目Ⅰ标“12·26”一般高处坠...