Ubuntu18.04 安裝redis5.0.5集羣

目標:使用3臺服務器A、B、C,每臺服務器部署一套主從(1主1從),三個主服務來平分redis槽

  • 10.108.1.88(6379、6380)
  • 10.108.1.89(6379、6380)
  • 10.108.1.90(6379、6380)

安裝Redis

建議下到

wget http://download.redis.io/releases/redis-5.0.5.tar.gz
tar -zxvf redis-5.0.5.tar.gz
cp -r redis-5.0.5 /usr/local/redis
cd /usr/local/redis/redis-5.0.5/

編譯並安裝

sudo make
sudo make install

集羣配置

  1. 使用utils路徑下的 install_server.sh安裝3個端口配置文件,下面以6379爲例
[root@node01 utils]# pwd
/usr/local/redis/redis-5.0.5/utils
[root@node01 utils]# sudo sh install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path [/opt/redis/bin/redis-server]
Selected config:
Port           : 6379
Config file    : /etc/redis/6379.conf
Log file       : /var/log/redis_6379.log
Data dir       : /var/lib/redis/6379
Executable     : /opt/redis/bin/redis-server
Cli Executable : /opt/redis/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!

image-20221020150240692

  1. 自行安裝2個端口(6379、6380)以後分別修改配置文件
#打開集羣模式
cluster-enabled yes
#集羣配置文件
cluster-config-file nodes_6379.conf
#集羣節點超時時間
cluster-node-timeout 5000
#允許其他服務器連接
protected-mode no
#本機IP地址
bind 10.108.1.88
#打開aof持久化模式
appendonly yes
  1. 主從(6379、6380)配置都修改完以後,以同樣的方式再添加10.108.1.89,10.108.1.90兩臺配置作爲集羣備用

開始部署集羣

  1. 分別在10.108.1.88、10.108.1.89、10.108.1.90 上執行啓動redis的命令
sudo redis-server /etc/redis/6379.con
sudo redis-server /etc/redis/6380.con
  1. 使用redic-cli部署集羣

    redis-cli --cluster create 10.108.1.88:6379 10.108.1.88:6380  10.108.1.89:6379 10.108.1.89:6380 10.108.1.90:6379 10.108.1.90:6380  --cluster-replicas 1
    

image-20221020150240692

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章