0、请使用物理机安装,虚拟机没编译成功

1、先查看一下系统版本,需要是centos6,内核2.6

cat /etc/*release
uname -r

[root@lvs-fullnat-one ~]# cat /etc/*release
CentOS release 6.5 (Final)
LSB_VERSION=base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
CentOS release 6.5 (Final)
CentOS release 6.5 (Final)
[root@lvs-fullnat-one ~]# uname -r
2.6.32-431.el6.x86_64
[root@lvs-fullnat-one ~]# 

2、从Redhat网站下载kernel的rpm

wget ftp://ftp.redhat.com/pub/redhat/linux/enterprise/6Server/en/os/SRPMS/kernel-2.6.32-220.23.1.el6.src.rpm
如果无法现在,请从网盘下载。连接:
;

3、从rpm中获得kerel源码

vim ~/.rpmmacros;
   add:
     %_topdir /home/pukong/rpms
     %_tmppath /home/pukong/rpms/tmp
     %_sourcedir /home/pukong/rpms/SOURCES
     %_specdir /home/pukong/rpms/SPECS
     %_srcrpmdir /home/pukong/rpms/SRPMS
     %_rpmdir /home/pukong/rpms/RPMS
     %_builddir /home/pukong/rpms/BUILD
  cd /home/pukong;
   mkdir rpms;
   mkdir rpms/tmp;
   mkdir rpms/SOURCES;
   mkdir rpms/SPECS;
   mkdir rpms/SRPMS;
   mkdir rpms/RPMS;
   mkdir rpms/BUILD;

useradd mockbuild
rpm -ivh kernel-2.6.32-220.23.1.el6.src.rpm
cd /home/pukong/rpms/SPECS
yum -y install rpm-build
yum -y install gcc zlib-devel patchutils xmlto asciidoc elfutils-libelf-devel  binutils-devel  newt-devel python-devel hmaccalc

yum -y install  rng-tools  openssl-devel
rngd -r /dev/urandom  ##rng-tools用于在执行rpmbuild -bb --target=`uname -m` kernel.spec的时候生成随机数,不然会卡在那里,但是根据卡的地方倒退回去会看到提示就执行rngd -r /dev/hwrandom,不行的话执行 rngd -r /dev/urandom,因此需要安装此工具

rpmbuild -bp kernel.spec;

最后的rpmbuild是一个可能是一个十分漫长的操作,请不要关闭xshell。

这时候你就能在/home/pukong/rpms/BUILD找到内核源码

[root@lvs-fullnat-one SPECS]#  cd /home/pukong/rpms/BUILD/;
[root@lvs-fullnat-one BUILD]# ls
kernel-2.6.32-220.23.1.el6

4、添加lvs patch

[Lvs-fullnat-synproxy.tar.gz]
https://pan.baidu.com/s/1sOnbGpnk7vZGoTxgEVDpAA
将文件放到服务器中

tar xvf Lvs-fullnat-synproxy.tar.gz 
cd lvs-fullnat-synproxy/
cp lvs-2.6.32-220.23.1.el6.patch /home/pukong/rpms/BUILD/kernel-2.6.32-220.23.1.el6/linux-2.6.32-220.23.1.el6.x86_64/

cd /home/pukong/rpms/BUILD/;
cd kernel-2.6.32-220.23.1.el6/linux-2.6.32-220.23.1.el6.x86_64/;

patch -p1

打完补丁,修改Makefile文件,给内核版本命名:

[root@lvs-fullnat-one linux-2.6.32-220.23.1.el6.x86_64]# uname -r
2.6.32-431.el6.x86_64
[root@lvs-fullnat-one linux-2.6.32-220.23.1.el6.x86_64]# vim Makefile

将Makefile中EXTRAVERSION 字段补上一个跟uname -r相似字段,如下图

VERSION = 2
PATCHLEVEL = 6
SUBLEVEL = 32
EXTRAVERSION = -431.toa.el6.x86_64
NAME = Man-Eating Seals of Antiquity
RHEL_MAJOR = 6
RHEL_MINOR = 2
RHEL_RELEASE = 219

注意修改.config文件中的参数,主要是为了扩大VS最大连接数,可以增大VS的吞吐量(并发连接量),如果值只是原本的4096可能会丢包

 vim .config

 CONFIG_IP_VS_TAB_BITS=22 

5、编译内核

make -j16 ##j是指同时作业的数量,可以不用添加此参数
make modules_install;
make install;

此时可能会报几个错

[root@lvs-fullnat-one linux-2.6.32-220.23.1.el6.x86_64]# make install;
sh /home/pukong/rpms/BUILD/kernel-2.6.32-220.23.1.el6/linux-2.6.32-220.23.1.el6.x86_64/arch/x86/boot/install.sh 2.6.322.6.32-431.el6.x86_64 arch/x86/boot/bzImage \
        System.map "/boot"
ERROR: modinfo: could not find module lpc_ich
ERROR: modinfo: could not find module ptp
[root@lvs-fullnat-one linux-2.6.32-220.23.1.el6.x86_64]# 

需要复制进来几个模块

cp /lib/modules/2.6.32-431.el6.x86_64/kernel/drivers/mfd/lpc_ich.ko /lib/modules/2.6.32-431.toa.el6.x86_64/kernel/drivers/mfd/

mkdir /lib/modules/2.6.32-431.toa.el6.x86_64/kernel/drivers/ptp
cp /lib/modules/2.6.32-431.el6.x86_64/kernel/drivers/ptp/ptp.ko /lib/modules/2.6.32-431.toa.el6.x86_64/kernel/drivers/ptp/

重新安装,会有几个警告,忽略即可

[root@lvs-fullnat-one linux-2.6.32-220.23.1.el6.x86_64]# make install;
sh /home/pukong/rpms/BUILD/kernel-2.6.32-220.23.1.el6/linux-2.6.32-220.23.1.el6.x86_64/arch/x86/boot/install.sh 2.6.32-431.toa.el6.x86_64 arch/x86/boot/bzImage \
        System.map "/boot"
WARNING: /lib/modules/2.6.32-431.toa.el6.x86_64/kernel/drivers/ptp/ptp.ko needs unknown symbol kmem_cache_alloc_trace
WARNING: /lib/modules/2.6.32-431.toa.el6.x86_64/kernel/drivers/ptp/ptp.ko needs unknown symbol posix_clock_register
WARNING: /lib/modules/2.6.32-431.toa.el6.x86_64/kernel/drivers/ptp/ptp.ko needs unknown symbol posix_clock_unregister
[root@lvs-fullnat-one linux-2.6.32-220.23.1.el6.x86_64]# 

6、修改内核文件

vim /boot/grub/grub.conf
修改default的值为0 表示先启动
引导文件中有两个引导启动段,一个是原本内核的linux,一个是新编译的内核,新编译的内核在上面,所以把default的值设为0,即表示使用新的内核引导系统了。

7、重启

reboot

lvs fullnat+ECMP【1】内核编译_第1张图片
微信公众号,随便发点有意思的东西