韦德国际bv1946_www.bv1946com_韦德国际1946手机版
做最好的网站

CentOS下LVS keepalived nginx tomcat部署实现

日期:2019-12-23编辑作者:韦德国际bv1946计算机

CentOS下LVS keepalived nginx tomcat部署实现

图片 1

# 节点分布情况

LVS-dr-master

eth0: 192.168.146.141

LVS-dr-slave

eth0:192.168.146.142

nginx1:

eth0:192.168.146.139

nginx2:

eth0:192.168.146.140

tomcat1:

eth0:192.168.146.138启用了4个tomcat

VIP: 192.168.146.200

# 拓扑如下所示

图片 2

# 具体配置

### lvs master

### 1、安装ipvsadm、keepalived

1yuminstall-ykeepalivedipvsadm

### 2、使用keepalived来管理lvs

脚本:

global_defs{router_idmaster_210}vrrp_instanceaiyou{stateMASTERinterfaceeth0virtual_router_id100#这个数值master和slave必须统一priority151#这个数值决定哪台服务器是masteradvert_int1authentication{auth_typePASSauth_pass123456}virtual_ipaddress{192.168.146.200}}virtual_server192.168.146.20080{delay_loop6lb_algowrrlb_kindDR#persistence_timeout50protocolTCPreal_server192.168.146.13980{weight1TCP_CHECK{connect_timeout3nb_get_retry3delay_before_retry3connect_port80}}real_server192.168.146.14080{weight1TCP_CHECK{connect_timeout3nb_get_retry3delay_before_retry3connect_port80}}}

### lvs slave

### 1、安装ipvsadm、keepalived

yuminstall-ykeepalivedipvsadm

### 2、使用keepalived来管理lvs

global_defs{router_idslave_211}vrrp_instanceaiyou{stateMASTERinterfaceeth0virtual_router_id100#这个数值master和slave必须统一priority150#这个数值决定哪台服务器是master这里我们比master数值低,所以角色是backup,advert_int1authentication{auth_typePASSauth_pass123456}virtual_ipaddress{192.168.146.200}}virtual_server192.168.146.20080{delay_loop6lb_algowrrlb_kindDR#persistence_timeout50protocolTCPreal_server192.168.146.13980{weight1TCP_CHECK{connect_timeout3nb_get_retry3delay_before_retry3connect_port80}}real_server192.168.146.14080{weight1TCP_CHECK{connect_timeout3nb_get_retry3delay_before_retry3connect_port80}}}

### nginx1

### nginx上要跑个脚本

#!/bin/bash##ScripttostartLVSDRrealserver.#description:LVSDRrealserver#./etc/rc.d/init.d/functionsVIP=192.168.146.200#这里根据需要改成自己的VIP地址host=`/bin/hostname`case"$1"instart)#StartLVS-DRrealserveronthismachine./sbin/ifconfiglodown/sbin/ifconfigloupecho1>/proc/sys/net/ipv4/conf/lo/arp_ignoreecho2>/proc/sys/net/ipv4/conf/lo/arp_announceecho1>/proc/sys/net/ipv4/conf/all/arp_ignoreecho2>/proc/sys/net/ipv4/conf/all/arp_announce/sbin/ifconfiglo:0$VIPbroadcast$VIPnetmask255.255.255.255up/sbin/routeadd-host$VIPdevlo:0;;stop)#StopLVS-DRrealserverloopbackdevice(s)./sbin/ifconfiglo:0downecho0>/proc/sys/net/ipv4/conf/lo/arp_ignoreecho0>/proc/sys/net/ipv4/conf/lo/arp_announceecho0>/proc/sys/net/ipv4/conf/all/arp_ignoreecho0>/proc/sys/net/ipv4/conf/all/arp_announce;;status)#StatusofLVS-DRrealserver.islothere=`/sbin/ifconfiglo:0|grep$VIP`isrothere=`netstat-rn|grep"lo:0"|grep$VIP`if[!"$islothere"-o!"isrothere"];then#Eithertherouteorthelo:0device#notfound.echo"LVS-DRrealserverStopped."elseecho"LVS-DRrealserverRunning."fi;;*)#Invalidentry.echo"$0:Usage:$0{start|status|stop}"exit1;;esac

### nginx2

### nginx上要跑个脚本

#!/bin/bash##ScripttostartLVSDRrealserver.#description:LVSDRrealserver#./etc/rc.d/init.d/functionsVIP=192.168.146.200#这里根据需要改成自己的VIP地址host=`/bin/hostname`case"$1"instart)#StartLVS-DRrealserveronthismachine./sbin/ifconfiglodown/sbin/ifconfigloupecho1>/proc/sys/net/ipv4/conf/lo/arp_ignoreecho2>/proc/sys/net/ipv4/conf/lo/arp_announceecho1>/proc/sys/net/ipv4/conf/all/arp_ignoreecho2>/proc/sys/net/ipv4/conf/all/arp_announce/sbin/ifconfiglo:0$VIPbroadcast$VIPnetmask255.255.255.255up/sbin/routeadd-host$VIPdevlo:0;;stop)#StopLVS-DRrealserverloopbackdevice(s)./sbin/ifconfiglo:0downecho0>/proc/sys/net/ipv4/conf/lo/arp_ignoreecho0>/proc/sys/net/ipv4/conf/lo/arp_announceecho0>/proc/sys/net/ipv4/conf/all/arp_ignoreecho0>/proc/sys/net/ipv4/conf/all/arp_announce;;status)#StatusofLVS-DRrealserver.islothere=`/sbin/ifconfiglo:0|grep$VIP`isrothere=`netstat-rn|grep"lo:0"|grep$VIP`if[!"$islothere"-o!"isrothere"];then#Eithertherouteorthelo:0device#notfound.echo"LVS-DRrealserverStopped."elseecho"LVS-DRrealserverRunning."fi;;*)#Invalidentry.echo"$0:Usage:$0{start|status|stop}"exit1;;esac

### 后端tomcat安装省略

采用一机多实例模式(非多虚拟主机)

### 测试

### master上验证

[[email protected]~]#ipvsadm-lnIPVirtualServerversion1.2.1(size=4096)ProtLocalAddress:PortSchedulerFlags->RemoteAddress:PortForwardWeightActiveConnInActConnTCP192.168.146.200:80wrr->192.168.146.139:80Route100->192.168.146.140:80Route100[[email protected]~]#

### slave上验证

[[email protected]~]#ipvsadm-lnIPVirtualServerversion1.2.1(size=4096)ProtLocalAddress:PortSchedulerFlags->RemoteAddress:PortForwardWeightActiveConnInActConnTCP192.168.146.200:80wrr->192.168.146.139:80Route100->192.168.146.140:80Route100[[email protected]~]#

参考文章:

# 节点分布情况 LVS-dr-master eth0: 192.168.146.141 LVS-dr-slave eth0:192.168.146.142 nginx1: eth0:192.168.146.139 nginx2: eth...

本文由韦德国际bv1946手机版发布于韦德国际bv1946计算机,转载请注明出处:CentOS下LVS keepalived nginx tomcat部署实现

关键词:

1.下载Redis for windows 的最新版本

一、准备文件 1.下载Redis for windows 的最新版本 下载地址: 安装到 c:Redis 目录下(Redis-x64-3.2.100.msi Windows服务版) 2.下...

详细>>

JDK 可以到官网下载

01.1 Windows环境下JDK安装与环境变量配置详细的图文教程 本节内容:JDK安装与环境变量配置 以下是详细步骤 一、准备...

详细>>

转义序列是以ESC开头

1、采用原生转义字符序列,对Windows有的版本不支持(比如win7),完美支持Linux 实现过程: 终端的字符颜色是用转义...

详细>>