mongodb配置---副本集-创新互联

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"}] } ) #创建数据库密码

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


文章标题:mongodb配置---副本集-创新互联
转载源于:http://lszwz.com/article/dsdjoi.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款