【环境】

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:

echo 'This is web 1' > /usr/share/nginx/html/index.html

systemctl restart nginx

web2:

echo 'This is web 1' > /usr/share/nginx/html/index.html

systemctl restart nginx

【Haproxy服务器】

yum -y install haproxy

编辑haproxy配置文件

vim /etc/haproxy/haproxy.cfg

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

#---------------------------------------------------------------------
# Example configuration for a possible web application. See the
# full configuration options online.
#
# http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#--------------------------------------------------------------------- #---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# ) configure syslog to accept network log events. This is done
# by adding the '-r' option to the SYSLOGD_OPTIONS in
# /etc/sysconfig/syslog
#
# ) configure local2 events to go to the /var/log/haproxy.log
# file. A line like the following can be added to
# /etc/sysconfig/syslog
#
# local2.* /var/log/haproxy.log
#
log 127.0.0.1 local2 # chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn
user haproxy
group haproxy
daemon # turn on stats unix socket
stats socket /var/lib/haproxy/stats #---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/
# option redispatch

retries
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn #---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend main *:
acl url_static path_beg -i /static /images /javascript /stylesheets
acl url_static path_end -i .jpg .gif .png .css .js use_backend static if url_static
default_backend app #---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend static
balance roundrobin
server static 127.0.0.1: check #---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend app
balance roundrobin
server app1 127.0.0.1: check
server app2 127.0.0.1: check
server app3 127.0.0.1: check
server app4 127.0.0.1: check
listen webcluster 0.0.0.0:
option httpchk GET /index.html
option persist
balance roundrobin
server inst1 192.168.136.170 check inter 2000 fall 3
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. 使用代码浏览WPF控件模版

    纯代码创建,不需要创建界面,创建WPF工程后,直接复制代码就可以使用. 当你手头没有Blend,又不记得以下这段代码,但是又想浏览控件模版的时候,就可以直接复制拿来用了. public partial ...

  2. python实现ssh及sftp功能

    1.在Linux上我们通过scp命令实现主机间的文件传送,通过ssh实现远程登录 ,比如 我们经常使用的xshell远程登录工具,就是基础ssh协议实现window主机远程登录Linux主机 下面简单 ...

  3. iOS - OC 使用运行时来获取并修改类

    前言:          Objective C的runtime技术功能非常强大,能够在运行时获取并修改类的各种信息,包括获取方法列表.属性列表.变量列表,修改方法.属性,增加方法,属性等等,本文对相 ...

  4. 3.Ubuntu/Deepin下安装Monaco/Menlo字体

    前段时间在一家公司实习,让IT给电脑安装了Ubuntu系统,用着挺好,但总感觉字体不太好看,网上小伙伴说Monaco字体不错,所以计划安装试试. 看了好多教程,不得不说,一些教程走下来真心是装不成功, ...

  5. Hbuilder中配置cmd

    步骤: 1. ①运行——>外部工具——>外部工具 配置2.  新建一个名为cmd(随意命名)的外部工具: 名称:cmd 要执行的命令或文件:C:\Windows\System32\cmd. ...

  6. stm32和cortex M3学习内核简单总结

    1.stm32综述 2.寄存器组 3.操作模式和特权级别 4.存储器映射 5.中断和异常 6.其他 Stm32综述 这可以说是我第一款认真学习的单片机了,学完这个就要开启我通往arm9的大门了,接下来 ...

  7. python selectors模块实现 IO多路复用机制的上传下载

    import selectorsimport socketimport os,time BASE_DIR = os.path.dirname(os.path.abspath(__file__))''' ...

  8. Elasticsearch vs Solr 搜索引擎对比和选型

    前言 全文搜索属于最常见的需求,开源的 Elasticsearch 是目前全文搜索引擎的首选. 基于Lucene它可以快速地储存.搜索和分析海量数据.维基百科.Stack Overflow.Githu ...

  9. Bash基础——内置命令

    前言 Shell有很多内置在其源代码中的命令.由于命令是内置的,所以Shell不必到磁盘上搜索它们.内置命令执行速度更快,不同的Shell内置命令有所不同. 如何查找内置命令 之前查了好久怎么收索内置 ...

  10. kubernetes集群初始化(二)

    参考地址:https://github.com/unixhot/salt-kubernetes 一.系统初始化 1.1.安装docker 所有节点都安装docker,设置docker国内yum源 [r ...