• redis单节点部署


    准备一台机器,系统版本为CentOS7。

    部署redis

    1、下载软件包

      

    1 wget http://download.redis.io/releases/redis-3.2.8.tar.gz

    2、解压

    1 tar xvf redis-3.2.8.tar.gz -C /usr/local/
    2 cd /usr/local/
    3 ln -sv redis-3.2.8/ redis
     

    3、编译

    1 yum groupinstall -y "Development Tools"
    2 cd redis
    3 make

    4、为多实例redis配置启动环境

    1 mkdir -pv /home/redis-cluster/{9000,9001,9002}
    2 
    3 cp src/{redis-server,redis-sentinel} /home/redis-cluster/9000/
    4 cp src/{redis-server,redis-sentinel} /home/redis-cluster/9001/
    5 cp src/{redis-server,redis-sentinel} /home/redis-cluster/9002/
    6 
    7 cp redis.conf sentinel.conf /home/redis-cluster/9000/
    8 cp redis.conf sentinel.conf /home/redis-cluster/9001/
    9 cp redis.conf sentinel.conf /home/redis-cluster/9002/

    5、修改配置文件

    # vim /home/redis-cluster/9000/redis.conf
    bind 172.60.0.170
    protected-mode no
    port 9000
    daemonize yes
    appendonly yes
    
    # cp /home/redis-cluster/9000/redis.conf /home/redis-cluster/9001/redis.conf
    # cp /home/redis-cluster/9000/redis.conf /home/redis-cluster/9002/redis.conf
    
    # vim /home/redis-cluster/9001/redis.conf
    port 9001
    slaveof 172.60.0.170 9000
    
    # vim /home/redis-cluster/9002/redis.conf
    port 9002
    slaveof 172.60.0.170 9000
    

      

    6、启动三个redis实例

    # cd /home/redis-cluster/9000/
    # ./redis-server redis.conf
    
    # cd ../9001/
    # ./redis-server redis.conf
    
    # cd ../9002/
    # ./redis-server redis.conf
    
    # ps -ef | grep redis
    root     23565     1  0 03:29 ?        00:00:03 ./redis-server 172.60.0.170:9000
    root     23569     1  0 03:29 ?        00:00:02 ./redis-server 172.60.0.170:9001
    root     23575     1  0 03:29 ?        00:00:02 ./redis-server 172.60.0.170:9002
    

      

    7、验证,查看主从状态

    # /usr/local/redis/src/redis-cli -h 172.60.0.170 -p 9000
    172.60.0.170:9000> set name keith
    OK
    172.60.0.170:9000> get name
    "keith"
    172.60.0.170:9000> info replication
    # Replication
    role:master
    connected_slaves:2
    slave0:ip=172.60.0.170,port=9001,state=online,offset=99,lag=1
    slave1:ip=172.60.0.170,port=9002,state=online,offset=99,lag=0
    master_repl_offset:99
    repl_backlog_active:1
    repl_backlog_size:1048576
    repl_backlog_first_byte_offset:2
    repl_backlog_histlen:98
    

      


    部署sentinel

    1、部署实例一

     1 # cd /home/redis-cluster/9000
     2 # vim sentinel.conf
     3 protected-mode no
     4 port 29000
     5 daemonize yes
     6 dir /home/redis-cluster/9000/logs
     7 sentinel monitor mymaster 172.60.0.170 9000 2
     8 # mkdir logs
     9 # ./redis-sentinel sentinel.conf
    10 # cp sentinel.conf ../9001/
    11 # cp sentinel.conf ../9002/

    2、部署实例二

    1 # cd ../9001/
    2 port 29001
    3 dir "/home/redis-cluster/9001/logs"
    4 # mkdir logs
    5 # ./redis-sentinel sentinel.conf

    3、部署实例三

     1 # cd ../9002/
     2 # vim sentinel.conf
     3 port 29002
     4 dir "/home/redis-cluster/9002/logs"
     5 # mkdir logs
     6 # ./redis-sentinel sentinel.conf
     7 # ps -ef | grep redis
     8 root     23565     1  0 03:29 ?        00:00:03 ./redis-server 172.60.0.170:9000
     9 root     23569     1  0 03:29 ?        00:00:03 ./redis-server 172.60.0.170:9001
    10 root     23575     1  0 03:29 ?        00:00:03 ./redis-server 172.60.0.170:9002
    11 root     23923     1  0 03:43 ?        00:00:04 ./redis-sentinel *:29000 [sentinel]
    12 root     23927     1  0 03:44 ?        00:00:04 ./redis-sentinel *:29001 [sentinel]
    13 root     23965     1  0 03:44 ?        00:00:04 ./redis-sentinel *:29002 [sentinel]

    4、验证

    # /usr/local/redis/src/redis-cli -h 172.60.0.170 -p 29000
    172.60.0.170:29000> sentinel masters
    1)  1) "name"
        2) "mymaster"
        3) "ip"
        4) "172.60.0.170"
        5) "port"
        6) "9000"
        7) "runid"
        8) "3236841c634359db724f73d4833b003683efa446"
        9) "flags"
       10) "master"
       11) "link-pending-commands"
       12) "0"
       13) "link-refcount"
       14) "1"
       15) "last-ping-sent"
       16) "0"
       17) "last-ok-ping-reply"
       18) "65"
       19) "last-ping-reply"
       20) "65"
       21) "down-after-milliseconds"
       22) "30000"
       23) "info-refresh"
       24) "4288"
       25) "role-reported"
       26) "master"
       27) "role-reported-time"
       28) "2885298"
       29) "config-epoch"
       30) "0"
       31) "num-slaves"
       32) "2"
       33) "num-other-sentinels"
       34) "2"
       35) "quorum"
       36) "2"
       37) "failover-timeout"
       38) "180000"
       39) "parallel-syncs"
       40) "1"
    172.60.0.170:29000> sentinel slaves mymaster
    1)  1) "name"
        2) "172.60.0.170:9002"
        3) "ip"
        4) "172.60.0.170"
        5) "port"
        6) "9002"
        7) "runid"
        8) "0e741da8193158b565113ec84c6384284d11b0bd"
        9) "flags"
       10) "slave"
       11) "link-pending-commands"
       12) "0"
       13) "link-refcount"
       14) "1"
       15) "last-ping-sent"
       16) "0"
       17) "last-ok-ping-reply"
       18) "133"
       19) "last-ping-reply"
       20) "133"
       21) "down-after-milliseconds"
       22) "30000"
       23) "info-refresh"
       24) "4338"
       25) "role-reported"
       26) "slave"
       27) "role-reported-time"
       28) "2915465"
       29) "master-link-down-time"
       30) "0"
       31) "master-link-status"
       32) "ok"
       33) "master-host"
       34) "172.60.0.170"
       35) "master-port"
       36) "9000"
       37) "slave-priority"
       38) "100"
       39) "slave-repl-offset"
       40) "632552"
    2)  1) "name"
        2) "172.60.0.170:9001"
        3) "ip"
        4) "172.60.0.170"
        5) "port"
        6) "9001"
        7) "runid"
        8) "4a500eedd644d89c565773d5e42faf4c2872295e"
        9) "flags"
       10) "slave"
       11) "link-pending-commands"
       12) "0"
       13) "link-refcount"
       14) "1"
       15) "last-ping-sent"
       16) "0"
       17) "last-ok-ping-reply"
       18) "133"
       19) "last-ping-reply"
       20) "133"
       21) "down-after-milliseconds"
       22) "30000"
       23) "info-refresh"
       24) "4338"
       25) "role-reported"
       26) "slave"
       27) "role-reported-time"
       28) "2915465"
       29) "master-link-down-time"
       30) "0"
       31) "master-link-status"
       32) "ok"
       33) "master-host"
       34) "172.60.0.170"
       35) "master-port"
       36) "9000"
       37) "slave-priority"
       38) "100"
       39) "slave-repl-offset"
       40) "632552"   
    

      

    转载:CentOS7单节点部署redis主从复制和sentinel - 开发者知识库 (itdaan.com)

  • 相关阅读:
    前后端分类状态下SpringSecurity的玩法
    拓展 centos 7
    linux 日志管理
    Linux 内存监控
    Linux 周期任务
    Linux 文件系统
    linux 磁盘管理
    图论 最短路总结
    进阶线段树之乘法操作
    暑假集训Day 10 小烈送菜
  • 原文地址:https://www.cnblogs.com/xianglei_/p/15345261.html
Copyright © 2020-2023  润新知