主机名 IP
master 192.168.30.130
node-1 192.168.30.131
node-2 192.168.30.132

在master上安装

[root@master ~]# tar -xf haproxy-1.4.22.tar.gz -C /usr/local/src/
[root@master ~]# cd /usr/local/src/
[root@master src]# cd haproxy-1.4.22/
[root@master haproxy-1.4.22]# ls
CHANGELOG  doc     examples  LICENSE   Makefile.bsd  README   src      tests  VERDATE
contrib    ebtree  include   Makefile  Makefile.osx  ROADMAP  SUBVERS  TODO   VERSION
[root@master haproxy-1.4.22]# vim Makefile
PREFIX = /usr/local/haproxy
SBINDIR = $(PREFIX)/sbin
MANDIR = $(PREFIX)/share/man
DOCDIR = $(PREFIX)/doc/haproxy#### TARGET system
# Use TARGET=<target_name> to optimize for a specifc target OS among the
# following list (use the default "generic" if uncertain) :
#    generic, linux22, linux24, linux24e, linux26, solaris,
#    freebsd, openbsd, cygwin, custom, aix52
TARGET = Linux26
[root@master haproxy-1.4.22]# make install
.........................
install -d /usr/local/haproxy/sbin
install haproxy /usr/local/haproxy/sbin
install -d /usr/local/haproxy/share/man/man1
install -m 644 doc/haproxy.1 /usr/local/haproxy/share/man/man1
install -d /usr/local/haproxy/doc/haproxy
...

配置haproxy

[root@master haproxy-1.4.22]# ls /usr/local/haproxy/  #可以看出目录下面没有配置文件,需要手动创建
doc  sbin  share
[root@master haproxy-1.4.22]# cd /usr/local/haproxy/
[root@master haproxy]# mkdir etc
[root@master haproxy]# cd etc/
[root@master etc]# touch haproxy.cfg
global
log 127.0.0.1  local0
#log 127.0.0.1  local1 notice
#log loghost    local0 info
maxconn 4096
chroot /usr/local/haproxy
uid 99                          #所属运行的用户uid
gid 99                          #所属运行的用户组
daemon                        #以后台形式运行haproxy
nbproc 1                        #启动1个haproxy实例
pidfile /usr/local/haproxy/haproxy.pid  #将所有进程写入pid文件
#debug
#quiet
defaults
log    global
log    127.0.0.1      local3        #日志文件的输出定向
mode    http                      #所处理的类别,默认采用http模式,可配置成tcp作4层消息转发
option  httplog                        #日志类别
option  httpclose      #每次请求完毕后主动关闭http通道,haproxy不支持keep-alive,只能模拟这>
种模式的实现
option  dontlognull
option  forwardfor      #如果后端服务器需要获得客户端真实ip需要配置的参数,可以从Http Head
er中获得客户端ip
option  redispatch            #当serverid对应的服务器挂掉后,强制定向到其他健康服务器
retries 2                    #2次连接失败就认为服务器不可用,主要通过后面的check检查
maxconn 2000
balance roundrobin                    #负载均衡算法
stats  uri    /haproxy-stats          #haproxy 监控页面的访问地址
# 可通过 http://localhost:80/haproxy-stats 访问
contimeout      5000              #连接超时时间
clitimeout      50000              #客户端连接超时时间
srvtimeout      50000              #服务器端连接超时时间
listen  localhost 0.0.0.0:80                  #运行的端口及主机名
mode    http
option  httpchk GET /index.html          #健康检测
server  s1 192.168.30.131:80  weight 3 check  #后端的主机 IP &权衡
server  s2 192.168.30.132:80 weight 3 check  #后端的主机 IP &权衡
#server  s3 192.168.148.110:8081 weight 3 check  #后端的主机 IP &权衡

启动和停止haproxy

[root@master ~]# /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/etc/haproxy.cfg
[root@master ~]# echo $?
0
[root@master ~]# ps -aux | grep haproxy | grep -v grep
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
nobody     2699  0.0  0.0  12260  1204 ?        Ss   17:42   0:00 /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/etc/haproxy.cfg
重启haproxy
[root@master ~]# /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/etc/haproxy.cfg -st `cat /usr/local/haproxy/haproxy.pid`
[root@master ~]# echo $?
0
[root@master ~]# killall haproxy
[root@master ~]# ps -aux | grep haproxy | grep -v grep
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ

