您好,登錄后才能下訂單哦!
卸載舊版本docker uninstall old version
sudo yum remove docker \
????????????????? docker-client \
????????????????? docker-client-latest \
????????????????? docker-common \
????????????????? docker-latest \
????????????????? docker-latest-logrotate \
????????????????? docker-logrotate \
????????????????? docker-engine
安裝repo install docker repo
sudo yum install -y yum-utils \
? device-mapper-persistent-data \
? lvm2
sudo yum-config-manager \
--add-repo \
??? https://download.docker.com/linux/centos/docker-ce.repo
安裝社區版本install Docker Engine-Community
sudo yum install -y docker-ce docker-ce-cli containerd.io --skip-broken
設置服務啟動和測試鏡像
sudo systemctl start docker
sudo systemctl enable docker
sudo docker run hello-world
安裝git和下載代碼
sudo yum install -y git
git clone https://github.com/AliyunContainerService/redis-cluster
cd redis-cluster
檢查docker compose文件
cat docker-compose.yml
master:
image: redis:3
slave:
image: redis:3
command: redis-server --slaveof redis-master 6379
links:
- master:redis-master
sentinel:
build: sentinel
environment:
- SENTINEL_DOWN_AFTER=5000
- SENTINEL_FAILOVER=5000
links:
- master:redis-master
- slave
在模板中定義了下面一系列服務
cat sentinel.conf
# Example sentinel.conf can be downloaded from http://download.redis.io/redis-stable/sentinel.conf
port 26379
dir /tmp
sentinel monitor mymaster redis-master 6379 $SENTINEL_QUORUM
sentinel down-after-milliseconds mymaster $SENTINEL_DOWN_AFTER
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster $SENTINEL_FAILOVER
并以sentinel模式啟動容器。其配置文件如下,其中包含了sentinel對名為"mymaster"的集群的監控配置
注意:
sudo yum install -y docker-compose
sudo docker-compose up -d
容我上個廁所
。。。。。。。。。。。
廁所回來都好了
docker ps
怎么只有2個哨兵,擴展到3個
docker-compose scale sentinel=3
順大便擴容2個slave redis
docker-compose scale slave=2
看下目前跑的內容
docker ps|sort -k2
改一個測試redis宕機的腳本
vi test.sh
MASTER_IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' rediscluster_master_1)
SLAVE_IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' rediscluster_slave_1)
SENTINEL_IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' rediscluster_sentinel_1)
echo Redis master: $MASTER_IP
echo Redis Slave: $SLAVE_IP
echo ------------------------------------------------
echo Initial status of sentinel
echo ------------------------------------------------
docker exec rediscluster_sentinel_1 redis-cli -p 26379 info Sentinel
echo Current master is
docker exec rediscluster_sentinel_1 redis-cli -p 26379 SENTINEL get-master-addr-by-name mymaster
echo ------------------------------------------------
echo Stop redis master
docker pause rediscluster_master_1
echo Wait for 10 seconds
sleep 10
echo Current infomation of sentinel
docker exec rediscluster_sentinel_1 redis-cli -p 26379 info Sentinel
echo Current master is
docker exec rediscluster_sentinel_1 redis-cli -p 26379 SENTINEL get-master-addr-by-name mymaster
echo ------------------------------------------------
echo Restart Redis master
docker unpause rediscluster_master_1
sleep 5
echo Current infomation of sentinel
docker exec rediscluster_sentinel_1 redis-cli -p 26379 info Sentinel
echo Current master is
docker exec rediscluster_sentinel_1 redis-cli -p 26379 SENTINEL get-master-addr-by-name mymaster
./test.sh
發現redis master 進行了切換
但是一臺主機的3個redis和3個sentinel 不能算高可用,需要將redis和sentinel部署到不同區域的多個主機中
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。