nginx load + keepalived high availability
- 1. Prepare the environment
- 2. Install and configure two web test pages
- 3. Installation and configuration nginx+keepalived
-
-
- 1. Install nginx from source code (two 136 137)
- 2. Configure nginx load balancing
- 3. Start nginx and test load balancing
- 4. Install and configure keepalived master (136)
- 5. Start keepalived and check whether the VIP is generated
- 6. Install and configure keepalived from (137)
- 7. Test to see if the VIP drifts from
-
- 4. Test VIP on the web
1. Prepare the environment
1. Prepare 4 virtual machines (mine is centos7.5 version)
Two as web test pages, two as load + high availability
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
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
3. Start nginx and test load balancing
[root@localhost nginx-1.12.2]# /usr/local/nginx/sbin/nginx
4. Install and configure keepalived master (136)
[root@localhost ~]# yum -y install keepalived
[root@localhost ~]# vim /etc/keepalived/keepalived.conf
5. Start keepalived and check whether the VIP is generated
[root@localhost ~]# systemctl start keepalived
6. Install and configure keepalived from (137)
[root@localhost ~]# yum -y install keepalived
[root@localhost ~]# vim /etc/keepalived/keepalived.conf
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