MongoDB 3.2.5安装过程详细记录(6)

[root@linuxidc limits.d]# cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never
[root@linuxidc limits.d]# cat /sys/kernel/mm/transparent_hugepage/defrag
[always] madvise never
[root@linuxidc limits.d]#
[root@linuxidc limits.d]# echo "never" > /sys/kernel/mm/transparent_hugepage/enabled
[root@linuxidc limits.d]# echo "never" >  /sys/kernel/mm/transparent_hugepage/defrag
[root@linuxidc limits.d]#
[root@linuxidc limits.d]# cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]
[root@linuxidc limits.d]#  cat /sys/kernel/mm/transparent_hugepage/defrag
always madvise [never]
[root@linuxidc limits.d]#
[root@linuxidc limits.d]#

8 创建mongodb实例管理脚本

为了方便对mongodb实例的启动和停止,可以先创建mongodb的启动脚本,停止脚本,然后在 /etc/init.d/ 目录下创建一个服务脚本,这样就可以用 service 进行实例管理了。

脚本1:启动脚本:

vim /home/mongodb/scripts/mongodb_start.sh

#!/bin/sh
# the scripts is used to start mongodb instance with port 27117.
# created by zhaofx on 20161019.
echo -n "Starting MongoDB port 27117 ... "
/usr/local/mongodb/bin/mongod --config /etc/mongodb/mongo_27117.conf &

脚本二:停止脚本:

vim /home/mongodb/scripts/mongodb_stop.sh

#!/bin/bash
# the scripts is used to stop mongodb instance with port 27117.
# created by zhaofx on 20161019.
echo -n "Stopping MongoDB port 27117"
pid=`ps -o pid,command ax | grep mongod | awk '!/awk/ && !/grep/ {print $1}'`;
if [ "${pid}" != "" ]; then
        kill -2 ${pid};
fi

脚本三:服务脚本:

vim /etc/init.d/mongodb

#! /bin/sh
# the scripts is used to mange mongodb service with linux service type.
# created by zhaofx on 20161019.
PATH=/usr/local/mongodb/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=mongodb
start(){
/home/mongodb/scripts/mongodb_start.sh
}
stop(){
/home/mongodb/scripts/mongodb_stop.sh
}
test -x $DAEMON || exit 0
set -e
case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        *)
                N=/etc/init.d/$NAME
                echo "Usage: $N {start|stop}" >&2
                exit 1
                ;;
esac
exit 0

修改脚本的属组,添加执行权限:

chown -R mongodb:mongodb  /home/mongodb/scripts/
chown  mongodb:mongodb  /etc/init.d/mongodb
chmod +x  /home/mongodb/scripts/mongodb_start.sh
chmod +x  /home/mongodb/scripts/mongodb_stop.sh
chmod +x  /etc/init.d/mongodb

最后执行服务启动和停止mongodb实例的过程为:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/837f8e0606de11eff08e167001205cb5.html