一、系统配置
单台服务器配置:
系统:Rocky Linux 8.7
配置:4核16G
Redis版本:7.0.5
安装目录:/data/software/redis-7.0.5
服务器IP及安装软件分布:
192.168.1.1 | Master | Redis、Sentinal |
192.168.1.2 | Slave1 | Redis、Sentinal |
192.168.1.3 | Slave2 | Redis、Sentinal |
二、安装过程(三台机器均进行如下操作)
1、下载Redis至下载目录
wget https://github.com/redis/redis/archive/refs/tags/7.0.5.tar.gz -O ./Redis-7.0.5.tar.gz
2、检查编译环境是否完整
sudo dnf -y install gcc gcc-c++ autoconf automake make
3、切换至Redis目录并安装Redis
cd ./redis-7.0.5/src
make install PREFIX=/data/software/redis-7.0.5
4、回到Redis根目录并复制配置文件至Redis安装目录
cd ../
cp ./redis.conf /data/software/redis-7.0.5
cp ./sentinel.conf /data/software/redis-7.0.5
5、修改配置文件
vim /data/software/redis-7.0.5/redis.conf
# 修改redis.conf对应配置,其他配置保持默认
bind 0.0.0.0
protected-mode no
daemonize yes
# Slave1/Slave2的log文件分别修改为redis-slave1.log与redis-slave2.log
logfile "/data/logs/redis/redis-master.log"
dir /data/software/redis-7.0.5/data
requirepass 123456
maxmemory 10gb
# Slave1/Slave2专属配置,Master不配置该值
slaveof 192.168.210.44 6379
masterauth Aa2298508@@
vim /data/software/redis-7.0.5/sentinel.conf
# 修改sentinel.conf默认配置,其他配置保持默认
protected-mode no
daemonize yes
logfile "/data/logs/redis/redis-sentinel.log"
dir /data/software/redis-7.0.5/data/sentinel
sentinel monitor mymaster 192.168.1.1 6379 2
sentinel auth-pass mymaster 123456
6、准备Redis启动文件夹
mkdir /data/logs
mkdir /data/logs/redis
mkdir /data/software/redis-7.0.5/data
mkdir /data/software/redis-7.0.5/data/sentinel
7、启动Redis与sentinel
cd /data/software/redis-7.0.5/bin
./redis-server ../redis.conf
./redis-sentinel ../sentinel.conf
8、读取日志,检查启动是否正常
#Slave1与Slave2的日志为redis-slave1.log与redis-slave2.log
tail -f /data/logs/redis/redis-master.log
tail -f /data/logs/redis/redis-sentinel.log