阿里云容器服务在使用的过程中,针对TCP负载均衡的场景,会遇到这样的问题:如果一个应用的客户端镜像和服务端镜像均部署在同一个节点(ECS)上面,由于受SLB的限制,该应用的客户端不能通过SLB访问本机的服务端。本文试图以常用的基于TCP协议的redis为例,逐步深入的方式来解决这个问题,同时带大家了解一下容器服务的概念。
解法一:通过调度容器,避免客户端和服务端容器部署在同一个节点
示例应用模板(使用了lb标签,和swarm fileter功能)
redis-master: ports:
– 6379:6379/tcp image: ‘redis:alpine’
labels:
aliyun.lb.port_6379: tcp://proxy_test:6379redis-client: image: ‘redis:alpine’
links:
– redis-master environment:
– ‘affinity:aliyun.lb.port_6379!=tcp://proxy_test:6379’
command: redis-cli -h 120.25.131.64
stdin_open: true tty: true
注意事项:
解法二:容器集群内部客户端使用link访问服务端,集群外部使用SLB
示例应用模板(使用了lb标签)
– redis-master command: redis-cli -h redis-master stdin_open: true tty: true
解法三:容器集群内部客户端使用自定义路由(基于HAProxy)作为代理访问服务端,集群外部使用SLB
示例应用模板(使用了lb标签,自定义路由镜像)
lb: image: registry.aliyuncs.com/acs/proxy:0.5
ports:
– ‘6379:6379/tcp’
restart: always labels:
# addon 使得proxy镜像有订阅注册中心的能力,动态加载服务的路由
aliyun.custom_addon: “proxy”
# 每台vm 部署一个该镜像的容器
aliyun.global: “true”
# 前端绑定SLB,使用lb标签
aliyun.lb.port_6379: tcp://proxy_test:6379
# 告诉系统,自定义路由需要等待master和slave启动之后再启动,并且对master和slave有依赖
aliyun.depends: redis-master,redis-slave environment:
# 支持加载路由的后端容器的范围,”*”表示整个集群,默认为应用内的服务 ADDITIONAL_SERVICES: “*”
EXTRA_DEFAULT_SETTINGS: “log rsyslog local0,log global,option httplog”
# 配置HAProxy工作于tcp模式 MODE: “tcp”
– rsyslog:rsyslogrsyslog: image: registry.cn-hangzhou.aliyuncs.com/linhuatest/rsyslog:latestredis-master: ports:
– 6379/tcp image: ‘redis:alpine’
# 告诉自定义路由需要暴露6379端口
aliyun.proxy.TCP_PORTS: “6379”
# 告诉系统,该服务的路由需要添加到自定义路由服务中
aliyun.proxy.required: “true”redis-slave: ports:
– redis-master labels:
aliyun.proxy.required: “true”
# 告诉系统,slave需要等待master启动之后再启动,并且对master有依赖
aliyun.depends: redis-master command: redis-server –slaveof redis-master 6379redis-client: image: ‘redis:alpine’
– lb:www.example.com labels:
aliyun.depends: lb command: redis-cli -h www.example.com stdin_open: true tty: true
该解决方案,做到了redis的主从架构,同时经过自定义路由镜像做负载均衡,做到了一定程度的高可用。
本文由知识库于2021-09-26发表在龙哥云资源网,如有疑问,请联系我们。本文链接:https://www.longgeyun.com/knowledge/5613.html
上一篇devops实践指南开发相关(devops能力成熟度模型)
下一篇阿里云短视频sdk集成(免费的短视频sdk)
高校最常见的食物中毒有哪些
急性肠胃炎与食物中毒怎么分辨
莫代尔面料和纯棉面料哪个好内裤 哪个儿童可以穿
为什么说开速腾的都不是一般人 速腾开出去有面子吗
活珠子和毛蛋的区别在哪里 哪个好吃
家里放石头的八大禁忌有哪些 家中石头最佳摆放位置
怎么判断自己帅还是丑男 男生怎样越长越帅
单身女生红绳戴左手还是右手 女生红绳戴哪里合适
Pr2020零基础快速入门
文字转语音App最新版3.0
APP下载页源码-带后台