大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
专注于为中小企业提供做网站、网站制作服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业建湖免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了上1000家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
卸载旧版本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部署到不同区域的多个主机中