linux-redis-6.0.4-哨兵配置(一主二从三哨兵)

---------------------------------------

安装gcc套装
yum install cpp
yum install binutils
yum install glibc
yum install glibc-kernheaders
yum install glibc-common
yum install glibc-devel
yum install gcc
yum install make

升级gcc
yum -y install centos-release-scl

yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils

scl enable devtoolset-9 bash

---------------以上如有安装可忽略------------------------------

wget http://download.redis.io/releases/redis-6.0.4.tar.gz
tar xzvf redis-4.0.8.tar.gz

cd redis-6.0.4

make
cd src
--编译安装 PREFIX=[你要安装的目录]
make install PREFIX=/usr/local/redis-6.0.4 

mkdir sentinel-config  存放配置文件

cd /home/redis/redis-6.0.4

cp redis.conf /usr/local/redis-6.0.4/sentinel-config/  复制源文件

cp sentinel.conf /usr/local/redis-6.0.4/sentinel-config/  复制源文件

cd /usr/local/redis-6.0.4/sentinel-config/

linux-redis-6.0.4-哨兵配置(一主二从三哨兵)_第1张图片

mkdir logs  日志文件

mkdir db     数据文件

linux-redis-6.0.4-哨兵配置(一主二从三哨兵)_第2张图片

-------------------------------------------------------------------------------------------------------------------
配置主节点
daemonize yes
bind 192.168.56.101 127.0.0.1
logfile "/usr/local/redis-6.0.4/sentinel-config/logs/redis.log"
dir "/usr/local/redis-6.0.4/sentinel-config/db"
requirepass xyhhxx
masterauth xyhhxx 设置连接主节点的密码(方便此主节点宕机重启之后,可以变为slave与新的master进行通信)
---------------------------------------------------------------------------------------------------------------------
配置从节点 1
daemonize yes
bind 192.168.56.102 127.0.0.1
logfile "/usr/local/redis-6.0.4/sentinel-config/logs/redis.log"
dir "/usr/local/redis-6.0.4/sentinel-config/db"
requirepass xyhhxx
masterauth xyhhxx
replicaof 192.168.56.101 6379

配置从节点 2
daemonize yes
bind 192.168.56.103 127.0.0.1
logfile "/usr/local/redis-6.0.4/sentinel-config/logs/redis.log"
dir "/usr/local/redis-6.0.4/sentinel-config/db"
requirepass xyhhxx
masterauth xyhhxx
replicaof 192.168.56.101 6379
--------------------------------------------------------------------------------------------------------------------

哨兵配置 3个 ip不一样,其他一样
bind 192.168.56.101 127.0.0.1
daemonize yes
dir "/usr/local/redis-6.0.4/sentinel-config/db"
logfile "/usr/local/redis-6.0.4/sentinel-config/logs/sentinel.log"
sentinel monitor mymaster 192.168.56.101 6379 2
sentinel down-after-milliseconds mymaster 1000
sentinel failover-timeout mymaster 3000
sentinel parallel-syncs mymaster 1
sentinel auth-pass mymaster xyhhxx
--------------------------------------------------------------------------------------------------------------------

启动命令

---redis

 /usr/local/redis-6.0.4/bin/redis-server /usr/local/redis-6.0.4/sentinel-config/redis.conf

---哨兵

 /usr/local/redis-6.0.4/bin/redis-sentinel /usr/local/redis-6.0.4/sentinel-config/sentinel.conf 

查看主从信息
redis-cli -p 6379
info replication

linux-redis-6.0.4-哨兵配置(一主二从三哨兵)_第3张图片

 查看哨兵信息
/usr/local/redis-6.0.4/bin/redis-cli -h 127.0.0.1 -p 26379  
info sentinel
查看当前谁是主节点linux-redis-6.0.4-哨兵配置(一主二从三哨兵)_第4张图片

--连接服务器

/usr/local/redis-6.0.4/bin/redis-cli -h 192.168.56.101 -p 6379 -a xyhhxx

--停止服务器
/usr/local/redis-6.0.4/bin/redis-cli -h 127.0.0.1 -p 6379 -a xyhhxx shutdown

springboot redis 节点配置

spring:
  redis:
    password: xyhhxx
    sentinel:
      master: mymaster
      nodes: 192.168.56.101:26379,192.168.56.102:26379,192.168.56.103:26379
    timeout: 20000
    database: 0

你可能感兴趣的:(utils,redis,linux,数据库)