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");

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM