拷贝utils目录下的redis_init_script到/etc/init.d目录下
cp ./redis_init_script /etc/init.d/redis
编辑/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.
# 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
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/bin:/root/bin
REDISPORT=6379
EXEC=/app/redis-5.0.7/redis/redis-server
CLIEXEC=/app/redis-5.0.7/redis/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/app/redis-5.0.7/redis/redis.conf"
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
;;
*)
echo "Please use start or stop as first argument"
;;
esac
保存,退出
给编辑好的配置文件设置权限
chmod 755 redis
测试一下是否能够通过该配置文件启动成功
/etc/init.d/redis start
启动成功
设置开机自启动
chkconfig redis on
reboot重启虚拟机,在可执行文件下使用redis-cli客户端命令测试连接成功
遇到的问题
持续更新中...