您的位置:首页 > 数据库 > Mongodb

centos7开机启动mongodb shard cluster

2015-06-26 10:10 696 查看
centos7开机启动mongodb shard cluster

分享光荣,盗链可耻。转载务必注明出处,鄙视盗链鼠辈。



shard配置

shard node1配置

shardsvr=true#注意此项
port=27018
rest=true
httpinterface=true
fork=true
dbpath=/mongo_data/shard/node1
logpath=/var/log/mongo/shard/node1.log
pidfilepath=/tmp/mongo_shard_node1.pid


shard node2配置

shardsvr=true#注意此项
port=27081
rest=true
httpinterface=true
fork=true
dbpath=/mongo_data/shard/node2
logpath=/var/log/mongo/shard/node2.log
pidfilepath=/tmp/mongo_shard_node2.pid


config server配置

configsvr = true#注意此项
port = 27019
rest=true
httpinterface=true
fork=true
dbpath=/mongo_data/shard/config
logpath=/var/log/mongo/shard/config.log
pidfilepath=/tmp/mongo_shard_config.pid


mongos配置

configdb = 127.0.0.1:27019#注意与configsvr一致
chunkSize = 64
httpinterface=true
fork=true
logpath=/var/log/mongo/shard/mongos.log
pidfilepath=/tmp/mongos.pid


shard启动脚本

启动,停止顺序自行思考,很好想

start_mongo_shard.sh
(先起shard node,再config server,再mongos)

#!/bin/sh
/usr/local/mongodb3.0/bin/mongod --config=/usr/local/mongodb3.0/shard_node1_server
/usr/local/mongodb3.0/bin/mongod --config=/usr/local/mongodb3.0/shard_node2_server
/usr/local/mongodb3.0/bin/mongod --config=/usr/local/mongodb3.0/shard_config_server
/usr/local/mongodb3.0/bin/mongos --config=/usr/local/mongodb3.0/shard_mongos_server


stop_mongo_shard.sh
(先停mongos,再config server,再shard node)

#!/bin/sh
kill `cat /tmp/mongos.pid`
kill `cat /tmp/mongo_shard_config.pid`
kill `cat /tmp/mongo_shard_node1.pid`
kill `cat /tmp/mongo_shard_node2.pid`


注意:启停脚本第一行
#!/bin/sh
非常重要,如果不写这行,命令行下脚本正常运行,但是在systemctl start xxxx启动mongodb服务时报错。详见后文。

shard开机自动启动

vim /usr/lib/systemd/system/mongodb.service

[unit]
Description=mongodb
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/mongodb3.0/start_mongo_shard.sh
ExecStop=/usr/local/mongodb3.0/stop_mongo_shard.sh
PrivateTmp=true

[Install]
WantedBy=multi-user.target


systemctl enable mongodb开机自动启动

启停:systemctl start mongodb // systemctl stop mongodb

错误备录

如果启停脚本不写第一行#!/bin/sh,命令行直接执行
start_mongo_shard.sh
没问题,但是systemctl start mongodb会报错,如下

[xxx@xxx-centos7 system]$ sudo systemctl status mongodb
mongodb.service
Loaded: loaded (/usr/lib/systemd/system/mongodb.service; enabled)
Active: failed (Result: exit-code) since 四 2015-06-25 15:03:58 CST; 9s ago
Process: 25509 ExecStart=/usr/local/mongodb3.0/start_mongo_shard.sh (code=exited, status=203/EXEC)
Main PID: 25426 (code=exited, status=203/EXEC)

6月 25 15:03:58 xxx-centos7 systemd[25509]: Failed at step EXEC spawning /usr/local/mongodb3.0/start_mongo_...rror
6月 25 15:03:58 xxx-centos7 systemd[1]: mongodb.service: control process exited, code=exited status=203
6月 25 15:03:58 xxx-centos7 systemd[1]: Failed to start mongodb.service.
6月 25 15:03:58 xxx-centos7 systemd[1]: Unit mongodb.service entered failed state.
Hint: Some lines were ellipsized, use -l to show in full.


加上#!/bin/sh后信息如下

[xxx@xxx-centos7 system]$ sudo systemctl status mongodb
mongodb.service
Loaded: loaded (/usr/lib/systemd/system/mongodb.service; enabled)
Active: active (running) since 四 2015-06-25 15:08:47 CST; 3s ago
Process: 25656 ExecStart=/usr/local/mongodb3.0/start_mongo_shard.sh (code=exited, status=0/SUCCESS)
Main PID: 25426 (code=exited, status=203/EXEC)
CGroup: /system.slice/mongodb.service
├─25659 /usr/local/mongodb3.0/bin/mongod --config=/usr/local/mongodb3.0/shard_node1_server
├─25674 /usr/local/mongodb3.0/bin/mongod --config=/usr/local/mongodb3.0/shard_node2_server
├─25689 /usr/local/mongodb3.0/bin/mongod --config=/usr/local/mongodb3.0/shard_config_server
└─25705 /usr/local/mongodb3.0/bin/mongos --config=/usr/local/mongodb3.0/shard_mongos_server
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: