LVS-Fullnat之编译内核 将fullnat模块添加到内核

主机环境   redhat6.5 64位

实验环境   ip 172.25.29.6

安装包     asciidoc-8.4.5-4.1.el6.noarch.rpm   

           Lvs-fullnat-synproxy.tar.gz

           kernel-2.6.32-220.23.1.el6.src.rpm  

           newt-devel-0.52.11-3.el6.x86_64.rpm              

           slang-devel-2.2.1-1.el6.x86_64.rpm

防火墙状态:关闭

重新编译内核之前,要保证根分区要有20G的内存。

如果没有足够的空间就添加一块20G的虚拟磁盘

1.给根分区分用lvm分20G的空间(如果有足够的空间,就不用做拉伸了)

[[email protected] ~]# fdisk -l                      #查看分区

Disk /dev/vdc: 21.5 GB, 21474836480 bytes       #新添加的磁盘

16 heads, 63 sectors/track, 41610 cylinders

Units = cylinders of 1008 * 512 = 516096 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

[[email protected] ~]# pvcreate /dev/vdc              #用pv分成物理块

Physical volume"/dev/vdc" successfully created

[[email protected] ~]# pvs                            #查看,pv成功

PV         VG       Fmt Attr PSize  PFree

/dev/vda2  VolGroup lvm2 a--   8.51g    0

/dev/vdc            lvm2 a--  20.00g 20.00g

[[email protected] ~]# vgs                            #查看

VG       #PV #LV #SN Attr   VSize VFree

VolGroup   1  2   0 wz--n- 8.51g    0

[[email protected] ~]# vgextend VolGroup /dev/vdc      #扩展VolGroup组

Volume group"VolGroup" successfully extended

[[email protected] ~]# vgs                             #查看

VG       #PV #LV #SN Attr   VSize VFree

VolGroup   2  2   0 wz--n- 28.50g 20.00g

[[email protected] ~]# lvextend -L 20G /dev/VolGroup/lv_root  #扩展lv

Extending logicalvolume lv_root to 20.00 GiB

Logical volume lv_rootsuccessfully resized

[[email protected] ~]# df -lh                           #查看,根分区7.5G

Filesystem                   Size  Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root 7.5G  1.5G  5.7G 21% /

tmpfs                        499M     0  499M  0% /dev/shm

/dev/vda1                    485M   55M  405M 12% /boot

[[email protected] ~]# resize2fs /dev/VolGroup/lv_root   #扩展文件系统

resize2fs 1.41.12 (17-May-2010)

Filesystem at /dev/VolGroup/lv_root is mounted on /; on-lineresizing required

old desc_blocks = 1, new_desc_blocks = 2

Performing an on-line resize of /dev/VolGroup/lv_root to5242880 (4k) blocks.

The filesystem on /dev/VolGroup/lv_root is now 5242880 blockslong.

[[email protected] ~]# df -lh                            #查看,根分区20G

Filesystem                   Size  Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root  20G  1.5G   18G  8% /

tmpfs                        499M     0  499M  0% /dev/shm

/dev/vda1                    485M   55M  405M 12% /boot

2. 重新编译内核,将fallnat模块添加到在内核及测试

 A)重新编译内核

[[email protected] mnt]# ls

asciidoc-8.4.5-4.1.el6.noarch.rpm   Lvs-fullnat-synproxy.tar.gz

kernel-2.6.32-220.23.1.el6.src.rpm  newt-devel-0.52.11-3.el6.x86_64.rpm

lvs-fullnat-synproxy               slang-devel-2.2.1-1.el6.x86_64.rpm

[[email protected] mnt]# rpm -vih kernel-2.6.32-220.23.1.el6.src.rpm    #安装内核包

[[email protected] mnt]# yum install rpm-build -y             #安装rpmbuild

[[email protected] mnt]# cd ~/rpmbuild/

[[email protected] rpmbuild]# ls

BUILD  BUILDROOT  RPMS SOURCES  SPECS  SRPMS

[[email protected] rpmbuild]# cd SPECS/

[[email protected] SPECS]# ls

kernel.spec

[[email protected] SPECS]# rpmbuild -bp kernel.spec          #生成内核源码

error: Failed build dependencies:

redhat-rpm-config isneeded by kernel-2.6.32-220.23.1.el6.x86_64

patchutils is neededby kernel-2.6.32-220.23.1.el6.x86_64

xmlto is needed bykernel-2.6.32-220.23.1.el6.x86_64

