1. 程式人生 > >實現fullnat模式的環境構造——編譯核心

實現fullnat模式的環境構造——編譯核心

#########實現FULLNAT模式##########

1.核心編譯 (FULLNAT模式要重編LVS機器核心)
[root@server4 ~]# free -m            ##檢視下本機空間,儘量給到至少2G ,因為編譯核心是會讀大量檔案,同時往硬盤裡寫入資訊,所以要有足夠的空間,否則編譯的速度會非常慢
             total       used       free     shared    buffers     cached
Mem:          1877        127       1749          0         13         35
-/+ buffers/cache:         78       1798
Swap:          991          0        991
需要準備的安裝包:
kernel-2.6.32-220.23.1.el6.src.rpm  asciidoc-8.4.5-4.1.el6.noarch.rpm  newt-devel-0.52.11-3.el6.x86_64.rpm  slang-devel-2.2.1-1.el6.x86_64.rpm Lvs-fullnat-synproxy.tar.gz

[root@server4 ~]# rpm -ivh kernel-2.6.32-220.23.1.el6.src.rpm         ##解壓rpm包
[root@server4 ~]# cd rpmbuild/
[root@server4 rpmbuild]# cd SPECS/
[root@server4 SPECS]# ls                        ##解壓成功後檢視下當前目錄必須有這個檔案
kernel.spec
[root@server4 SPECS]# yum install -y rpm-build                ##安裝這個命令後面編譯要用到
[root@server4 SPECS]# cd ..
[root@server4 rpmbuild]# ls
SOURCES  SPECS
[root@server4 rpmbuild]# cd SPECS/
[root@server4 SPECS]# rpmbuild -bp kernel.spec                 ##解開原始碼
error: Failed build dependencies:
    gcc >= 3.4.2 is needed by kernel-2.6.32-220.23.1.el6.x86_64
    redhat-rpm-config is needed by kernel-2.6.32-220.23.1.el6.x86_64
    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
    zlib-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
    python-devel is needed by 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 by kernel-2.6.32-220.23.1.el6.x86_64



[root@server4 SPECS]# yum  install redhat-rpm-config patchutils xmlto asciidoc elfutils-libelf-devel binutils-devel newt-devel python-devel perl-ExtUtils-Embed hmaccalc -y         ##根據提示安裝需要的包,解決依賴性
[root@server4 SPECS]# rpmbuild -bp kernel.spec error: Failed build dependencies:
    gcc >= 3.4.2 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
    newt-devel is needed by kernel-2.6.32-220.23.1.el6.x86_64
[root@server4 SPECS]# yum install -y gcc asciidoc newt-devel        ##根據提示安裝需要的包
[root@server4 SPECS]# rpmbuild -bp kernel.spec
error: Failed build dependencies:
    asciidoc 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  
[root@server4 ~]# yum install newt-devel-0.52.11-3.el6.x86_64.rpm asciidoc-8.4.5-4.1.el6.noarch.rpm  slang-devel-2.2.1-1.el6.x86_64.rpm  -y                    ##這三個包之間有依賴性
 
[root@server4 SPECS]# rpmbuild -bp kernel.spec                 ##
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.8TCaQ7
+ umask 022
+ cd /root/rpmbuild/BUILD
+ LANG=C
+ export LANG
+ unset DISPLAY
+ patch_command='patch -p1 -F1 -s'
+ '[' '!' -d kernel-2.6.32-220.23.1.el6/vanilla-2.6.32-220.23.1.el6/ ']'
+ rm -f pax_global_header
+ cd /root/rpmbuild/BUILD
+ rm -rf kernel-2.6.32-220.23.1.el6
+ /bin/mkdir -p kernel-2.6.32-220.23.1.el6
+ cd kernel-2.6.32-220.23.1.el6
+ /bin/tar -xf -
+ /usr/bin/bzip2 -dc /root/rpmbuild/SOURCES/linux-2.6.32-220.23.1.el6.tar.bz2

+ gpg --homedir . --batch --gen-key /root/rpmbuild/SOURCES/genkey
gpg: WARNING: unsafe permissions on homedir `.'
gpg: keyring `./secring.gpg' created

