偶数为稳定版:例如1.0,1.2,1.4
下载并安装:
wget http://download.redis.io/releases/redis-5.0.10.tar.gz
tar -xf redis-5.0.10.tar.gz
mv redis-5.0.10 /usr/local/redis
cd /usr/local/redis/
yum -y install gcc
make MALLOC=libc
make PREFIX=/usr/local/redis install
#没有gcc无法安装上面两步
临时启动:
[root@localhost redis]# cd bin/
[root@localhost bin]# ./redis-server
3653:C 27 Dec 2020 22:59:12.858 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
3653:C 27 Dec 2020 22:59:12.858 # Redis version=5.0.10, bits=64, commit=00000000, modified=0, pid=3653, just started
3653:C 27 Dec 2020 22:59:12.858 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
3653:M 27 Dec 2020 22:59:12.859 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 5.0.10 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 3653
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
3653:M 27 Dec 2020 22:59:12.861 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
3653:M 27 Dec 2020 22:59:12.861 # Server initialized
3653:M 27 Dec 2020 22:59:12.861 # 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.
3653:M 27 Dec 2020 22:59:12.861 # 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.
3653:M 27 Dec 2020 22:59:12.861 * Ready to accept connections
编辑systemctl服务配置文件并设置开机自启:
vim /usr/lib/systemd/system/redis.service
[Unit]
Description=Redis
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[root@localhost redis]# vim redis.conf
#136行修改为:daemonize yes
加载系统服务:
systemctl daemon-reload
systemctl enable redis
systemctl start redis
[root@localhost redis]# systemctl status redis
● redis.service - Redis
Loaded: loaded (/usr/lib/systemd/system/redis.service; disabled; vendor preset: disabled)
Active: active (running) since Sun 2020-12-27 23:05:46 EST; 1min 32s ago
Process: 3877 ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf (code=exited, status=0/SUCCESS)
Main PID: 3878 (redis-server)
CGroup: /system.slice/redis.service
└─3878 /usr/local/redis/bin/redis-server 127.0.0.1:6379
Dec 27 23:05:46 localhost.localdomain systemd[1]: Starting Redis...
Dec 27 23:05:46 localhost.localdomain redis-server[3877]: 3877:C 27 Dec 2020 23:05:46.471 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
Dec 27 23:05:46 localhost.localdomain redis-server[3877]: 3877:C 27 Dec 2020 23:05:46.471 # Redis version=5.0.10, bits=64, commit=00000000, modified=0, pid=387...t started
Dec 27 23:05:46 localhost.localdomain redis-server[3877]: 3877:C 27 Dec 2020 23:05:46.471 # Configuration loaded
Dec 27 23:05:46 localhost.localdomain systemd[1]: Started Redis.
Hint: Some lines were ellipsized, use -l to show in full.
最后给经常用到的redis命令行工具redis-cli做一个软连接:
ln -s /usr/local/redis/bin/redis-cli /usr/local/bin/redis-cli
#如果不管用就写到系统环境变量里面vim /etc/profile
export PATH=$PATH:/usr/local/redis/bin
记得重新加载:source /etc/profile
连接redis:
[root@localhost redis]# redis-cli
127.0.0.1:6379> exit
客户端管理工具使用ip连接redis服务:
vim /usr/local/redis/bin/redis.conf
69行注释掉:bind 127.0.0.1
88行修改参数: protected-mode no
重启redis即可:systemctl restart redis.service
以下为redis.conf文件中内容:
daemonize yes # 修改原值no为yes, 用来配置redis为后台驻留
#bind 127.0.0.1 # 注释掉该行, 使得redis可远程链接
protected-mode no # 修改为no, 禁用保护模式
设置登录密码:
[root@localhost ~]# redis-cli
127.0.0.1:6379> config set requirepass 123456
OK
127.0.0.1:6379> exit
[root@localhost ~]# redis-cli -h 127.0.0.1 -p 6379 -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> exit
修改redis.conf配置文件:
找到#requirepass foobared去掉注释的#,把foobared替换成自己的密码即可。
最后重启redis服务。