下面分 CentOS 7 / CentOS 8(Stream) 两种常见情况说明,推荐 优先用 yum/dnf 安装,简单稳定;需要新版本再考虑 源码编译。
# 1. 安装 EPEL 源
sudo yum install -y epel-release
# 2. 安装 Redis
sudo yum install -y redis
# 3. 启动并设置开机自启
sudo systemctl start redis
sudo systemctl enable redis
# 4. 检查状态
sudo systemctl status redis
# 1. 安装 Redis(CentOS 8 自带 AppStream)
sudo dnf install -y redis
# 2. 启动并设置开机自启
sudo systemctl start redis
sudo systemctl enable redis
# 3. 检查状态
sudo systemctl status redis
/etc/redis.conf
sudo vi /etc/redis.conf
修改:
# 注释掉或改为 0.0.0.0
bind 0.0.0.0
# 关闭保护模式
protected-mode no
requirepass your_password
sudo systemctl restart redis
redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> auth your_password
OK
sudo yum install -y gcc make
cd /usr/local/src
wget https://download.redis.io/releases/redis-7.2.4.tar.gz
tar -zxvf redis-7.2.4.tar.gz
cd redis-7.2.4
make
make install
redis-server
sudo firewall-cmd --add-port=6379/tcp --permanent
sudo firewall-cmd --reload
bindprotected-modejournalctl -u redis -xe
如果你愿意,可以告诉我:
我可以给你一份 生产级 Redis 配置模板。