温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Docker Compose 单机部署Redis+Senti

发布时间:2020-08-15 11:59:13 来源:网络 阅读:902 作者:pcdog 栏目:云计算

Docker Compose 单机部署Redis+Senti

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部署到不同区域的多个主机中

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI