• Redis主从复制集群


    实验环境

            三台服务器,一台master,两台slave

    部署

    1. yum -y install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
    2. yum -y --enablerepo=remi install redis

     修改配置文件

    1. 主配置:
    2. [root@xingdian-server-20 /]# grep -Ev "^$|#" /etc/redis.conf
    3. bind 10.0.0.155 127.0.0.1
    4. protected-mode yes
    5. port 6379
    6. tcp-backlog 511
    7. timeout 0
    8. tcp-keepalive 300
    9. daemonize no
    10. supervised no
    11. pidfile /var/run/redis_6379.pid
    12. loglevel notice
    13. logfile /var/log/redis/redis.log
    14. databases 16
    15. always-show-logo yes
    16. save 900 1
    17. save 300 10
    18. save 60 10000
    19. stop-writes-on-bgsave-error yes
    20. rdbcompression yes
    21. rdbchecksum yes
    22. dbfilename dump.rdb
    23. rdb-del-sync-files no
    24. dir /var/lib/redis
    25. replica-serve-stale-data yes
    26. replica-read-only yes
    27. repl-diskless-sync no
    28. repl-diskless-sync-delay 5
    29. repl-diskless-load disabled
    30. repl-disable-tcp-nodelay no
    31. replica-priority 100
    32. acllog-max-len 128
    33. requirepass redisb
    34. lazyfree-lazy-eviction no
    35. lazyfree-lazy-expire no
    36. lazyfree-lazy-server-del no
    37. replica-lazy-flush no
    38. lazyfree-lazy-user-del no
    39. oom-score-adj no
    40. oom-score-adj-values 0 200 800
    41. appendonly no /"是否启用AOF"
    42. appendfilename
    43. appendfsync everysec
    44. no-appendfsync-on-rewrite no
    45. auto-aof-rewrite-percentage 100
    46. auto-aof-rewrite-min-size 64mb
    47. aof-load-truncated yes
    48. aof-use-rdb-preamble yes
    49. lua-time-limit 5000
    50. slowlog-log-slower-than 10000
    51. slowlog-max-len 128
    52. latency-monitor-threshold 0
    53. notify-keyspace-events ""
    54. hash-max-ziplist-entries 512
    55. hash-max-ziplist-value 64
    56. list-max-ziplist-size -2
    57. list-compress-depth 0
    58. set-max-intset-entries 512
    59. zset-max-ziplist-entries 128
    60. zset-max-ziplist-value 64
    61. hll-sparse-max-bytes 3000
    62. stream-node-max-bytes 4096
    63. stream-node-max-entries 100
    64. activerehashing yes
    65. client-output-buffer-limit normal 0 0 0
    66. client-output-buffer-limit replica 256mb 64mb 60
    67. client-output-buffer-limit pubsub 32mb 8mb 60
    68. hz 10
    69. dynamic-hz yes
    70. aof-rewrite-incremental-fsync yes
    71. rdb-save-incremental-fsync yes
    72. jemalloc-bg-thread yes
    1. slave-1配置文件:
    2. [root@xingdian-server-21 /]# grep -Ev "^$|#" /etc/redis.conf
    3. bind 0.0.0.0
    4. protected-mode yes
    5. port 6379
    6. tcp-backlog 511
    7. timeout 0
    8. tcp-keepalive 300
    9. daemonize no
    10. supervised no
    11. pidfile /var/run/redis_6379.pid
    12. loglevel notice
    13. logfile /var/log/redis/redis.log
    14. databases 16
    15. always-show-logo yes
    16. save 900 1
    17. save 300 10
    18. save 60 10000
    19. stop-writes-on-bgsave-error yes
    20. rdbcompression yes
    21. rdbchecksum yes
    22. dbfilename dump.rdb
    23. rdb-del-sync-files no
    24. dir /var/lib/redis
    25. replicaof 10.0.0.155 6379
    26. masterauth redis
    27. replica-serve-stale-data yes
    28. replica-read-only yes
    29. repl-diskless-sync no
    30. repl-diskless-sync-delay 5
    31. repl-diskless-load disabled
    32. repl-disable-tcp-nodelay no
    33. replica-priority 100
    34. acllog-max-len 128
    35. requirepass redis
    36. lazyfree-lazy-eviction no
    37. lazyfree-lazy-expire no
    38. lazyfree-lazy-server-del no
    39. replica-lazy-flush no
    40. lazyfree-lazy-user-del no
    41. oom-score-adj no
    42. oom-score-adj-values 0 200 800
    43. appendonly no
    44. appendfilename "appendonly.aof"
    45. appendfsync everysec
    46. no-appendfsync-on-rewrite no
    47. auto-aof-rewrite-percentage 100
    48. auto-aof-rewrite-min-size 64mb
    49. aof-load-truncated yes
    50. aof-use-rdb-preamble yes
    51. lua-time-limit 5000
    52. slowlog-log-slower-than 10000
    53. slowlog-max-len 128
    54. latency-monitor-threshold 0
    55. notify-keyspace-events ""
    56. hash-max-ziplist-entries 512
    57. hash-max-ziplist-value 64
    58. list-max-ziplist-size -2
    59. list-compress-depth 0
    60. set-max-intset-entries 512
    61. zset-max-ziplist-entries 128
    62. zset-max-ziplist-value 64
    63. hll-sparse-max-bytes 3000
    64. stream-node-max-bytes 4096
    65. stream-node-max-entries 100
    66. activerehashing yes
    67. client-output-buffer-limit normal 0 0 0
    68. client-output-buffer-limit replica 256mb 64mb 60
    69. client-output-buffer-limit pubsub 32mb 8mb 60
    70. hz 10
    71. dynamic-hz yes
    72. aof-rewrite-incremental-fsync yes
    73. rdb-save-incremental-fsync yes
    74. jemalloc-bg-thread yes
    1. slave-2配置文件:
    2. [root@xingdian-server-22 /]# grep -Ev "^$|#" /etc/redis.conf
    3. bind 0.0.0.0
    4. protected-mode yes
    5. port 6379
    6. tcp-backlog 511
    7. timeout 0
    8. tcp-keepalive 300
    9. daemonize no
    10. supervised no
    11. pidfile /var/run/redis_6379.pid
    12. loglevel notice
    13. logfile /var/log/redis/redis.log
    14. databases 16
    15. always-show-logo yes
    16. save 900 1
    17. save 300 10
    18. save 60 10000
    19. stop-writes-on-bgsave-error yes
    20. rdbcompression yes
    21. rdbchecksum yes
    22. dbfilename dump.rdb
    23. rdb-del-sync-files no
    24. dir /var/lib/redis
    25. replicaof 10.0.0.155 6379
    26. masterauth redis
    27. replica-serve-stale-data yes
    28. replica-read-only yes
    29. repl-diskless-sync no
    30. repl-diskless-sync-delay 5
    31. repl-diskless-load disabled
    32. repl-disable-tcp-nodelay no
    33. replica-priority 100
    34. acllog-max-len 128
    35. requirepass redis
    36. lazyfree-lazy-eviction no
    37. lazyfree-lazy-expire no
    38. lazyfree-lazy-server-del no
    39. replica-lazy-flush no
    40. lazyfree-lazy-user-del no
    41. oom-score-adj no
    42. oom-score-adj-values 0 200 800
    43. appendonly no
    44. appendfilename "appendonly.aof"
    45. appendfsync everysec
    46. no-appendfsync-on-rewrite no
    47. auto-aof-rewrite-percentage 100
    48. auto-aof-rewrite-min-size 64mb
    49. aof-load-truncated yes
    50. aof-use-rdb-preamble yes
    51. lua-time-limit 5000
    52. slowlog-log-slower-than 10000
    53. slowlog-max-len 128
    54. latency-monitor-threshold 0
    55. notify-keyspace-events ""
    56. hash-max-ziplist-entries 512
    57. hash-max-ziplist-value 64
    58. list-max-ziplist-size -2
    59. list-compress-depth 0
    60. set-max-intset-entries 512
    61. zset-max-ziplist-entries 128
    62. zset-max-ziplist-value 64
    63. hll-sparse-max-bytes 3000
    64. stream-node-max-bytes 4096
    65. stream-node-max-entries 100
    66. activerehashing yes
    67. client-output-buffer-limit normal 0 0 0
    68. client-output-buffer-limit replica 256mb 64mb 60
    69. client-output-buffer-limit pubsub 32mb 8mb 60
    70. hz 10
    71. dynamic-hz yes
    72. aof-rewrite-incremental-fsync yes
    73. rdb-save-incremental-fsync yes
    74. jemalloc-bg-thread yes

    注意:

    配置文件参数地址:https://xingdian-file.oss-cn-hangzhou.aliyuncs.com/redis-config.txt

    启动服务

    systemctl start redis

    验证服务

    1. [root@xingdian-server-20 /]# redis-cli -a redis -h 10.0.0.3
    2. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    3. 127.0.0.1:6379> info replication
    4. # Replication
    5. role:master
    6. connected_slaves:2
    7. slave0:ip=172.17.0.6,port=6379,state=online,offset=70,lag=0
    8. slave1:ip=172.17.0.7,port=6379,state=online,offset=70,lag=0
    9. master_replid:12e24fe583640c88aff07733c7bcd1acb32c4dd2
    10. master_replid2:0000000000000000000000000000000000000000
    11. master_repl_offset:70
    12. second_repl_offset:-1
    13. repl_backlog_active:1
    14. repl_backlog_size:1048576
    15. repl_backlog_first_byte_offset:1
    16. repl_backlog_histlen:70
    17. 127.0.0.1:6379> set t1 aa
    18. OK
    19. 127.0.0.1:6379> quit
    20. slave端:
    21. [root@xingdian-server-21 /]# redis-cli -h 172.17.0.6 -a redis
    22. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    23. 172.17.0.6:6379> get t1
    24. "aa"

  • 相关阅读:
    3. 工业大数据的创新价值
    python学习笔记:引用、浅拷贝和深拷贝(底层原理)
    Flutter打包iOS过程中pod访问github失败
    沉睡者 - 网上赚钱:网赚经验分享
    1158 Telefraud Detection – PAT甲级真题
    【机器学习300问】78、都有哪些神经网络的初始化参数方法?
    云计算认证哪个好?考什么内容?
    GC调优思路
    VMware中安装WindowsXP虚拟机详细步骤
    创建一个electron桌面备忘录
  • 原文地址:https://blog.csdn.net/2301_77190706/article/details/133652378