设置持久化目录
默认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是被注释的,如果需要请取消注释并填写正确的值。
其他管理工具请参考