二,利用HAProxy实现负载均衡
1. 利用HAProxy实现负载均衡
192.168.1.222 (haproxy)---------负载均衡----------(192.168.1.100)
安装配置HAproxy
wget http://haproxy.1wt.eu/download/1.3/src/haproxy-1.3.14.2.tar.gz
mv haproxy-1.3.14.2 haproxy
cd haproxy
make
2. 创建配置文件
# vi haproxy.cfg
内容:
# this config needs haproxy-1.1.28 or haproxy-1.2.2
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
#log loghost local0 info
maxconn 5555
chroot /usr/share/haproxy
uid 99
gid 99
daemon
#debug
#quiet
defaults
log global
mode http
option httplog
option dontlognull
retries 3
redispatch
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000
listen app1 0.0.0.0:8080
mode http
option httplog
option dontlognull
cookie SERVERID rewrite
balance roundrobin
option httpchk
server app1_1 192.168.1.222:80 cookie app1inst1 check inter 2000 rise 2 fall 5
server app1_2 192.168.1.100:80 cookie app1inst2 check inter 2000 rise 2 fall 5
# server app1_3 192.168.0.108:80 cookie app1inst3 check inter 2000 rise 2 fall 5
# server app1_4 220.181.6.6:80 cookie app1inst4 check inter 2000 rise 2 fall 5
stats uri /my_stats # 访问时:http://192.168.1.222:8080/my_stats
stats realm Statistics\ for\ MyApp1-2
stats auth admin:uplooking # 帐号:密码
stats scope .
stats scope app2
listen app2 0.0.0.0:8443
mode tcp
option ssl-hello-chk
balance source
server inst1 192.168.1.222:443 check inter 2000 fall 3
server inst2 192.168.1.100:443 check inter 2000 fall 3
# server back1 192.168.0.254:443 backup
stats uri /my_stats
stats realm Statistics\ for\ MyApp2
stats scope .
errorloc 502 http://192.168.1.222/error502.html
errorfile 503 /site/haproxy/errors/503.http
# ./haproxy –f examples/haproxy.cfg 启动服务.
监控状态图示 http://192.168.0.222:8080/my_stats,输入用户名密码查看状态。
三.相关介绍
#./haproxy –help //haproxy相关命令参数介绍.
haproxy -f <配置文件> [-n 最大并发连接总数] [-N 每个侦听的最大并发数] [-d] [-D] [-q] [-V] [-c] [-p <pid文件>] [-s] [-l] [-dk]
[-ds] [-de] [-dp] [-db] [-m <内存限制M>] [{-sf|-st} pidlist...]
-d 前台,debug模式
-D daemon模式启动
-q 安静模式,不输出信息
-V 详细模式
-c 对配置文件进行语法检查
-s 显示统计数据
-l 显示详细统计数据
-dk 不使用kqueue
-ds 不使用speculative epoll
-de 不使用epoll
-dp 不使用poll
-db 禁用后台模式,程序跑在前台
-sf <pidlist>
程序启动后向pidlist里的进程发送FINISH信号,这个参数放在命令行的最后
-st <pidlist>
程序启动后向pidlist里的进程发送TERMINATE信号,这个参数放在命令行的最后
四,更高级的应用参考相关文档
官方参考手册: http://haproxy.1wt.eu/download/1.3/doc/haproxy-en.txt
http://www.howtoforge.com/high-availability-load-balancer-haproxy-heartbeat-debian-etch
using haproxy to proxy multiple named-based virtual hosts
haproxy is one of the best layer 7 loadbalancing solutions for web administrators. It is feature rich in Access Control Lists and header manipulation capabilities.It is a fast and easy-to-configure web proxy.
The following shows how to configure haproxy to proxy multiple named-based virtual hosts typically configured in Apache and Nginx.
OS: CentOS release 4.7 (Final)
Kernel: Linux 2.6.9-34.ELsmp
- [root@localhost ~]# haproxy -v
- HA-Proxy version 1.3.20 2009/08/09
- Copyright 2000-2009 Willy Tarreau <w@1wt.eu>
Content of the runtime configuration file: /etc/haproxy.cfg
- global
- maxconn 20000
- log 127.0.0.1 local0
- uid 99
- gid 99
- chroot /var/empty
- daemon
- frontend public
- bind 192.168.1.10:80
- mode http
- log global
- option httplog
- option dontlognull
- option httpclose
- option forwardfor
- maxconn 20000
- timeout client 6000
- acl site_1 hdr_beg(host)-i i.yaknet.cn
- use_backend i if site_1
- acl site_2 hdr_beg(host)-i s.yaknet.cn
- use_backend s if site_2
- default_backend s
- backend i
- mode http
- balance source
- cookie SERVERID prefix
- retries 3
- timeout connect 6000
- timeout server 6000
- server srv_i_101 192.168.1.101:80 cookie i101 weight 5 check inter 15000 rise 2 fall 3
- server srv_i_102 192.168.1.102:80 cookie i102 weight 5 check inter 15000 rise 2 fall 3
- server srv_i_103 192.168.1.103:80 cookie i102 weight 5 check inter 15000 rise 2 fall 3
- backend s
- mode http
- balance source
- cookie SERVERID prefix
- retries 3
- timeout connect 6000
- timeout server 6000
- server srv_s_201 192.168.1.201:80 cookie s201 weight 5 check inter 15000 rise 2 fall 3
- server srv_s_202 192.168.1.202:80 cookie s202 weight 5 check inter 15000 rise 2 fall 3
- server srv_s_203 192.168.1.203:80 cookie s202 weight 5 check inter 15000 rise 2 fall 3
To make your haproxy log properly,you should also modify /etc/syslog.conf and one line:
- local0.*/var/log/haproxy.log
and then start syslogd with `syslogd -r -m 0`.
See, how easy it is to set up such a smart and fast proxy!
Also, for avoiding single point of failure (SPOF), you can turn to keepalived or heartbeat, then you will have high-availability haproxy loadbalanced web server farms.
本日志由 flyinweb 于 2009-09-21 14:27:43 发表,目前已经被浏览 6174 次,评论 0 次;
引用通告:http://www.517sou.net/Article/255/Trackback.ashx
It is quite useful and interesting too.
VIRT 的上限是64G,也就是36位, cat /proc/cpuinfo的结果是:addre
昨天要准备用线程重写webbench,试验了下Fedora Linux 2.6.35.14
不明白您的具体的意思是什么?
已经发送到你QQ邮箱
http://www.2mysite.net/scriptencoder/screnc.asp 站长你好,看
你好,我发现一个问题,就是从mysqld2同步过来的数据,在mysqld1的
晕,我说是怎么回事情,原来我和你一样,忘记设置了活动分区