- 下载Redis6.2.6
wget https://download.redis.io/releases/redis-6.2.6.tar.gz
- 如果遇到如下错误(非必须步骤)
wget: command not found
需要执行命令先安装wget
yum -y install wget
然后再下载Redis6.2.6
wget https://download.redis.io/releases/redis-6.2.6.tar.gz
- 解压
cd /usr/local
tar xzf redis-6.2.6.tar.gz
- 安装
cd redis-6.2.6
make
- 如果遇到如下错误提示
/bin/sh: cc: command not found
- 安装gcc
yum install -y gcc
- 重新执行make安装
make distclean && make
- 修改配置
- 打开配置文件
vi /usr/local/redis-6.2.6/redis.conf
- 更新配置
protected-mode no #关闭保护模式
daemonize yes #守护进程模式开启
#bind 127.0.0.1 #注释配置后开启远程访问
port 6379 # 端口
requirepass 123456 #密码
- 启动服务
/usr/local/redis-6.2.6/src/redis-server /usr/local/redis-6.2.6/redis.conf
- 连接测试
/usr/local/redis-6.2.6/src/redis-cli -h 127.0.0.1 -p 6379 -a 123456
- 停止服务
/usr/local/redis-6.2.6/src/redis-cli -p 6379 -a 123456 shutdown
- 开机运行
- 新建文件redis.service
vi /lib/systemd/system/redis.service
- 写入配置
[Unit]
Description=The redis-server Process Manager
Documentation=https://redis.io/
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/redis-6.2.6/src/redis-server /usr/local/redis-6.2.6/redis.conf
ExecStop=/usr/local/redis-6.2.6/src/redis-cli -h 127.0.0.1 -p 6379 -a 123456
[Install]
WantedBy=multi-user.target
- redis.service文件授权
systemctl daemon-reexec
- 开运运行设置
systemctl enable redis.service
- 添加防火墙端口号
- 添加端口号
firewall-cmd --zone=public --add-port=6379/tcp --permanent
- 重载防火墙立即生效
firewall-cmd --reload