nginx+keepalived实现高可用
实验环境
192.168.186.100 虚拟vip
192.168.186.129 centos7 安装nginx、keepalived的服务器
192.168.186.130 centos7 安装nginx、keepalived的服务器
192.168.186.128 centos7 提供真实服务的httpd服务器
192.168.186.131 centos7 提供真实服务的httpd服务器
本地windows
关闭防火墙和selinux
systemctl stop firewalld setenforce 0
|
httpd服务器配置
yum install httpd -y
listen 8080
echo web1 > a.html echo web2 > a.html
systemctl start httpd
|
nginx负载均衡器配置
nginx配置
upstream myserver { server 192.168.186.128:8080; server 192.168.186.131:8080; } server { listen 80 default_server; listen [::]:80 default_server; server_name 192.168.186.100; root /usr/share/nginx/html;
include /etc/nginx/default.d/*.conf;
location / { proxy_pass http://myserver/a.html; } }
|
keepalived配置
global_defs { router_id LVS_DEVEL } vrrp_instance VI_1 { state MASTER interface ens33 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.186.100 } }
global_defs { router_id LVS_DEVEL } vrrp_instance VI_1 { state MASTER interface ens33 virtual_router_id 51 priority 99 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.186.100 } }
|
查看虚拟vip是否生成、是否能够自动漂移
ip address
ping 192.168.186.100
systemctl stop keepalived ip address
|
测试
在windows浏览器输入192.168.186.100:80,成功轮询访问到真实httpd服务器的页面