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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章