一、常见的Web集群调度器
目前常见的Web集群调度器分为软件和硬件 软件通常使用开源的LVS、Haproxy、Nginx 硬件一般使用比较多的时F5,也有很多人使用国内的一些产品,如梭子鱼、绿盟等
二、Haproxy应用分析
LVS在企业应用中抗负载能力很强,但存在不足
LVS不支持正则处理,不能实现动静分离 对于大型网站,LVS的实施配置复杂,维护成本相对较高 Haproxy是一款可提供高可用性、负载均衡、及基于TCP和HTTP应用的代理的软件
适用于负载打的Web站点 运行在硬件上可支持以万计的并发连接的连接请求
实验报告
资源列表
主机 操作系统 IP 配置 haproxy CentOS7 192.168.72.131 2C4G web01 CentOS7 192.168.72.132 2C4G web02 CentOS7 192.168.72.133 2C4G
基础环境
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed - i "s/^SELINUX=.*/SELINUX=disabled/g" / etc/ selinux/ config
hostnamectl set - hostname haproxy
hostnamectl set - hostname web01
hostnamectl set - hostname web02
curl - o / etc/ yum. repos. d/ CentOS- Base. repo https: // mirrors. aliyun. com/ repo/ Centos- 7 . repo
curl - o / etc/ yum. repos. d/ CentOS- Base. repo http: // mirrors. 163 . com/ . help / CentOS7- Base- 163 . repo
curl - o / etc/ yum. repos. d/ CentOS- Base. repo https: // repo. huaweicloud. com/ repository/ conf/ CentOS- 7 - anon. repo
一、编译安装Nginx
安装支持软件
yum - y install pcre- devel zlib- devel gcc+ + gcc
创建运行用户、组
useradd - M - s / sbin/ nologin nginx
二、源码编译及安装
1、解包
tar zxf nginx- 1.12 .0 . tar. gz - C / usr/ src/
cd / usr/ src/ nginx- 1.12 .0 /
2、配置编译安装
. / configure - - prefix= / usr/ local/ nginx - - user= nginx - - group= nginx - - with - http_stub_status_module
make & & make install
3、优化执行路径
ln - s / usr/ local/ nginx/ sbin/ nginx / usr/ local/ sbin/
ls - l / usr/ local/ sbin/ nginx
三、Nginx 的运行控制
1、检查配置文件
[ root@nginx ~ ]
nginx: the configuration file / usr/ local/ nginx/ conf/ nginx. conf syntax is ok
nginx: configuration file / usr/ local/ nginx/ conf/ nginx. conf test is successful
2、启动、停止 Nginx
[ root@nginx nginx- 1.12 .0 ]
conf html logs sbin
[ root@nginx nginx- 1.12 .0 ]
[ root@nginx nginx- 1.12 .0 ]
LISTEN 0 128 * : 80 * : * users: ( ( "nginx" , pid= 12266 , fd= 6 ) , ( "nginx" , pid= 12265 , fd= 6 ) )
[ root@nginx nginx- 1.12 .0 ]
[ root@nginx nginx- 1.12 .0 ]
四、编译安装Haproxy
1、安装gcc
yum - y install pcre- devel bzip2- devel gcc- c+ +
2、解包
tar xf haproxy- 1.5 .19 . tar. gz
cd haproxy- 1.5 .19
3、源码编译安装
make TARGET= linux2628
make install
[ root@haproxy haproxy- 1.5 .19 ]
[ root@haproxy haproxy- 1.5 .19 ]
global
log 127.0 .0 .1 local3
log 127.0 .0 .1 local1 notice
maxconn 4096
uid 99
gid 99
daemon
defaults
log global
mode http
option httplog
option dontlognull
retries 3
redispatch
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000
listen web 0.0 .0 .0 : 80
option httpchk GET / index. html
balance roundrobin
server web01 192.168 .72 .132 : 80 check inter 2000 fall 5
server web02 192.168 .72 .133 : 80 check inter 2000 fall 5
创建软连接
ln - s / usr/ local/ sbin/ haproxy / usr/ sbin/
ls - l / usr/ local/ sbin/ haproxy
[ root@haproxy haproxy- 1.5 .19 ]
[ root@haproxy ~ ]
anaconda- ks. cfg haproxy- 1.5 .19 haproxy- 1.5 .19 . tar. gz
[ root@haproxy ~ ]
[ root@haproxy ~ ]
init. d/ inittab inputrc
[ root@haproxy ~ ]
- rw- r- - r- - 1 root root 2553 8 月 12 09 : 44 / etc/ init. d/ haproxy
chmod + x / etc/ init. d/ haproxy
chkconfig - - add / etc/ init. d/ haproxy
systemctl start haproxy
[ root@haproxy ~ ]
LISTEN 0 128 * : 80 * : * users: ( ( "haproxy" , pid= 97460 , fd= 4 ) )
测试
[ root@haproxy ~ ]
Web01
[ root@haproxy ~ ]
Web02
[ root@haproxy ~ ]
Web01
[ root@haproxy ~ ]
Web02
[ root@haproxy ~ ]
sed - i 's/#$ModLoad imudp/$ModLoad imudp/g' / etc/ rsyslog. conf
sed - i 's/#$UDPServerRun 514/$UDPServerRun 514/g' / etc/ rsyslog. conf
[ root@haproxy ~ ]
local3. * / var/ log/ haproxy. log
systemctl restart rsyslog
systemctl restart haproxy
[ root@haproxy ~ ]
/ var/ log/ haproxy. log