• redis 5.0.3主从 部署


    环境准备

    • 准备机器
    节点名称 ip地址 cpu 内存
    yz-redis-prod10067 10.148.100.67 8c 32G
    yz-redis-prod10068 10.148.100.68 8c 32G
    • 系统配置
    #修改系统参数
    echo 'never' > /sys/kernel/mm/transparent_hugepage/defrag
    echo 'never' > /sys/kernel/mm/transparent_hugepage/defrag
    
    #加入开机启动项
    vi /etc/rc.local
    echo 'never' > /sys/kernel/mm/transparent_hugepage/defrag
    echo 'never' > /sys/kernel/mm/transparent_hugepage/enabled
    
    #修改内核参数
    vi /etc/sysctl.conf
    
    vm.overcommit_memory = 1
    net.core.somaxconn= 1024
    vm.max_map_count=655360
    
    #使内核参数生效
    sysctl -p
    
    #修改连接数
    ulimit -n 655350
    
    • 下载安装包编辑
    wget http://download.redis.io/releases/redis-5.0.3.tar.gz
    tar -xf redis-5.0.3.tar.gz -C /opt
    cd /opt/redis-5.0.3
    make && make install
    
    • 主节点修改配置文件并启动
    mkdir /export/redis6600
    cd /export/redis6600
    mkdir  {data,etc,logs}
    
    #准备主配置文件,同时开启aof 和 rdb
    
    # cat /export/redis6600/etc/redis.conf 
    bind 0.0.0.0
    daemonize yes
    #protected-mode no
    pidfile "/export/redis6600/pid/redis.pid"
    port 6600
    timeout 216000
    tcp-keepalive 0
    tcp-backlog 511
    loglevel notice
    logfile "/export/redis6600/logs/redis.log"
    databases 16
    stop-writes-on-bgsave-error yes
    rdbcompression yes
    rdbchecksum yes
    dbfilename "dump.rdb"
    dir "/export/redis6600/data"
    replica-serve-stale-data yes
    replica-read-only no
    repl-disable-tcp-nodelay no
    replica-priority 100
    appendonly yes
    appendfsync everysec
    appendfilename "append-6600.aof"
    no-appendfsync-on-rewrite no
    aof-use-rdb-preamble yes
    auto-aof-rewrite-percentage 100
    auto-aof-rewrite-min-size 64mb
    lua-time-limit 5000
    slowlog-log-slower-than 10000
    slowlog-max-len 128
    maxmemory 512mb
    maxmemory-policy allkeys-lru
    
    ###security######
    rename-command KEYS "RKEYS"
    rename-command FLUSHALL ""
    rename-command FLUSHDB "RFLUSHDB"
    
    notify-keyspace-events ""
    hash-max-ziplist-entries 512
    hash-max-ziplist-value 256
    list-max-ziplist-entries 512
    list-max-ziplist-value 64
    set-max-intset-entries 512
    zset-max-ziplist-entries 128
    zset-max-ziplist-value 64
    activerehashing yes
    activedefrag yes
    save 900 1
    save 300 10
    save 60 10000
    
    client-output-buffer-limit normal 0 0 0
    client-output-buffer-limit replica 0 0 0
    client-output-buffer-limit pubsub 32mb 8mb 60
    hz 10
    aof-rewrite-incremental-fsync yes
    requirepass "Mso7-Bk0=wV~O"
    # Generated by CONFIG REWRITE
    masterauth "Mso7-Bk0=wV~O"
    
    #启动redis
    redis-server /export/redis6600/etc/redis.conf  & 
    
    • 从节点修改配置文件并启动
    mkdir /export/redis6600
    cd /export/redis6600
    mkdir  {data,etc,logs}
    
    #准备从配置文件,同时开启aof 和 rdb
    #  cat /export/redis6600/etc/redis.conf 
    bind 0.0.0.0
    daemonize yes
    #protected-mode no
    pidfile "/export/redis6600/pid/redis.pid"
    port 6600
    timeout 216000
    tcp-keepalive 0
    tcp-backlog 511
    loglevel notice
    logfile "/export/redis6600/logs/redis.log"
    databases 16
    stop-writes-on-bgsave-error yes
    rdbcompression yes
    rdbchecksum yes
    dbfilename "dump.rdb"
    dir "/export/redis6600/data"
    replica-serve-stale-data yes
    replica-read-only no
    repl-disable-tcp-nodelay no
    replica-priority 100
    appendonly yes
    appendfsync everysec
    appendfilename "append-6600.aof"
    no-appendfsync-on-rewrite no
    aof-use-rdb-preamble yes
    auto-aof-rewrite-percentage 100
    auto-aof-rewrite-min-size 64mb
    lua-time-limit 5000
    slowlog-log-slower-than 10000
    slowlog-max-len 128
    maxmemory 512mb
    maxmemory-policy allkeys-lru
    
    ###security######
    rename-command KEYS "RKEYS"
    rename-command FLUSHALL ""
    rename-command FLUSHDB "RFLUSHDB"
    
    notify-keyspace-events ""
    hash-max-ziplist-entries 512
    hash-max-ziplist-value 256
    list-max-ziplist-entries 512
    list-max-ziplist-value 64
    set-max-intset-entries 512
    zset-max-ziplist-entries 128
    zset-max-ziplist-value 64
    activerehashing yes
    activedefrag yes
    save 900 1
    save 300 10
    save 60 10000
    
    client-output-buffer-limit normal 0 0 0
    client-output-buffer-limit replica 0 0 0
    client-output-buffer-limit pubsub 32mb 8mb 60
    hz 10
    aof-rewrite-incremental-fsync yes
    requirepass "Mso7-Bk0=wV~O"
    # Generated by CONFIG REWRITE
    replicaof 10.148.100.67 6600   
    masterauth "Mso7-Bk0=wV~O"
    
    
    #启动redis
    redis-server /export/redis6600/etc/redis.conf  & 
    

    测试主从

    #在主节点添加key
    redis-cli  -p 6600
    127.0.0.1:6600> AUTH Mso7-Bk0=wV~O
    OK
    127.0.0.1:6600> SET testa aaa
    OK
    127.0.0.1:6600> get testa
    "aaa"
    
    #从节点验证
    # redis-cli  -p 6600
    127.0.0.1:6600>  AUTH Mso7-Bk0=wV~O
    OK
    127.0.0.1:6600> get testa
    "aaa"
    
    #证明主从配置成功。
    
  • 相关阅读:
    Cookie&Session会话跟踪技术
    JS前端数据多条件筛选(商品搜索)
    vue数据传递的特殊实现技巧
    Vue2.x directive自定义指令
    vue 自定义组件使用v-model
    Array.prototype.slice.call(arguments)探究
    webstorm快捷键汇总
    表单添加缩略图及截图js代码
    CSS水平垂直居中的几种方法
    下载页面判断客户端
  • 原文地址:https://www.cnblogs.com/lixinliang/p/15945499.html
Copyright © 2020-2023  润新知