1. 新建一个文件 vim /etc/init.d/Redis 2. 将下面内容粘贴到文件中 #!/bin/sh #chkconfig: 2345 90 10 #description: Redis is a persistent
vim /etc/init.d/Redis
#!/bin/sh
#chkconfig: 2345 90 10
#description: Redis is a persistent key-value database
PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis_6379.pid
CONF="/myredis/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
if [ "$?"="0" ]
then
echo "Redis is running..."
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$REDIS_CLI -p $REDISPORT SHUTDOWN
while [ -x ${PIDFILE} ]
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
REDISPORT=6379 # 端口号
EXEC=/usr/local/bin/redis-server # 执行脚本的地址
REDIS_CLI=/usr/local/bin/redis-cli # 客户端执行脚本的地址
PIDFILE=/var/run/redis_6379.pid # 进程id文件地址,启动redis后才能看见
CONF="/myredis/redis.conf" #配置文件地址
chmod 755 /etc/init.d/redis
/etc/init.d/redis start
Starting Redis server...
Redis is running...
chkconfig --add /etc/init.d/redis
chkconfig redis on
查看第一步的配置文件信息,是否和第二步的文件信息一致,vim粘贴会出现粘贴不全的问题
--结束END--
本文标题: Redis设置为开机自启动
本文链接: https://lsjlt.com/news/5196.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0