先下载tar包

1
2
3
4
wget https://download.redis.io/releases/redis-7.0.12.tar.gz
# or 手动 https://redis.io/downloads
tar -xzf redis-7.0.12.tar.gz
cd redis-7.0.12

安装

1
make && make install PREFIX=/usr/local/redis

单机配置

1
2
3
4
5
6
bind 0.0.0.0        # 允许远程连接(生产环境建议绑定具体IP)
protected-mode no # 关闭保护模式(若需远程访问)
daemonize yes # 后台运行
pidfile /var/run/redis_6379.pid
logfile /var/log/redis_6379.log
dir /var/lib/redis # 数据存储目录(需提前创建)

集群配置

1
2
3
4
5
6
7
8
9
10
11
12
13
cat > /opt/redis-cluster/7000/redis.conf <<EOF
port 7000
cluster-enabled yes
cluster-config-file nodes-7000.conf
cluster-node-timeout 5000
appendonly yes
daemonize yes
bind 0.0.0.0
protected-mode no
pidfile /var/run/redis_7000.pid
logfile /opt/redis-cluster/7000/redis.log
dir /opt/redis-cluster/7000/
EOF