查看帮助

[root@master ~]# /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/etc/haproxy.cfg  --help
HA-Proxy version 1.4.22 2012/08/09
Copyright 2000-2012 Willy Tarreau <w@1wt.eu>Usage : haproxy [-f <cfgfile>]* [ -vdVD ] [ -n <maxconn> ] [ -N <maxpconn> ][ -p <pidfile> ] [ -m <max megs> ]-v displays version ; -vv shows known build options. -d enters debug mode ; -db only disables background mode.-V enters verbose mode (disables quiet mode)-D goes daemon-q quiet mode : don't display messages-c check mode : only check config files and exit-n sets the maximum total # of connections (2000)-m limits the usable amount of memory (in MB)-N sets the default, per-proxy maximum # of connections (2000)-p writes pids of all children to this file-de disables epoll() usage even when available-ds disables speculative epoll() usage even when available-dp disables poll() usage even when available-sf/-st [pid ]* finishes/terminates old pids. Must be last arguments.

开启日志收集

[root@master ~]# vim /etc/rsyslog.conf
.........大约在13,14行,开启UDPServerRun
13 $ModLoad imudp
14 $UDPServerRun 514
..........大约在60行左右
61 local7.*                                                /var/log/boot.log   #在此行下面添加如下两行内容
62 local3.*                                                /var/log/haproxy.log
63 local0.*                                                /var/log/haproxy.log
重启rsyslog服务
[root@master ~]# service rsyslog restart
Shutting down system logger:                               [  OK  ]
Starting system logger:                                    [  OK  ]

在node-1和node-2上

安装httpd和php
[root@node-1 ~]# yum install -y httpd php
创建测试页面
[root@node-1 ~]# echo "<h1>Web-Server:192.168.30.131</h1>" > /var/www/html/index.html
[root@node-1 ~]# service httpd restart
在node-2上安装httpd和php
[root@node-2 ~]# yum install -y httpd php
[root@node-2 ~]# echo "<h1>Web-Server:192.168.30.132</h1>" > /var/www/html/index.html
[root@node-2 ~]# service httpd restart

浏览器测试

按F5刷新

查看haproxy的工作状态

配置文件模板和启动脚本的模板可以在这个目录下查看

[root@master ~]# cd /usr/local/src/haproxy-1.4.22/examples/
[root@master examples]# ls
acl-content-sw.cfg     debug2html                init.haproxy
auth.cfg               debugfind                 init.haproxy.flx0
build.cfg              errorfiles                linux-2.4.21-40.EL-custom.diff
check                  examples.cfg              option-http_proxy.cfg
check.conf             haproxy-1.1.21-flx.1.pkg  rc.highsock
config.rc.haproxy      haproxy.cfg               stats_haproxy.sh
content-sw-sample.cfg  haproxy.init              tarpit.cfg
cttproxy-src.cfg       haproxy.spec              test-section-kw.cfg
debug2ansi             haproxy.vim               url-switching.cfg
比如创建开机启动
[root@master examples]# cp haproxy.init /etc/init.d/haproxy
[root@master examples]# chkconfig --add haproxy
[root@master examples]# chkconfig haproxy on
[root@master examples]# chkconfig haproxy --list
haproxy            0:off    1:off    2:on    3:on    4:on    5:on    6:off

转载于:https://www.cnblogs.com/zd520pyx1314/p/9130270.html