gpg: keyring `./pubring.gpg' created                    ##在這裡會停下,需要在開一個終端,產生隨機數才會繼續


[root@server4~]# yum provides */rngd                    ##yum provides用來查詢這個命令有哪個包提供
Loaded plugins: product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
HighAvailability/filelists_db                         |  38 kB     00:00     
LoadBalancer/filelists_db                             | 3.9 kB     00:00     
ResilientStorage/filelists_db                         |  39 kB     00:00     
ScalableFileSystem/filelists_db                       | 3.0 kB     00:00     
rhel-source/filelists_db                              | 3.8 MB     00:00     
rng-tools-2-13.el6_2.x86_64 : Random number generator related utilities
Repo        : rhel-source
Matched from:
Filename    : /etc/sysconfig/rngd
Filename    : /sbin/rngd
Filename    : /etc/rc.d/init.d/rngd

[root@server4 ~]# yum install -y rng-tools-2-13.el6_2.x86_64

[root@server4 ~]# rngd -r /dev/urandom                    ##用這個命令產生隨機數


[root@server4 ~]# tar zxf Lvs-fullnat-synproxy.tar.gz             ##
[root@server4 ~]# cd lvs-fullnat-synproxy/
[root@server4 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
[root@server4 lvs-fullnat-synproxy]# cp lvs-2.6.32-220.23.1.el6.patch
[root@server4 lvs-fullnat-synproxy]# cp lvs-2.6.32-220.23.1.el6.patch ~/rpmbuild/BUILD/kernel-2.6.32-220.23.1.el6/linux-2.6.32-220.23.1.el6.x86_64/
[root@server4 lvs-fullnat-synproxy]# cd ~/rpmbuild/BUILD/kernel-2.6.32-220.23.1.el6/linux-2.6.32-220.23.1.el6.x86_64/
[root@server4 linux-2.6.32-220.23.1.el6.x86_64]# patch -p1 < lvs-2.6.32-220.23.1.el6.patch ##打補丁
[root@server4 linux-2.6.32-220.23.1.el6.x86_64]# vim Makefile        ##擴充套件版本,寫入你需要編譯的版本
  4 EXTRAVERSION = -220.23.1.el6

[root@server4 linux-2.6.32-220.23.1.el6.x86_64]# make            ##編譯
[root@server4 linux-2.6.32-220.23.1.el6.x86_64]# make modules_install    ##匯入安裝模組

[[email protected]_64]# make install        ##安裝的是引導檔案,在/boot目錄下就有你所編譯的核心檔案vmlinuz-2.6.32-220.23.1.el6



[root@server4 ~]# vim /boot/grub/grub.conf         
##修改核心啟動引數,因為你所編好的核心檔案就加在原有版本的上面,因此default的要改成0,開機時才會進入你所編譯的核心版本
default=0                                ##改成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 rhgb quiet
        initrd /initramfs-2.6.32-220.23.1.el6.img
title Red Hat Enterprise Linux (2.6.32-431.el6.x86_64)            ##原有的系統核心版本####
        root (hd0,0)
        kernel /vmlinuz-2.6.32-431.el6.x86_64 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 rhgb quiet
        initrd /initramfs-2.6.32-431.el6.x86_64.img
[root@server4 ~]# uname -r                        ##重啟後就是編譯的版本
2.6.32-220.23.1.el6

編譯核心重啟之後,開始安裝LVS TOOLS(編譯完核心先重啟機器載入新的核心,否則下面模組無法安裝)

2.編譯keepalived

[root@server4 ~]# cd lvs-fullnat-synproxy/
[root@server4 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
[root@server4 lvs-fullnat-synproxy]# tar zxf lvs-tools.tar.gz
[root@server4 lvs-fullnat-synproxy]# cd tools/
[root@server4 tools]# ls
ipvsadm  keepalived  quagga  rpm
[root@server4 tools]# cd /lib/modules/
[root@server4 modules]# ls
2.6.32-220.23.1.el6  2.6.32-431.el6.x86_64
[root@server1 ~]# cd lvs-fullnat-synproxy/tools/keepalived/
[root@server1 keepalived]# ls
AUTHOR     configure     doc         keepalived          README
bin        configure.in  genhash     keepalived.spec.in  TODO
build      CONTRIBUTORS  INSTALL     lib                 VERSION
ChangeLog  COPYING       install-sh  Makefile.in
[root@server1 keepalived]# yum install -y popt-devel openssl-devel
[root@server1 keepalived]# ./configure  --with-kernel-dir="/lib/modules/`uname -r`/build"

[root@server1 keepalived]# make && make install


[root@server4 ipvsadm]# which ipvsadm
/sbin/ipvsadm

3.編譯ipvsadm
[root@server1 ~]# cd lvs-fullnat-synproxy/tools/ipvsadm/
[root@server1 ipvsadm]# make

[root@server1 ipvsadm]# make install


[root@server1 ipvsadm]# /etc/init.d/ipvsadm status
[root@server4 ipvsadm]# ipvsadm -l
IP Virtual Server version 1.2.1 (size=4194304)    
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn


  --ipip         -i                   ipip encapsulation (tunneling)
  --fullnat      -b                   fullnat mode
  --masquerading -m                   masquerading (NAT)

fullnat環境配置完成