您好,登錄后才能下訂單哦!
有感:
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 ~]#
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。