目前常見的Web集群調(diào)度器分為軟件和硬件,軟件通常使用開源的LVS、Haproxy、 Nginx, 硬件一般使用比較多的是F5,也有很多人使用國內(nèi)的一些產(chǎn)品,如梭子魚、綠盟等
創(chuàng)新互聯(lián)建站是一家專注于網(wǎng)站設(shè)計制作、網(wǎng)站建設(shè)與策劃設(shè)計,振安網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)建站做網(wǎng)站,專注于網(wǎng)站建設(shè)10年,網(wǎng)設(shè)計領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:振安等地區(qū)。振安做網(wǎng)站價格咨詢:18980820575
1.LVS不支持正則處理,不能實現(xiàn)動靜分離
2.對于大型網(wǎng)站,LVS的實施配置復(fù)雜,維護成本相對較高
1.特別適用于負載特別大的Web站點
2.運行在當(dāng)前的硬件.上可支持數(shù)以萬計的并發(fā)連接連接請求
1.RR (Round Robin):
RR算法是最簡單最常用的一-種算法,即輪詢調(diào)2.理解舉例:
有三個節(jié)點A、B、C,第一個用戶訪問會被指派到節(jié)點A,第二個用戶訪問會被指派到節(jié)點B,第三個用戶訪問會被指派到節(jié)點第四個用戶訪問繼續(xù)指派到節(jié)點A,輪詢分配訪問請求實現(xiàn)負載均衡效果
SH即基于來源訪問調(diào)度算法,此算法用于一些有Session會話記錄在服務(wù)器端的場景,可以基于來源的IP、Cookie等做集群調(diào)度
①有三個節(jié)點A、B、C,第一個用戶第一次訪問被指派到了A,第二個用戶第一次訪問被指派到了B
②當(dāng)?shù)谝粋€用戶第二次訪問時會被繼續(xù)指派到A,第二個用戶第二次訪問時依舊會被指派到B,只要負載均衡調(diào)度器不重啟,第一個用戶訪問都會被指派到A,第二個用戶訪問都會被指派到B,實現(xiàn)集群的調(diào)度
③此調(diào)度算法好處是實現(xiàn)會話保持,但某些IP訪問量非常大時會引起負載不均衡,部分節(jié)點訪問量超大,影響業(yè)務(wù)使用
Nginx1:192.168.100.201---->CentOS 7-2
Nginx2:192.168.100.202---->CentOS 7-3
調(diào)度服務(wù)器:192.168.100.210---->CentOS 7-4
客戶機:192.168.100.58---->win 7-1
[root@localhost ~]# yum install pcre-devel zlib-devel gcc gcc-c++ make -y
//改網(wǎng)卡為僅主機模式
[root@localhost ~]# 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保存退出
[root@localhost ~]# service network restart
Restarting network (via systemctl): [ 確定 ]
[root@localhost ~]# mkdir /aaa
[root@localhost ~]# mount.cifs //192.168.10.189/rpm /aaa
Password for root@//192.168.10.189/rpm:
[root@localhost ~]# cd /aaa
[root@localhost 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
[root@localhost aaa]# cd tomcat/
[root@localhost 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
[root@localost tomcat]# tar zxvf nginx-1.12.0.tar.gz -C /opt/
[root@localhost tomcat]# cd /opt/
[root@localhost opt]# useradd -M -s /sbin/nologin nginx
[root@localhost opt]# cd nginx-1.12.0/
[root@localhost nginx-1.12.0]# ls
auto CHANGES.ru configure html man src
CHANGES conf contrib LICENSE README
[root@localhost nginx-1.12.0]# ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx
[root@localhost nginx-1.12.0]# make && make install
[root@localhost nginx-1.12.0]# cd /usr/local/nginx/html/
[root@localhost html]# echo "this is accp web" > test.html
[root@localhost html]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
[root@localhost 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
[root@localhost html]# nginx
[root@localhost html]# netstat -ntap | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 6408/nginx: master
[root@localhost html]# systemctl stop firewalld.service
[root@localhost html]# setenforce 0
[root@localhost ~]# yum install pcre-devel zlib-devel gcc gcc-c++ make -y
//改網(wǎng)卡為僅主機模式
[root@localhost ~]# 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保存退出
[root@localhost ~]# service network restart
Restarting network (via systemctl): [ 確定 ]
[root@localhost ~]# mkdir /aaa
[root@localhost ~]# mount.cifs //192.168.10.189/rpm /aaa
Password for root@//192.168.10.189/rpm:
[root@localhost ~]# cd /aaa
[root@localhost 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
[root@localhost aaa]# cd tomcat/
[root@localhost 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
[root@localost tomcat]# tar zxvf nginx-1.12.0.tar.gz -C /opt/
[root@localhost tomcat]# cd /opt/
[root@localhost opt]# useradd -M -s /sbin/nologin nginx
[root@localhost opt]# cd nginx-1.12.0/
[root@localhost nginx-1.12.0]# ls
auto CHANGES.ru configure html man src
CHANGES conf contrib LICENSE README
[root@localhost nginx-1.12.0]# ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx
[root@localhost nginx-1.12.0]# make && make install
[root@localhost nginx-1.12.0]# cd /usr/local/nginx/html/
[root@localhost html]# echo "this is benet web" > test.html
[root@localhost html]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
[root@localhost 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
[root@localhost html]# nginx
[root@localhost html]# netstat -ntap | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 6408/nginx: master
[root@localhost html]# systemctl stop firewalld.service
[root@localhost html]# setenforce 0
[root@localhost ~]# yum install bzip2-devel pcre-devel gcc gcc-c++ make -y
//改網(wǎng)卡為僅主機模式
[root@localhost ~]# 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保存退出
[root@localhost ~]# service network restart
Restarting network (via systemctl): [ 確定 ]
[root@localhost ~]# mkdir /aaa
[root@localhost ~]# mount.cifs //192.168.10.189/rpm /aaa
Password for root@//192.168.10.189/rpm:
[root@localhost ~]# cd /aaa
[root@localhost 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
[root@localhost aaa]# tar zxvf haproxy-1.5.19.tar.gz -C /opt/
[root@localhost aaa]# cd /opt
[root@localhost opt]# ls
haproxy-1.5.19 rh
[root@localhost opt]# cd haproxy-1.5.19/
[root@localhost haproxy-1.5.19]# make TARGET=linux26
[root@localhost haproxy-1.5.19]# make install
[root@localhost haproxy-1.5.19]# mkdir /etc/haproxy
[root@localhost haproxy-1.5.19]# cp examples/haproxy.cfg /etc/haproxy/
[root@localhost haproxy-1.5.19]# vim /etc/haproxy/haproxy.cfg
//其中chroot /usr/share/haproxy 根目錄刪除
//其中 redispatch 請求轉(zhuǎn)發(fā)給宕機服務(wù)器刪除
//下面的所有的Listen全部刪除,按88dd
//然后添加以下內(nèi)容
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保存退出
[root@localhost haproxy-1.5.19]# cp examples/haproxy.init /etc/init.d/haproxy
[root@localhost haproxy-1.5.19]# chmod +x /etc/init.d/haproxy
[root@localhost haproxy-1.5.19]# chkconfig --add haproxy
[root@localhost haproxy-1.5.19]# ln -s /usr/local/sbin/haproxy /usr/sbin/haproxy
[root@localhost haproxy-1.5.19]# service haproxy start
Starting haproxy (via systemctl): [ 確定 ]
[root@localhost haproxy-1.5.19]# systemctl stop firewalld.service
[root@localhost haproxy-1.5.19]# setenforce 0