2024-02-02
藏龙卧虎
00
请注意,本文编写于 311 天前,最后修改于 311 天前,其中某些信息可能已经过时。

目录

简介

简介

在 linux 服务器上,有时需要手动安装 Redis,为了便捷管理 Redis 并设置开机自启,可以尝试使用本脚本。

PS:不保证能够直接使用,请根据自身情况自行修改。

sh
#! /bin/sh # chkconfig: 2345 10 90 # Description: Startup script for redis webserver on Debian. Place in /etc/init.d and # run 'update-rc.d -f redis defaults', or use the appropriate command on your # distro. For CentOS/Redhat run: 'chkconfig --add redis' ### BEGIN INIT INFO # Provides: redis # Required-Start: $all # Required-Stop: $all # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: starts the redis web server # Description: starts redis using start-stop-daemon ### END INIT INFO PATH=/usr/local/redis/bin:/sbin:/bin # 本机存放redis命令的目录 FilePath=/usr/local/redis # 文件地址 REDISPORT=6379 # redis的默认端口,与redis.conf中一致 SERVER=$FilePath/bin/redis-server # redis服务端 CLIENT=$FilePath/bin/redis-cli # redis客户端 PIDFILE=$FilePath/logs/redis.pid # reids的进程文件生成的位置 CONF=$FilePath/conf/redis.conf # redis的配置文件所在的目录 case "$1" in start) if [ -f $PIDFILE ];then echo "$PIDFILE exist, process is already running." exit 1 else echo "Starting Redis server..." $SERVER $CONF fi if [ "$?"="0" ];then echo "Redis started successfully" exit 1 else echo "Redis started failed" fi ;; stop) if [ ! -f $PIDFILE ];then echo "$PIDFILE doesn't exist, process is not running." exit 1 else PID=$(cat $PIDFILE) echo "Stopping Redis server..." $CLIENT -p $REDISPORT SHUTDOWN sleep 1 while [ -x $PIDFILE ] do echo "Waiting for Redis to shutdown..." sleep 1 done echo "Redis stopped" fi ;; restart|force-reload) $0 stop sleep 2 $0 start ;; *) echo "Usage: $0 {start|stop|restart|force-reload}" exit 1 ;; esac
如果对你有用的话,可以打赏哦
打赏
ali pay
wechat pay

本文作者:DingDangDog

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!