1、安装前的准备工作
redis的安装需要系统上已经安装了gcc和tcl,进入/usr/local,目录,然后默认安装即可
yum install tcl
yum install gcc
2、下载redis,解压缩,进入目录后进行编译
wget http://download.redis.io/releases/redis-5.0.4.tar.gz
tar xzf redis-5.0.4.tar.gz
cd redis-5.0.4
make
3、进入src,然后开启服务,你会发现有报错,报错可能有以下几种情况,不要慌,跟着错误提示一步步解决就可以了
3.1 Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf,启动时没有指明配置文件,启动命令,指明配置文件
./redis-server ../redis.conf
3.2 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.
vim /etc/sysctl.conf
将下面一行添加到配置文件中
vm.overcommit_memory = 1
然后,让配置生效
sysctl -p
3.3 you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix thisissue run the command ‘echo never > /sys/kernel/mm/transparent_hugepage/enabled’ as root, and add it to your /etc/rc.local in order to retain thesetting after a reboot. Redis must be restarted after THP is disabled.
将
echo never > /sys/kernel/mm/transparent_hugepage/enabled
添加到
/etc/rc.local
中,然后执行
source /etc/rc.local
生效配置。
4、等到报错问题都解决,还需要将redis的启动方式改为后台启动
vim /usr/local/redis-5.0.4/redis.conf
然后修改
daemonize yes
然后再次启动,添加刚刚修改的配置文件就可以了。
./redis-server ../redis.conf
5、如果需要远程链接,还需要将配置文件做如下修改
vim /usr/local/redis-5.0.4/redis.conf
将bind 127.0.0.1
注释掉,这句的意思时redis只能本地链接
将protected-mode yes
,修改为no,关闭保护模式
6、redis服务更新配置文件后需要关闭重启,直接重新开启是不行的
redis-cli -h 127.0.0.1 -p 6379 shutdown //停止服务
如果发现redis-cli命令找不到就将redis-cli复制到/usr/local/bin/目录中
sudo cp src/redis-cli /usr/local/bin/