redis设置开机启动
时间:2019-01-14 15:28 来源:未知 作者:IT
1.编写脚本
vi /etc/init.d/redis
2.复制下面代码到脚本中
注意要修改成自己的redis的安装路径和自己的conf文件存放路径
也就是修改第 6、7、10 行
这里我以 /opt/redis-3.2.5/路径为例
#!/bin/sh
# chkconfig: 2345 10 90
# description: Start and Stop redis
REDISPORT=6379
EXEC=/opt/redis-3.2.5/src/redis-server
CLIEXEC=/opt/redis-3.2.5/src/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/opt/redis/redis.conf"
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF &
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
restart)
"$0" stop
sleep 3
"$0" start
;;
*)
echo "Please use start or stop or restart as first argument"
;;
esac
3.保存退出,设置权限
chmod 777 /etc/init.d/redis
4.启动redis
并设置开机自启
打开redis命令:service redis start
关闭redis命令:service redis stop
设为开机启动:chkconfig redis on
设为开机关闭:chkconfig redis off
5、重启linux之后
ps -ef |grep redis
(责任编辑:IT)
1.编写脚本
vi /etc/init.d/redis
2.复制下面代码到脚本中
注意要修改成自己的redis的安装路径和自己的conf文件存放路径
也就是修改第 6、7、10 行
这里我以 /opt/redis-3.2.5/路径为例
#!/bin/sh
# chkconfig: 2345 10 90
# description: Start and Stop redis
REDISPORT=6379
EXEC=/opt/redis-3.2.5/src/redis-server
CLIEXEC=/opt/redis-3.2.5/src/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/opt/redis/redis.conf"
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF &
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
restart)
"$0" stop
sleep 3
"$0" start
;;
*)
echo "Please use start or stop or restart as first argument"
;;
esac
3.保存退出,设置权限
chmod 777 /etc/init.d/redis
4.启动redis
并设置开机自启
打开redis命令:service redis start
关闭redis命令:service redis stop
设为开机启动:chkconfig redis on
设为开机关闭:chkconfig redis off
5、重启linux之后
ps -ef |grep redis
|