cd redis-5.0.6
cp redis.conf redis_6379.conf
vi redis_6379.conf
# 註釋掉它,以便讓外網訪問
# bind 127.0.0.1
# 關閉保護模式
protected-mode no
# Redis默認不是以守護進程的方式運行,可以通過該配置項修改,使用yes啓用守護進程
# 啓用守護進程後,Redis會把pid寫到一個pidfile中,在/var/run/redis.pid
daemonize yes
# 當Redis以守護進程方式運行時,Redis默認會把pid寫入/var/run/redis.pid文件,可以通過pidfile指定
pidfile /var/run/redis_6379.pid
# 指定Redis監聽端口,默認端口爲6379
# 如果指定0端口,表示Redis不監聽TCP連接
port 6379
# 工作目錄.
# 指定本地數據庫存放目錄,文件名由上一個dbfilename配置項指定
#
# Also the Append Only File will be created inside this directory.
#
# 注意,這裏只能指定一個目錄,不能指定文件名
# 設置密碼
requirepass ****
# dir /var/redis/6379
# 最後一行 /var/redis/6379 這個目錄還沒有,需要我們創建,用於存放redis的持久化文件。
設置開機自啓
cd /etc/init.d
touch redis
vi redis
複製以下代碼
#!/bin/sh
# chkconfig: 2345 10 90
# description: Start and Stop redis
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/opt/redis-5.0.6/redis_6379.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