1、客戶(hù)端添加VM1網(wǎng)卡,配置和服務(wù)器同網(wǎng)段IP地址

2、訪(fǎng)問(wèn)第一臺(tái)nginx服務(wù)器

3、客戶(hù)端更換IP地址訪(fǎng)問(wèn)第二臺(tái)nginx服務(wù)器

四、部署Haproxy服務(wù)器

Haproxy概述及工作原理詳細(xì)配置參考博文:Haproxy搭建Web群集概述
Centos 7基于Haproxy搭建高可用Web群集

1、安裝haproxy

[root@centos03 ~]# yum -y install pcre-devel bzip2-devel  <!--安裝依賴(lài)程序-->
[root@centos03 ~]# ls
anaconda-ks.cfg  haproxy-1.4.24.tar.gz  initial-setup-ks.cfg
[root@centos03 ~]# tar zxvf haproxy-1.4.24.tar.gz -C /usr/src/  <!--解壓縮haproxy壓縮包-->
[root@centos03 ~]# cd /usr/src/haproxy-1.4.24/  
[root@centos03 haproxy-1.4.24]# make TARGET=linux26 <!--編譯haproxy支持64位系統(tǒng)-->
[root@centos03 haproxy-1.4.24]# make install  <!--安裝haproxy-->

2、生成haproxy配置文件

[root@centos03 ~]# mkdir /etc/haproxy  <!--創(chuàng)建保存haproxy配置文件目錄-->
[root@centos03 ~]# cp /usr/src/haproxy-1.4.24/examples/haproxy.cfg /etc/haproxy/ 
                <!--生成配置文件-->
[root@centos03 ~]# cp /usr/src/haproxy-1.4.24/examples/haproxy.init /etc/init.d/haproxy 
         <!--創(chuàng)建haproxy服務(wù)控制腳本-->
[root@centos03 ~]# chmod  x /etc/init.d/haproxy <!--添加執(zhí)行權(quán)限-->
[root@centos03 ~]# chkconfig --add haproxy <!--添加為系統(tǒng)服務(wù)-->
 [root@centos03 ~]# chkconfig --level 35 haproxy on <!--設(shè)置開(kāi)機(jī)自動(dòng)啟動(dòng)-->
[root@centos03 ~]# cp /usr/src/haproxy-1.4.24/haproxy /usr/sbin/ <!--優(yōu)化程序執(zhí)行命令-->
[root@centos03 ~]# mkdir -p /usr/share/haproxy <!--創(chuàng)建服務(wù)運(yùn)行的臨時(shí)目錄-->

3、配置haproxy群集

[root@centos03 ~]# vim /etc/haproxy/haproxy.cfg   <!--修改haproxy主配置文件-->
listen  nginx 192.168.100.30:80   <!--Haproxy服務(wù)器IP地址-->
        balance roundrobin
        server  web01 192.168.100.10:80 check inter 2000 fall 3   <!--第一臺(tái)Nginx的IP-->
        server  web02 192.168.100.20:80 check inter 2000 fall 3  <!--第二臺(tái)Nginx的IP-->
[root@centos03 ~]# /etc/init.d/haproxy start  <!--啟動(dòng)haproxy服務(wù)-->
Starting haproxy (via systemctl):                          [  確定  ]

1)客戶(hù)端訪(fǎng)問(wèn)192.168.100.30

2)客戶(hù)端更換IP地址重新訪(fǎng)問(wèn)

五、配置Firewalld防火墻(雙網(wǎng)卡)

關(guān)于Firewalld防火墻的概述及詳細(xì)配置請(qǐng)參考博文:Centos 7的Firewalld防火墻基礎(chǔ)
Centos 7的firewalld防火墻地址偽裝和端口轉(zhuǎn)發(fā)原理
centos 7之firewalld防火墻配置IP偽裝和端口轉(zhuǎn)發(fā)案例詳解

