创建redis启动脚本
[root@node03 init.d]# touch?redis?
编辑redis启动脚本
注意:redis的安装路径: /root/redis/,按照实际安装路径来即可。
#!/bin/sh
#
# chkconfig: 2345 10 90
# description: Start and Stop redis
### BEGIN INIT INFO
# Provides: redis_6379
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Redis data structure server
# Description: Redis data structure server. See https://redis.io
### END INIT INFO
REDISPORT=6379 #redis的默认端口,要和下文中的redis.conf中一致
EXEC=/root/redis/bin/redis-server #redis服务端的命令
CLIEXEC=/root/redis/bin/redis-cli #redis客户端的命令
PIDFILE=/var/run/redis_${REDISPORT}.pid #reids的进程文件生成的位置
CONF="/root/redis/bin/redis.conf" #redis的配置文件所在的目录
#AUTH="1234" 这句没什么用可以不要
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|force-reload)
${0} stop
${0} start
;;
*)
echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
exit 1
esac
给启动脚本赋权限
[root@node03 init.d]#?chmod +777 redis?
启动redis服务
[root@node03 init.d]#?service redis start
|