Nginx+Tomcat+Keepalived实现高可用web集群

网友投稿 715 2023-03-09

本站部分文章、图片属于网络上可搜索到的公开信息,均用于学习和交流用途,不能代表睿象云的观点、立场或意见。我们接受网民的监督,如发现任何违法内容或侵犯了您的权益,请第一时间联系小编邮箱jiasou666@gmail.com 处理。

Nginx+Tomcat+Keepalived实现高可用web集群

Nginx+Tomcat+Keepalived实现高可用web集群:

环境:CenOS 6.5Nginx-Master:10.10.10.128Nginx-Backup:10.10.10.129Tomcat1:10.10.10.130Tomcat2:10.10.10.131VIP:10.10.10.100

环境:CenOS 6.5Nginx-Master:10.10.10.128Nginx-Backup:10.10.10.129Tomcat1:10.10.10.130Tomcat2:10.10.10.131VIP:10.10.10.100

一、环境基础配置

1、更换国内yum源

2、关闭防火墙、SELinux

3、时间同步

二、Web端安装Web服务

二、Nginx反向代理安装

三、使用Keepalived实现高可用

1、安装:    yum install keepalived -y2、修改配置文件/etc/keepalived/keepalived.confMASTER 端:! Configuration File for keepalivedvrrp_script check_nginx {        script "/etc/keepalived/check_nginx.sh"        interval 2        weight 2}global_defs {   notification_email {     acassen@firewall.loc     failover@firewall.loc     sysadmin@firewall.loc   }   notification_email_from Alexandre.Cassen@firewall.loc   smtp_server 192.168.200.1   smtp_connect_timeout 30   router_id LVS_DEVEL1}vrrp_instance VI_1 {    state MASTER    interface eth0    virtual_router_id 51    priority 100    advert_int 1    authentication {        auth_type PASS        auth_pass 1111    }    virtual_ipaddress {        10.10.10.100/24 dev eth0   } track_script {        check_nginx   }}BACKUP端:修改:router_id LVS_DEVEL2state BACKUPpriority 90检测Nginx脚本:#!/bin/bashnginxpid=`ps -C nginx --no-header | wc -l`if [ $nginxpid -eq 0 ];then        /etc/init.d/keepalived stopfichmod +x /etc/keepalived/check_nginx.sh重启Keepalived服务service keepalived restart

1、安装: yum install keepalived -y2、修改配置文件/etc/keepalived/keepalived.confMASTER 端:! Configuration File for keepalivedvrrp_script check_nginx { script "/etc/keepalived/check_nginx.sh" interval 2 weight 2}global_defs { notification_email { acassen@firewall.loc failover@firewall.loc sysadmin@firewall.loc } notification_email_from Alexandre.Cassen@firewall.loc smtp_server 192.168.200.1 smtp_connect_timeout 30 router_id LVS_DEVEL1}vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 10.10.10.100/24 dev eth0 } track_script { check_nginx }}BACKUP端:修改:router_id LVS_DEVEL2state BACKUPpriority 90检测Nginx脚本:#!/bin/bashnginxpid=`ps -C nginx --no-header | wc -l`if [ $nginxpid -eq 0 ];then /etc/init.d/keepalived stopfichmod +x /etc/keepalived/check_nginx.sh重启Keepalived服务service keepalived restart

四、检验服务的高可用

Nginx1执行:killall nginx发现 web访问依然正常Tomcat1执行:/usr/local/apache-tomcat-9.0.7/bin/shutdown.sh发现 web访问依然正常高可用的环境搭建完毕。

Nginx1执行:killall nginx发现 web访问依然正常Tomcat1执行:/usr/local/apache-tomcat-9.0.7/bin/shutdown.sh发现 web访问依然正常高可用的环境搭建完毕。

上一篇:分布式压测系列之Jmeter4.0第一季
下一篇:Nginx和Tomcat的管理脚本
相关文章

 发表评论

暂时没有评论,来抢沙发吧~