时间:2022-12-06 02:00
redis开机自启动的方法:1、打开终端;2、输入命令编写脚本;3、将代码复制到脚本中;4,、输入命令保存退出,设置权限;5、输入命令启动redis即可。
具体操作步骤:
1、首先打开终端命令行模式。
2、输入以下命令编写脚本。
vi /etc/init.d/redis
3、将以下代码复制到脚本中。
#!/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
4、输入以下命令保存退出并设置权限。
chmod 777 /etc/init.d/redis
5、输入以下命令启动redis服务即可。
service redis start
相关操作命令:
/usr/local/bin/redis-server #启动redis服务
/home/data/redis-3.2.1/redis.conf #启动redis服务
./redis-cli -p 6379 shutdown #关闭redis服务,-p参数指定端口号