您的位置:首页 > 数据库 > Redis

CentOS_6.5安装Redis_3.0.2

2016-10-12 11:16 501 查看
1.解压、编译、安装redis-3.0.2
tar zxvf redis-3.0.2.tar.gz -C /usr/local/redis/
cd /usr/local/redis/
make && make install
2.创建redis相关目录
mkdir -p /usr/local/redis/log
mkdir -p /usr/local/redis/pid
mkdir -p /usr/local/redis/db
3.编辑redis.conf配置文件
cp redis.conf /etc/redis.conf
vim /etc/redis.conf
daemonize yes
pidfile /usr/local/redis/pid/redis.pid
port 6379
tcp-backlog 511
timeout 600
tcp-keepalive 0
loglevel notice
logfile /usr/local/redis/log/redis.log
databases 16
save 900 1
save 300 10
save 60 10000
rdbcompression yes
dbfilename dump.rdb
dir /usr/local/redis/db
slave-serve-stale-data yes
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
slowlog-log-slower-than 10000
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
4.创建redis服务脚本,并赋予权限
vim /etc/init.d/redis
#!/bin/sh
#chkconfig:        2345 60 40
#Description:        Start and Stopredis
#Provides:        redis
# Default-Start:    2 3 4 5
#Default-Stop:        0 1 6
PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli
PIDFILE=/usr/local/redis/pid/redis.pid
CONF="/etc/redis.conf"
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already runningor crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
if [ "$?"="0" ]
then
echo "Redis is running..."
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is notrunning"
else
PID=$(cat $PIDFILE)
echo "Stopping Redis server..."
$REDIS_CLI -p $REDISPORT SHUTDOWN
while [ -x ${PIDFILE} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis is stopped"
fi
;;
restart|force-reload)
${0} stop
${0} start
;;
*)
echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}">&2
exit 1
esac
5.添加redis服务开机启动
chmod a+x /etc/init.d/redis
chkconfig --add redis
chkconfig --level 2345 redis on
chkconfig --list | grep redis
6.启动redis服务
service redis start
ps -aux | grep redis
netstat -anptu | grep 6379
7.防火墙启用6379端口
iptables -A INPUT -p tcp --dport 6379 -j ACCEPT
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  安装 配置 centos