10.1 Redis 安装

子章节
CentOS / RHEL(yum)
# 安装 EPEL 源
sudo yum install -y epel-release

# 安装 Redis
sudo yum install -y redis

# 启动并设置开机自启
sudo systemctl start redis
sudo systemctl enable redis

# 检查运行状态
sudo systemctl status redis

# 测试连接
redis-cli ping

Ubuntu / Debian(apt)
# 更新包索引
sudo apt update

# 安装 Redis
sudo apt install -y redis-server

# 启动并设置开机自启
sudo systemctl start redis-server
sudo systemctl enable redis-server

# 检查运行状态
sudo systemctl status redis-server

# 测试连接
redis-cli ping

源码编译安装
# 下载源码
wget https://download.redis.io/releases/redis-7.2.5.tar.gz
tar -xzf redis-7.2.5.tar.gz
cd redis-7.2.5

# 编译安装
make
sudo make install

# 启动 Redis
redis-server /path/to/redis.conf

常用配置
# 编辑配置文件
sudo vim /etc/redis/redis.conf

# 常见配置项
bind 0.0.0.0 # 允许远程连接
requirepass yourpassword # 设置密码
daemonize yes # 后台运行