docker centos yum 安装redis并设置自启动
yum 安装redis后,主要文件位置如下:
/usr/bin/redis-cli
/usr/bin/redis-server
/etc/redis.conf
/etc/init.d/redis
要设置redis自启动
1、编辑/etc/init.d/redis脚本如下:
#!/bin/sh
# chkconfig: 2345 10 90
# description: Start and Stop redis
REDISPORT=6379
EXEC=/usr/redis/redis-3.2.4/src/redis-server
CLIEXEC=/usr/redis/redis-3.2.4/src/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/usr/redis/redis-3.2.4/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
;;
restart)
"$0" stop
sleep 3
"$0" start
;;
*)
echo "Please use start or stop or restart as first argument"
;;
esac
2、然后还需要设置
[root@1b6b19c9df4f /]# chkconfig redis on
Note: Forwarding request to 'systemctl enable redis.service'.
Synchronizing state of redis.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable redis
Created symlink /etc/systemd/system/multi-user.target.wants/redis.service → /usr/lib/systemd/system/redis.service.
参考 https://www.cnblogs.com/skyessay/p/6433349.html

centos 版本:
[root@1b6b19c9df4f /]# cat /etc/redhat-release
CentOS Linux release 8.3.2011