Linux操作系统下的集群原理及实战经历( 二 )


2 Networking部分:;
[*] Kernel/User netlink socket;
[*] Routing messages;
<*> Netlink device emulation;
* [*] Network firewalls;
[*] Socket Filtering;
<*> Unix domain sockets;
* [*] TCP/IP networking;
[*] IP: multicasting;
[*] IP: advanced router;
[ ] IP: policy routing;
[ ] IP: equal cost multipath;
[ ] IP: use TOS value as routing key;
[ ] IP: verbose route monitoring;
[ ] IP: large routing tables;
[ ] IP: kernel level autoconfiguration;
* [*] IP: firewalling;
[ ] IP: firewall packet netlink device;
* [*] IP: transparent proxy support;
* [*] IP: masquerading;
--- Protocol-specific masquerading support will be built as modules.;
* [*] IP: ICMP masquerading;
--- Protocol-specific masquerading support will be built as modules.;
* [*] IP: masquerading special modules support;
* IP: ipautofw masq support (EXPERIMENTAL)(NEW);
* IP: ipportfw masq support (EXPERIMENTAL)(NEW);
* IP: ip fwmark masq-forwarding support (EXPERIMENTAL)(NEW);
* [*] IP: masquerading virtual server support (EXPERIMENTAL)(NEW);
[*] IP Virtual Server debugging (NEW) <--最好选择此项,以便观察LVS的调试信息;
* (12) IP masquerading VS table size (the Nth power of 2) (NEW);
* IPVS: round-robin scheduling (NEW);
* IPVS: weighted round-robin scheduling (NEW);
* IPVS: least-connection scheduling (NEW);
* IPVS: weighted least-connection scheduling (NEW);
* IPVS: locality-based least-connection scheduling (NEW);
* IPVS: locality-based least-connection with replication scheduling;
(NEW);
* [*] IP: optimize as router not host;
* IP: tunneling;
IP: GRE tunnels over IP;
[*] IP: broadcast GRE over IP;
[*] IP: multicast routing;
[*] IP: PIM-SM version 1 support;
[*] IP: PIM-SM version 2 support;
* [*] IP: aliasing support;
[ ] IP: ARP daemon support (EXPERIMENTAL);
* [*] IP: TCP syncookie support (not enabled per default);
--- (it is safe to leave these untouched);
< > IP: Reverse ARP;
[*] IP: Allow large windows (not recommended if <16Mb of memory);
< > The IPv6 protocol (EXPERIMENTAL)
上面,带*号的为必选项 。然后就是常规的编译内核过程,不再赘述 。
在这里要注意一点:如果你使用的是RedHat自带的内核或者从RedHat下载的内核版本,已经预先打好了LVS的补丁 。这可以通过查看/usr/src/linux/net/目录下有没有几个ipvs开头的文件来判断:如果有,则说明已经打过补丁 。
编写LVS配置文件,实例中的配置文件如下:

#lvs_dr.conf (C) Joseph Mack mack@ncifcrf.gov
LVS_TYPE=VS_DR;
INITIAL_STATE=on;
VIP=eth0:101 192.168.0.101 255.255.255.0 192.168.0.0;
DIRECTOR_INSIDEIP=eth0 192.168.0.1 192.168.0.0 255.255.255.0 192.168.0. 255;
SERVICE=t telnet rr rs1:telnet rs2:telnet;
SERVICE=t www rr rs1:www rs2:www;
SERVER_VIP_DEVICE=dummy0;
SERVER_NET_DEVICE=eth0;
#----------end lvs_dr.conf------------------------------------
将该文件置于/etc/lvs目录下 。
使用LVS的配置脚本产生lvs.conf文件 。该配置脚本可以从http://www.linuxvirtualserver.org/Joseph.Mack/configure-lvs_0.8.tar.gz 单独下载,在ipvs-1.0.6-2.2.19.tar.gz包中也有包含脚本configure的使用方法:

[root@vs2 lvs]# configure lvs.conf
这样会产生几个配置文件,这里我们只使用其中的rc.lvs_dr文件 。修改/etc/rc.d/init.d/rc.local,增加如下几行:

echo 1 > /proc/sys/net/ipv4/ip_forward;
echo 1 > /proc/sys/net/ipv4/ip_always_defrag;
# 显示最多调试信息;
echo 10 > /proc/sys/net/ipv4/vs/debug_level
配置NFS服务 。这一步仅仅是为了方便管理,不是必须的步骤 。假设配置文件lvs.conf文件放在/etc/lvs目录下,则/etc/exports文件的内容为:

/etc/lvs ro(rs1,rs2)
然后使用exportfs命令输出这个目录:

[root@vs2 lvs]# exportfs
如果遇到什么麻烦,可以尝试:

推荐阅读