CentOS编译安装redis

下载解压

1
2
wget http://download.redis.io/releases/redis-3.2.9.tar.gz
tar zxvf redis-3.2.9.tar.gz -C /usr/src

编译安装

1
2
cd /usr/src/redis-3.2.9/
make PREFIX=/data/reids install

配置

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
echo "PATH=$PATH:/data/redis/bin" >> /etc/profile
source /etc/profile
./utils/install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path [/data/redis/bin/redis-server]
Selected config:
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /var/log/redis_6379.log
Data dir : /var/lib/redis/6379
Executable : /data/redis/bin/redis-server
Cli Executable : /data/redis/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!

启动警告错误

用这个脚本管理之前,需要先配置下面的内核参数,否则Redis脚本在重启或停止redis时,将会报错,并且不能自动在停止服务前同步数据到磁盘上:

1
2
3
4
5
6
7
8
9
#WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
echo 1 > /proc/sys/vm/overcommit_memory
echo "vm.overcommit_memory = 1 " >> /etc/sysctl.conf
sysctl -p
#WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/enabled >> /etc/rc.local
#WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
echo 511 > /proc/sys/net/core/somaxconn

默认监听的端口是本地,如果要远程连接要修改配置

/etc/redis/6379.conf```
1
2
```
bind 0.0.0.0

修改之后重启服务

1
/etc/init.d/redis_6379 restart

测试

$ redis-cli 
redis 127.0.0.1:6379> ping 
PONG 
redis 127.0.0.1:6379> set foo bar
redis 127.0.0.1:6379> get foo 
bar
坚持原创技术分享,您的支持将鼓励我继续创作!