Ai
1 Star 2 Fork 0

BrianChou/shell-mongodb-cluster

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
mongodb 3.70 KB
一键复制 编辑 原始数据 按行查看 历史
jun3.xiong 提交于 2021-06-06 12:15 +08:00 . init
#!/bin/bash
# chkconfig:2345 30 70
# description: Mongo database
# precessname: mongod
source /etc/profile
mongodb_cluster_home="/opt/mongodb_cluster"
config_configfile="$mongodb_cluster_home/conf/config.conf"
mongos_configfile="$mongodb_cluster_home/conf/mongos.conf"
shard1_configfile="$mongodb_cluster_home/conf/shard_server1.conf"
shard2_configfile="$mongodb_cluster_home/conf/shard_server2.conf"
shard3_configfile="$mongodb_cluster_home/conf/shard_server3.conf"
config_datadir="$mongodb_cluster_home/config_server/data"
shard1_datadir="$mongodb_cluster_home/shard_server1/data"
shard2_datadir="$mongodb_cluster_home/shard_server2/data"
shard3_datadir="$mongodb_cluster_home/shard_server3/data"
config_pidfile="$mongodb_cluster_home/config_server/logs/configsvr.pid"
mongos_pidfile="$mongodb_cluster_home/mongos/logs/mongos.pid"
shard1_pidfile="$mongodb_cluster_home/shard_server1/logs/shard1.pid"
shard2_pidfile="$mongodb_cluster_home/shard_server2/logs/shard2.pid"
shard3_pidfile="$mongodb_cluster_home/shard_server3/logs/shard3.pid"
function start-config(){
#print the tips
echo -n $"Starting mongod of config_server:"
su - mongodb -c "mongod -f $config_configfile"
#get the result
RETVAL=$?
if [ $RETVAL -eq 0 ];then
touch $config_datadir/mongod.lock
fi
}
function stop-config(){
#print the tips
echo $"stopping mongod of config_server:"
su - mongodb -c "mongod --shutdown --dbpath $config_datadir"
RETVAL=$?
if [ $RETVAL -eq 0 ];then
rm -f $config_datadir/mongod.lock
rm -f $config_pidfile
fi
}
function start-mongos(){
#print the tips
echo $"Starting mongod of mongos_server:"
su - mongodb -c "mongos -f $mongos_configfile"
}
function stop-mongos(){
echo $"stopping mongod of mongos_server:"
kill `cat $mongos_pidfile`
RETVAL=$?
if [ $RETVAL -eq 0 ];then
rm -f $mongos_pidfile
fi
}
function start-shard1(){
#print the tips
echo $"Starting mongod of shard1_server:"
su - mongodb -c "mongod -f $shard1_configfile"
#get the result
RETVAL=$?
if [ $RETVAL -eq 0 ];then
$shard1_datadir/mongod.lock
fi
}
function stop-shard1(){
echo $"stopping mongod of shard1_server:"
su - mongodb -c "mongod --shutdown --dbpath $shard1_datadir"
RETVAL=$?
if [ $RETVAL -eq 0 ];then
rm -f $shard1_datadir/mongod.lock
rm -f $shard1_pidfile
fi
}
function start-shard2(){
#print the tips
echo $"Starting mongod of shard2_server:"
su - mongodb -c "mongod -f $shard2_configfile"
#get the result
RETVAL=$?
if [ $RETVAL -eq 0 ];then
$shard2_datadir/mongod.lock
fi
}
function stop-shard2(){
echo $"stopping mongod of shard2_server:"
su - mongodb -c "mongod --shutdown --dbpath $shard2_datadir"
RETVAL=$?
if [ $RETVAL -eq 0 ];then
rm -f $shard2_datadir/mongod.lock
rm -f $shard2_pidfile
fi
}
function start-shard3(){
#print the tips
echo $"Starting mongod of shard3_server:"
su - mongodb -c "mongod -f $shard3_configfile"
#get the result
RETVAL=$?
if [ $RETVAL -eq 0 ];then
$shard3_datadir/mongod.lock
fi
}
function stop-shard3(){
echo $"stopping mongod of shard3_server:"
su - mongodb -c "mongod --shutdown --dbpath $shard3_datadir"
RETVAL=$?
if [ $RETVAL -eq 0 ];then
rm -f $shard3_datadir/mongod.lock
rm -f $shard3_pidfile
fi
}
RETVAL=0
case "$1" in
start)
start-config
start-shard1
start-shard2
start-shard3
start-mongos
;;
stop)
stop-mongos
stop-shard1
stop-shard2
stop-shard3
stop-config
;;
restart)
$0 stop
$0 start
;;
esac
exit $RETVAL
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/brianchou/shell-mongodb-cluster.git
git@gitee.com:brianchou/shell-mongodb-cluster.git
brianchou
shell-mongodb-cluster
shell-mongodb-cluster
master

搜索帮助