Redis集群設(shè)置密碼訪問(wèn)的實(shí)現(xiàn)
一、背景
1.1 主機(jī)位置
假定Redis集群服務(wù)部署在:111.111.111.111 主機(jī)上
1.2 偽分布式-配置文件位置
配置文件路徑:
[root@bigdata-test-db-0001 ~]# find / -name redis.conf /data/redis_cluster/7001/redis.conf /data/redis_cluster/7002/redis.conf /data/redis_cluster/7003/redis.conf /data/redis_cluster/7004/redis.conf /data/redis_cluster/7005/redis.conf /data/redis_cluster/7000/redis.conf
1.3 添加環(huán)境變量(略)
命令行工具路徑(已加入系統(tǒng)環(huán)境變量中):
redis-cli命令位置: /usr/local/bin/redis-cli vim /etc/profile export PATH=$PATH:/usr/local/bin
1.4 集群?jiǎn)⑼2僮?/h3>
啟動(dòng)集群:
cd /data/redis_cluster [root@bigdata-test-db-0001 redis_cluster]# redis-server 7000/redis.conf [root@bigdata-test-db-0001 redis_cluster]# redis-server 7001/redis.conf [root@bigdata-test-db-0001 redis_cluster]# redis-server 7002/redis.conf [root@bigdata-test-db-0001 redis_cluster]# redis-server 7003/redis.conf [root@bigdata-test-db-0001 redis_cluster]# redis-server 7004/redis.conf [root@bigdata-test-db-0001 redis_cluster]# redis-server 7005/redis.conf
關(guān)閉集群:
redis-cli -h 111.111.111.111 -p 7001 shutdown redis-cli -h 111.111.111.111 -p 7000 shutdown redis-cli -h 111.111.111.111 -p 7001 shutdown redis-cli -h 111.111.111.111 -p 7002 shutdown redis-cli -h 111.111.111.111 -p 7003 shutdown redis-cli -h 111.111.111.111 -p 7004 shutdown redis-cli -h 111.111.111.111 -p 7005 shutdown
1.5 操作無(wú)密碼的redis集群
無(wú)密碼命令行訪問(wèn):
[root@bigdata-test-db-0001 ~]# redis-cli -h 111.111.111.111 -p 7000 111.111.111.111:7000> keys * 1) "k3" 2) "k2" 111.111.111.111:7000> get k2 "v2" 111.111.111.111:7000> get k3 "v3"
二、為redis集群設(shè)置密碼
2.1 配置步驟
111.111.111.111:7000>
從7000到7005,依次按如下方式添加用于auth的password:
cd /data/redis_cluster
[root@bigdata-test-db-0001 redis_cluster]# vim 7000/redis.conf
添加如下語(yǔ)句:
requirepass ${YOUR_PASSWORD}
使用password方式連接redis集群:
如果去除集群訪問(wèn)密碼:
在700[0~5]中將配置文件中的 “requirepass ${YOUR_PASSWORD}” 注釋,重啟即可。
2.2 集群?jiǎn)⑼2僮?/h3>
啟動(dòng)集群:
cd /data/redis_cluster [root@bigdata-test-db-0001 redis_cluster]# redis-server 7000/redis.conf [root@bigdata-test-db-0001 redis_cluster]# redis-server 7001/redis.conf [root@bigdata-test-db-0001 redis_cluster]# redis-server 7002/redis.conf [root@bigdata-test-db-0001 redis_cluster]# redis-server 7003/redis.conf [root@bigdata-test-db-0001 redis_cluster]# redis-server 7004/redis.conf [root@bigdata-test-db-0001 redis_cluster]# redis-server 7005/redis.conf
關(guān)閉集群:
redis-cli -h 111.111.111.111 -p 7001 -a ${YOUR_REDIS_PASSWORD} shutdown
redis-cli -h 111.111.111.111 -p 7000 -a ${YOUR_REDIS_PASSWORD} shutdown
redis-cli -h 111.111.111.111 -p 7001 -a ${YOUR_REDIS_PASSWORD} shutdown
redis-cli -h 111.111.111.111 -p 7002 -a ${YOUR_REDIS_PASSWORD} shutdown
redis-cli -h 111.111.111.111 -p 7003 -a ${YOUR_REDIS_PASSWORD} shutdown
redis-cli -h 111.111.111.111 -p 7004 -a ${YOUR_REDIS_PASSWORD} shutdown
redis-cli -h 111.111.111.111 -p 7005 -a ${YOUR_REDIS_PASSWORD} shutdown
2.3 操作有密碼的redis集群
通過(guò)密碼方式訪問(wèn)到redis集群:
redis-cli -h 111.111.111.111 -p 7000 -c -a ${YOUR_PASSWORD} --raw
111.111.111.111:7000> keys *
k3
k2
111.111.111.111:7000> get k3
-> Redirected to slot [4576] located at 111.111.111.111:7003
v3
111.111.111.111:7003> get v2
-> Redirected to slot [13550] located at 111.111.111.111:7002
到此這篇關(guān)于Redis集群設(shè)置密碼訪問(wèn)的文章就介紹到這了,更多相關(guān)Redis集群設(shè)置密碼訪問(wèn)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
利用Redis進(jìn)行數(shù)據(jù)緩存的項(xiàng)目實(shí)踐
在實(shí)際的業(yè)務(wù)場(chǎng)景中,Redis 一般和其他數(shù)據(jù)庫(kù)搭配使用,用來(lái)減輕后端數(shù)據(jù)庫(kù)的壓力,本文就介紹了利用Redis進(jìn)行數(shù)據(jù)緩存的項(xiàng)目實(shí)踐,具有一定的參考價(jià)值,感興趣的可以了解一下2022-06-06
redis和rabbitmq實(shí)現(xiàn)延時(shí)隊(duì)列的示例代碼
在高并發(fā)場(chǎng)景下,延遲隊(duì)列顯得尤為重要,本文主要介紹了兩種方式,redis和rabbitmq實(shí)現(xiàn)延時(shí)隊(duì)列,具有一定的參考價(jià)值,感興趣的可以了解一下2024-03-03
從MySQL到Redis的簡(jiǎn)單數(shù)據(jù)庫(kù)遷移方法
這篇文章主要介紹了從MySQL到Redis的簡(jiǎn)單數(shù)據(jù)庫(kù)遷移方法,注意Redis數(shù)據(jù)庫(kù)基于內(nèi)存,并不能代替?zhèn)鹘y(tǒng)數(shù)據(jù)庫(kù),需要的朋友可以參考下2015-06-06

