本来想通过DNF直接安装redis的,但是dnf中的redis5.0的版本有点老旧,就需要使用redis源码方式安装。
# 安装编译工具 sudo dnf group install "Development Tools"
wget https://download.redis.io/releases/redis-6.2.4.tar.gz tar xzf redis-6.2.4.tar.gz cd redis-6.2.4 make
sudo make install
sudo mkdir /etc/redis sudo cp redis.conf /etc/redis/ sudo vim /etc/redis/redis.conf
修改三处:
许可所有 ip 都可以访问,注释一行:
#bind 127.0.0.1 -::1
设置密码:
requirepass 123456
使用 systemd,去掉注释:
supervised auto
设置 SysV 服务脚本:
sudo vim /usr/lib/systemd/system/redis.service
内容:
[Unit] Description=Redis After=network.target [Service] ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf ExecReload=/usr/local/bin/redis-server -s reload ExecStop=/usr/local/bin/redis-server -s stop PrivateTmp=true [Install] WantedBy=multi-user.target
sudo systemctl daemon-reload sudo systemctl enable redis sudo systemctl start redis sudo systemctl status redis
redis-cli 127.0.0.1:6379> auth 123456 OK 127.0.0.1:6379> PING PONG 127.0.0.1:6379> info keyspace # Keyspace
# 开放端口 sudo firewall-cmd --zone=public --add-port=6379/tcp --permanent # 重启防火墙 sudo firewall-cmd --reload # 查看防火墙 sudo firewall-cmd --list-all # 第二种方式查看防火墙 sudo firewall-cmd --list-all --zone=public