【环境】

Centos 7.2

Web1:192.168.136.170

web2:192.168.136.166

Haproxy:192.168.136.173

【web服务器1、2】

安装Nginx(可参考YUM快速搭建LNMP)两台Web服务器都需要安装Nginx

为了方便区分web服务器,我们编辑下首页

web1:

  1. echo 'This is web 1' > /usr/share/nginx/html/index.html
  2.  
  3. systemctl restart nginx

web2:

  1. echo 'This is web 1' > /usr/share/nginx/html/index.html
  2.  
  3. systemctl restart nginx

【Haproxy服务器】

yum -y install haproxy

编辑haproxy配置文件

vim /etc/haproxy/haproxy.cfg

(下列红色的#部分,是需要注释的,最下方的是web服务器的地址,如有多个节点,就继续添加)

  1. #---------------------------------------------------------------------
  2. # Example configuration for a possible web application. See the
  3. # full configuration options online.
  4. #
  5. # http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
  6. #
  7. #---------------------------------------------------------------------
  8.  
  9. #---------------------------------------------------------------------
  10. # Global settings
  11. #---------------------------------------------------------------------
  12. global
  13. # to have these messages end up in /var/log/haproxy.log you will
  14. # need to:
  15. #
  16. # ) configure syslog to accept network log events. This is done
  17. # by adding the '-r' option to the SYSLOGD_OPTIONS in
  18. # /etc/sysconfig/syslog
  19. #
  20. # ) configure local2 events to go to the /var/log/haproxy.log
  21. # file. A line like the following can be added to
  22. # /etc/sysconfig/syslog
  23. #
  24. # local2.* /var/log/haproxy.log
  25. #
  26. log 127.0.0.1 local2
  27.  
  28. # chroot /var/lib/haproxy
  29. pidfile /var/run/haproxy.pid
  30. maxconn
  31. user haproxy
  32. group haproxy
  33. daemon
  34.  
  35. # turn on stats unix socket
  36. stats socket /var/lib/haproxy/stats
  37.  
  38. #---------------------------------------------------------------------
  39. # common defaults that all the 'listen' and 'backend' sections will
  40. # use if not designated in their block
  41. #---------------------------------------------------------------------
  42. defaults
  43. mode http
  44. log global
  45. option httplog
  46. option dontlognull
  47. option http-server-close
  48. option forwardfor except 127.0.0.0/
  49. # option redispatch
  50. retries
  51. timeout http-request 10s
  52. timeout queue 1m
  53. timeout connect 10s
  54. timeout client 1m
  55. timeout server 1m
  56. timeout http-keep-alive 10s
  57. timeout check 10s
  58. maxconn
  59.  
  60. #---------------------------------------------------------------------
  61. # main frontend which proxys to the backends
  62. #---------------------------------------------------------------------
  63. frontend main *:
  64. acl url_static path_beg -i /static /images /javascript /stylesheets
  65. acl url_static path_end -i .jpg .gif .png .css .js
  66.  
  67. use_backend static if url_static
  68. default_backend app
  69.  
  70. #---------------------------------------------------------------------
  71. # static backend for serving up images, stylesheets and such
  72. #---------------------------------------------------------------------
  73. backend static
  74. balance roundrobin
  75. server static 127.0.0.1: check
  76.  
  77. #---------------------------------------------------------------------
  78. # round robin balancing between the various backends
  79. #---------------------------------------------------------------------
  80. backend app
  81. balance roundrobin
  82. server app1 127.0.0.1: check
  83. server app2 127.0.0.1: check
  84. server app3 127.0.0.1: check
  85. server app4 127.0.0.1: check
  86. listen webcluster 0.0.0.0:
  87. option httpchk GET /index.html
  88. option persist
  89. balance roundrobin
  90. server inst1 192.168.136.170 check inter 2000 fall 3
  91. server inst2 192.168.136.166 check inter 2000 fall 3

然后访问haproxy地址,查看是否会对两台web服务器进行轮询访问。

Centos 7 安装 Haproxy的更多相关文章

  1. Centos 编译安装Haproxy

    一.环境介绍 1.Centos6 2. haproxy-1.4.25.tar.gz 二.安装 $ curl -O http://haproxy.1wt.eu/download/1.4/src/hapr ...

  2. CentOS6.5 安装HAProxy 1.5.20

    [在CentOS下安装haproxy] sudo yum install haproxy 编辑配置文件 vim /etc/haproxy/haproxy.cfg #------------------ ...

  3. centos 7 下安装haproxy

    1 haproxy 下载 从如下目录下载haproxy:http://www.haproxy.org/download/1.7/src/haproxy-1.7.1.tar.gz 2 haproxy 安 ...

  4. 安装haproxy和haproxy命令

    HaProxy系列文章:http://www.cnblogs.com/f-ck-need-u/p/7576137.html 1.安装haproxy CentOS自带了haproxy,但可能版本比较老. ...

  5. NoSql1 在Linux(CentOS)上安装memcached及使用

    前言:       今天是初五,生活基本要从过年的节奏中回归到正常的生活了,所以想想也该想想与工作有关的事情了.我之前在工作中会经常使用memcached和redis,但是自己一直没有时间系统的好好看 ...

  6. 在Ubuntu|CentOS上安装Shutter截图工具及快捷键设置

    简介 Shutter前身叫GScrot,它是一款相当棒的截图软件. 通过Shutter,你可以截取包括选定区域.全屏幕.窗口.窗口内的控件甚至网页的图像.通过内置的强大插件机制,你可以在截图后,对图像 ...

  7. CentOS下安装hadoop

    CentOS下安装hadoop 用户配置 添加用户 adduser hadoop passwd hadoop 权限配置 chmod u+w /etc/sudoers vi /etc/sudoers 在 ...

  8. CentOS下安装使用start-stop-daemon

    CentOS下安装使用start-stop-daemon 在centos下下了个自启动的服务器脚本 执行的时候发现找不到start-stop-daemon命令 好吧 执行手动编译一下 加上这个命令 w ...

  9. CentOS 7 安装 Docker

    CentOS 7 安装 Docker 这里介绍 ContOS 7 的安装 docker V1.2+,包括阿里云加速 docker 镜像下载的设置,这对提升使用 docker 体验至关重要.其他系统安装 ...

随机推荐

  1. Hibernate持久化,生命周期

    一 .生命周期   1.1  . 说明 持久化类就是我们所说的实体类,实体类(持久化类)对象是有状态的. 为什么实体类对象会有状态? 答:由于HIbernate框架是一个先映射,后操作的框架.所谓的状 ...

  2. k8s安装ingress

    1. 环境准备 安装nginx-ingress-controller和backend cd /etc/yum.repos.d/mainfests 下载镜像的脚本 vi ingressnginx.sh ...

  3. Spring Cloud Alibaba学习笔记(6) - Sentinel使用总结

    使用Sentinel API Sentinel主要有三个核心Api: SphU:定义资源,让资源收到监控,保护资源 SphU 包含了 try-catch 风格的 API.用这种方式,当资源发生了限流之 ...

  4. win7用驱动精灵安装了bcm94352ac蓝牙驱动后还是不能用蓝牙的解决方法

    驱动精灵安装了驱动后,设备管理器处显示Bluetooth USB,但是没法用蓝牙,找不到蓝牙图标,后来在华硕官方下载了win7的Broadcom 蓝牙驱动程序装上之后就好了

  5. elementUI表单验证

    elementUI表单验证非常方便,我们直奔主题: <template> <el-form ref="orderForm" :model="orderF ...

  6. 1+X证书学习日志——盒模型

    ##   padding的作用:                 控制子元素和父元素之间的位置关系                              padding设置方法:          ...

  7. 有用的vscode快捷键大全+自定义快捷键

    VS Code是前端的一个比较好用的代码编辑器,但是我们不能老是局限于鼠标操作呀,有时候很不方便,所以呢,快捷键大全来啦,有的可能会和你们电脑自带的快捷键冲突呢,这时候,你自己设置一下就好了呀 一.v ...

  8. Android studio如何连接三星手机

    打开Android studio,选择Trouble Shoot device connections: 这个菜单项会自动扫描本地已经用USB线连接的设备: 已经成功扫描出了我的Galaxy C7 P ...

  9. 删除MRP单据

    select *into newtable from a_mplist 把a_mplist的表中的数据复制到newtable表中结构也是一样的 insert into newtable select ...

  10. Date与String的相互转换

    构造函数 日期:new Date();//获取当前日期,精确到毫秒. 日期:new Date(long date);//即1970 年 1 月 1 日 00:00:00 GMT(Greenwich M ...