zoukankan      html  css  js  c++  java
  • 单点安装redis+哨兵

    下载地址

    http://redis.io/download/ 
    http://219.239.26.13/files/205900000B7E5F47/download.redis.io/releases/redis-4.0.9.tar.gz

    创建程序目录

    mkdir /data/
    #目录结构自己调整 redis编译完成后,有用的文件是 redis.conf sentinel.conf src/redis-* 可执行文件

    解压并编译

    yum -y install  gcc tcl gcc-c++ make
    tar zxvf redis-4.0.9.tar.gz
    mv redis-4.0.9 /data/
    cd redis-4.0.9
    make
    make install 

    规划目录结构

    [root@qiqi3 data]# tree redis-4.0.9/
    redis-4.0.9/
    ├── 6379
    │   ├── conf
    │   │   └── redis.conf
    │   ├── data
    │   │   └── dump.rdb
    │   ├── login.sh
    │   ├── logs
    │   │   └── redis.log
    │   ├── sentinel
    │   │   ├── sentinel.conf
    │   │   ├── sentinel.log
    │   │   └── start_sentinel.sh
    │   └── start.sh
    └── bin
        ├── redis-benchmark
        ├── redis-check-aof
        ├── redis-check-rdb
        ├── redis-cli
        ├── redis-sentinel
        ├── redis-server
        ├── redis-trib.rb
        ├── runtest
        ├── runtest-cluster
        └── runtest-sentinel
    
    6 directories, 18 files
    笔者的目录结构

    修改配置文件 redis.conf

    #常规修改项
    bind 1.1.1.1 pidfile "/app/redis-3.2.11/6379/run/redis_6379.pid" logfile "/app/redis-3.2.11/6379/logs/redis.log" dir "/app/redis-3.2.11/6379/data"
    maxmemory 268435456 #设置最大使用内存

    修改配置文件 sentinel.conf

    bind 1.1.1.1
    dir "/data/redis-4.0.9/6379/sentinel"
    logfile "/data/redis-4.0.9/6379/sentinel/sentinel.log"

    启动redis

    /data/redis-4.0.9/bin/redis-server /data/redis-4.0.9/6379/conf/redis.conf &
    /data/redis-4.0.9/bin/redis-sentinel /data/redis-4.0.9/6379/sentinel/sentinel.conf &

    登录redis

    #如果绑定了固定ip 就指定ip登录 否则会被拒绝
    /app/redis-3.2.11/bin/redis-cli -h 172.16.1.29 -p 6379

    设置密码

    打开文件/etc/redis.conf,找到其中的# requirepass foobared,去掉前面的#,并把foobared改成你的密码。

    使用密码登录

    /app/redis-3.2.11/bin/redis-cli -h 172.16.1.29 -p 6379 -a 123

     当第一启动redis的时候,可能会产生一些警告

    WARNING The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
     WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
     WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.

    可以看到存在3条启动警告信息:

    第一个错误和第二个错误可以同时解决,第一个错误大概是说somaxconn的值128设置过小,此值受限于系统的somaxconn与tcp_max_syn_backlog这两个值,所以应该把这两个内核参数值调大,第二个错误是过量使用内存设置为0!在低内存环境下,后台保存可能失败。请在/etc/sysctl.conf 添加一项 ‘vm.overcommit_memory = 1′ ,然后重启(或者运行命令’sysctl vm.overcommit_memory=1’ )使其生效。

    针对警告所做的修改:

     # vim /etc/sysctl.conf
     net.core.somaxconn = 20480
     #最大队列长度,应付突发的大并发连接请求,默认为128
     net.ipv4.tcp_max_syn_backlog = 20480
     #半连接队列长度,此值受限于内存大小,默认为1024
     vm.overcommit_memory = 1
     #过量使用内存设置为0!
     # sysctl -p
    第三个警告错误是需要关闭Linux (THP) 透明内存
    
     # vim /etc/rc.local
     echo never > /sys/kernel/mm/transparent_hugepage/enabled #在开机脚本里追加此命令
  • 相关阅读:
    RabbitMq使用说明
    php使用rabbitmq需安装amqp拓展协议
    新建springboot web项目pom报错
    HttpRunner Manager 接口自动化平台搭建
    数据库存储过程进行批量插入数据
    Windows系统下Robot Framework的安装
    利用Charles模拟客户端弱网环境进行弱网测试
    JMeter进行简单的接口压测
    JMeter的安装和使用
    grep, sed 和 awk 学习总结
  • 原文地址:https://www.cnblogs.com/lazyball/p/8946064.html
Copyright © 2011-2022 走看看