背景介绍
之前在阿里巴巴lvs的github上看到有人问在dell r730服务器上编译2.6.32-220的内核启动时出现kernel panic的情况。我现在的公司正好也有这批机器,试了一下果真报错,后来问隔壁艺龙的大神,得知应该是内核版本太低导致的,可以考虑移植到2.6.32-358的内核上,亲测可用,以下是搭建lvs-fullnat的步骤。
-----------------------------
写在前面的话:原本应该在微店写的博客,结果离职电脑上交后才发现还没有完成,来了深圳腾讯也没服务器环境继续做实验了,只好一拖再拖,终于在一台虚拟机上完成内核编译,之前确认该编译办法可以把lvs-fullnat成功运行在高版本内核中
安装步骤
安装必要软件:
1yum -y install m4 gcc redhat-rpm-config xmlto asciidoc elfutils-libelf-devel binutils-devel newt-devel perl-ExtUtils-Embed hmaccalc rng-tools下载源码
12345678mkdir /home/lvscd /home/lvs去百度云盘下载220内核的ipvs和ip_vs.h上传到/home/lvs文件夹下链接: https://pan.baidu.com/s/1miLp7BE 密码: wdh7tar zxvf ipvs.tar.gzwget http://vault.centos.org/6.4/os/Source/SPackages/kernel-2.6.32-358.el6.src.rpmwget http://kb.linuxvirtualserver.org/images/a/a5/Lvs-fullnat-synproxy.tar.gztar zxvf Lvs-fullnat-synproxy.tar.gz
编译内核重启
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859cat > ~/.rpmmacros << EOF%_topdir /home/lvs/rpms%_tmppath /home/lvs/rpms/tmp%_sourcedir /home/lvs/rpms/SOURCES%_specdir /home/lvs/rpms/SPECS%_srcrpmdir /home/lvs/rpms/SRPMS%_rpmdir /home/lvs/rpms/RPMS%_builddir /home/lvs/rpms/BUILDEOFcd /home/lvsmkdir rpmsmkdir rpms/tmpmkdir rpms/SOURCESmkdir rpms/SPECSmkdir rpms/SRPMSmkdir rpms/RPMSmkdir rpms/BUILDuseradd -s /sbin/nologin mockbuildrpm -ivh kernel-2.6.32-358.el6.src.rpmcd /home/lvs/rpms/SOURCESvim config-generic把第一行的# 改成 # x86_64,把 CONFIG_IP_VS_TAB_BITS=12 改成 CONFIG_IP_VS_TAB_BITS=20cd /home/lvs/rpms/SPECSvim kernel.spec把 # % define buildid .local 修改为%define buildid .ipvs_20bitrpmbuild -bp kernel.spec会卡在下面:+ gpg --homedir . --batch --gen-key /home/lvs/rpms/SOURCES/genkeygpg: WARNING: unsafe permissions on homedir `.'gpg: keyring `./secring.gpg' createdgpg: keyring `./pubring.gpg' created再打开服务器的另一个终端输入如下命令:rngd打lvs-fullnat patch和toa pathcd /home/lvs/rpms/BUILD/kernel-2.6.32-358.el6/linux-2.6.32-358.el6.ipvs_20bit.x86_64/cp /home/lvs/lvs-fullnat-synproxy/lvs-2.6.32-220.23.1.el6.patch ./cp /home/lvs/lvs-fullnat-synproxy/toa-2.6.32-220.23.1.el6.patch ./cp /home/lvs/ip_vs.h /home/lvs/rpms/BUILD/kernel-2.6.32-358.el6/linux-2.6.32-358.el6.ipvs_20bit.x86_64/include/net/cd /home/lvs/rpms/BUILD/kernel-2.6.32-358.el6/linux-2.6.32-358.el6.ipvs_20bit.x86_64/net/netfilter/ipvs/rm -rf *cp /home/lvs/ipvs/* /home/lvs/rpms/BUILD/kernel-2.6.32-358.el6/linux-2.6.32-358.el6.ipvs_20bit.x86_64/net/netfilter/ipvs/cd /home/lvs/rpms/BUILD/kernel-2.6.32-358.el6/linux-2.6.32-358.el6.ipvs_20bit.x86_64/patch -p1 < ./lvs-2.6.32-220.23.1.el6.patchpatch -p1 < ./toa-2.6.32-220.23.1.el6.patchcp configs/kernel-2.6.32-x86_64.config .configvim Makefile修改EXTRAVERSION = -358.e16.lvs-fullnatmake -j16这里看你多少cpu核心就写多少就行make modules_installmake installvim /etc/grub.conf修改内核启动参数default=0,并在kernel一行中,添加“nohz=off ”(如果不关闭nohz,大压力下CPU0可能会消耗过高,压力不均匀)reboot重启。重启后加载驱动安装工具
123456789101112131415161718192021222324modprobe ip_vsmodprobe ip_vs_rrmodprobe ip_vs_wrrmodprobe ip_vs_shmodprobe iptable_filtermodprobe ip_tablesmodprobe toa安装工具cd /home/lvs/lvs-fullnat-synproxytar xzf lvs-tools.tar.gzcd toolscd keepalived/./configure --with-kernel-dir=”/lib/modules/`uname -r`/build”makemake installcd /home/lvs/lvs-fullnat-synproxy/tools/ipvsadm/makemake installquagga可以 yum -y install quagga安装也可以编译安装cd /home/lvs/lvs-fullnat-synproxy/tools/quagga./configuremakemake install
性能调优
ethtool -K p4p1 gro off ethtool -K p4p1 lro off ethtool -K p4p1 rx off && sleep 1 && ethtool -K p4p1 rx on & echo 1 > /proc/sys/net/ipv4/tcp_syncookies echo 500000 > /proc/sys/net/core/netdev_max_backlog echo 500000 > /proc/sys/net/ipv4/tcp_max_syn_backlog echo 1 > /proc/sys/net/ipv4/ip_forward echo 0 > /proc/sys/net/ipv4/conf/all/send_redirects echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce echo 2000 > /proc/sys/net/unix/max_dgram_qlen 记得把以上命令加到/etc/rc.local
最后附上编译好的rpm内核包,没有亲测过不确定完全没问题
链接: https://pan.baidu.com/s/1jHTQT9s 密码: j4mcipvsadm的使用这里就不做赘述了。。。github上很详细的介绍。。。。。。。
总算把之前没完成的作业写完了,科科
感谢艺龙大神的方案,希望大家都能用上lvs_fullnat哈,有问题可以多讨论,有的好的方案欢迎大家多多留言