成都网站建设设计

将想法与焦点和您一起共享

LNMP+Tomcat+Keepalived+LVS多端口负载均衡

应用场景:Keepalived+LVS高可+负载均衡集群架构中rs同时跑httpd(80端口)和Java(8080端口)服务,使用Keepalived负载均衡多个端口。 如果想全部由80端口提供服务,则Keepalived+LVS负载均衡层就只开启80端口,内部节点使用nginx代理8080端口。

创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:网站设计、成都网站制作、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的丹徒网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

多端口负载均衡

[root@director sbin]# yum install -y keepalived [root@Centos-1 sbin]# vim /etc/keepalived/keepalived.conf vrrp_instance VI_1 { state BACKUP interface ens192 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass password } virtual_ipaddress { 192.168.14.13 } } virtual_server 192.168.14.13 80 { delay_loop 10 lb_algo wlc lb_kind DR persistence_timeout 180 protocol TCP real_server 192.168.14.127 80 { weight 100 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } real_server 192.168.14.128 80 { weight 100 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } real_server 192.168.14.129 80 { weight 100 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } } virtual_server 192.168.14.13 8080 { delay_loop 10 lb_algo wlc lb_kind DR persistence_timeout 180 protocol TCP real_server 192.168.14.127 8080 { weight 100 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } real_server 192.168.14.128 8080 { weight 100 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } real_server 192.168.14.129 8080 { weight 100 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } }

在dir2上执行同样的操作,lvs多端口负载均衡,需要注意的是dir2机器上state改为BACKUP,priority设为90。

nginx反向代理Tomcat

在rs上创建nginx代理虚拟主机,名为zrlog.conf,然后配置内容如下:

[root@128rs2 ~]# vim /usr/local/nginx/conf/vhosts/zrlog.conf server { listen 80; server_name www.3zuzrlog.com; location / { proxy_pass http://localhost:8080; proxy_redirect default; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }

此时Keepalived+LVS只需监听80端口即可:

[root@Centos-1 sbin]# vim /etc/keepalived/keepalived.conf vrrp_instance VI_1 { state BACKUP interface ens192 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass password } virtual_ipaddress { 192.168.14.13 } } virtual_server 192.168.14.13 80 { delay_loop 10 lb_algo wlc lb_kind DR persistence_timeout 180 protocol TCP real_server 192.168.14.127 80 { weight 100 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } real_server 192.168.14.128 80 { weight 100 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } real_server 192.168.14.129 80 { weight 100 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } }


当前标题:LNMP+Tomcat+Keepalived+LVS多端口负载均衡
转载注明:http://chengdu.cdxwcx.cn/article/cgjogj.html