Redis开机启动
拷贝初始化脚本
拷贝redis/utils/redis_init_script到系统开机启动文件夹etc/init.d下。
cp /usr/local/redis-4.0.2/utils/redis_init_script /etc/init.d/redis
修改Redis安装路径
修改/etc/init.d/redis文件内EXEC、CLIEXEC和CONF为对应的redis安装路径。
#
# Simple Redis init.d script conceived to work on Linux systems
# assit 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
EXEC=/home/admin/redis-5.0.9/src/redis-server
CLIEXEC=/home/admin/redis-5.0.9/src/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="home/admin/redis-5.0.9/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
3、开机启动设置,执行一下命令:
- 添加redis服务:
chkconfig --add redis
- 设为开机启动 :
chkconfig redis on
- 打开redis命令:
service redis start
- 关闭redis命令:
service redis stop
4、redis启动状态检查
运行脚本,能看到下方图片中所示的127.0.0.1:6379的进程,就说明服务启动了。
ps aux | grep redis