Build LVS-DR cluster and configure nginx load balancing based on CentOS 7

Table of contents

1. Build an LVS-DR cluster based on CentOS 7

1. Preliminary preparation

1. Turn off the firewall

2. Install ifconfig

3. Prepare four virtual machines

2. On DS

2.1. Configure LVS virtual IP

2.2. Manually perform configuration to add LVS service and add two RSs.

2.3. View configuration

3. On the RS side (the third and fourth stations)

3.1. Configure Web server

3.2. Configure the default homepage

3.3. Start the service

3.4. Test: Access the web server on the client

3.5. Bind VIP

3.6. Configure host routing

3.7. Suppress ARP response

4. Test on the client

 2. Configure nginx load balancing

1. Install and deploy nginx

2. Intranet server 151

3. Intranet server 152

4. Proxy server 150

5. Client

1. Build an LVS-DR cluster based on CentOS 7

1. Preliminary preparation

1. Turn off the firewall


[root@localhost ~]# systemctl stop firewalld

2. Install ifconfig

yum install net-tools.x86_64 -y

3. Prepare four virtual machines

ip use
192.168.226.150 client
192.168.226.151 lvs
192.168.226.152

RS

192.168.226.153 RS

2. On DS

2.1. Configure LVS virtual IP

安装ipvsadm
yum install ipvsadm -y

增加IP
ifconfig ens33:200 192.168.226.200 netmask 255.255.255.255 up

2.2. Manually perform configuration to add LVS service and add two RSs.

[root@localhost ~]# ipvsadm -C
[root@localhost ~]# ipvsadm -A -t 192.168.226.200:80 -s rr
[root@localhost ~]# ipvsadm -a -t 192.168.226.200:80 -r 192.168.226.151:80 -g
[root@localhost ~]# ipvsadm -a -t 192.168.226.200:80 -r 192.168.226.152:80 -g

2.3 . View configuration

3. On the RS side (the third and fourth stations)

3.1. Configure Web server

yum install httpd -y

3.2. Configure the default homepage

hostname -I 取地址

[root@backup ~]# echo "web test page, ip is `hostname -I`." > /var/www/html/index.html

3.3. Start the service

[root@backup ~]# systemctl start httpd

3.4. Test: Access the web server on the client

[root@localhost ~]# curl 192.168.226.147
web test page, ip is 192.168.226.147 .
[root@localhost ~]# curl 192.168.226.148
web test page, ip is 192.168.226.148 .

3.5. Bind VIP

ifconfig lo:200 192.168.226.200 netmask 255.255.255.255 up

3.6. Configure host routing

route add -host 192.168.226.200 dev lo

3.7. Suppress ARP response

调整内核参数,关闭arp响应

echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce

4. Test on the client

 2. Configure nginx load balancing

1. Install and deploy nginx

Deploy Nginx on Linux system_Funny Dog’s Blog-CSDN Blog

2. Intranet server 151

[root@localhost ~]# vim /etc/nginx/conf.d/vhost.conf
server {
        listen 80;
        server_name web1.yunjisuan.com;

        location / {
                root /usr/share/nginx/html/web1;
                index index.html index.htm;
        }
        access_log /usr/share/nginx/html/web1/logs/access_bbs.log main;

}
[root@localhost ~]# mkdir -p /usr/share/nginx/html/web1/logs
[root@localhost ~]# echo "`hostname -I `web1" > /usr/share/nginx/html/web1/index.html
[root@localhost ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@localhost ~]# systemctl restart nginx

3. Intranet server 152

[root@localhost ~]# vim /etc/nginx/conf.d/vhost.conf
server {
        listen 80;
        server_name web1.yunjisuan.com;

        location / {
                root /usr/share/nginx/html/web1;
                index index.html index.htm;
        }
        access_log /usr/share/nginx/html/web1/logs/access_bbs.log main;

}


[root@localhost ~]# mkdir -p /usr/share/nginx/html/web1/logs
[root@localhost ~]# echo "`hostname -I `web1" > /usr/share/nginx/html/web1/index.html
[root@localhost ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@localhost ~]# systemctl restart nginx

4. Proxy server 150

[root@localhost ~]# vim /etc/nginx/conf.d/lb_test.conf
upstream www_server_pools {
        server 192.168.226.151:80 weight=1;
        server 192.168.231.152:80 weight=1;
}
server {
        listen 80;
        server_name web1.haha.com;
        location / {
                proxy_pass http://www_server_pools;
                proxy_set_header Host $host;
        }
}

5. Client

[root@localhost ~]# vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.226.150 web1.haha.com
[root@localhost ~]# for ((i=1;i<=6;i++)); do curl web1.haha.com; done
192.168.226.152 web1
192.168.226.151 web1
192.168.226.152 web1
192.168.226.151 web1
192.168.226.152 web1
192.168.226.151 web1

Guess you like

Origin blog.csdn.net/shenql_/article/details/132173458