LVS
常用的模式有三种,这三种在常见的Linux
发行版本上面都是默认提供的,但是还有一种已经开源的模式FullNat
,官方文档提示需要结合内核2.6.32-220.23.1.el6
来进行编译使用,这篇文章主要用来演示,编译内核2.6.32-220.23.1.el6
,并且提供支持LVS Full Nat
首先今天的配置需要以下的软件包
asciidoc-8.4.5-4.1.el6.noarch.rpm //内核编译过程中依赖的软件包
newt-devel-0.52.11-3.el6.x86_64.rpm
kernel-2.6.32-220.23.1.el6.src.rpm //内核源码包
slang-devel-2.2.1-1.el6.x86_64.rpm
Lvs-fullnat-synproxy.tar.gz //LVS FullNat软件包
- 首先来安装内核的补丁软件包
[root@server20 haproxy]# rpm -ivh kernel-2.6.32-220.23.1.el6.src.rpm
[root@server20 haproxy]# rpm -ivh kernel-2.6.32-220.23.1.el6.src.rpm
1:kernel warning: user mockbuild does not exist - using root
warning: group mockbuild does not exist - using root
warning: user mockbuild does not exist - using root
warning: group mockbuild does not exist - using root
warning: user mockbuild does not exist - using root
- 上面的输出信息表示使用
root
用户的身份执行 - 接下来查看用户家目录里面的信息
[root@server20 ~]# cd rpmbuild/
BUILD/ BUILDROOT/ RPMS/ SOURCES/ SPECS/ SRPMS/
[root@server20 ~]# cd rpmbuild/SOURCES/
[root@server20 SOURCES]# ls
check-kabi config-s390x-rhel
config-debug config-x86_64-debug
config-debug-rhel config-x86_64-debug-rhel
config-framepointer config-x86_64-generic
config-generic config-x86_64-generic-rhel
config-generic-rhel config-x86_64-nodebug
config-i686 config-x86_64-nodebug-rhel
.....
.....
- 还有
[root@server20 rpmbuild]# cd SPECS/
[root@server20 SPECS]# ls
kernel.spec
- 然后制作成为
rpm
软件包,交给各个节点来安装,接下来需要解决依赖关系
[root@server20 SPECS]# rpmbuild -bp kernel.spec
error: Failed build dependencies:
patchutils is needed by kernel-2.6.32-220.23.1.el6.x86_64
xmlto is needed by kernel-2.6.32-220.23.1.el6.x86_64
asciidoc is needed by kernel-2.6.32-220.23.1.el6.x86_64
elfutils-libelf-devel is needed by kernel-2.6.32-220.23.1.el6.x86_64
binutils-devel is needed by kernel-2.6.32-220.23.1.el6.x86_64
newt-devel is needed by kernel-2.6.32-220.23.1.el6.x86_64
hmaccalc is needed by kernel-2.6.32-220.23.1.el6.x86_64
- 下载以下软件包来解决依赖关系
[root@server20 SPECS]# yum install patchutils \
xmlto \
elfutils-libelf-devel \
binutils-devel \
hmaccalc -y
- 还有三个软件包,需要自己额外下载
[root@server20 SPECS]# yum localinstall \
/mnt/haproxy/slang-devel-2.2.1-1.el6.x86_64.rpm \
/mnt/haproxy/asciidoc-8.4.5-4.1.el6.noarch.rpm \
/mnt/haproxy/newt-devel-0.52.11-3.el6.x86_64.rpm -y
- 还需要提供一个命令工具
[root@server20 ~]# yum install rng-tools-2-13.el6_2.x86_64 -y
- 再次执行
[root@server20 SPECS]# rpmbuild -bp kernel.spec
....
....
....
gpg: WARNING: unsafe permissions on homedir `.'
gpg: keyring `./secring.gpg' created
gpg: keyring `./pubring.gpg' created
+ cat
###
### Key pair generated.
###
+ '[' -s /root/rpmbuild/SOURCES/extrakeys.pub ']'
+ gpg --homedir . --no-default-keyring --keyring kernel.pub --import /root/rpmbuild/SOURCES/extrakeys.pub
gpg: WARNING: unsafe permissions on homedir `.'
gpg: ./trustdb.gpg: trustdb created
gpg: key CD09BEDA: public key "Red Hat Enterprise Linux Driver Update Program <secalert@redhat.com>" imported
gpg: Total number processed: 1
gpg: imported: 1
+ gpg --homedir . --export --keyring ./kernel.pub Red
gpg: WARNING: unsafe permissions on homedir `.'
+ gcc -o scripts/bin2c scripts/bin2c.c
+ scripts/bin2c ksign_def_public_key __initdata
+ cd ..
+ exit 0
- 解压文件,并且拷贝补丁
[root@server20 haproxy]# tar -zxf Lvs-fullnat-synproxy.tar.gz
[root@server20 linux-2.6.32-220.23.1.el6.x86_64]# pwd
/root/rpmbuild/BUILD/kernel-2.6.32-220.23.1.el6/linux-2.6.32-220.23.1.el6.x86_64
[root@server20 linux-2.6.32-220.23.1.el6.x86_64]# cp /mnt/haproxy/lvs-fullnat-synproxy/lvs-2.6.32-220.23.1.el6.patch .
- 为
2.6.32-220.23.1.el6.x86_64
添加内核补丁文件
[root@server20 linux-2.6.32-220.23.1.el6.x86_64]# patch -p1 < lvs-2.6.32-220.23.1.el6.patch
- 更改
Makefile
文件
[root@server20 linux-2.6.32-220.23.1.el6.x86_64]# vim Makefile
添加:
EXTRAVERSION = -220.23.1.el6
- 然后执行
[root@server20 linux-2.6.32-220.23.1.el6.x86_64]# make
这个过程需要很长的时间
- 在执行
make
操作过程中,需要注意的是
- 1.硬盘根分区最好大于
30G
,rhel6.5
根分区多使用LVM
,关于如何扩展,参考以前的文章; - 2.能够使用的内存最好在
2G
以上,否则会出现内存不够,导致make
进程被内核杀死;
- 1.硬盘根分区最好大于
- 执行
[root@server20 linux-2.6.32-220.23.1.el6.x86_64]# visudo
添加
test ALL=(ALL) NOPASSWD: ALL
- 接下来执行
[root@server20 linux-2.6.32-220.23.1.el6.x86_64]# make modules_install
- 最后执行
[root@server20 linux-2.6.32-220.23.1.el6.x86_64]# make install
- 接下来查看启动目录
boot
就会多了几个文件
[root@server20 boot]# ls
System.map-2.6.32-220.23.1.el6
initramfs-2.6.32-220.23.1.el6.img
vmlinuz-2.6.32-220.23.1.el6
- 查看
grub.conf
里面新加了几个选项
[root@server20 boot]# vim grub/grub.conf
更改
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux Server (2.6.32-220.23.1.el6)
root (hd0,0)
kernel /vmlinuz-2.6.32-220.23.1.el6 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM nohz=off rhgb quiet
initrd /initramfs-2.6.32-220.23.1.el6.img
- 然后使用新的内核重新主机,并且使用命令来查看现在使用的内核
[root@server20 ~]# uname -r
2.6.32-220.23.1.el6
- 编译内核并且重新启动的任务就完成了
新内核使用的
modules
文件,同样在/lib/modules/2.6.32-220.23.1.el6/
目录里面移除
ipvsadm
[root@server20 ~]# yum remove ipvsadm -y
[root@server20 ~]# cd /mnt/haproxy/lvs-fullnat-synproxy/
[root@server20 lvs-fullnat-synproxy]# tar -zxf lvs-tools.tar.gz
- 首先来编译安装
keepalived
- 这里可能会出现一个错误
[root@server20 keepalived]# ./configure --with-kernel-dir=/lib/modules/2.6.32-220.23.1.el6/build/
configure: error: Popt libraries is required
需要执行
[root@server20 keepalived]# yum install popt-devel -y
- 接下来继续进行编译安装
[root@server20 keepalived]# ./configure --with-kernel-dir=/lib/modules/2.6.32-220.23.1.el6/build/
Keepalived configuration
------------------------
Keepalived version : 1.2.2
Compiler : gcc
Compiler flags : -g -O2
Extra Lib : -lpopt -lssl -lcrypto -lnl
Use IPVS Framework : Yes
IPVS sync daemon support : Yes
IPVS use libnl : Yes
Use VRRP Framework : Yes
Use Debug flags : No
[root@server20 keepalived]# make
[root@server20 keepalived]# make install
- 解析来编译安装
ipvsadm
[root@server20 keepalived]# cd ../ipvsadm/
- 这里在编译安装的过程中出现了下面的错误
../keepalived/keepalived/libipvs-2.6/libipvs.a(libipvs.o):/mnt/haproxy/lvs-fullnat-synproxy/tools/keepalived/keepalived/libipvs-2.6/libipvs.c:437: more undefined references to `nlmsg_free' follow
collect2: ld returned 1 exit status
make: *** [ipvsadm] Error 1
- 首先移除一个软件包
[root@server20 ipvsadm]# yum remove libnl-devel -y
- 然后删除上面解压的
lvs
的软件包
[root@server20 lvs-fullnat-synproxy]# rm -fr tools/
- 重新进行解压,并且进行安装
[root@server20 lvs-fullnat-synproxy]# tar -zxf lvs-tools.tar.gz
[root@server20 keepalived]# ./configure --with-kernel-dir=/lib/modules/2.6.32-220.23.1.el6/build/
Keepalived configuration
------------------------
Keepalived version : 1.2.2
Compiler : gcc
Compiler flags : -g -O2
Extra Lib : -lpopt -lssl -lcrypto
Use IPVS Framework : Yes
IPVS sync daemon support : Yes
IPVS use libnl : No //这个发生了改变
Use VRRP Framework : Yes
Use Debug flags : No
[root@server20 keepalived]# make
[root@server20 keepalived]# make install
[root@server20 keepalived]# cd ../ipvsadm/
[root@server20 ipvsadm]# make
gcc -Wall -Wunused -Wstrict-prototypes -g -DVERSION=\"1.26\" -DSCHEDULERS=\""rr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq"\" -DPE_LIST=\""sip"\" -DHAVE_POPT -DHAVE_NET_IP_VS_H -c -o ipvsadm.o ipvsadm.c
ipvsadm.c: In function ‘print_largenum’:
ipvsadm.c:1445: warning: field width should have type ‘int’, but argument 2 has type ‘size_t’
gcc -Wall -Wunused -Wstrict-prototypes -g -DVERSION=\"1.26\" -DSCHEDULERS=\""rr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq"\" -DPE_LIST=\""sip"\" -DHAVE_POPT -DHAVE_NET_IP_VS_H -c -o config_stream.o config_stream.c
gcc -Wall -Wunused -Wstrict-prototypes -g -DVERSION=\"1.26\" -DSCHEDULERS=\""rr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq"\" -DPE_LIST=\""sip"\" -DHAVE_POPT -DHAVE_NET_IP_VS_H -c -o dynamic_array.o dynamic_array.c
gcc -Wall -Wunused -Wstrict-prototypes -g -o ipvsadm ipvsadm.o config_stream.o dynamic_array.o ../keepalived/keepalived/libipvs-2.6/libipvs.a -lpopt
- 上面执行
make
的过程是没有什么错误的,然后执行make install
[root@server20 ipvsadm]# make install
[root@server20 ipvsadm]# make install
if [ ! -d /sbin ]; then mkdir -p /sbin; fi
install -m 0755 ipvsadm /sbin
install -m 0755 ipvsadm-save /sbin
install -m 0755 ipvsadm-restore /sbin
[ -d /usr/man/man8 ] || mkdir -p /usr/man/man8
install -m 0644 ipvsadm.8 /usr/man/man8
install -m 0644 ipvsadm-save.8 /usr/man/man8
install -m 0644 ipvsadm-restore.8 /usr/man/man8
[ -d /etc/rc.d/init.d ] || mkdir -p /etc/rc.d/init.d
install -m 0755 ipvsadm.sh /etc/rc.d/init.d/ipvsadm
- 在前面移除
ipvsadm
之后,这个命令照常是可以使用的
[root@server20 ipvsadm]# ipvsadm
IP Virtual Server version 1.2.1 (size=4194304)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
- 接下来查看
Full Nat
模式
[root@server20 ipvsadm]# ipvsadm --help
底下有列出
--gatewaying -g gatewaying (direct routing) (default)
--ipip -i ipip encapsulation (tunneling)
--fullnat -b fullnat mode //这个模式如果需要需要手动打补丁
--masquerading -m masquerading (NAT)
- 一般来说,
red hat [6.5]
内核提供的只包含以下三种模式
--gatewaying -g gatewaying (direct routing) (default)
--ipip -i ipip encapsulation (tunneling)
--masquerading -m masquerading (NAT)
- 接下来还需要安装,
[root@server20 quagga]# cd /mnt/haproxy/lvs-fullnat-synproxy/tools/quagga
cd /home/pukong/tools/quagga;
./configure --disable-ripd --disable-ripngd --disable-bgpd --disable-watchquagga --disable-doc --enable-user=root --enable-vty-group=root --enable-group=root --enable-zebra --localstatedir=/var/run/quagga
[root@server20 quagga]# make
[root@server20 quagga]# make install