来一发CentOS下LVS+keepalived+nginx+tomcat安排完成
如果您觉得本篇CentOSLinux教程讲得好,请记得点击右边漂浮的分享程序,把好文章分享给你的小伙伴们!#节点散布情形
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
#拓扑以下所示
#详细设置
###lvsmaster
###1、装置ipvsadm、keepalived
1
yuminstall-ykeepalivedipvsadm
###2、利用keepalived来办理lvs
剧本:
global_defs
{
router_idmaster_210
}
vrrp_instanceaiyou{
stateMASTER
inte***ceeth0
virtual_router_id100#这个数值master和slave必需一致
priority151#这个数值决意哪台办事器是master
advert_int1
authentication{
auth_typePASS
auth_pass123456
}
virtual_ipaddress{
192.168.146.200
}
}
virtual_server192.168.146.20080{
delay_loop6
lb_algowrr
lb_kindDR
#persistence_timeout50
protocolTCP
real_server192.168.146.13980{
weight1
TCP_CHECK{
connect_timeout3
nb_get_retry3
delay_before_retry3
connect_port80
}
}
real_server192.168.146.14080{
weight1
TCP_CHECK{
connect_timeout3
nb_get_retry3
delay_before_retry3
connect_port80
}
}
}
###lvsslave
###1、装置ipvsadm、keepalived
yuminstall-ykeepalivedipvsadm
###2、利用keepalived来办理lvs
global_defs
{
router_idslave_211
}
vrrp_instanceaiyou{
stateMASTER
inte***ceeth0
virtual_router_id100#这个数值master和slave必需一致
priority150#这个数值决意哪台办事器是master这里我们比master数值低,以是脚色是backup,
advert_int1
authentication{
auth_typePASS
auth_pass123456
}
virtual_ipaddress{
192.168.146.200
}
}
virtual_server192.168.146.20080{
delay_loop6
lb_algowrr
lb_kindDR
#persistence_timeout50
protocolTCP
real_server192.168.146.13980{
weight1
TCP_CHECK{
connect_timeout3
nb_get_retry3
delay_before_retry3
connect_port80
}
}
real_server192.168.146.14080{
weight1
TCP_CHECK{
connect_timeout3
nb_get_retry3
delay_before_retry3
connect_port80
}
}
}
###nginx1
###nginx上要跑个剧本
#!/bin/bash
#
#ScripttostartLVSDRrealserver.
#description:LVSDRrealserver
#
./etc/rc.d/init.d/functions
VIP=192.168.146.200#这里依据必要改成本人的VIP地点
host=`/bin/hostname`
case"$1"in
start)
#StartLVS-DRrealserveronthismachine.
/sbin/ifconfiglodown
/sbin/ifconfigloup
echo1>/proc/sys/net/ipv4/conf/lo/arp_ignore
echo2>/proc/sys/net/ipv4/conf/lo/arp_announce
echo1>/proc/sys/net/ipv4/conf/all/arp_ignore
echo2>/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:0down
echo0>/proc/sys/net/ipv4/conf/lo/arp_ignore
echo0>/proc/sys/net/ipv4/conf/lo/arp_announce
echo0>/proc/sys/net/ipv4/conf/all/arp_ignore
echo0>/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."
else
echo"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/functions
VIP=192.168.146.200#这里依据必要改成本人的VIP地点
host=`/bin/hostname`
case"$1"in
start)
#StartLVS-DRrealserveronthismachine.
/sbin/ifconfiglodown
/sbin/ifconfigloup
echo1>/proc/sys/net/ipv4/conf/lo/arp_ignore
echo2>/proc/sys/net/ipv4/conf/lo/arp_announce
echo1>/proc/sys/net/ipv4/conf/all/arp_ignore
echo2>/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:0down
echo0>/proc/sys/net/ipv4/conf/lo/arp_ignore
echo0>/proc/sys/net/ipv4/conf/lo/arp_announce
echo0>/proc/sys/net/ipv4/conf/all/arp_ignore
echo0>/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."
else
echo"LVS-DRrealserverRunning."
fi
;;
*)
#Invalidentry.
echo"$0:Usage:$0{start|status|stop}"
exit1
;;
esac
###后端tomcat装置省略
接纳一机多实例形式(非多假造主机)
###测试
###master上考证
#ipvsadm-ln
IPVirtualServerversion1.2.1(size=4096)
ProtLocalAddress:PortSchedulerFlags
->RemoteAddress:PortForwardWeightActiveConnInActConn
TCP192.168.146.200:80wrr
->192.168.146.139:80Route100
->192.168.146.140:80Route100
#
###slave上考证
#ipvsadm-ln
IPVirtualServerversion1.2.1(size=4096)
ProtLocalAddress:PortSchedulerFlags
->RemoteAddress:PortForwardWeightActiveConnInActConn
TCP192.168.146.200:80wrr
->192.168.146.139:80Route100
->192.168.146.140:80Route100
#
参考文章:
http://www.ckuyun.com/2014/05/lvs_keepalived_nginx_tomcat.html
如果您觉得本篇CentOSLinux教程讲得好,请记得点击右边漂浮的分享程序,把好文章分享给你的小伙伴们!
来一发CentOS下LVS+keepalived+nginx+tomcat安排完成
尽我能力帮助他人,在帮助他人的同时你会深刻巩固知识。来一发CentOS下LVS+keepalived+nginx+tomcat安排完成
安装一个新的软件时先看README,再看INSTALL然后看FAQ,最后才动手安装,这样遇到问题就知道为什么。如果Linux说明文档不看,结果出了问题再去论坛来找答案反而浪费时间。 一定要学好命令,shell是命令语言,命令解释程序及程序设计语言的统称,shell也负责用户和操作系统之间的沟通。 就这样,我们一边上OS理论课,一边上这个实验,这样挺互补的,老师讲课,一步一步地布置任务 直到学习Linux这门课以后,我才知道,原来我错了。? 不同于Windows?系统需要花钱购买,因为Linux的核心是免费的,自由使用的,核心源代码是开放的。 我是学习嵌入式方向的,这学期就选修了这门专业任选课。 熟悉系统的基本操作,Linux的图形界面直观,操作简便,多加上机练习就可熟悉操作,在Linux下学习办公软件等常用软件。 学习Linux应具备的。[书籍+网络资源]
页:
[1]