ustbfym 2019-12-04
目前常见的Web集群调度器分为软件和硬件,软件通常使用开源的LVS、Haproxy、 Nginx, 硬件一般使用比较多的是F5,也有很多人使用国内的一些产品,如梭子鱼、绿盟等
1.LVS不支持正则处理,不能实现动静分离
2.对于大型网站,LVS的实施配置复杂,维护成本相对较高
1.特别适用于负载特别大的Web站点
2.运行在当前的硬件.上可支持数以万计的并发连接连接请求
1.RR (Round Robin):
RR算法是最简单最常用的一-种算法,即轮询调2.理解举例:
有三个节点A、B、C,第一个用户访问会被指派到节点A,第二个用户访问会被指派到节点B,第三个用户访问会被指派到节点第四个用户访问继续指派到节点A,轮询分配访问请求实现负载均衡效果
SH即基于来源访问调度算法,此算法用于一些有Session会话记录在服务器端的场景,可以基于来源的IP、Cookie等做集群调度
①有三个节点A、B、C,第一个用户第一次访问被指派到了A,第二个用户第一次访问被指派到了B
②当第一个用户第二次访问时会被继续指派到A,第二个用户第二次访问时依旧会被指派到B,只要负载均衡调度器不重启,第一个用户访问都会被指派到A,第二个用户访问都会被指派到B,实现集群的调度
③此调度算法好处是实现会话保持,但某些IP访问量非常大时会引起负载不均衡,部分节点访问量超大,影响业务使用
Nginx1:192.168.100.201---->CentOS 7-2
Nginx2:192.168.100.202---->CentOS 7-3
调度服务器:192.168.100.210---->CentOS 7-4
客户机:192.168.100.58---->win 7-1
[ ~]# yum install pcre-devel zlib-devel gcc gcc-c++ make -y //改网卡为仅主机模式 [ ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 BOOTPROTO="static" IPADDR=192.168.100.201 NETMASK=255.255.255.0 GATEWAY=192.168.100.1 //修改完成后输入:wq保存退出 [ ~]# service network restart Restarting network (via systemctl): [ 确定 ] [ ~]# mkdir /aaa [ ~]# mount.cifs //192.168.10.189/rpm /aaa Password for //192.168.10.189/rpm: [ ~]# cd /aaa [ aaa]# ls apr-1.6.2.tar.gz jdk apr-util-1.6.0.tar.gz john-1.8.0.tar.gz awstats-7.6.tar.gz lf.jpg cronolog-1.6.2-14.el7.x86_64.rpm mysql Discuz_X3.4_SC_UTF8.zip nginx-1.12.2.tar.gz error.png php extundelete-0.2.4.tar.bz2 TC haproxy-1.5.19.tar.gz tomcat httpd-2.4.29.tar.bz2 tomcat.tmp hzw.jpeg wh.jpg [ aaa]# cd tomcat/ [ tomcat]# ls apache-tomcat-7.0.54.tar.gz jdk-8u91-linux-x64.tar.gz apache-tomcat-8.5.16.tar.gz nginx-1.12.0.tar.gz jdk-7u65-linux-x64.gz nginx-1.6.0.tar.gz [ tomcat]# tar zxvf nginx-1.12.0.tar.gz -C /opt/ [ tomcat]# cd /opt/ [ opt]# useradd -M -s /sbin/nologin nginx [ opt]# cd nginx-1.12.0/ [ nginx-1.12.0]# ls auto CHANGES.ru configure html man src CHANGES conf contrib LICENSE README [ nginx-1.12.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx [ nginx-1.12.0]# make && make install [ nginx-1.12.0]# cd /usr/local/nginx/html/ [ html]# echo "this is accp web" > test.html [ html]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ [ html]# nginx -t 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 [ html]# nginx [ html]# netstat -ntap | grep 80 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 6408/nginx: master [ html]# systemctl stop firewalld.service [ html]# setenforce 0
[ ~]# yum install pcre-devel zlib-devel gcc gcc-c++ make -y //改网卡为仅主机模式 [ ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 BOOTPROTO="static" IPADDR=192.168.100.202 NETMASK=255.255.255.0 GATEWAY=192.168.100.1 //修改完成后输入:wq保存退出 [ ~]# service network restart Restarting network (via systemctl): [ 确定 ] [ ~]# mkdir /aaa [ ~]# mount.cifs //192.168.10.189/rpm /aaa Password for //192.168.10.189/rpm: [ ~]# cd /aaa [ aaa]# ls apr-1.6.2.tar.gz jdk apr-util-1.6.0.tar.gz john-1.8.0.tar.gz awstats-7.6.tar.gz lf.jpg cronolog-1.6.2-14.el7.x86_64.rpm mysql Discuz_X3.4_SC_UTF8.zip nginx-1.12.2.tar.gz error.png php extundelete-0.2.4.tar.bz2 TC haproxy-1.5.19.tar.gz tomcat httpd-2.4.29.tar.bz2 tomcat.tmp hzw.jpeg wh.jpg [ aaa]# cd tomcat/ [ tomcat]# ls apache-tomcat-7.0.54.tar.gz jdk-8u91-linux-x64.tar.gz apache-tomcat-8.5.16.tar.gz nginx-1.12.0.tar.gz jdk-7u65-linux-x64.gz nginx-1.6.0.tar.gz [ tomcat]# tar zxvf nginx-1.12.0.tar.gz -C /opt/ [ tomcat]# cd /opt/ [ opt]# useradd -M -s /sbin/nologin nginx [ opt]# cd nginx-1.12.0/ [ nginx-1.12.0]# ls auto CHANGES.ru configure html man src CHANGES conf contrib LICENSE README [ nginx-1.12.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx [ nginx-1.12.0]# make && make install [ nginx-1.12.0]# cd /usr/local/nginx/html/ [ html]# echo "this is benet web" > test.html [ html]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ [ html]# nginx -t 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 [ html]# nginx [ html]# netstat -ntap | grep 80 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 6408/nginx: master [ html]# systemctl stop firewalld.service [ html]# setenforce 0
[ ~]# yum install bzip2-devel pcre-devel gcc gcc-c++ make -y //改网卡为仅主机模式 [ ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 BOOTPROTO="static" IPADDR=192.168.100.210 NETMASK=255.255.255.0 GATEWAY=192.168.100.1 //修改完成后输入:wq保存退出 [ ~]# service network restart Restarting network (via systemctl): [ 确定 ] [ ~]# mkdir /aaa [ ~]# mount.cifs //192.168.10.189/rpm /aaa Password for //192.168.10.189/rpm: [ ~]# cd /aaa [ aaa]# ls apr-1.6.2.tar.gz jdk apr-util-1.6.0.tar.gz john-1.8.0.tar.gz awstats-7.6.tar.gz lf.jpg cronolog-1.6.2-14.el7.x86_64.rpm mysql Discuz_X3.4_SC_UTF8.zip nginx-1.12.2.tar.gz error.png php extundelete-0.2.4.tar.bz2 TC haproxy-1.5.19.tar.gz tomcat httpd-2.4.29.tar.bz2 tomcat.tmp hzw.jpeg wh.jpg [ aaa]# tar zxvf haproxy-1.5.19.tar.gz -C /opt/ [ aaa]# cd /opt [ opt]# ls haproxy-1.5.19 rh [ opt]# cd haproxy-1.5.19/ [ haproxy-1.5.19]# make TARGET=linux26 [ haproxy-1.5.19]# make install [ haproxy-1.5.19]# mkdir /etc/haproxy [ haproxy-1.5.19]# cp examples/haproxy.cfg /etc/haproxy/ [ haproxy-1.5.19]# vim /etc/haproxy/haproxy.cfg //其中chroot /usr/share/haproxy 根目录删除 //其中 redispatch 请求转发给宕机服务器删除 //下面的所有的Listen全部删除,按88dd //然后添加以下内容 listen webcluster 0.0.0.0:80 option httpchk GET /test.html balance roundrobin server instl 192.168.100.201:80 check inter 2000 fall 3 server inst2 192.168.100.202:80 check inter 2000 fall 3 //修改完成后输入:wq保存退出 [ haproxy-1.5.19]# cp examples/haproxy.init /etc/init.d/haproxy [ haproxy-1.5.19]# chmod +x /etc/init.d/haproxy [ haproxy-1.5.19]# chkconfig --add haproxy [ haproxy-1.5.19]# ln -s /usr/local/sbin/haproxy /usr/sbin/haproxy [ haproxy-1.5.19]# service haproxy start Starting haproxy (via systemctl): [ 确定 ] [ haproxy-1.5.19]# systemctl stop firewalld.service [ haproxy-1.5.19]# setenforce 0