加入收藏 | 设为首页 | 会员中心 | 我要投稿 应用网_丽江站长网 (http://www.0888zz.com/)- 科技、建站、数据工具、云上网络、机器学习!
当前位置: 首页 > 站长资讯 > 外闻 > 正文

搭建高可用负载均衡器: haproxy+keepalived

发布时间:2018-08-31 10:05:22 所属栏目:外闻 来源:云栖社区
导读:副标题#e# 企业业务量比较小的时候,单台服务器就可以满足业务需要了。但是随着业务发展,单服务器的问题就凸显出来了: 当服务器挂掉时,业务就会中断 当业务量增加,单台服务器性能变差,如何透明的扩展服务器和带宽,增加服务器吞吐量 负载均衡器可以解

把后端服务器IP(192.168.1.2, 192.168.1.3, 192.168.1.4)加到backend里

  1. #--------------------------------------------------------------------- 
  2. # Global settings 
  3. #--------------------------------------------------------------------- 
  4. global 
  5.     log         127.0.0.1 local2 
  6.  
  7.     chroot      /var/lib/haproxy 
  8.     pidfile     /var/run/haproxy.pid 
  9.     maxconn     4096 
  10.     user        haproxy 
  11.     group       haproxy 
  12.     daemon 
  13.  
  14.     # turn on stats unix socket 
  15.     stats socket /var/lib/haproxy/stats 
  16.  
  17. listen stats 
  18.     bind    *:9000 
  19.     mode    http 
  20.     stats   enable 
  21.     stats   hide-version 
  22.     stats   uri       /stats 
  23.     stats   refresh   30s 
  24.     stats   realm     Haproxy Statistics 
  25.     stats   auth      admin:admin 
  26.  
  27.  
  28. frontend  k8s-api 
  29.     bind *:443 
  30.     mode tcp 
  31.     option tcplog 
  32.     tcp-request inspect-delay 5s 
  33.     tcp-request content accept if { req_ssl_hello_type 1 } 
  34.     default_backend k8s-api-backend 
  35.  
  36. backend k8s-api-backend 
  37.     mode tcp 
  38.     option tcplog 
  39.     option tcp-check 
  40.     balance roundrobin 
  41.     server master1 192.167.1.2:80 maxconn 1024 weight 5 check 
  42.     server master2 192.167.1.3:80 maxconn 1024 weight 5 check 
  43.     server master3 192.167.1.4:80 maxconn 1024 weight 5 check 

2.5 配置nginx

给nginx添加SSL证书,配置过程略

  1. vi /usr/share/nginx/html/index.html 

把index.html里面字符串Welcome to nginx改成Welcome to nginx HA

3 启动服务

3.1 启动nginx

  1. sudo systemctl start nginx 
  2. sudo systemctl enable nginx 

3.2 启动haproxy

  1. sudo systemctl start haproxy 
  2. sudo systemctl enable haproxy 

(编辑:应用网_丽江站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读