04. 启停redis服务

栏目: 数据库 · 发布时间: 6年前

  • 启动

    • 查看redis.conf文件,可以通过general中的说明,配置通过systemd来启停 redis 和查看redis状态(作者没有采用,而是使用service管理,service配置参考《02. Instal redis on Linux》)

      • 这里直接说通过service启动命令: service redis_server start  #这里redis_server名称依据配置service是的init脚本名;配置文件使用路径查看redis_server脚本。

    • 其它启动方式:也可以编辑启动脚本来启动redis

      • 编辑启动脚本

shell>vi start-redis.sh
#!/bin/bash
source /etc/profile
REDIS_HOME=/ghca/redis-3.2.6
$REDIS_HOME/bin/redis-server $REDIS_HOME/etc/redis.conf
    • 直接使用服务可执行程序和配置文件路径 来启动redis

shell>$REDIS_HOME/bin/redis-server redis.conf        #即可,不过可以在启动命令总添加参数
  • 停止

    • 呼应启动第一条

      • service redis_server stop

    • 直接kill 进程号 (kill -15 PID)

    • 使用redis-cli客户端

shell>redis -h host/ip -p port SHUTDOWN
向redis-server端发送SHUTDOWN命令
  • 其提供脚本参考:自己写的启停redis-server脚本

#!/bin/sh
 
REDISPORT=6666
EXEC=./redis-server
CLIEXEC=./redis-cli
AUTHPASSWD='Passwd_By_Zjq;'  # 如果设置了密码,这里是需要设置的,因为利用redis-cli 发送shutdown信号需要提供密码。
 
PIDFILE=/ghca/redis/bin/redis_${REDISPORT}.pid
CONF="/ghca/redis/etc/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 -a $AUTHPASSWD -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

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Coding the Matrix

Coding the Matrix

Philip N. Klein / Newtonian Press / 2013-7-26 / $35.00

An engaging introduction to vectors and matrices and the algorithms that operate on them, intended for the student who knows how to program. Mathematical concepts and computational problems are motiva......一起来看看 《Coding the Matrix》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具