概述
1.复制/redis/utils/redis_init_script到/etc/init.d/
执行复制语句:
sudo cp /redis-stable/utils/redis_init_script /etc/init.d/redis
2.修改/etc/init.d/redis内容
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
### 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-server执行文件位置
EXEC=/usr/local/bin/redis-server
#设置redis-cli执行文件位置
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
#设置配置文件位置
CONF="/etc/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
;;
*)
echo "Please use start or stop as first argument"
;;
esac
此时能用service redis start
开启redis服务
3.设置redis服务开机自启
执行命令将redis服务加入开机启动队列
sudo update-rc.d redis defaults
最后
以上就是文艺铃铛为你收集整理的Ubuntu设置开机自启redis服务的全部内容,希望文章能够帮你解决Ubuntu设置开机自启redis服务所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复