Nginx+keepalived clustered high availability
- Environmental preparation
-
- No-1 installation service
- Install and configure nginx to achieve load balancing
- Arrangement No-2
- No-1 start nginx, verify the load
- No-1 placement keepalived
- Start the service and verify high availability
-
- Simulate a single point of failure
- Please visit the principle of keepalived: [keepalived principle and module](https://blog.csdn.net/qing1912/article/details/108790048)
- For detailed explanation of keepalived+LVS deployment and principles, please visit: [keepalived+LVS clustered deployment](https://blog.csdn.net/qq_49296785/article/details/108476658)
Environmental preparation
C entos7 four, turn off the firewall, turn off selinux
- No-1 Prevent single point of failure and nginx load balancing
192.168.112.153
192.168.112.154 - No-2 httpd simulated web page
192.168.112.160
192.168.112.161
- Principle rendering
Description: The two highly available devices should be divided into master and backup, and VIP defined. After nginx load balancing is configured, keepalived configures the RS end of the local machine and the ip address of the other keepalived. When both are alive, regardless of access to VIP or Both master and backup can be accessed. When a single point of failure occurs (when one end of the master or backup fails), the VIP is elegant and continuous flow is realized!
No-1 installation service
yum -y install gcc gcc-c++ pcre-devel zlib-devel keepalived
-
Upload nginx package
-
-
You can also download the latest nginx package from the official website
Install and configure nginx to achieve load balancing
tar xf nginx-1.18.0.tar.gz 解压
cd nginx-1.18.0 进入目录
./configure 检测编译环境
make && make install 编译并安装
Modify nginx configuration file
vim /usr/local/nginx/conf/nginx.conf
- Lines 34~37 define the back-end server with load [outside the server]
- Add proxy [in server] on line 49
Arrangement No-2
- Install httpd
yum -y install httpd
- Write test page
vim /var/www/html/index.html
Content web1, the other one is different, web2
- Start httpd, verify the port
No-1 start nginx, verify the load
/usr/local/nginx/sbin/nginx
No-1 placement keepalived
vim /etc/keepalived/keepalived.conf
- Delete the extra line
- 8 lines define master
- Line 9 modify the network card to ens33
- 11 Behavior weight [backup power is less important than master]
- The 18th line defines VIP. The ip master and backup that are not occupied in this network segment
are required to have different configurations, and the others are the same!!!
- Fill in the VIP on line 22 and modify the port to 80
- 24 behavioral algorithm
- Comment out the persistence timeout on line 26 [symbol is! 】
- The ip and port of the RS end on line 29
- Modify line 31 to check for tcp
- 32 lines delete the redundant ones, add the connection port in the next line
Start the service and verify high availability
systemctl start keepalived
- View VIP
ip a show ens33
- Verification rendering, VIP of master
- All live, master, bakcup and VIP are all accessible to achieve load
Simulate a single point of failure
- Stop the master side, check VIP elegant
systemctl stop keepalived
- Backup check
- Webpage test renderings
- Although the master side has been deactivated, the load can still be achieved, and the VIP is floating