centos8 redis 6.2.6源码安装+主从哨兵
文章目录
- centos8 redis 6.2.6源码安装+主从哨兵
- 下载解压
- 编译安装
- 配置
- 配置systemd
- 服务启停及开机启动
- 登录验证
- 主从同步
- 配置哨兵
- 哨兵注册systemd
centos8 redis 6.2.6源码安装+主从哨兵
单机安装
下载解压
cd /data
wget http://download.redis.io/releases/redis-6.2.6.tar.gz
tar xf redis-6.2.6.tar.gz
cd redis-6.2.6/
编译安装
make PREFIX=/usr/local/redis6 install
如果编译提示jemallo文件不存在,清空make缓存重新编译
make distclea
make clean
配置
mkdir /usr/local/redis6/conf
cp redis.conf /usr/local/redis6/conf/
mkdir -p /data/redis6/data
mkdir -p /data/redis6/logs
vi /usr/local/redis6/conf/redis.conf
#配置参数,其他默认
bind 0.0.0.0
protected-mode no
port 6379
daemonize yes
logfile "/data/redis6/logs/redis.log"
dir /data/redis6/data/
maxmemory 2048MB
io-threads 4
requirepass mh112233
配置systemd
vi /lib/systemd/system/redis6.service
[Unit]
Description=Redis
After=network.target
[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/redis6/bin/redis-server /usr/local/redis6/conf/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
服务启停及开机启动
systemctl daemon-reload
systemctl start redis6
systemctl enable redis6
登录验证
ln -s /usr/local/redis6/bin/redis-cli /usr/bin/redis-cli
redis-cli -h 127.0.0.1 -p 6379 -a mh112233
set a 11
get a
主从同步
#从节点增加配置,ip指向主节点
replicaof 192.168.122.230 6379
#配置密码
masterauth mh112233
#检查主从同步状态
info replication
配置哨兵
cp sentinel.conf /usr/local/redis6/conf/
mkdir -p /data/redis6/data/sentinel
vi /usr/local/redis6/conf/sentinel.conf
#配置参数,其他默认
bind 0.0.0.0
protected-mode no
port 26379
daemonize yes
logfile "/data/redis6/logs/sentinel.log"
dir /data/redis6/data/sentinel/
#指定Redis主节点主机IP地址和端口,ip根据实际情况调整,mymaster这个名称随便取,下面配置时也需要指定这个名称,客户端连接时也会使用
#最后的2是指需要有2个以上sentinel节点认为redis主节点失效,才是真的失效,一般为(sentinel总数/2+1)
sentinel monitor mymaster 192.168.122.230 6379 2
#配置连接密码,此处的密码需要与 redis.conf里面配置的连接密码一致
sentinel auth-pass mymaster mh112233
哨兵注册systemd
vi /lib/systemd/system/sentinel.service
[Unit]
Description=Redis-sentinel
After=network.target
[Service]
Type=forking
PIDFile=/var/run/redis-sentinel.pid
ExecStart=/usr/local/redis6/bin/redis-sentinel /usr/local/redis6/conf/sentinel.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start sentinel
systemctl enable sentinel
#连接哨兵服务,检查状态
redis-cli -h 127.0.0.1 -p 26379
info sentinel