Mongodb启动和关闭脚本化.md
2020-02-26 本文已影响0人
平凡的运维之路
Mongodb停止和启动脚本
- 见下面代码mongostop 停止脚本
#!/bin/bash
mongodstart(){
numactl --interleave=all /home/mongodb/mongodb_3.2.12/bin/mongod -f /home/mongodb/config/config*.conf
numactl --interleave=all /home/mongodb/mongodb_3.2.12/bin/mongod -f /home/mongodb/config/shard1*.conf
numactl --interleave=all /home/mongodb/mongodb_3.2.12/bin/mongod -f /home/mongodb/config/shard2*.conf
numactl --interleave=all /home/mongodb/mongodb_3.2.12/bin/mongod -f /home/mongodb/config/shard3*.conf
}
mongostart(){
/home/mongodb/mongodb_3.2.12/bin/mongos -f /home/mongodb/config/mongos*.conf
}
main(){
mongodstart
mongostart
}
main
- 见下面代码mongostart 启动脚本
#!/bin/bash
mongodstop(){
/home/mongodb/mongodb_3.2.12/bin/mongod --shutdown -f /home/mongodb/config/config*.conf
/home/mongodb/mongodb_3.2.12/bin/mongod --shutdown -f /home/mongodb/config/shard1*.conf
/home/mongodb/mongodb_3.2.12/bin/mongod --shutdown -f /home/mongodb/config/shard2*.conf
/home/mongodb/mongodb_3.2.12/bin/mongod --shutdown -f /home/mongodb/config/shard3*.conf
}
mongosstop(){
#/home/mongodb/mongodb_3.2.12/bin/mongos --shutdown -f /home/mongodb/config/mongos*.conf
mongosPid=$(ps -ef|grep mongos|grep "\-f"|awk '{print $2}')
kill -15 $mongosPid
}
main(){
mongodstop
mongosstop
}
main
- 可以定义别名的方式,如下定义:
[mongodb@mongodb02 ~]$ vim .bashrc
alias mongostop='cd /home/mongodb/mongodb_3.2.12/bin && /bin/bash mongostop'
alias mongostart='cd /home/mongodb/mongodb_3.2.12/bin && /bin/bash mongostart'