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为初始化脚本文件)