asciidoc is needed bykernel-2.6.32-220.23.1.el6.x86_64

elfutils-libelf-develis needed by kernel-2.6.32-220.23.1.el6.x86_64

binutils-devel isneeded by kernel-2.6.32-220.23.1.el6.x86_64

newt-devel is neededby kernel-2.6.32-220.23.1.el6.x86_64

python-devel is neededby kernel-2.6.32-220.23.1.el6.x86_64

perl(ExtUtils::Embed)is needed by kernel-2.6.32-220.23.1.el6.x86_64

hmaccalc is needed bykernel-2.6.32-220.23.1.el6.x86_64

[[email protected] SPECS]# yum install redhat-rpm-config patchutilsxmlto elfutils-libelf-devel binutils-devel python-devel hmaccalcperl-ExtUtils-Embed -y     #安装所缺少的包

[[email protected] SPECS]# cd /mnt/

[[email protected] mnt]# rpm -vihnewt-devel-0.52.11-3.el6.x86_64.rpm                                                                                  #安装编译内核时所需要的包

slang-devel-2.2.1-1.el6.x86_64.rpmasciidoc-8.4.5-4.1.el6.noarch.rpm

warning: newt-devel-0.52.11-3.el6.x86_64.rpm: Header V3 RSA/SHA1Signature, key ID c105b9de: NOKEY

Preparing...               ########################################### [100%]

1:slang-devel           ########################################### [ 33%]

2:newt-devel             ###########################################[ 67%]

3:asciidoc              ########################################### [100%]

[[email protected] mnt]#cd -

[[email protected] SPECS]# rpmbuild -bp kernel.spec

如果出现这种情况

则需:

[[email protected] ~]# yum provides */rngd      #上面的图片提示,输入rngd -r /dev/urandom,查找命令所在的安装包

Loaded plugins: product-id, subscription-manager

This system is not registered to Red Hat SubscriptionManagement. You can use subscription-manager to register.

rng-tools-2-13.el6_2.x86_64 : Random number generator relatedutilities

Repo        : rhel6.5

Matched from:

Filename    :/etc/sysconfig/rngd

Filename    : /sbin/rngd

Filename    :/etc/rc.d/init.d/rngd

[[email protected] ~]# yum install rng-tools-2-13.el6_2.x86_64 -y     #安装

[[email protected] ~]# rngd -r /dev/urandom                           #输入命令

#查看,运行通过

[[email protected] SPECS]# cd /mnt/

[[email protected] mnt]# ls

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

[[email protected] mnt]# tar zxf Lvs-fullnat-synproxy.tar.gz      #解压

[[email protected] mnt]# ls

asciidoc-8.4.5-4.1.el6.noarch.rpm   Lvs-fullnat-synproxy.tar.gz

kernel-2.6.32-220.23.1.el6.src.rpm  newt-devel-0.52.11-3.el6.x86_64.rpm

lvs-fullnat-synproxy               slang-devel-2.2.1-1.el6.x86_64.rpm

[[email protected] mnt]# cd lvs-fullnat-synproxy/                 #进入解压之后的包

[[email protected] lvs-fullnat-synproxy]# ls                      #查看

lvs-2.6.32-220.23.1.el6.patch README

lvs-tools.tar.gz              toa-2.6.32-220.23.1.el6.patch

[[email protected] lvs-fullnat-synproxy]# cd~/rpmbuild/BUILD/kernel-2.6.32-220.23.1.el6/linux-2.6.32-220.23.1.el6.x86_64/

[[email protected] linux-2.6.32-220.23.1.el6.x86_64]# cp/mnt/lvs-fullnat-synproxy/lvs-2.6.32-220.23.1.el6.patch .                                  #将刚查看的包移动到当前

[[email protected] linux-2.6.32-220.23.1.el6.x86_64]# patch-p1<lvs-2.6.32-220.23.1.el6.patch                                           #打lvs的补丁

[[email protected] linux-2.6.32-220.23.1.el6.x86_64]# vimMakefile #进入,添加版本号,作为区别

4 EXTRAVERSION =-220.23.1.el6

[[email protected] linux-2.6.32-220.23.1.el6.x86_64]# make

[[email protected] linux-2.6.32-220.23.1.el6.x86_64]# makemodules_install   #安装内核模块

[[email protected] linux-2.6.32-220.23.1.el6.x86_64]# makeinstall  #安装