[root@centos04 ~]# cp /etc/sysconfig/network-scripts/ifcfg-ens32 /etc/sysconfig/network-scripts/ifcfg-ens34   <!--復(fù)制ens34網(wǎng)卡配置文件-->
[root@centos04 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens34  
                 <!--編輯ens34網(wǎng)卡配置文件-->
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
NAME=ens34
DEVICE=ens34
ONBOOT=yes
IPADDR=192.168.200.254  <!--外網(wǎng)的IP地址-->
NATEMASK=255.255.255.0
dns1=192.168.200.254   <!--添加DNS-->
[root@centos04 ~]# systemctl restart network   <!--重新啟動(dòng)網(wǎng)卡服務(wù)-->
[root@centos04 ~]# vim /etc/sysctl.conf   <!--開(kāi)啟路由功能-->
net.ipv4.ip_forward = 1
[root@centos04 ~]# sysctl -p  <!--刷新配置-->
[root@centos01 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens32  
                 <!--編輯ens32網(wǎng)卡配置文件-->
GATEWAY=192.168.100.40  
     <!--網(wǎng)站服務(wù)器和Haproxy服務(wù)器添加網(wǎng)關(guān)(內(nèi)網(wǎng)所有服務(wù)器都要添加網(wǎng)關(guān))-->
[root@centos01 ~]# systemctl restart network  <!--重新啟動(dòng)網(wǎng)卡服務(wù)-->
[root@centos04 ~]# systemctl start firewalld.service   <!--啟動(dòng)防火墻-->
[root@centos04 ~]# systemctl enable firewalld.service  <!--設(shè)置開(kāi)機(jī)自動(dòng)啟動(dòng)-->
[root@centos04 ~]# firewall-cmd --add-interface=ens34 --zone=external   
        <!--將ens34接口加入到external區(qū)域-->
The interface is under control of NetworkManager, setting zone to \\\'external\\\'.
success
[root@centos04 ~]# firewall-cmd --add-interface=ens32 --zone=trusted  
            <!--將ens32接口加入到trusted區(qū)域-->
The interface is under control of NetworkManager, setting zone to \\\'trusted\\\'.
success
[root@centos04 ~]# firewall-cmd --get-active-zones   <!--查看所有激活的區(qū)域-->
external
  interfaces: ens34
trusted
  interfaces: ens32
[root@centos04 ~]# firewall-cmd --remove-masquerade --zone=external   
           <!--關(guān)閉默認(rèn)的IP地址偽裝-->
success
[root@centos04 ~]# firewall-cmd --add-rich-rule=\\\'rule family=ipv4 source address=192.168.100.0/24 masquerade\\\' <!--external區(qū)域配置IP地址偽裝-->
success
[root@centos04 ~]# firewall-cmd --add-rich-rule=\\\'rule family=ipv4 destination address=192.168.200.254/32 forward-port port=80 protocol=tcp to-addr=192.168.100.30\\\'
<!--配置端口映射;將trusted區(qū)域的192.168.100.30的80端口映射到external區(qū)域的
 192.168.200.254的80端口-->
success
[root@centos04 ~]# firewall-cmd --zone=external --add-service=http
            <!--external區(qū)域允許http協(xié)議-->
success
[root@centos04 ~]# firewall-cmd --zone=external --add-service=dns   
        <!--external區(qū)域允許 dns協(xié)議-->
success
[root@centos04 ~]# firewall-cmd --zone=external --list-all<!--查看external區(qū)域的詳細(xì)信息-->
external (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens34
  sources: 
  services: ssh http dns
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
    rule family=ipv4 source address=192.168.100.0/24 masquerade
    rule family=ipv4 destination address=192.168.200.254/32 forward-port port=80 protocol=tcp to-addr=192.168.100.30

六、部署DNS

關(guān)于DNS詳細(xì)配置及概述請(qǐng)參考博文:CentOS7簡(jiǎn)單搭建DNS服務(wù)

[root@centos04 ~]# yum -y install bind bind-chroot bind-utils <!--安裝依賴(lài)軟件-->
[root@centos04 ~]# echo  > /etc/named.conf   
[root@centos04 ~]# vim /etc/named.conf   <!--編輯DNS主配置文件-->
options {
        listen-on       port    53      { any; };
        directory       /var/named;
};
zone    benet.com        IN      {
        type    master;
        file    benet.com.zone;
};

[root@centos04 ~]# named-checkconf -z /etc/named.conf
          <!--檢查DNS主配置文件是否錯(cuò)誤-->
[root@centos04 ~]# vim /var/named/benet.com.zone
           <!--編輯benet.com正向解析區(qū)域配置文件-->
$TTL    86400
@       SOA     benet.com.       root.benet.com.(
        2020021801
        1H
        15M
        1W
        1D
)
@       NS      centos04.benet.com.
centos04 A      192.168.200.254
www      A      192.168.200.254
[root@centos04 ~]# named-checkzone benet.com /var/named/benet.com.zone  
         <!--檢查正向解析區(qū)域配置文件是否錯(cuò)誤--> 
zone benet.com/IN: loaded serial 2020021801
OK
[root@centos04 ~]# chmod  x /var/named/benet.com.zone   
        <!--正向解析區(qū)域配置文件添加執(zhí)行權(quán)限-->
[root@centos04 ~]# chown named:named /var/named/benet.com.zone<!--修改屬組屬組-->
[root@centos04 ~]# systemctl start named  <!--啟動(dòng)服務(wù)-->
[root@centos04 ~]# systemctl enable named  <!--設(shè)置服務(wù)開(kāi)機(jī)自動(dòng)啟動(dòng)-->

七、部署外網(wǎng)客戶(hù)端

1、客戶(hù)端配置IP地址、添加DNS地址

2、客戶(hù)端使用域名訪(fǎng)問(wèn)

3、客戶(hù)端更換IP地址重新訪(fǎng)問(wèn)

———————— 本文至此結(jié)束,感謝閱讀 ————————

更多關(guān)于云服務(wù)器域名注冊(cè),虛擬主機(jī)的問(wèn)題,請(qǐng)?jiān)L問(wèn)三五互聯(lián)官網(wǎng):www.shinetop.cn

贊(0)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享網(wǎng)絡(luò)內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。郵箱:3140448839@qq.com。本站原創(chuàng)內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明出處:三五互聯(lián)知識(shí)庫(kù) » CentOS 7搭建Haproxy Nginx Firewalld DNS負(fù)載均衡

登錄

找回密碼

注冊(cè)