redis持久化目錄設置,設置開機自啓與web端管理工具

設置持久化目錄

默認rdb和aof文件的目錄是./,以不同位置的腳本啓動redis,這些文件的位置都會改變,因此我們需要設置一個固定的位置,打開redis.conf,修改dir的對應位置即可。

rdbchecksum yes

# The filename where to dump the DB
dbfilename dump.rdb

# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir 需要的存儲位置

設置redis服務器開機啓動

redis已經提供了一個開機自啓的腳本範例,redis安裝目錄/utils/redis-init-script。我們只需要稍加修改即可(REDISPORT,EXEC,CLIEXEC,PIDFILE,CONF幾個參數的值,修改爲安裝和配置時對應的參數即可)。

# Provides:     redis_6379
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    Redis data structure server
# Description:          Redis data structure server. See https://redis.io
### END INIT INFO

REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.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 -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

設置完腳本後,copy一份到/etc/init.d中,命令爲redis,然後通過chkconfig設置開機自啓。

sudo chkconfig redis on

Web端管理工具phpRedisAdmin

下載地址

README中安裝方法已經介紹的很詳細了,有一點需要補充說明的是,當你redis已非默認設置的時候,例如新增了密碼,改變了端口等等,記得更改phpredisadmin安裝目錄/includes/config.sample.inc.php(如果你copy了一份命令爲config.inc.php,記得修改它,因爲它的優先級高於config.sample.inc.php)中的對應的參數,默認auth是被註釋的,如果需要請取消註釋並填寫正確的值。
其他管理工具請參考

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章