1、下载redis
切换到/usr/local目录下,下载最新稳定版
https://download.redis.io/redis-stable.tar.gz
2、解压Redis
tar -zxvf redis-stable.tar.gz
3、进入解压目录
cd /usr/local/redis-stable
4、安装
make 或 make PREFIX=/usr/local/redis install #安装到指定目录中
5、如果编译失败安装gcc
yum install gcc
6、启动服务
进入解压目录
src/redis-server
出现以下界面,启动成功
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 7.0.4 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 37166
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | https://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
7、本地连接
[root@localhost redis-stable]# src/redis-cli
127.0.0.1:6379> select 1
8、修改配置文件支持后台运行和远程连接
#bind 127.0.0.1 -::1 #注释bind
daemonize no改为daemonize yes
protected-mode yes改为protected-mode no
设置密码
requirepass 密码
9、开机自启
复制配置文件 redis.conf /etc/redis/ ,改名6379.conf
cp -r redis.conf /etc/redis/6379.conf
复制配置文件
cp utils/redis_init_script /etc/init.d/redis
修改配置文件
vi /etc/init.d/redis
#修改到自己的安装执行目录
EXEC=/usr/local/redis-stable/src/redis-server
CLIEXEC=/usr/local/redis-stable/src/redis-cli
保存退出,修改权限
chmod 777 /etc/init.d/redis
开机自启动
chkconfig redis on
启动/停止服务
service redis start
service redis stop
开启防火墙端口
firewall-cmd --zone=public --add-port=6379/tcp --permanent