zoukankan      html  css  js  c++  java
  • redis哨兵模式增加密码认证

    redis哨兵模式增加密码认证

    ------------服务器端修改---------------


    1、首选找到各个节点的redis.conf

    打开文件内找到这一行

     #requirepass 后面写密码

    改成 

    requirepass 你自己的密码

    2、然后修改 多个节点下的sentinel.conf

    # 当在Redis实例中开启了requirepass foobared 授权密码 这样所有连接Redis实例的客户端都要提供密码
    # 设置哨兵sentinel 连接主从的密码 注意必须为主从设置一样的验证密码
    # sentinel auth-pass <master-name> <password>
    sentinel auth-pass mymaster 密码


    3、关闭Redis

    进入redis-cli

    save
    shutdown

    ps -ef | grep sentinel
    kill sentinel的进程号。

    4、重启
    在redis安装目录执行
    先启动master,后启动slave。

    cd /usr/redis/redis-3.2.8/src/
    ./redis-server /home/redis/6379/redis.conf
    ./redis-server /home/redis/6380/redis.conf
    ./redis-server /home/redis/6381/redis.conf
    
    #然后执行
    
    ./redis-sentinel /home/redis/6379/sentinel.conf
    ./redis-sentinel /home/redis/6380/sentinel.conf
    ./redis-sentinel /home/redis/6381/sentinel.conf

     ------------java代码的修改----------------

    //连接池配置
    JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
    jedisPoolConfig.setMaxTotal(10);
    jedisPoolConfig.setMaxIdle(5);
    jedisPoolConfig.setMinIdle(5);
    //哨兵信息
    Set<String> sentinels = new HashSet<String>(Arrays.asList(
        "192.168.11.128:26379",
        "192.168.11.129:26379",
        "192.168.11.130:26379"
    ));
    //创建连接池
    //mymaster是我们配置给哨兵的服务名称
    //sentinels是哨兵信息
    //jedisPoolConfig是连接池配置
    //abcdefg是连接Redis服务器的密码
    //new JedisSentinelPool("mymaster", sentinels, jedisPoolConfig);改为下面的代码就行其他的不用动
    
    JedisSentinelPool pool = new JedisSentinelPool("mymaster", sentinels, jedisPoolConfig, "abcdefg");
  • 相关阅读:
    友好城市, 美团笔试题
    字符串计数, 美团笔试题
    公交车, 美团笔试题
    交错序列, 美团笔试题
    题目列表, 美团笔试题, 字符串数组比较
    图的遍历, 美团笔试题
    最长全1串, 美团笔试题
    外卖满减, 美团笔试题
    种花, 美团笔试题
    考试策略, 美团笔试题
  • 原文地址:https://www.cnblogs.com/liwei1994/p/12581744.html
Copyright © 2011-2022 走看看