当前位置: 移动技术网 > IT编程>数据库>MongoDB > 04. 启停redis服务

04. 启停redis服务

2019年02月21日  | 移动技术网IT编程  | 我要评论

好上居,黄长健,织缘网

  • 启动
    • 查看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

 

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网