#在kernel一行中,添加“nohz=off ”(如果不关闭nohz,大压力下CPU0可能会消耗过高,压力不均匀)

[[email protected] linux-2.6.32-220.23.1.el6.x86_64]# vim/boot/grub/grub.conf  #进入引导文件

10 default=0

16         kernel /vmlinuz-2.6.32-220.23.1.el6 roroot=/dev/mapper/VolGroup-lv_    rootnomodeset rd_NO_LUKS.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_sw    ap SYSFONT=latarcyrheb-sun16crashkernel=auto rd_LVM_LV=VolGroup/lv_root KE    YBOARDTYPE=pc KEYTABLE=usrd_NO_DM nohz=off rhgb quiet

[[email protected] linux-2.6.32-220.23.1.el6.x86_64]# reboot      #重启

[[email protected] ~]# uname -r                                   #查看版本号,编译成功

2.6.32-220.23.1.el6

B)安装keepalived和ipvsadm

[[email protected] ~]# ipvsadm -l                               #查看

IP Virtual Server version 1.2.1 (size=4194304)

Prot LocalAddress:Port Scheduler Flags

->RemoteAddress:Port           ForwardWeight ActiveConn InActConn

[[email protected] ipvsadm]# ipvsadm --help | grep fullnat     #查看,fullnat模块并没有

[[email protected] ~]# yum remove ipvsadm -y                   #卸载,重新安装

[[email protected] ~]# cd /mnt/

[[email protected] mnt]# ls

asciidoc-8.4.5-4.1.el6.noarch.rpm   Lvs-fullnat-synproxy.tar.gz

newt-devel-0.52.11-3.el6.x86_64.rpm  lvs-fullnat-synproxy

kernel-2.6.32-220.23.1.el6.src.rpm  slang-devel-2.2.1-1.el6.x86_64.rpm

[[email protected] mnt]# cd lvs-fullnat-synproxy/

[[email protected]erver6 lvs-fullnat-synproxy]# ls

lvs-2.6.32-220.23.1.el6.patch README

lvs-tools.tar.gz              toa-2.6.32-220.23.1.el6.patch

[[email protected] lvs-fullnat-synproxy]# tar zxf lvs-tools.tar.gz  #解压

[[email protected] lvs-fullnat-synproxy]# ls

lvs-2.6.32-220.23.1.el6.patch README                        tools

lvs-tools.tar.gz              toa-2.6.32-220.23.1.el6.patch

[[email protected] lvs-fullnat-synproxy]# cd tools/

[[email protected] tools]# ls

ipvsadm  keepalived  quagga rpm

[[email protected] tools]# cd keepalived/                           #切换目录

[[email protected] keepalived]# ll -d /lib/modules/`uname -r`/build #查看

lrwxrwxrwx 1 root root 80 Oct 20 12:23/lib/modules/2.6.32-220.23.1.el6/build ->/root/rpmbuild/BUILD/kernel-2.6.32-220.23.1.el6/linux-2.6.32-220.23.1.el6.x86_64

[[email protected] keepalived]# ./configure--with-kernel-dir=/lib/modules/2.6.32-220.23.1.el6/build                                             #配置,生成Makfile

如有下面报错:

则需:

[[email protected] keepalived]# yum install -y openssl-devel

[[email protected] keepalived]# ./configure--with-kernel-dir=/lib/modules/2.6.32-220.23.1.el6/build                                             #重新配置

如下报错:

则需:

[[email protected] keepalived]# yum install popt-devel -y

[[email protected] keepalived]# ./configure --with-

kernel-dir=/lib/modules/2.6.32-220.23.1.el6/build              #重新配置

结果:

[[email protected] keepalived]# make                     #编译

[[email protected] keepalived]# make install             #安装

[[email protected] keepalived]# cd ..

[[email protected] tools]# cd ipvsadm/

[[email protected] ipvsadm]# make                        #编译

[[email protected] ipvsadm]# make install                #安装ipvsadm

C)测试

[[email protected] ipvsadm]# ipvsadm --help | grep fullnat  #查看,内核添加fullnat模块成功

--fullnat      -b                   fullnat mode

[[email protected] ipvsadm]# vim /boot/grub/grub.conf    #将引导文件里的default该回原来的数值

10 default=2

时间: 2024-11-04 15:50:19

LVS-Fullnat之编译内核 将fullnat模块添加到内核的相关文章

解析 Linux 内核可装载模块的版本检查机制

