centos5.9下安装redis

本文描述了如何在centos5.9环境下安装redis

安装编译环境

安装编译器

安装编译器gcc
1
yum install gcc gcc-c++ kernel-devel

安装jemalloc

安装jemalloc
1
2
3
4
5
6
wget http://www.canonware.com/download/jemalloc/jemalloc-3.3.1.tar.bz2
tar xfvj jemalloc-3.3.1.tar.bz2
cd jemalloc-3.3.1
./configure
make
make install

安装tcl

安装tcl
1
2
3
4
5
6
wget http://prdownloads.sourceforge.net/tcl/tcl8.6.0-src.tar.gz
tar xfvz tcl8.6.0-src.tar.gz
cd tcl8.6.0/unix
./configure
make
make install

安装redis

安装redis
1
2
3
wget http://redis.googlecode.com/files/redis-2.6.13.tar.gz
tar xvfz redis-2.6.13.tar.gz
cd redis-2.6.13

修改文件

安装redis
1
2
make test
make

若make失败请做如下修改

Makefile开头加 CFLAGS= -march=i686
src/.make_settings里的OPT,改为OPT=-O2  -march=i686

make test会卡住, 忽略之

配置redis

/etc/init.d/redis_6379
1
2
3
4
5
6
7
sudo cp src/redis-server /usr/local/bin/
sudo cp src/redis-cli /usr/local/bin/
mkdir /etc/redis
mkdir /var/redis
cp utils/redis_init_script /etc/init.d/redis_6379
cp redis.conf /etc/redis/6379.conf
mkdir /var/redis/6379

vim /etc/redis/6379.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
daemonize yes
pidfile /var/run/redis.pid
port 6379
timeout 0
tcp-keepalive 0
loglevel notice
logfile /var/log/redis_6379.log
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
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
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
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
#绑定ip
#bind 127.0.0.1

启动redis

1
redis-server /etc/redis/6379.conf

测试

1
2
3
redis-cli
redis 127.0.0.1:6379> ping
PONG