5.realserver配置3.LVS调度机的OSPF配置

【最佳答案】a.添加启动服务脚本/etc/init.d/lvs_realserver请自行按需要修改脚本中SNS_VIP变量#!/bin/sh### BEGIN INIT INFO# Provides: lvs_realserver# Derealserver配置 1 a.添加启动服务脚本/etc/init.d/lvs_realserver请自行按需要修改脚本中SNS_VIP变量
#!/bin/sh### BEGIN INIT INFO# Provides: lvs_realserver# Default-Start:3 4 5# Default-Stop: 0 1 6# Short-Description: LVS real_server service scripts# Description: LVS real_server start and stop controller### END INIT INFO#Copyright 2013 lxcong##chkconfig: - 20 80##Author:xxxx@xxxx#有多个虚拟IP,以空格分隔SNS_VIP="1.1.1.1". /etc/rc.d/init.d/functionsif [[ -z "$SNS_VIP"]];thenecho 'Please set vips in '$0' with SNS_VIP!'fi start(){num=0for loop in $SNS_VIPdo/sbin/ifconfig lo:$num $loop netmask 255.255.255.255 broadcast $loop/sbin/route add -host $loop dev lo:$num((num++))doneecho "1" >/proc/sys/net/ipv4/conf/lo/arp_ignoreecho "2" >/proc/sys/net/ipv4/conf/lo/arp_announceecho "1" >/proc/sys/net/ipv4/conf/all/arp_ignoreecho "2" >/proc/sys/net/ipv4/conf/all/arp_announcesysctl -e -p >/dev/null 2>&1} stop(){num=0for loop in $WEB_VIPdo/sbin/ifconfig lo:$num down/sbin/route del -host $loop >/dev/null 2>&1((num++))doneecho "0" >/proc/sys/net/ipv4/conf/lo/arp_ignoreecho "0" >/proc/sys/net/ipv4/conf/lo/arp_announceecho "0" >/proc/sys/net/ipv4/conf/all/arp_ignoreecho "0" >/proc/sys/net/ipv4/conf/all/arp_announcesysctl -e -p >/dev/null 2>&1} case "$1" instart)startecho "RealServer Start OK";;stop)stopecho "RealServer Stoped";;restart)stopstart;;*)echo "Usage: $0 {start|stop|restart}"exit 1esacexit 0
b.启动服务service lvs_realserver startchkconfig lvs_realserver on
总结到这里,LVS Cluster架构已部署完了,如果各位有其他更好的LVS扩展方式请留意或者联系我,互相交流 QQ:83766787 。另外以前做了一个LVS的管理平台,但是一直都做得不好,也希望有相关平台开发经验的能联系我,交流交流、
650) this.width=650;" title="QQ截图20130710233858" alt="QQ截图20130710233858" src="https://www.baikezhishi.com/upload/article/20230115/qcwlmrspofk.png" "1002"="" height="560" data-src="https://www.baikezhishi.com/upload/article/20230115/ch05sgz3k4t.jpg">


