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

继续执行

[root@localhost 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  
[root@localhost src]# cd ..
[root@localhost redis-4.0.11]# vim redis.conf 
#可通过查询命令:/daemonize 进行快速定位
daemonize yes   # 守护进程模式开启


[root@localhost redis-4.0.11]# cd src/
[root@localhost 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

#查看时候启动
[root@localhost 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命令杀死进程
[root@localhost redis-4.0.11]#  kill -9 7977

#设置redis开机自启动
[root@localhost etc]# mkdir redis
[root@localhost redis-4.0.11]# cp redis.conf /etc/redis/6379.conf
[root@localhost redis-4.0.11]# cp utils/redis_init_script /etc/init.d/redisd
[root@localhost redis-4.0.11]# cd /etc/init.d/
[root@localhost 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。

[root@localhost var]# service redisd start
#报错: /var/run/redis_6379.pid exists, process is already running or crashed
#[重要]如果是没有数据的情况下
[root@localhost var]# rm /var/run/redis_6379.pid
[root@localhost 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
[root@localhost 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

#客户端测试
[root@localhost redis]# cd /soft/redis-4.0.11
[root@localhost redis-4.0.11]# cd src/
[root@localhost src]# ./redis-cli 
127.0.0.1:6379> set "a" "valueA"
#OK
127.0.0.1:6379> get "a"
#"valueA"

猜你喜欢

转载自www.cnblogs.com/brokencolor/p/9938571.html