本地环境:Centos 7.6

 

https://redis.io/download

在官网找了半天只有5.0  6.0的下载地址,没有找到4.0的下载址,

http://www.redis.cn/download.html

redis中文网上才找到下载地址。

 

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

tar xvf redis-4.0.11.tar.gz -C /usr/local/

cd /usr/local/redis-4.0.11/

make

 

 

提示这些表示安装完成:

Hint: It's a good idea to run 'make test' ;)

make[1]: Leaving directory `/usr/local/redis-4.0.11/src'

[root@iZ8vbdjpjvhsbz4w10d7rhZ redis-4.0.11]# src/redis-server    #启动数据库

 

新开一个窗口,连接写入查询数据库

[root@iZ8vbdjpjvhsbz4w10d7rhZ redis-4.0.11]# /usr/local/redis-4.0.11/src/redis-cli 
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set a 1
OK
127.0.0.1:6379> get a
"1"
127.0.0.1:6379>

 

将  /usr/local/redis-4.0.11/src/ 目录添加到PATH环境变量中

vi ~/.bash_profile 

PATH=$PATH:/usr/local/redis-4.0.11/src/

source  ~/.bash_profile 

 

看下redis-server 命令行参数

[root@iZ8vbdjpjvhsbz4w10d7rhZ redis-4.0.11]# src/redis-server --help
Usage: ./redis-server [/path/to/redis.conf] [options]
       ./redis-server - (read config from stdin)
       ./redis-server -v or --version
       ./redis-server -h or --help
       ./redis-server --test-memory <megabytes>

Examples:
       ./redis-server (run the server with default conf)  #不加参数会加载默认的conf配置文件
       ./redis-server /etc/redis/6379.conf          #指定某个conf配置文件
       ./redis-server --port 7777                #指定端口号,这个参数在conf配置文件中也有
       ./redis-server --port 7777 --slaveof 127.0.0.1 8888  #指定端口号和主库的IP地址、端口号
       ./redis-server /etc/myredis.conf --loglevel verbose   #指定配置文件,同时指定loglevel参数值为 verbose
Sentinel mode: ./redis-server /etc/sentinel.conf --sentinel   #以哨兵的模式启动,后续会写

可以看到,参数可以显式的在运行redis-server时指定,如果显式指定的参数与配置文件中的参数值不同,则以显式指定的参数值为准。

 

编辑配置文件,修改如下几个参数

 

vi /usr/local/redis-4.0.11/redis.conf



bind 0.0.0.0    #允许所有IP连接redis数据库

appendonly yes    #开启aof日志

dir /usr/local/redis-4.0.11  #指定rdb生成的文件目录,这个参数默认值是./ 意味着rdb文件会生成在redis-server运行时的目录下。

保存退出,再次启动,可以看到启动执行

[root@iZ8vbdjpjvhsbz4w10d7rhZ redis-4.0.11]# redis-server /usr/local/redis-4.0.11/redis.conf
16989:C 16 May 17:11:35.859 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
16989:C 16 May 17:11:35.859 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=16989, just started
16989:C 16 May 17:11:35.859 # Configuration loaded
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 4.0.11 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 16989
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'

16989:M 16 May 17:11:35.860 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
16989:M 16 May 17:11:35.860 # Server initialized
16989:M 16 May 17:11:35.860 # 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.
16989:M 16 May 17:11:35.860 # 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.
16989:M 16 May 17:11:35.860 * Ready to accept connections