DockerCompose如何单机配置Redis与Senti

这篇文章给大家分享的是有关Docker Compose单机配置redis与Senti的内容。小编觉得挺实用的,因此分享给大家学习。如下资料是关于Docker Compose单机配置Redis与Senti的步骤。

创新互联公司专注于企业成都营销网站建设、网站重做改版、昔阳网站定制设计、自适应品牌网站建设、成都h5网站建设成都做商城网站、集团公司官网建设、成都外贸网站制作、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为昔阳等各大城市提供网站开发制作服务。

Docker Compose如何单机配置Redis与Senti

卸载旧版本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

Docker Compose如何单机配置Redis与Senti

安装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

在模板中定义了下面一系列服务

  • master: Redis master
  • slave: Redis slave
  • sentinel: Redis Sentinel

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"的集群的监控配置

注意:

  • slave和sentinel容器初始化配置的Redis master节点主机名为"redis-master",这里我们利用了Docker容器连接的别名机制来连接master和sentinel/slave容器实例
  • 由于我们会部署3个Sentinel,我们把sentinel的"quorum"设置为2,只有两个sentinel同意故障切换,才会真正切换相应的redis master节点。

sudo yum install -y docker-compose

sudo docker-compose up -d

Docker Compose如何单机配置Redis与Senti

厕所回来都好了

docker ps

Docker Compose如何单机配置Redis与Senti

怎么只有2个哨兵,扩展到3个

docker-compose scale sentinel=3

Docker Compose如何单机配置Redis与Senti

顺大便扩容2个slave redis

docker-compose scale slave=2

Docker Compose如何单机配置Redis与Senti

看下目前跑的内容

docker ps|sort -k2

Docker Compose如何单机配置Redis与Senti

改一个测试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 进行了切换

Docker Compose如何单机配置Redis与Senti

但是一台主机的3个redis和3个sentinel 不能算高可用,需要将redis和sentinel部署到不同区域的多个主机中

以上就是Docker Compose单机配置Redis与Senti的详细内容了,看完之后是否有所收获呢?如果想了解更多相关内容,欢迎关注创新互联行业资讯!


新闻名称:DockerCompose如何单机配置Redis与Senti
标题来源:http://pwwzsj.com/article/gphiii.html