542179528 发表于 2019-1-2 10:19:25

高可用haproxy调度varnish服务器缓存后端动静分离集群架构

  (1) 动静分离部署wordpress,动静都要能实现负载均衡,要注意会话的问题;
  (2) 在haproxy和后端主机之间添加varnish进行缓存;
  (3) 设计拓扑;
  (4) haproxy的设定要求:
   (a) stats page,要求仅能通过本地访问使用管理接口;
   (b) 动静分离;
   (c) 分别考虑不同的服务器组的调度算法;
  (5) haproxy高可用;
  实验规划:
  利用keepalived主备高可用两个haproxy服务器
  对varnish缓存服务器做高可用
  动态web集群
  静态web集群
  haproxy1:   172.16.1.4
  haproxy2:   172.16.1.2
  varnish1:   172.16.1.5
  varnish2:   172.16.1.6
  dynamic server1:172.16.1.3
  dynamic server2:172.16.1.7
  static server1: 172.16.1.10
  static server2: 172.16.1.8
  拓扑图
http://s1.运维网.com/images/20171212/1513085450337534.png
  一、两台haproxy配置文件配置
http://s1.运维网.com/images/20171212/1513085482777792.png
http://s1.运维网.com/images/20171212/1513085498969840.png
  启动服务
  ~]# systemctl start haproxy
  ~]# systemctl status haproxy#查看状态
  ~]# ss -tnlp#查看80和9999端口是否启用
  ~]# systemctl enable haproxy #设置开机启动
  二、keepalived的配置
  
  haproxy1的keepalived配置
http://s1.运维网.com/images/20171212/1513085542310661.png
  haproxy2的keepalived配置
  http://s1.运维网.com/images/20171212/1513085565783107.png
  三、两台varnish主机的配置
  更改varnish的监听端口为80
  # vim /etc/varnish/varnish.params
  VARNISH_LISTEN_PORT=80
  varnish配置文件内容
  # vim /etc/varnish/default.vcl
http://s1.运维网.com/images/20171212/1513085733239445.png
http://s1.运维网.com/images/20171212/1513085740448375.png
http://s1.运维网.com/images/20171212/1513085747702920.png
  编译使配置生效
  # varnishadm -S /etc/varnish/secret -T 127.0.0.1:6082
  200
  -----------------------------
  Varnish Cache CLI 1.0
  -----------------------------
  Linux,3.10.0-327.el7.x86_64,x86_64,-smalloc,-smalloc,-hcritbit
  varnish-4.0.5 revision 07eff4c29
  Type 'help' for command list.
  Type 'quit' to close CLI session.
  vcl.list
  200
  available       0 boot
  active          0 myconf3
  varnish> vcl.load conf1 default.vcl
  200
  VCL compiled.
  vcl.use conf1
  200
  VCL 'conf1' now active
  vcl.list
  200
  available       0 boot
  available       0 myconf3
  active          0 conf1
  四、后端动静服务器wordpress主机配置
  后端amp配置不做赘述
  在动态主机的/var/www/html/下创建health.php用于动态健康状态检查
  DynamicServer is Health.
  在静态主机的/var/www/html/下创建health.html用于静态健康状态检查
  StaticServer is Health.
  五、客户端查看
  客户端登陆haproxy的stats page
http://s1.运维网.com/images/20171212/1513085776778396.png
  关闭一台varnish服务器后,可以在stats page看到一台正常运行,一台关闭了
http://s1.运维网.com/images/20171212/1513085784639234.png
  登陆wordpress可以看到之前正常上传图片的博客
http://s1.运维网.com/images/20171212/1513085793925583.png
  六、总结
  
  1、架构优点:
  (1)HAProxy为Varnish缓存服务器提供了高可用的负载均衡,其使用的算法,也为Varnish提升了缓存命中率;
  (2)HAProxy提供Web图形化管理界面,使得管理更加便捷高效;
  (3)Varnish的高效缓存机制极大的提升了Web应用的性能,降低了Web服务器的压力;
  (4)Varnish给后端Web服务器提供了高可用负载均衡,并使用了动态分离技术,保障了后端主机的冗余,显著提升了其性能;
  (5)使用Keepalive对HAproxy做高可用解决了单点故障问题。
  2、不足之处:
  (1)该架构没有解决存储的问题。
  解决方案:可以使用NFS+Rsync+inodify实现数据实时同步,再用keepalive做高可用。
  (2)MysqlServer,没有分离
  解决方案:独立数据库服务器,对其设置数据库主从复制,读写分离;



页: [1]
查看完整版本: 高可用haproxy调度varnish服务器缓存后端动静分离集群架构