LVS调度机的OSPF配置 2 a.安装软路由软件quaggayum ?y install quagga
b.配置zerba.confvim /etc/quagga/zebra.conf
hostname lvs-route-1password xxxxxxenable password xxxxxxlog file /var/log/zebra.logservice password-encryption
c.配置ospfd.confvim /etc/quagga/ospfd.conf
#ospf的配置类似于上面三层设备,注意需要把vip声明出去(1.1.1.1)log file /var/log/ospf.loglog stdoutlog sysloginterface eth0ip ospf hello-interval 1ip ospf dead-interval 4router ospfospf router-id 192.168.0.1log-adjacency-changesauto-cost reference-bandwidth 1000network 1.1.1.1/32 area 0.0.0.0network 192.168.0.0/24 area 0.0.0.0
d.开启IP转发sed ?i ‘/net.ipv4.ip_forward/d’ /etc/sysctl.confecho "net.ipv4.ip_forward = 1" >> /etc/sysctl.confsysctl ?p
e.开启服务/etc/init.d/zebra start /etc/init.d/ospfd start chkconfig zebra on chkconfig ospfd on
三层设备OSPF配置 3#查找与三层交换与lvs调度相连的端口,在本文端口分别为 g1/0/2 g1/0/3 g1/0/6#把g1/0/2改为三层端口,并配上IPinterface GigabitEthernet1/0/2port link-mode routeip address 192.168.0.1 255.255.255.0#配置ospf的参数, timer hello是发送hello包的间隔,timer dead是存活的死亡时间 。默认是10,40 。#hello包是ospf里面维持邻居关系的报文,这里配置是每秒发送一个,当到4秒还没有收到这个报文,就会认为这个邻居已经丢失,需要修改路由ospf timer hello 1ospf timer dead 4ospf dr-priority 100#如此类推,把g1/0/3 g1/0/6都配置上interface GigabitEthernet1/0/3port link-mode routeip address 192.168.3.1 255.255.255.0ospf timer hello 1ospf timer dead 4ospf dr-priority 99interface GigabitEthernet1/0/6port link-mode routeip address 192.168.2.1 255.255.255.0ospf timer hello 1ospf timer dead 4ospf dr-priority 98#配置ospfospf 1area 0.0.0.0network 192.168.0.0 0.0.0.255network 192.168.3.0 0.0.0.255network 192.168.2.0 0.0.0.255
硬件资源准备 4 三层设备: 本文用的是h3c 5800三层交换机
LVS调度机三台: 192.168.0.2 192.168.2.2 192.168.3.2
Realserver三台:1.1.1.100 1.1.1.101 1.1.1.102
LVS keepalived配置 5 在此架构下,LVS只能配置成DR模式 。如果要配置成NAT模式,我的想法是,需要参照上面的方式让LVS调度机与内网三层设备配置ospf,此方法未验证,有其他方案请告知 。
a.修改配置文件 keepalived.conf ,在Cluster架构中,所有调度机用相同的配置文件vim /etc/keepalived/keepalived.conf
#keepalived的全局配置global_defs {notification_email {lxcong@gmail.com}notification_email_from lvs_notice@gmail.comsmtp_server 127.0.0.1smtp_connect_timeout 30router_id Ospf_LVS_1}#VRRP实例,在这个架构下所有的LVS调度机都配置成MASTERvrrp_instance LVS_Cluster{##创建实例 实例名为LVS_Clusterstate MASTER #备份服务器上将MASTER改为BACKUPinterface eth0##VIP 捆绑网卡virtual_router_id 100##LVS_ID在同一个网络中,LVS_ID是唯一的priority 100#选举的优先级,优先级大的为MASTER备份服务上将100改为99advert_int 1#发送vrrp的检查报文的间隔,单位秒authentication {##认证信息 。可以是PASS或者AHauth_type PASSauth_pass 08856CD8}virtual_ipaddress {1.1.1.1}}#LVS实例,在本文采用的是DR模式,WRR调度方式 。其实在这种架构下也只能使用DR模式virtual_server 1.1.1.1 80 {delay_loop 6lb_algo wrrlb_kind DRpersistence_timeout 60protocol TCP real_server 1.1.1.100 80 {weight 1# 权重inhibit_on_failure# 若此节点故障,则将权重设为零(默认是从列表中移除)TCP_CHECK {connect_timeout 3nb_get_retry 3delay_before_retry 3connect_port 80}}real_server 1.1.1.101 80 {weight 1# 权重inhibit_on_failure# 若此节点故障,则将权重设为零(默认是从列表中移除)TCP_CHECK {connect_timeout 3nb_get_retry 3delay_before_retry 3connect_port 80}}real_server 1.1.1.102 80 {weight 1# 权重inhibit_on_failure# 若此节点故障,则将权重设为零(默认是从列表中移除)TCP_CHECK {connect_timeout 3nb_get_retry 3delay_before_retry 3connect_port 80}}}