Nginx+KeepAlive方案
机器规划和架构图
部署nginx负载均衡
配置nginx负载
安装nginx服务
[root@linux-node4 ~]# yum -y install nginx
配置反向代理
[root@lb-master ~]# vim /etc/nginx/nginx.conf stream { log_format main '$remote_addr $upstream_addr - [$time_local] $status $upstream_bytes_sent'; access_log /var/log/nginx/django-access.log main; upstream django-apiserver { server 192.168.56.62:80; server 192.168.56.63:80; } server { listen 88; proxy_pass django-apiserver; } }
完整配置如下
看一下即可,都是nginx默认配置
http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; \#tcp_nopush on; keepalive_timeout 65; \#gzip on; include /etc/nginx/conf.d/*.conf; }
测试反向代理可用性
[root@lb-master ~]# vim /etc/keepalived/keepalived.conf global_defs { notification_email { acassen@firewall.loc failover@firewall.loc sysadmin@firewall.loc } notification_email_from Alexandre.Cassen@firewall.loc smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id NGINX_MASTER } \# 健康监测nginx vrrp_script check_nginx { script "/etc/keepalived/check_nginx.sh" # 设置检查nginx是否存活的脚本位置 } \# keepalive热备组配置 vrrp_instance VI_1 { state MASTER # 配置当前keepalive为master角色 interface eth0 # 网卡名字,必须和实际网卡名称一致,默认是ens33 virtual_router_id 51 # VRRP 路由 ID实例,每个实例是唯一的 priority 100 # 优先级,备服务器设置 90 advert_int 1 # 指定VRRP 心跳包通告间隔时间,默认1秒 authentication { auth_type PASS auth_pass 1111 # 设置keepalive的master和slave之间简单的秘钥认证 } virtual_ipaddress { 192.168.56.60/24 # 设置keepalive虚拟IP地址 } track_script { check_nginx } }
做最野的狼