转自:http://www.ibm.com/developerworks/cn/linux/l-cn-kernelmodules/ 为保持 Linux 内核的稳定与可持续发展,内核在发展过程中引进了可装载模块这一特性.内核可装载模块就是可在内核运行时加载到内核的一组代码.通常 , 我们会在两个版本不同的内核上装载同一模块失败,即使是在两个相邻的补丁级(Patch Level)版本上.这是因为内核在引入可装载模块的同时,对模块采取了版本信息校验.这是一个与模块代码无关,却与内核相连的机制.该校验机

linux学习之路之模块管理和内核编译

我们知道linux内核再启动过程中,主要完成以下几种功能: 1.侦测硬件信息 2.驱动初始化(可能借助intrd文件加载硬件模块) 3.以只读方式挂载根文件系统 4.转载第一支程序init 如果我们的kernel识别不了某些硬件或者实现不了某些功能的话,那么只能将某些功能代码添加在内核当中,或者将这些功能代码做成模块的形式,kernel需要哪些模块就直接调用这些模块即可.通过这两种功能就可以实现相应的功能. 而不同的实现机制和kernel设计有关. kernel设计分为2种: 一种是单内核:这种

Linux编译模块小技巧-内核配置文件快速查询模块

# Linux编译模块小技巧-内核配置文件快速查询模块# 参考: https://www.linuxidc.com/Linux/2016-10/136157.htmFeb 09 00:49:17 ArchLinux mount[336]: modprobe: FATAL: Module fuse not found in directory /lib/modules/5.5.2Feb 09 00:49:17 ArchLinux mount[289]: fuse: device not found

第四十天:编译可加载模块

linux刚刚开始的时候仅仅支持intel 386 ,后来不断的被移植到越来越多的平台上,包括ARM ,POWERPC,所有的代码设备驱动代码都编译到内核中,这明显不现实,这时候就需要通过内核模块的形式来加载驱动.当然模块不一定是驱动,也可以是为驱动提供某种功能. 现在先编写一个简单的linux模块. 1 #include <linux/init.h> 2 #include <linux/module.h> 3 4 MODULE_LICENSE("GPL");

linux、内核源码、内核编译与配置、内核模块开发、内核启动流程(转)

linux是如何组成的?答:linux是由用户空间和内核空间组成的为什么要划分用户空间和内核空间?答:有关CPU体系结构,各处理器可以有多种模式,而LInux这样的划分是考虑到系统的安全性,比如X86可以有4种模式RING0~RING3  RING0特权模式给LINUX内核空间RING3给用户空间linux内核是如何组成的?答:linux内核由SCI(System Call Interface)系统调用接口.PM(Process Management)进程管理.MM(Memory Managem

在Ubuntu上为Android增加硬件抽象层(HAL)模块访问Linux内核驱动程序(老罗学习笔记3)

在Android硬件抽象层(HAL)概要介绍和学习计划一文中,我们简要介绍了在Android系统为为硬件编写驱动程序的方法.简单来说,硬件驱动程序一方面分布在Linux内核中,另一方面分布在用户空间的硬件抽象层中.接着,在Ubuntu上为Android系统编写Linux内核驱动程序一文中举例子说明 了如何在Linux内核编写驱动程序.在这一篇文章中,我们将继续介绍Android系统硬件驱动程序的另一方面实现,即如何在硬件抽象层中增加硬件模块来和内核驱动程序交互.在这篇文章中,我们还将学习到如何在

给已经编译安装了的nginx 添加http_ssl_module模块

环境:centos6.7 因为需要https ,要用到http_ssl_module模块,但http_ssl_module并不属于nginx的基本模块所以自己重新编译添加 1.首先看下内核和系统的版本号. [[email protected] ~]# uname -a Linux zabbix.nnkj.com 2.6.32-573.el6.x86_64 #1 SMP Thu Jul 23 15:44:03 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux [[em

单独编译apache的rewrite模块

 单独编译apache的rewrite模块 当我们编译安装好apache的时候,就像这样: ./configure \ --prefix=/usr/local/apache \   //安装的路径 --with-included-apr \        // 跨平台 --enable-so \                 //启用DSO --enable-deflate=shared \    //动态共享的方式编译deflate模块 --enable-expires=shared \  

linux内核hello world模块编写

#include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> int param = 0; /* 设备模块注册时执行的初始化函数 */ static int __init initialization_module(void) { printk("Hello world.\n"); printk("param = %d.\n", param)