CentOS開機啓動redis

創建自啓動腳本:redis

vi /etc/init.d/redis

輸入以下內容:tomcat

#!/bin/bash
#
# tomcat startup script for the redis server
#
# chkconfig: 2345 90 10
# description: start the redis deamon
#
# Source function library
. /etc/rc.d/init.d/functions
 
#腳本名稱
prog=redis

#redis安裝目錄、配置目錄
REDIS_HOME=/usr/local/bin
REDIS_HOME_CONFIG=/usr/redis
export REDIS_HOME
export REDIS_HOME_CONFIG

#PID_FILE檢測
REDIS_PID_FILE=/var/run/redis_6379.pid

#服務命令行
REDIS_EXEC_CLI=$REDIS_HOME/redis-cli
export REDIS_EXEC_CLI

#服務器端口
REDIS_PORT=6379

#服務器配置
REDIS_CONFIG=$REDIS_HOME_CONFIG/redis.conf

#服務啓動命令
REDIS_EXEC_START=$REDIS_HOME/redis-server
#export REDIS_EXEC_START

#服務關閉命令
REDIS_EXEC_STOP=$REDIS_EXEC_CLI
#export REDIS_EXEC_STOP


case "$1" in   
    start)
    if [ -f $REDIS_PID_FILE ]
    then
        echo "$REDIS_PID_FILE exists, process is already running or crashed"
    else
        echo "Starting Redis server..."  
        $REDIS_EXEC_START $REDIS_CONFIG
    fi
    ;;   
    
    stop)
    if [ ! -f $REDIS_PID_FILE ]
    then
        echo "$REDIS_PID_FILE does not exists, process is not running"
    else
        PID=$(cat $REDIS_PID_FILE)
        echo "Stopping Redis server..."
        $REDIS_EXEC_STOP -p $REDIS_PORT shutdown
        while [ -x /proc/${PID} ]
        do
            echo "Waiting for Redis to shutdown ..."
            sleep 1
        done
        echo "Redis stopped"
    fi
    ;;   
    
    restart)
    ${0} stop
    ${0} start
    ;;   
*)   
    echo "Usage: $prog {start|stop|restart}" 
    ;; 
esac
exit 0

修改文件爲可運行文件:bash

chmod a+x redis

查看redis開機啓動狀況:服務器

chkconfig --list

如沒有,則添加到系統啓動隊列中:命令行

chkconfig --add redis

從新檢查redis開機啓動狀況,若成功,則應顯示以下內容:rest

redis 0:off 1:off 2:on 3:on 4:on 5:on 6:offcode

 

使用下列命令對redis進行重啓、中止、啓動:server

service redis restart/stop/start/force-reload

 

修改redis綁定機器ip,以便redis desktop manager鏈接隊列

vi /usr/redis/redis.conf
bind 127.0.0.1 192.168.0.248
相關文章
相關標籤/搜索