標籤:使用 io 檔案 for ar art cti 代碼 log
redis啟動分為兩種:開發環境、生產環境
一、開發環境
1、cd redis-2.8.13/src
2、 ./redis-server 啟動服務端
3、./redis-cli 啟動用戶端
二、生產環境(隨系統開機啟動)
1、配置redis初始化指令碼(樣本在/redis-2.8.13/utils/下),並放在/etc/init.d/下(命名為redis_6379)
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
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
如何修改此初始化指令檔:修改redis服務端要監聽的連接埠號碼:6379(預設)
二、在/etc目錄下建立目錄:/etc/redis 和 /var/redis/6379,並存放相應的檔案
1、/etc/redis/ 存放設定檔,命名為6379.cof (模板在原始碼目錄/redis-2.8.13/)
edis configuration file example
daemonize no //修改為yes 使redis以守護進程模式啟動
pidfile /var/run/redis.pid //修改為/var/run/redis_6379.pid 設定redis的PID檔案的路徑
port 6379 //修改為6379 監聽連接埠號碼
timeout 0
loglevel notice
logfile ""
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir ./ //修改為/var/redis/6379 設定持久化檔案的路徑
slave-serve-stale-data yes
slave-read-only yes
repl-disable-tcp-nodelay no
slave-priority 100
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
lua-time-limit 5000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
2、在/var/redis/連接埠號碼 目錄下存放 持久化檔案 (使用該組件時在存放)
3、sudo update-rc.d redis_6379 defaults (配置隨機啟動命令 redis_6379為初始化指令檔)
redis啟動過程