1. 下載下傳
http://download.redis.io/releases/
本文以6.2.0版本為例
2. Redis單體服務安裝
1. 檔案解壓
下載下傳的redis-6.2.0.tar.gz檔案上傳到linux伺服器的/usr/local/目錄下,解壓縮
tar -zxvf redis-6.2.0.tar.gz
,得到redis-6.2.0檔案夾
2. 編譯安裝
進入redis-6.2.0檔案夾,執行指令
make
編譯
編譯結束之後,安裝redis
make PREFIX=/usr/local/redis install
安裝到/usr/local/redis目錄下。
啟動redis前,先修改redis-6.2.0下的redis.conf配置檔案,比如:
daemonize yes
# Redis預設是不作為守護程序來運作的。你可以把這個設定為"yes"讓它作為守護程序來運作。
# 注意,當作為守護程序的時候,Redis會把程序ID寫到 /var/run/redis.pid
pidfile /var/run/redis.pid
# 當以守護程序方式運作的時候,Redis會把程序ID預設寫到 /var/run/redis.pid。你可以在這裡修改路徑。
port 6379
# 接受連接配接的特定端口,預設是6379。
# 如果端口設定為0,Redis就不會監聽TCP套接字。
bind 伺服器ip
# 如果你想的話,你可以綁定單一接口;如果這裡沒單獨設定,那麼所有接口的連接配接都會被監聽。
requirepass xxxxxx
# 要求用戶端在處理任何指令時都要驗證身份和密碼。
- 需要說明的是,在叢集配置中使用linux伺服器的公網ip,會導緻無法啟動的問題,我們需要使用
查詢的ip(如圖紅色部分,然後設定 bind 紅色部分的ip )ifconfig
Redis叢集部署操作流程(版本大于5.0)
3. 啟動redis
将修改後的redis.conf複制到/usr/local/redis/conf/下
cd /usr/local/redis
mkdir conf
cp /usr/local/redis-6.2.0/redis.conf /usr/local/redis/bin
啟動redis
cd /usr/local/redis/bin
./redis-server ./…/conf/redis.conf
然後通過RDM軟體或者指令
./redis-cli -h 127.0.0.1 -p 6379 -a yourpass
登入使用
3. Redis叢集部署
- 将安裝成功的redis目錄複制到/usr/local/redis_cluster下建立的7001、7002、7003、7004、7005、7006檔案夾下,
- 依次redis.conf修改配置檔案如下(以7001舉例):
bind ifconfig的ip
port 7001
cluster-enabled yes
cluster-config-file nodes_7001.conf
pidfile /var/run/redis_7001.pid
appendonly yes
cluster-node-timeout 5000(自己定逾時時間)
requirepass yourpassword
- 啟動7001
cd /usr/local/redis_cluster/7001/bin ./redis-server
/usr/local/redis_cluster/7006/conf/redis.conf
- 其他節點同理
- 檢視
ps -ef | grep redis
netstat -tnlp | grep redis
![]()
Redis叢集部署操作流程(版本大于5.0)
- 啟動叢集
./redis-cli --cluster create --cluster-replicas 1 192.168.xx.xx:7001
192.168.xx.xx:7002 192.168.xx.xx:7003 192.168.xx.xx:7004 192.168.xx.xx:7005 192.168.xx.xx:7006 -a yourpassword
![]()
Redis叢集部署操作流程(版本大于5.0)