基于一个一个物理机搭建Redis的主从架构并设置哨兵机制

    技术2024-11-19  9

    基于上一篇文章:Centos7编译安装Redis

    # 配置/opt/redis/6379.conf,启动6379 为master节点,配置文件我并没有修改 # 按理来说redis默认的启动是单节点 daemonize yes #设置redis 为后台运行 # replicaof <masterip> <masterport> #当前任然是注释状态,没有放开 # 配置 6380 为第一台从节点,配置文件我放在了 /opt/redis/6380.conf daemonize yes replicaof 127.0.0.1 6379 #告诉当前从机,master 节点的ip和端口 # 同理:配置 6382 为第二台从节点,配置文件我放在了 /opt/redis/6382.conf daemonize yes replicaof 127.0.0.1 6379 #告诉当前从机,master 节点的ip和端口 #/opt/redis/26379.conf设置第一台哨兵的IP port 26379 daemonize yes logfile "/opt/redis/log/redis_26379.log" dir "/tmp" sentinel deny-scripts-reconfig yes sentinel monitor mymaster 127.0.0.1 6379 2 sentinel config-epoch mymaster 3 sentinel leader-epoch mymaster 3 #/opt/redis/26380.conf设置第二台哨兵的IP port 26380 daemonize yes logfile "/opt/redis/log/redis_26380.log" dir "/tmp" sentinel deny-scripts-reconfig yes sentinel monitor mymaster 127.0.0.1 6379 2 sentinel config-epoch mymaster 3 sentinel leader-epoch mymaster 3 #/opt/redis/26382.conf设置第三台哨兵的IP port 26382 daemonize yes logfile "/opt/redis/log/redis_26382.log" dir "/tmp" sentinel deny-scripts-reconfig yes sentinel monitor mymaster 127.0.0.1 6379 2 sentinel config-epoch mymaster 3 sentinel leader-epoch mymaster 3 #启动 对应的主从机器 redis-server /opt/redis/6379.conf redis-server /opt/redis/6380.conf redis-server /opt/redis/6382.conf #启动 对应的哨兵机器 redis-server /opt/redis/26379.conf redis-server /opt/redis/26380.conf redis-server /opt/redis/26382.conf # 查看一下进程 ps -ef | grep redis root 7323 1 0 11:46 ? 00:00:06 redis-server 127.0.0.1:6379 root 7341 1 0 11:52 ? 00:00:05 redis-server 127.0.0.1:6380 root 5667 1 0 10:46 ? 00:00:17 redis-server 127.0.0.1:6382 root 7351 1 0 11:54 ? 00:00:11 redis-server *:26379 [sentinel] root 7271 1 0 11:37 ? 00:00:13 redis-server *:26380 [sentinel] root 7276 1 0 11:37 ? 00:00:14 redis-server *:26382 [sentinel]

     

    Processed: 0.026, SQL: 9