haproxy+pecemaker

haproxy+pecemaker

环境

  • server4 haproxy
  • server2 和 server3 apache

安装haproxy:

[root@server4 ~]# ls
anaconda-ks.cfg                   haproxy-1.6.11.tar.gz        pssh-2.3.1-2.1.x86_64.rpm
crmsh-1.2.6-0.rc2.2.1.x86_64.rpm  Lvs-fullnat-synproxy.tar.gz
drbd-8.4.3.tar.gz                 nginx-1.12.0.tar.gz
[root@server4 ~]# tar zxf haproxy-1.6.11.tar.gz 
[root@server4 ~]# cd haproxy-1.6.11
[root@server4 haproxy-1.6.11]# ls
CHANGELOG  CONTRIBUTING  ebtree    include  MAINTAINERS  README   src      tests    VERSION
contrib    doc           examples  LICENSE  Makefile     ROADMAP  SUBVERS  VERDATE
[root@server4 haproxy-1.6.11]# cat README | grep "linux26" 
  - linux26     for Linux 2.6 and above
  - linux2628   for Linux 2.6.28, 3.x, and above (enables splice and tproxy)
    $ make TARGET=linux26 USE_OPENSSL=1 SSL_INC=$STATICLIBSSL/include SSL_LIB=$STATICLIBSSL/lib ADDLIB=-ldl
    $ make TARGET=linux26 USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1
    $ make TARGET=linux2628 USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1
    $ make TARGET=linux26 ARCH=i386 USE_OPENSSL=1 ADDLIB=-lz
[root@server4 haproxy-1.6.11]# uname -r
2.6.32-431.el6.x86_64
[root@server4 haproxy-1.6.11]# yum install gcc rpm-bulid -y 
[root@server4 haproxy-1.6.11]# ls examples/
acl-content-sw.cfg  content-sw-sample.cfg  errorfiles    init.haproxy           stats_haproxy.sh
auth.cfg            debug2ansi             haproxy.init  option-http_proxy.cfg  transparent_proxy.cfg
check               debug2html             haproxy.spec  seamless_reload.txt
check.conf          debugfind              haproxy.vim   ssl.cfg
[root@server4 haproxy-1.6.11]# rpmbuild -bb examples/haproxy.spec 
error: File /root/rpmbuild/SOURCES/haproxy-1.6.11.tar.gz: No such file or directory
[root@server4 haproxy-1.6.11]# cp ~/haproxy-1.6.11.tar.gz /root/rpmbuild/SOURCES/
[root@server4 haproxy-1.6.11]# rpmbuild -bb examples/haproxy.spec 
[root@server4 haproxy-1.6.11]# cd /root/rpmbuild/RPMS/x86_64/
[root@server4 x86_64]# ls
haproxy-1.6.11-1.x86_64.rpm  haproxy-debuginfo-1.6.11-1.x86_64.rpm
[root@server4 x86_64]# yum install haproxy-1.6.11-1.x86_64.rpm 
[root@server4 haproxy-1.6.11]# cd examples/
[root@server4 examples]# ls
acl-content-sw.cfg  content-sw-sample.cfg  errorfiles    init.haproxy           stats_haproxy.sh
auth.cfg            debug2ansi             haproxy.init  option-http_proxy.cfg  transparent_proxy.cfg
check               debug2html             haproxy.spec  seamless_reload.txt
check.conf          debugfind              haproxy.vim   ssl.cfg
[root@server4 examples]# cp content-sw-sample.cfg /etc/haproxy/
[root@server4 examples]# mv /etc/haproxy/content-sw-sample.cfg /etc/haproxy/haproxy.cfg
[root@server4 examples]# vim /etc/haproxy/haproxy.cfg 
[root@server4[root@server4 examples]# useradd -M -s /sbin/nologin -u 600 haproxy
[root@server4 examples]# id haproxy
uid=600(haproxy) gid=600(haproxy) groups=600(haproxy)
[root@server4 examples]# cat /etc/haproxy/haproxy.cfg | grep -v "#" 

global
        maxconn         10000
        stats socket    /var/run/haproxy.stat mode 600 level admin
        log             127.0.0.1 local0
        uid             600
        gid             600
        chroot          /var/empty
        daemon

defaults
        mode            http
        log             global
        option          httplog
        option          dontlognull
        monitor-uri     /monitoruri
        maxconn         8000
        timeout client  30s

        retries         2
        option redispatch
        timeout connect 5s
        timeout server  30s

        stats uri       /admin/stats

frontend public
    bind           172.25.32.4:80
    default_backend         static

backend static
        balance         roundrobin
        server          web1 172.25.32.2:80 check inter 1000
        server          web2 172.25.32.3:80 check inter 1000 weight 2
[root@server4 ~]# tail -n 2 /etc/security/limits.conf 
# End of file
haproxy          -        nofile          8000
[root@server4 examples]# /etc/init.d/haproxy start
Starting haproxy:                                          [  OK  ]

server2 ,server3

[root@server3 ~]# /etc/init.d/httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 172.25.32.3 for ServerName
                                                           [  OK  ]
[root@server2 ~]# /etc/init.d/httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 172.25.32.2 for ServerName
                                                           [  OK  ]

测试:

kiosk@foundation32 Desktop]$  for i in {1..10}; do curl 172.25.32.4 ;done 
<h2>www.linux.org apache-server3</h2>
<h2>www.linux.org apache-server3</h2>
<h1>www.linux.org-apache-server2</h1>
<h2>www.linux.org apache-server3</h2>
<h2>www.linux.org apache-server3</h2>
<h1>www.linux.org-apache-server2</h1>
<h2>www.linux.org apache-server3</h2>
<h2>www.linux.org apache-server3</h2>
<h1>www.linux.org-apache-server2</h1>
<h2>www.linux.org apache-server3</h2>
[kiosk@foundation32 Desktop]$  for i in {1..10}; do curl 172.25.32.4 ;done 
<h2>www.linux.org apache-server3</h2>
<h1>www.linux.org-apache-server2</h1>
<h2>www.linux.org apache-server3</h2>
<h2>www.linux.org apache-server3</h2>
<h1>www.linux.org-apache-server2</h1>
<h2>www.linux.org apache-server3</h2>
<h2>www.linux.org apache-server3</h2>
<h1>www.linux.org-apache-server2</h1>
<h2>www.linux.org apache-server3</h2>
<h2>www.linux.org apache-server3</h2>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值