Redis安装(单机)

1.下载redis源代码,我的版本是4.0.9
官方下载地址:https://redis.io/download
或者此处下载:
链接:https://pan.baidu.com/s/1Xh756lygYXiz0SHSgg1zxQ 密码:1ey9
2.将redis源码拷贝到Linux中并解压
3.编译
需要提前安装好gcc相关的包( yum install -y open-ssl-devel gcc glibc gcc-c*)

[root@store01 redis-4.0.9]# cd /home/redis-4.0.9/
[root@store01 redis-4.0.9]# male MALLOC=libc
cd src && make install PREFIX=/usr/local/redis

此处可能会编译不成功并提示执行make test,可能会出现问题(如果成功编译,跳过此处):
Redis need tcl 8.5 or newer
解决方法为:

wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz  
sudo tar xzvf tcl8.6.1-src.tar.gz  -C /usr/local/  
cd  /usr/local/tcl8.6.1/unix/  
sudo ./configure  
sudo make  
sudo make install 

4.复制默认配置文件

mkdir -p /usr/local/redis/conf
cp /home/redis-4.0.9/redis.conf /usr/local/redis/conf/

5.启动redis

[root@store01 redis] cd /usr/local/redis
[root@store01 redis]# bin/redis-server ./conf/redis.conf 
58853:C 02 Apr 16:23:04.439 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
58853:C 02 Apr 16:23:04.439 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=58853, just started
58853:C 02 Apr 16:23:04.439 # Configuration loaded
58853:M 02 Apr 16:23:04.441 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 4.0.9 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 58853
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

58853:M 02 Apr 16:23:04.445 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/c/somaxconn is set to the lower value of 128.
58853:M 02 Apr 16:23:04.445 # Server initialized
58853:M 02 Apr 16:23:04.445 # WARNING overcommit_memory is set to 0! Background save may fail under low memory cition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'ctl vm.overcommit_memory=1' for this to take effect.
58853:M 02 Apr 16:23:04.445 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. Thisll create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernem/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after aboot. Redis must be restarted after THP is disabled.
58853:M 02 Apr 16:23:04.445 * Ready to accept connections

6.上面有三条WARNING信息
6.1.WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
解决方式:

第一种:无需重启系统即可生效;但重启以后信息丢失
[root@localhost ~]# echo 511 >/proc/sys/net/core/somaxconn

第二种:即可生效,重启不会丢失
1. 编辑/etc/sysctl.conf文件,在其后追加
net.core.somaxconn = 511

2. sysctl.conf生效
[root@localhost ~]# sysctl -p

6.2.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.
解决方法:

第一种:无需重启系统即可生效;但重启以后信息丢失
[root@localhost ~]# echo 1 > /proc/sys/vm/overcommit_memory

第二种:即可生效,重启不会丢失
1. 编辑/etc/sysctl.conf文件,在其后追加
vm.overcommit_memory=1

2. sysctl.conf生效
[root@localhost ~]# sysctl -p

6.3.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 > /sys/kernel/mm/transparent_hugepage/enabled’ as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
解决方式:
第一种方式我试了没起作用,所以用的第二种。

第一种方法:重启生效,不会丢失
1. 编辑/etc/rc.local,在最后新增如下内容:
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
   echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
2. 重新启动系统
[root@localhost redis]# reboot

第二种方法:及时生效,重启丢失
[root@localhost redis]# echo never > /sys/kernel/mm/transparent_hugepage/enabled

7.设置后台启动
现在redis不是后台启动的,当前用户关闭窗口或停止进程,redis会被关闭。
设置后台启动:

vi /usr/local/redis/conf/redis.conf 
修改其中的daemonize属性为 yes
再次启动redis:
redis-server /usr/local/redis/conf/redis.conf 

7.客户端连接
redis-cli
具体操作见参考[3]中。
参考blog:
[1]https://www.cnblogs.com/thomaschen750215/p/7206991.html
[2]https://www.cnblogs.com/wangchunniu1314/p/6339416.html
[3]https://www.cnblogs.com/xiewenming/p/7687364.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值