Mongodb 3.2.8: 集群环境搭建

简介

MongoDB是一种面向文档的数据库管理系统,由C++撰写而成,以此来解决应用程序开发社区中的大量现实问题。2007年10月,MongoDB由10gen团队所发展。2009年2月首度推出。

##mongodb集群部署步骤:

#全局配置

mkdir -pv /data/soft

cd /data/soft/

wget http://downloads.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.8.tgz

 

tar -xf mongodb-linux-x86_64-rhel70-3.2.8.tgz -C /usr/local/

cd /usr/local/

ln -sv mongodb-linux-x86_64-rhel70-3.2.8/ mongodb

mkdir -p /usr/local/mongodb/data

 

cat >> /etc/profile << "EOF"

export PATH=$PATH::/usr/local/mongodb/bin

EOF

source /etc/profile 

mkdir -p /usr/local/mongodb/{master,arbiter,slave}/data

#主节点/仲裁节点:

192.168.1.120

备节点:

192.168.1.121/192.168.1.122

#主上的配置

cat > /usr/local/mongodb/mongodb-master.conf << "EOF"

port=27017

dbpath= /usr/local/mongodb/master/data

logpath= /usr/local/mongodb/master/mongodb.log

logappend=true

fork=true

maxConns=500

#auth = true

replSet=ht

oplogSize=10000

EOF

 

cat > /usr/local/mongodb/mongodb-arbiter.conf << "EOF"

port=37017

dbpath= /usr/local/mongodb/arbiter/data

logpath= /usr/local/mongodb/arbiter/mongodb.log

logappend=true

fork=true

maxConns=500

#auth = true

replSet=ht

oplogSize=10000

EOF

 

#从上的配置

cat > /usr/local/mongodb/mongodb-slave.conf << "EOF"

port=27017

dbpath= /usr/local/mongodb/slave/data

logpath= /usr/local/mongodb/slave/mongodb.log

logappend=true

fork=true

maxConns=500

#auth = true

replSet=ht

oplogSize=10000

EOF

 

#主的服务启动脚本

cat > /lib/systemd/system/mongodb-master.service << "EOF"

[Unit]

Description=mongodb

After=network.target remote-fs.target nss-lookup.target

 

[Service]

Type=forking

ExecStart=/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/mongodb-master.conf

ExecReload=/bin/kill -s HUP $MAINPID

ExecStop=/usr/local/mongodb/bin/mongod --shutdown -f /usr/local/mongodb-master.conf

PrivateTmp=true

 

[Install]

WantedBy=multi-user.target

EOF

  

chmod 755 /lib/systemd/system/mongodb-master.service

 

systemctl daemon-reload

systemctl enable mongodb-master.service

systemctl restart mongodb-master.service

systemctl status mongodb-master.service

 

cat > /lib/systemd/system/mongodb-arbiter.service << "EOF"

[Unit]

Description=mongodb

After=network.target remote-fs.target nss-lookup.target

 

[Service]

Type=forking

ExecStart=/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/mongodb-arbiter.conf

ExecReload=/bin/kill -s HUP $MAINPID

ExecStop=/usr/local/mongodb/bin/mongod --shutdown -f /usr/local/mongodb-arbiter.conf

PrivateTmp=true

 

[Install]

WantedBy=multi-user.target

EOF

 

chmod 755 /lib/systemd/system/mongodb-arbiter.service

 

systemctl daemon-reload

systemctl enable mongodb-arbiter.service

systemctl restart mongodb-arbiter.service

systemctl status mongodb-arbiter.service

 

#从的服务启动脚本

cat > /lib/systemd/system/mongodb-slave.service << "EOF"

[Unit]

Description=mongodb

After=network.target remote-fs.target nss-lookup.target

 

[Service]

Type=forking

ExecStart=/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/mongodb-slave.conf

ExecReload=/bin/kill -s HUP $MAINPID

ExecStop=/usr/local/mongodb/bin/mongod --shutdown -f /usr/local/mongodb-slave.conf

PrivateTmp=true

 

[Install]

WantedBy=multi-user.target

EOF

 

 

chmod 755 /lib/systemd/system/mongodb-slave.service

 

systemctl daemon-reload

systemctl enable mongodb-slave.service

systemctl restart mongodb-slave.service

systemctl status mongodb-slave.service

 

#主上集群控制

mongo 127.0.0.1:27017/admin

use admin

 

cfg={_id:"ht", members:[{_id:0,host:'192.168.1.120:27017',priority:3}, {_id:1,host:'192.168.1.121:27017',priority:2}, {_id:2,host:'192.168.1.122:27017',priority:1}, {_id:3,host:'192.168.1.121:37017',arbiterOnly:true}]};

 

rs.initiate(cfg);

rs.status();

rs.slaveOk();

posted @ 2018-04-09 10:25  Williams_Guozi  阅读(377)  评论(0编辑  收藏  举报
本站总访问量 本站总访客量人次 本博客总访问量