RHEL 6.5----haproxy实现负载均衡相关推荐

  1. saltstack实现haproxy+keepalived负载均衡+高可用(二)

    一键部署haproxy+keepalived实现负载均衡+高可用 实验环境: !!!!    特别注意: www.westos.org为test1的minion名字 test1: 172.25.1.1 ...

  2. 架构师课程之-haproxy专业级负载均衡软件权威讲解

    老男孩培训顶级架构师课程[企业场景haproxy专业负载均衡架构方案]教学大纲 2014/4/12日激情开讲! 伙伴们,既然选择了远方,就只顾风雨兼程! 老男孩老师已经做好了自断筋脉,把全部功力都传给 ...

  3. HAProxy 的负载均衡服务器,Redis 的缓存服务器

    问答社区网络 StackExchange 由 100 多个网站构成,其中包括了 Alexa 排名第 54 的 StackOverflow.StackExchang 有 400 万用户,每月 5.6 亿 ...

  4. RabbitMQ + 镜像队列 + HAProxy 实现负载均衡的集群

    RabbitMQ + 镜像队列 + HAProxy 实现负载均衡的集群 一.集群管理(RabbitMQ扩容) 1. 环境介绍 hostname ip mq1 192.168.80.16 mq2 192 ...

  5. lvs,haproxy实现负载均衡

    lvs,haproxy实现负载均衡 转载于:https://www.cnblogs.com/panxuejun/p/6245632.html

  6. Haproxy实现负载均衡及相关配置(添加日志、设定自动刷新时间、控制访问、动静分离、读写分离)

    1.HAProxy简介 (1)HAProxy 是一款提供高可用性.负载均衡以及基于TCP(第四层)和HTTP(第七层)应用的代理软件,支持虚拟主机,它是免费.快速并且可靠的一种解决方案. HAProx ...

  7. 架构测试:HAproxy实现负载均衡,前端为nginx+php,数据库实现读写分离和高可用...

    环境: • 202.106.0.6: as client • 202.106.0.17:as firewall • 202.106.0.147: as powerDNS • 192.168.205.2 ...

  8. LVS/HAProxy/Nginx负载均衡对比

    2019独角兽企业重金招聘Python工程师标准>>> 现在网站发展的趋势对网络负载均衡的使用是随着网站规模的提升根据不同的阶段来使用不同的技术: 一种是通过硬件来进行进行,常见的硬 ...

  9. HAProxy实现负载均衡及高可用集群(corosync+pacemaker)

    一.haproxy haproxy 是一款提供高可用性.负载均衡以及基于TCP(第四层)和HTTP(第七层)应用的代理软件,支持虚拟主机,它是免费.快速并且可靠的一种解决方案. HAProxy特别适用 ...

  10. Haproxy实现负载均衡

    含义及理解: 1 . HAProxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机, 它是免费.快速并且可靠的一种解决方案.HAProxy特别适用于那些负载特大的web站点, ...

最新文章

  1. 2021-05-21 深入理解SLAM技术 【4】射影几何--2面中心射影
  2. 14 位大咖导师集结完毕,阿里云云原生加速器就等你来
  3. Java黑皮书课后题第5章:*5.42(金融应用:求销售额)如下重写编程练习题5.39:①使用for循环替代do-while循环②允许用户自己输入COMMISSION_SOUGHT而非将它固定为常量
  4. Silverlight OOB Setup
  5. 解决MATLAB不能设置为.m文件默认打开方式
  6. mysql 锁 代码_MySQL中的锁实例
  7. 最新!MongoDB 重磅发布 MongoDB 5.0 和无服务器 Atlas
  8. FID使用(Frechet Inception Distance score)
  9. struts html:select 默认选中,Struts2自动选择下拉框的值
  10. linux用户批量修改密码,Linux 命令详解 chpasswd 批量修改用户密码
  11. nginx反向代理后获取不到客户端的ip地址问题
  12. Jquery 网站保存信息提示消息实现,提示后自动消失
  13. linux rs232驱动程序,Ubuntu安装USB to RS232驱动
  14. 深入浅出MySQL之优化
  15. 有什么软件可以测试U盘性能,最新版本:U盘性能检查测试软件简介
  16. 前端核心工作内容有哪些?
  17. java中refresh是什么_JavaWeb Refresh响应头代码实例详解
  18. 国内外RTI产品调查情况(转)
  19. ONF开源白皮书:SDN解决方案案例——校园SDN
  20. 从虚拟光驱启动计算机,让你的ISO文件成为光盘运行起来虚拟光驱Daemon Tools教程 -电脑资料...

热门文章

  1. Vue+axios+Node+express实现文件上传(用户头像上传)
  2. 不会点SQLite,都不好意思说自己是开发的 1
  3. Mysql 高负载排查思路
  4. 【剑指Offer学习】【面试题22:栈的压入、弹出序列】
  5. 华为实习日记——第三十七天
  6. android 如何正确使用 泛型 和 多参数 “偷懒”
  7. 《CLR via C#》精髓:静态类
  8. Json Formatter 1.0 Json格式化工具
  9. 2004-6-22+ 用vs.net做的留言板
  10. python安装pil库-python第三方库PIL.Image安装