AIOps 一场颠覆传统运维的盛筵
715
2023-03-09
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访问依然正常高可用的环境搭建完毕。
发表评论
暂时没有评论,来抢沙发吧~