|
概述
Haproxy下载地址:http://pkgs.fedoraproject.org/repo/pkgs/haproxy/
关闭SElinux、配置防火墙
1、vi /etc/selinux/config
?
|
1
2
3
4
5
6
7
8
9
|
SELINUX=disabled
:wq!
setenforce 0
|
2、vi /etc/sysconfig/iptables #编辑
?
|
1
2
3
4
5
6
7
8
9
|
-A RH-Firewall-1-INPUT -d 224.0.0.18 -j ACCEPT
-A RH-Firewall-1-INPUT -p vrrp -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
:wq!
/etc/init.d/iptables restart
|
安装HAProxy
1、创建HAProxy运行账户和组
?
|
1
2
3
|
groupadd haproxy
useradd -g haproxy haproxy -s /bin/false
|
2、安装:
?
|
1
2
3
4
5
6
7
8
9
10
11
12
|
[root@A local]
[root@A local]
[root@A local]
[root@A local]
[root@A local]
|
3、设置HAProxy
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
mkdir -p /usr/local/haproxy/conf
mkdir -p /etc/haproxy
touch /usr/local/haproxy/conf/haproxy.cfg
ln -s /usr/local/haproxy/conf/haproxy.cfg /etc/haproxy/haproxy.cfg
cp -r /usr/local/src/haproxy-1.6.9/examples/errorfiles /usr/local/haproxy/errorfiles
ln -s /usr/local/haproxy/errorfiles /etc/haproxy/errorfiles
mkdir -p /usr/local/haproxy/log
touch /usr/local/haproxy/log/haproxy.log
ln -s /usr/local/haproxy/log/haproxy.log /var/log/haproxy.log
cp /usr/local/src/haproxy-1.6.9/examples/haproxy.init /etc/rc.d/init.d/haproxy
chmod +x /etc/rc.d/init.d/haproxy
chkconfig haproxy on
ln -s /usr/local/haproxy/sbin/haproxy /usr/sbin
|
4、配置haproxy.cfg参数
?
|
1
2
3
|
cp /usr/local/haproxy/conf/haproxy.cfg /usr/local/haproxy/conf/haproxy.cfg-bak
vi /usr/local/haproxy/conf/haproxy.cfg
|
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
global
log 127.0.0.1 local2
chroot /usr/local/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
defaults
mode http
log global
option dontlognull
option httpclose
option httplog
option forwardfor
option redispatch
timeout connect 10000
timeout client 300000
timeout server 300000
maxconn 60000
retries 3
listen stats
bind 0.0.0.0:1080
stats refresh 30s
stats uri /stats
stats realm Haproxy Manager
stats auth admin:admin
frontend main
bind 0.0.0.0:80
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 dynamic
backend static
balance roundrobin
server static 127.0.0.1:80 check
backend dynamic
balance roundrobin
server websrv1 10.252.97.106:80 check maxconn 2000
server websrv2 10.117.8.20:80 check maxconn 2000
errorfile 403 /etc/haproxy/errorfiles/403.http
errorfile 500 /etc/haproxy/errorfiles/500.http
errorfile 502 /etc/haproxy/errorfiles/502.http
errorfile 503 /etc/haproxy/errorfiles/503.http
errorfile 504 /etc/haproxy/errorfiles/504.http
|
?
|
1
2
3
4
5
6
7
|
:wq!
service haproxy start
service haproxy stop
service haproxy restart
|
5、设置HAProxy日志
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
vi /etc/syslog.conf
local0.* /var/log/haproxy.log
local3.* /var/log/haproxy.log
:wq!
vi /etc/sysconfig/syslog
SYSLOGD_OPTIONS="-r -m 0"
:wq!
service syslog restart
|
6.浏览器打开haproxy的监控页面
如下:http://120.55.95.103:1080/stats //说明:1080即haproxy配置文件中监听端口,stats 即haproxy配置文件中的监听名称
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:http://www.cnblogs.com/xibei666/p/5877548.html |