1. 程式人生 > >centos7.5 安裝 redis-4.0.11

centos7.5 安裝 redis-4.0.11

1.下載redis包

wget wget http://download.redis.io/releases/redis-4.0.11.tar.gz

2.解壓安裝

#解壓
tar zxvf redis-4.0.11.tar.gz
#安裝
 cd redis-4.0.11
#執行make

#執行make時報錯:/bin/sh: cc: command not found--如果沒報錯可跳過

sudo yum -y install gcc gcc-c++ libstdc++-devel

##報錯
# make[1]: Entering directory `/opt/redis-2.6
.14/src' # CC adlist.o # In file included from adlist.c:34: # zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory # zmalloc.h:55:2: error: #error "Newer version of jemalloc required" # make[1]: *** [adlist.o] Error 1 # make[1]: Leaving directory `/opt/redis-2.6.14/src' # make: *** [all] Error 2
#執行 make MALLOC=libc #執行完上面的命令後,系統提示 'Hint: To run 'make test' is a good idea' make test #報錯: You need tcl 8.5 or newer in order to run the Redis test #安裝tcl sudo yum install tcl

繼續執行

[[email protected] redis-4.0.11]# cd src && make install

#Hint: It's a good idea to run 'make
test' ;) # INSTALL install # INSTALL install # INSTALL install # INSTALL install # INSTALL install #看到顯示INSTALL install說明成功

3.驗證啟動redis-server

換到redis src目錄下
 cd src
 ./redis-server
 
#7965:C 07 Nov 10:38:19.858 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
#7965:C 07 Nov 10:38:19.858 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=7965, just started
#7965:C 07 Nov 10:38:19.858 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
#7965:M 07 Nov 10:38:19.860 * Increased maximum number of open files to 10032 (it was originally set to 1024).
#                _._                                                  
#           _.-``__ ''-._                                             
#      _.-``    `.  `_.  ''-._           Redis 4.0.11 (00000000/0) 64 bit
#  .-`` .-```.  ```\/    _.,_ ''-._                                   
# (    '      ,       .-`  | `,    )     Running in standalone mode
# |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
# |    `-._   `._    /     _.-'    |     PID: 7965
#  `-._    `-._  `-./  _.-'    _.-'                                   
# |`-._`-._    `-.__.-'    _.-'_.-'|                                  
# |    `-._`-._        _.-'_.-'    |           http://redis.io        
#  `-._    `-._`-.__.-'_.-'    _.-'                                   
# |`-._`-._    `-.__.-'    _.-'_.-'|                                  
# |    `-._`-._        _.-'_.-'    |                                  
#  `-._    `-._`-.__.-'_.-'    _.-'                                   
#      `-._    `-.__.-'    _.-'                                       
#          `-._        _.-'                                           
#              `-.__.-'                                               
#
#7965:M 07 Nov 10:38:19.863 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
#7965:M 07 Nov 10:38:19.863 # Server initialized
#7965:M 07 Nov 10:38:19.863 # 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.
#7965:M 07 Nov 10:38:19.863 # 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.
#7965:M 07 Nov 10:38:19.863 * Ready to accept connections
#

4.配置

(1)配置為redis-server守護程序(即啟動不會被redis-server佔用視窗導致我們無法幹別的事情)

#修改redis.conf  
[[email protected] src]# cd ..
[[email protected] redis-4.0.11]# vim redis.conf 
#可通過查詢命令:/daemonize 進行快速定位
daemonize yes   # 守護程序模式開啟


[[email protected] redis-4.0.11]# cd src/
[[email protected] src]# ./redis-server ../redis.conf
#7976:C 07 Nov 10:52:22.184 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
#7976:C 07 Nov 10:52:22.184 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=7976, just started
#7976:C 07 Nov 10:52:22.184 # Configuration loaded

#檢視時候啟動
[[email protected] src]# ps -aux|grep redis
#root       2835  0.0  0.1 150932  1540 pts/0    T    09:46   0:00 wget http://download.redis.io/releases/redis-4.0.11.tar.gz
#root       7977  0.0  0.2 141836  2040 ?        Ssl  10:52   0:00 ./redis-server 127.0.0.1:6379
#root       7982  0.0  0.0 112720   984 pts/0    R+   10:53   0:00 grep --color=auto redis

(2)設定redis開機自啟動

#使用kill命令殺死程序
[[email protected] redis-4.0.11]#  kill -9 7977

#設定redis開機自啟動
[[email protected] etc]# mkdir redis
[[email protected] redis-4.0.11]# cp redis.conf /etc/redis/6379.conf
[[email protected] redis-4.0.11]# cp utils/redis_init_script /etc/init.d/redisd
[[email protected] redis-4.0.11]# cd /etc/init.d/
[[email protected] init.d]# chkconfig redisd on

#service redisd does not support chkconfig

#解決方法:
#使用vim編輯redisd檔案,在第一行加入如下兩行註釋,儲存退出

# chkconfig:   2345 90 10
# description:  Redis is a persistent key-value database

#註釋的意思是,redis服務必須在執行級2,34,5下被啟動或關閉,啟動的優先順序是90,關閉的優先順序是10。

[[email protected] var]# service redisd start
#報錯: /var/run/redis_6379.pid exists, process is already running or crashed
#[重要]如果是沒有資料的情況下
[[email protected] var]# rm /var/run/redis_6379.pid
[[email protected] redis]# service redisd start
#Starting Redis server...
#8206:C 07 Nov 11:31:26.807 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
#8206:C 07 Nov 11:31:26.807 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=8206, just started
#8206:C 07 Nov 11:31:26.807 # Configuration loaded
[[email protected] redis]# ps -aux|grep redis
#root       8207  0.0  0.1  38240  1988 ?        Ssl  11:31   0:00 /usr/local/bin/redis-server 127.0.0.1:6379
#root       8212  0.0  0.0 112720   984 pts/0    R+   11:31   0:00 grep --color=auto redis

測試一下redis-cli

#客戶端測試
[[email protected] redis]# cd /soft/redis-4.0.11
[[email protected] redis-4.0.11]# cd src/
[[email protected] src]# ./redis-cli 
127.0.0.1:6379> set "a" "valueA"
#OK
127.0.0.1:6379> get "a"
#"valueA"