Nginx load principle + keepalived high availability use

1. Prepare the environment

1. Prepare 4 virtual machines (mine is centos7.5 version)

Two as web test pages, two as load + high availability
Insert picture description hereInsert picture description here

2. Turn off the firewall setenforce

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0

2. Install and configure two web test pages

1. Install apache first

[root@localhost ~]# yum -y install httpd

2. Edit the html test page for easy distinction

[root@localhost ~]# vim /var/www/html/index.html
web1
[root@localhost ~]# vim /var/www/html/index.html
web2

3. Start and view the test page

[root@localhost ~]# systemctl start httpd

Insert picture description here
Insert picture description here

3. Installation and configuration nginx+keepalived

1. Install nginx from source code (two 136 137)

先安装依赖
[root@localhost ~]# yum -y install gcc gcc-c++ pcre-devel zlib-devel
下载nginx源码包  http://nginx.org/  nginx官方网址

[root@localhost ~]# tar xzf nginx-1.12.2.tar.gz 
[root@localhost ~]# cd nginx-1.12.2
[root@localhost nginx-1.12.2]# ./configure && make && make install

2. Configure nginx load balancing

[root@localhost nginx-1.12.2]# vim /usr/local/nginx/conf/nginx.conf

Insert picture description here

3. Start nginx and test load balancing

[root@localhost nginx-1.12.2]# /usr/local/nginx/sbin/nginx 

Insert picture description here
Insert picture description here

4. Install and configure keepalived master (136)

[root@localhost ~]# yum -y install keepalived
[root@localhost ~]# vim /etc/keepalived/keepalived.conf 

Insert picture description here
Insert picture description here

5. Start keepalived and check whether the VIP is generated

[root@localhost ~]# systemctl start keepalived

Insert picture description here

6. Install and configure keepalived from (137)

[root@localhost ~]# yum -y install keepalived
[root@localhost ~]# vim /etc/keepalived/keepalived.conf 

Insert picture description here
Insert picture description here

7. Test to see if the VIP drifts from

先把从上的keepalived 启动
[root@localhost nginx-1.12.2]# systemctl start keepalived

在主上把keepalived 关掉
[root@localhost ~]# systemctl stop keepalived

Insert picture description here

4. Test VIP on the web

Insert picture description here

If you can’t get out, pay attention to your firewall to release the port and VRRP

Guess you like

Origin blog.csdn.net/Q274948451/article/details/109080596