阿里云负载均衡配置多域名_阿里云slb限流措施方法

阿里云负载均衡配置多域名_阿里云slb限流措施方法,第1张

阿里云负载均衡配置多域名_阿里云slb限流措施方法 阿里云容器服务在使用的过程中,针对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.64stdin_open: true tty: true注意事项:如果发现调度不生效,进入服务列表,选择你需要调度的服务,选择重新调度,选择强制重新调度强制重新调度会丢弃已有容器的volume,请做好相应的备份迁移工作解法二:容器集群内部客户端使用link访问服务端,集群外部使用SLB示例应用模板(使用了lb标签)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 command: redis-cli -h redis-master stdin_open: true tty: true解法三:容器集群内部客户端使用自定义路由(基于HAProxy)作为代理访问服务端,集群外部使用SLB示例应用模板(使用了lb标签,自定义路由镜像)lb: image: registry.aliyuncs.com/acs/proxy:0.5ports:– ‘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”links:– rsyslog:rsyslogrsyslog: image: registry.cn-hangzhou.aliyuncs.com/linhuatest/rsyslog:latestredis-master: ports:– 6379/tcp image: ‘redis:alpine’labels:# 告诉自定义路由需要暴露6379端口aliyun.proxy.TCP_PORTS: “6379”# 告诉系统,该服务的路由需要添加到自定义路由服务中aliyun.proxy.required: “true”redis-slave: ports:– 6379/tcp image: ‘redis:alpine’links:– redis-master labels:# 告诉自定义路由需要暴露6379端口aliyun.proxy.TCP_PORTS: “6379”# 告诉系统,该服务的路由需要添加到自定义路由服务中aliyun.proxy.required: “true”# 告诉系统,slave需要等待master启动之后再启动,并且对master有依赖aliyun.depends: redis-master command: redis-server –slaveof redis-master 6379redis-client: image: ‘redis:alpine’links:– lb:www.example.com labels:aliyun.depends: lb command: redis-cli -h www.example.com stdin_open: true tty: true该解决方案,做到了redis的主从架构,同时经过自定义路由镜像做负载均衡,做到了一定程度的高可用。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/tougao/651804.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-17
下一篇 2022-04-17

发表评论

登录后才能评论

评论列表(0条)

保存