Redis的多种发动方法比较!51CTO博客 - 乐橙lc8

Redis的多种发动方法比较!51CTO博客

2019-01-03 10:43:11 | 作者: 碧萱 | 标签: 发动,装备,自己 | 浏览: 2533

有感:

Redis玩了良久时刻,诚心感觉发动方法仍是自己界说的便利!


1)直接发动和封闭:(装备文件默许)

敞开:redis-server &(&后台运转)

#daemonize yes(也可装备文件修正此参数)

封闭:redis-cli shutdown or killall -9 redis-server

 

2)指定装备文件发动:

redis-server /etc/redis.conf(装备文件可自己界说)

假如更改了redis默许端口:

redis-cli shutdown (-p 端口)

redis-cli shutdown (-p 端口) (-a 认证暗码)


3)自己界说发动文件并装备(引荐)

[root@redis1 ~]# cpredis-2.8.24/utils/redis_init_script /etc/init.d/redis

注册为体系效劳:

[root@redis1 ~]# sed -i 2i #chkconfig:2345 80 90 /etc/init.d/redis

[root@redis1 ~]# chkconfig --add redis

修正装备文件(由于途径自己界说,sed也能够)

REDISPORT=7000  #留意slave端口自己界说即可

EXEC=/usr/local/redis/bin/redis-server

CLIEXEC=/usr/local/redis/bin/redis-cli

 

PIDFILE=/var/run/redis_${REDISPORT}.pid

CONF="/etc/redis/${REDISPORT}.conf"


脚本如下(自己装备的,我们也可在此基础上进行修正)

#!/bin/sh
#chkconfig: 2345 80 90
# Simple Redis init.d script conceivedto work on Linux systems
# as it does use of the /procfilesystem.
 
REDISPORT=7000
EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/usr/local/redis/bin/redis-cli
 
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"
 
case "$1" in
   start)
       if [ -f $PIDFILE ]
       then
                echo -e "\033[31m $PIDFILEexists, process is already running or crashed \033[0m"
       else
                echo -e "\033[32m Waitingfor Redis to start...\033[0m"
                $EXEC $CONF
                if [ $? -eq 0 ]
                then
                echo -e "\033[32m Redis isalready started successfully! \033[0m"
                else
                echo -e "\033[31m Redisstart fail \033[0m"
                fi
       fi
       ;;
   stop)
       if [ ! -f $PIDFILE ]
       then
                echo -e "\033[31m $PIDFILEdoes not exist, process is not running \033[0m"
       else
                PID=$(cat $PIDFILE)
                echo -e "\033[32m Waitingfor Redis to stop ... \033[0m"
                $CLIEXEC -p $REDISPORT  shutdown
                while [ -x /proc/${PID} ] 
                do
                    echo -e "\033[32mWaiting for Redis to shutdown ... \033[0m"
                   sleep 1
                done
                echo -e "\033[32m Redis isalready stopped successfully! \033[0m"
       fi
       ;;
   status)
                 ps aux|grep redis-server|grep-v grep &>/dev/null
                 if [ $? -eq 0 ]
                 then
                 echo -e "\033[32m Redisis running... \033[0m"
                 else
                 echo -e "\033[31m Redisis already stopped \033[0m"
                 fi
                 ;;
   restart)
               $CLIEXEC -p $REDISPORT  shutdown
               if [ $? -eq 0 ]
               then
               echo -e "\033[32m Redis isalready stopped successfully! \033[0m"
               else 
               echo -e "\033[31m Redisstop fail \033[0m"
               fi
               $EXEC $CONF
               if [ $? -eq 0 ]
               then
               echo -e "\033[32m Redis isalready started successfully! \033[0m"
               else
               echo -e "\033[31m Redisstart fail \033[0m"
               fi
               ;;
    *)
     echo "the usage is service redis start|stop|status|restart"
     esac

检查redis状况,发动,封闭,重启

[root@redis1 ~]# /etc/init.d/redis status
 Redis is running... 
[root@redis1 ~]# /etc/init.d/redis stop
 Waiting for Redis to stop ... 
 Waiting for Redis to shutdown ... 
 Redis is already stopped successfully! 
[root@redis1 ~]# /etc/init.d/redis start
 Waiting for Redis to start...
 Redis is already started successfully! 
[root@redis1 ~]# /etc/init.d/redis restart
 Redis is already stopped successfully! 
 Redis is already started successfully! 
[root@redis1 ~]#
[root@redis1 ~]# ps aux|grep redis-server|grep -v grep
root       2881  0.1  0.1 128296  1692 ?        Ssl  12:45   0:01 /usr/local/redis/bin/redis-server *:7000              
[root@redis1 ~]#



版权声明
本文来源于网络,版权归原作者所有,其内容与观点不代表乐橙lc8立场。转载文章仅为传播更有价值的信息,如采编人员采编有误或者版权原因,请与我们联系,我们核实后立即修改或删除。

猜您喜欢的文章