编译内核
关掉其他虚拟机,然后给本虚拟机分配2g内存,可以更大,如果有的话
磁盘可用空间必须大于10g
参考网站http://kb.linuxvirtualserver.org/wiki/IPVS_FULLNAT_and_SYNPROXY
[root@server1 ~]# df -H
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 20G 1.3G 18G 7% /
tmpfs 985M 0 985M 0% /dev/shm
/dev/vda1 508M 35M 448M 8% /boot
[root@server1 ~]# ls
anaconda-ks.cfg install.log.syslog keepalived-2.0.6.tar.gz
install.log keepalived-2.0.6
[root@server1 ~]# rm -rf *
[root@server1 ~]# pwd
/root
本次实验所需的非yum源自带安装包如下
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
[root@server1 ~]# ls
kernel-2.6.32-220.23.1.el6.src.rpm Lvs-fullnat-synproxy.tar.gz
安装 创建rpm的二进制软件包和源码软件包
[root@server1 ~]# yum install -y rpm-build
[root@server1 ~]# ls
kernel-2.6.32-220.23.1.el6.src.rpm Lvs-fullnat-synproxy.tar.gz
安装内核编译软件
[root@server1 ~]# rpm -ivh kernel-2.6.32-220.23.1.el6.src.rpm
[root@server1 ~]# ls
kernel-2.6.32-220.23.1.el6.src.rpm Lvs-fullnat-synproxy.tar.gz rpmbuild
[root@server1 ~]# cd rpmbuild/
[root@server1 rpmbuild]# ls
SOURCES SPECS
[root@server1 rpmbuild]# cd SOURCES/
[root@server1 SOURCES]# ls
略
[root@server1 SOURCES]# cd ..
[root@server1 rpmbuild]# cd SPECS/
[root@server1 SPECS]# ls
kernel.spec
[root@server1 SPECS]# rpmbuild -bp kernel.spec # ##需要的环境挺多,一个个安装
error: Failed build dependencies:
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
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@server1 SPECS]# yum install -y redhat-rpm-config patchutils xmlto asciidoc elfutils-libelf-devel binutils-devel newt-devel python-devel hmaccalc perl-ExtUtils-Embed
Loaded plugins: product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Install Process
No package asciidoc available.
No package newt-devel available.
[root@server1 SPECS]# cd
[root@server1 ~]# ls
asciidoc-8.4.5-4.1.el6.noarch.rpm rpmbuild
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
[root@server1 ~]# yum install -y slang-devel-2.2.1-1.el6.x86_64.rpm newt-devel-0.52.11-3.el6.x86_64.rpm
[root@server1 ~]# cd rpmbuild/
[root@server1 rpmbuild]# cd SPECS/
[root@server1 SPECS]# ls
kernel.spec
[root@server1 SPECS]# rpmbuild -bp kernel.spec
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.pICiub
+ umask 022
此时等待时间过长,需要在开一个终端,产生随机数才会继续
[kiosk@foundation53 ~]$ ssh root@172.25.53.1
root@172.25.53.1's password:
Last login: Tue Jul 31 10:24:10 2018 from 172.25.53.250
[root@server1 ~]# yum provides */rngd
Loaded plugins: product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
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@server1 ~]# yum install rng-tools-2-13.el6_2.x86_64 -y
[root@server1 ~]# rngd -r /dev/urandom
执行完成
[root@server1 SPECS]# cd
[root@server1 ~]# 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 rpmbuild
Lvs-fullnat-synproxy.tar.gz slang-devel-2.2.1-1.el6.x86_64.rpm
[root@server1 ~]# tar zxf Lvs-fullnat-synproxy.tar.gz
[root@server1 ~]# 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 rpmbuild
lvs-fullnat-synproxy slang-devel-2.2.1-1.el6.x86_64.rpm
Lvs-fullnat-synproxy.tar.gz
[root@server1 ~]# cd lvs-fullnat-synproxy/
[root@server1 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@server1 lvs-fullnat-synproxy]# uname -r 此版本可添加到makefile中
2.6.32-431.el6.x86_64
[root@server1 ~]# cd rpmbuild/
[root@server1 rpmbuild]# ls
BUILD BUILDROOT RPMS SOURCES SPECS SRPMS
[root@server1 rpmbuild]# cd BUILD
[root@server1 BUILD]# ls
kernel-2.6.32-220.23.1.el6
[root@server1 BUILD]# cd kernel-2.6.32-220.23.1.el6/
[root@server1 kernel-2.6.32-220.23.1.el6]# ls
linux-2.6.32-220.23.1.el6.x86_64 vanilla-2.6.32-220.23.1.el6
[root@server1 kernel-2.6.32-220.23.1.el6]# cd linux-2.6.32-220.23.1.el6.x86_64/
[root@server1 linux-2.6.32-220.23.1.el6.x86_64]# ls
arch config-s390x-kdump kernel.pub~
block config-s390x-kdump-rhel kernel.sec
check-kabi config-s390x-rhel lib
config-debug config-x86_64-debug MAINTAINERS
config-debug-rhel config-x86_64-debug-rhel Makefile
config-framepointer config-x86_64-generic Makefile.common
config-generic config-x86_64-generic-rhel merge.pl
config-generic-rhel config-x86_64-nodebug mm
config-i686 config-x86_64-nodebug-rhel net
config-i686-debug config-x86-generic perf
config-i686-debug-rhel config-x86-generic-rhel pubring.gpg
config-i686-nodebug COPYING random_seed
config-i686-nodebug-rhel CREDITS README
config-i686-rhel crypto REPORTING-BUGS
config-ia64-generic-rhel Documentation samples
config-nodebug drivers scripts
config-nodebug-rhel extract.pub secring.gpg
config-powerpc64 extrakeys.pub security
config-powerpc64-kdump firmware sound
config-powerpc64-rhel fs temp-i686-debug-final
config-powerpc-generic include temp-i686-final
config-powerpc-generic-rhel init tools
configs ipc trustdb.gpg
config-s390x kabitool usr
config-s390x-debug Kbuild virt
config-s390x-debug-rhel kernel
config-s390x-generic-rhel kernel.pub
[root@server1 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@server1 linux-2.6.32-220.23.1.el6.x86_64]# find / -name lvs-2.6*
/root/lvs-fullnat-synproxy/lvs-2.6.32-220.23.1.el6.patch
[root@server1 linux-2.6.32-220.23.1.el6.x86_64]# cp /root/lvs-fullnat-synproxy/lvs-2.6.32-220.23.1.el6.patch .
[root@server1 linux-2.6.32-220.23.1.el6.x86_64]# ll lvs-2.6.32-220.23.1.el6.patch
-rw-r--r-- 1 root root 475082 Jul 31 11:03 lvs-2.6.32-220.23.1.el6.patch
[root@server1 linux-2.6.32-220.23.1.el6.x86_64]# patch -p1 < lvs-2.6.32-220.23.1.el6.patch
patching file .config
patching file net/netfilter/ipvs/Kconfig
patching file net/netfilter/ipvs/Makefile
[root@server1 linux-2.6.32-220.23.1.el6.x86_64]# vim Makefile
将2.6.32-431.el6.x86_64添加扩展版本,写入你需要编译的版本
[root@server1 linux-2.6.32-220.23.1.el6.x86_64]# make ##编译
[root@server1 linux-2.6.32-220.23.1.el6.x86_64]# make modules_install ##导入安装模块
[root@server1 linux-2.6.32-220.23.1.el6.x86_64]# make install ##安装的是引导文件,在/boot目录下就有你所编译的内核文件
sh /root/rpmbuild/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.el6.x86_64 arch/x86/boot/bzImage \
System.map "/boot"
[root@server1 linux-2.6.32-220.23.1.el6.x86_64]# cd /boot/
[root@server1 boot]# ls
config-2.6.32-431.el6.x86_64 System.map
efi System.map-2.6.32-431.el6.x86_64
grub System.map-2.6.32-431.el6.x86_64.old
initramfs-2.6.32-431.el6.x86_64.img vmlinuz
lost+found vmlinuz-2.6.32-431.el6.x86_64
symvers-2.6.32-431.el6.x86_64.gz vmlinuz-2.6.32-431.el6.x86_64.old
[root@server1 boot]# cd grub/
[root@server1 grub]# ls
device.map grub.conf minix_stage1_5 stage2
e2fs_stage1_5 iso9660_stage1_5 reiserfs_stage1_5 ufs2_stage1_5
fat_stage1_5 jfs_stage1_5 splash.xpm.gz vstafs_stage1_5
ffs_stage1_5 menu.lst stage1 xfs_stage1_5
[root@server1 grub]# vim grub.conf
##修改内核启动参数,因为你所编好的内核文件就加在原有版本的上面,因此default的要改成0,开机时才会进入你所编译的内核版本
default=0 ##改成0才会在进入系统时访问你所编译的版本
[root@server1 grub]# cat grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/mapper/VolGroup-lv_root
# initrd /initrd-[generic-]version.img
#boot=/dev/vda
default=0
[root@server1 grub]# reboot
[kiosk@foundation53 ~]$ ssh root@172.25.53.1root@172.25.53.1's password:
Last login: Tue Jul 31 10:56:12 2018 from 172.25.53.250
[root@server1 ~]#
[root@server1 ~]# ipvsadm -l
Size改变,内核编译成功
IP Virtual Server version 1.2.1 (size=4194304)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 172.25.53.100:http rr
-> localhost:http Local 1 0 0
[root@server1 ~]# uname -r
2.6.32-431.el6.x86_64
[root@server1 ~]# rpm -q ipvsadm
ipvsadm-1.26-2.el6.x86_64
卸载ipvsadm
[root@server1 ~]# yum remove ipvsadm
Removed:
ipvsadm.x86_64 0:1.26-2.el6
Dependency Removed:
ldirectord.x86_64 0:3.9.5-3.1
Complete!
[root@server1 ~]# uname -r
2.6.32-431.el6.x86_64
[root@server1 ~]# 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 rpmbuild
lvs-fullnat-synproxy slang-devel-2.2.1-1.el6.x86_64.rpm
Lvs-fullnat-synproxy.tar.gz
[root@server1 ~]# cd lvs-fullnat-synproxy/
[root@server1 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
编译内核重启之后,开始安装LVS TOOLS(编译完内核先重启机器加载新的内核,否则下面模块无法安装)
[root@server1 lvs-fullnat-synproxy]# tar zxf lvs-tools.tar.gz
[root@server1 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
[root@server1 lvs-fullnat-synproxy]# cd tools/
[root@server1 tools]# ls
ipvsadm keepalived quagga rpm
[root@server1 tools]# cd 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]# uname -r
2.6.32-431.el6.x86_64
[root@server1 keepalived]# cd /lib/modules/
[root@server1 modules]# ls
2.6.32-431.el6.x86_64
[root@server1 modules]# cd 2.6.32-431.el6.x86_64/
[root@server1 2.6.32-431.el6.x86_64]# ls
build modules.dep modules.networking modules.usbmap
extra modules.dep.bin modules.ofmap source
kernel modules.drm modules.order updates
modules.alias modules.ieee1394map modules.pcimap vdso
modules.alias.bin modules.inputmap modules.seriomap weak-updates
modules.block modules.isapnpmap modules.symbols
modules.ccwmap modules.modesetting modules.symbols.bin
[root@server1 2.6.32-431.el6.x86_64]# ll
total 3184
lrwxrwxrwx 1 root root 80 Jul 31 12:00 build -> /root/rpmbuild/BUILD/kernel-2.6.32-220.23.1.el6/linux-2.6.32-220.23.1.el6.x86_64
drwxr-xr-x. 2 root root 4096 Nov 11 2013 extra
drwxr-xr-x 12 root root 4096 Jul 31 12:01 kernel
-rw-r--r-- 1 root root 529526 Jul 31 12:03 modules.alias
-rw-r--r-- 1 root root 509216 Jul 31 12:03 modules.alias.bin
-rw-r--r--. 1 root root 1413 Nov 11 2013 modules.block
-rw-r--r-- 1 root root 69 Jul 31 12:03 modules.ccwmap
-rw-r--r-- 1 root root 192080 Jul 31 12:03 modules.dep
-rw-r--r-- 1 root root 280986 Jul 31 12:03 modules.dep.bin
-rw-r--r--. 1 root root 68 Nov 11 2013 modules.drm
-rw-r--r-- 1 root root 665 Jul 31 12:03 modules.ieee1394map
-rw-r--r-- 1 root root 141 Jul 31 12:03 modules.inputmap
-rw-r--r-- 1 root root 1236 Jul 31 12:03 modules.isapnpmap
-rw-r--r--. 1 root root 29 Nov 11 2013 modules.modesetting
-rw-r--r--. 1 root root 1956 Nov 11 2013 modules.networking
-rw-r--r-- 1 root root 74 Jul 31 12:03 modules.ofmap
-rw-r--r--. 1 root root 73619 Jul 31 12:00 modules.order
-rw-r--r-- 1 root root 375656 Jul 31 12:03 modules.pcimap
-rw-r--r-- 1 root root 715 Jul 31 12:03 modules.seriomap
-rw-r--r-- 1 root root 193747 Jul 31 12:03 modules.symbols
-rw-r--r-- 1 root root 247912 Jul 31 12:03 modules.symbols.bin
-rw-r--r-- 1 root root 773964 Jul 31 12:03 modules.usbmap
lrwxrwxrwx 1 root root 80 Jul 31 12:00 source -> /root/rpmbuild/BUILD/kernel-2.6.32-220.23.1.el6/linux-2.6.32-220.23.1.el6.x86_64
drwxr-xr-x. 2 root root 4096 Nov 11 2013 updates
drwxr-xr-x. 2 root root 4096 Jul 27 17:22 vdso
drwxr-xr-x. 2 root root 4096 Nov 11 2013 weak-updates
[root@server1 2.6.32-431.el6.x86_64]# cd
[root@server1 ~]# cd lvs-fullnat-synproxy/
[root@server1 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
[root@server1 lvs-fullnat-synproxy]# cd tools/
[root@server1 tools]# ls
ipvsadm keepalived quagga rpm
[root@server1 tools]# cd 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]# ./configure --with-kernel-dir="/lib/modules/`uname -r`/build"
configure: error: Popt libraries is required
[root@server1 keepalived]# yum install -y popt-devel
Installed:
popt-devel.x86_64 0:1.13-7.el6
Complete!
[root@server1 keepalived]# ./configure --with-kernel-dir="/lib/modules/`uname -r`/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@server1 keepalived]# make
[root@server1 keepalived]# make install
编译ipvsadm
[root@server1 keepalived]# cd /home/pukong/tools/ipvsadm
-bash: cd: /home/pukong/tools/ipvsadm: No such file or directory
[root@server1 keepalived]# cd /usr/local/
[root@server1 local]# ls
bin etc games include keepalived lib lib64 libexec sbin share src
[root@server1 local]# cd etc/
[root@server1 etc]# ls
keepalived rc.d sysconfig
[root@server1 etc]# cd ..
[root@server1 local]# pwd
/usr/local
[root@server1 local]# ls
bin etc games include keepalived lib lib64 libexec sbin share src
[root@server1 local]# cd bin/
[root@server1 bin]# ls
genhash
[root@server1 bin]# cd ..
[root@server1 local]# cd sbin/
[root@server1 sbin]# ls
keepalived
[root@server1 sbin]# pwd
/usr/local/sbin
[root@server1 sbin]# cd
[root@server1 ~]# cd lvs-fullnat-synproxy/
[root@server1 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
[root@server1 lvs-fullnat-synproxy]# cd tools/
[root@server1 tools]# ls
ipvsadm keepalived quagga rpm
[root@server1 tools]# cd ipvsadm/
[root@server1 ipvsadm]# ls
config_stream.c dynamic_array.h ipvsadm-save PERSISTENCE_ENGINES
config_stream.h ipvsadm.8 ipvsadm-save.8 README
contrib ipvsadm.c ipvsadm.sh SCHEDULERS
debian ipvsadm-restore ipvsadm.spec.in VERSION
dynamic_array.c ipvsadm-restore.8 Makefile
[root@server1 ipvsadm]# make
[root@server1 ipvsadm]# make install
[root@server1 ipvsadm]# cd
[root@server1 ~]# ipvsadm -l
IP Virtual Server version 1.2.1 (size=4194304)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 172.25.53.100:http rr
-> localhost:http Local 1 0 0
[root@server1 ~]# which ipvsadm
/sbin/ipvsadm
fullnat环境配置完成