爲了定位keepalived VIP的問題, 一步一步定位到IPVS, IPVS默認是沒有打開Debug模式的, 若須要打開Debug模式須要從新編譯IPVS模塊加載後才行, 最好的方式固然是僅僅編譯IPVS模塊就行, 可是實踐過程當中發現單獨編譯IPVS模塊存在諸多問題, 暫且先放一放, 後續再整理整理單獨編譯IPVS模塊的文章.html
先查看本地主機內核版本, 這一步主要是爲了防止應用切換內核版本後不兼容, 故編譯的內核儘可能確保跟本來內核版本一致linux
[root@10-10-88-195 ~]# uname -a Linux 10-10-88-195 3.10.0-693.el7.x86_64 #1 SMP Thu Jul 6 19:56:57 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux [root@10-10-88-195 ~]#
[root@10-10-88-195 ~]# cat /etc/redhat-release Red Hat Enterprise Linux Server release 7.4 (Maipo)
注: 從redhat上面下載須要註冊帳號git
最官方的方式固然是從kernel.org上面去下載, 可是找了一圈發現kernel.org上面沒有3.10.0版本的內核, 好在redhat上面有找到版本一致的內核docker
* 進入[redhat](https://access.redhat.com/downloads/content/rhel---7/x86_64/2456/kernel/3.10.0-693.el7/x86_64/fd431d51/package) 選擇693版本
* 下載Source Package
* 將rpm包下載到`~/root/`目錄下
[root@10-10-88-195 ~]# ls -lh total 89M -rw-------. 1 root root 1.6K Jun 13 11:48 anaconda-ks.cfg -rw-r--r-- 1 root root 89M Jul 13 2017 kernel-3.10.0-693.el7.src.rpm [root@10-10-88-195 ~]#
經過 rpm -ivh
安裝, 可能會有warning, 可忽略app
[root@10-10-88-195 kernels]# rpm -ivh kernel-3.10.0-693.el7.src.rpm warning: kernel-3.10.0-693.el7.src.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Updating / installing... 1:kernel-3.10.0-693.el7 ################################# [100%]
安裝完成以後默認會在~/root目錄下生成一個rpmbuild文件夾工具
[root@10-10-88-195 ~]# ls -lh total 89M -rw-------. 1 root root 1.6K Jun 13 11:48 anaconda-ks.cfg -rw-r--r-- 1 root root 89M Jul 13 2017 kernel-3.10.0-693.el7.src.rpm drwxr-xr-x 4 root root 34 Sep 26 17:37 rpmbuild [root@10-10-88-195 ~]#
進入到/root/rpmbuild/SOURCES
目錄能夠看到linux-3.10.0-693.el7.tar.xz
, 解壓到當前目錄下測試
[root@10-10-88-195 SOURCES]# tar -xvf linux-3.10.0-693.el7.tar.xz
[root@10-10-40-97 linux-3.10.0-693.el7]# yum groupinstall -y "Development Tools"
bcui
千萬千萬不要漏掉了bc這個小工具, 就由於漏掉了bc, make的時候沒有報錯, 可是就是編譯不出來vmlinux線程
[root@10-10-40-98 linux-3.10.0-693.el7]# yum install -y bc
[root@10-10-88-195 linux-3.10.0-693.el7]# yum install -y elfutils-libelf-devel
[root@10-10-88-195 linux-3.10.0-693.el7]# yum install ncurses-devel -y
進入到解壓後的目錄
/root/rpmbuild/SOURCES/linux-3.10.0-693.el7
debug
[root@10-10-88-195 linux-3.10.0-693.el7]# make menuconfig
進入 Networking support > Networking options > Network packet filtering framework (Netfilter) > IP virtual server support
選中IP virtual server debugging, 按y勾選打開IPVS的Debug支持
對於內核編譯的配置到這一步就夠了, 可是爲了方便校驗或者區別本身編譯的內核, 最好給本身的編譯的內核打上一個本地的版本號
進入 General setup ->
選中 Local version - append to kernel release, 按enter進入
好比添加一個icebug的本地版本號
保存退出便可
接下來就是編譯內核了, 爲了編譯可以快一些, 能夠選擇多開幾個線程進行編譯
[root@10-10-88-195 linux-3.10.0-693.el7]# grep -c processor /proc/cpuinfo 8 [root@10-10-88-195 linux-3.10.0-693.el7]#
[root@10-10-88-195 linux-3.10.0-693.el7]# make -j16
能夠看到系統負載已經佔滿了
接下來就是等待....
[root@10-10-88-195 linux-3.10.0-693.el7]# make modules_install
[root@10-10-88-195 linux-3.10.0-693.el7]# make install sh ./arch/x86/boot/install.sh 3.10.0-icebug arch/x86/boot/bzImage \ System.map "/boot" [root@10-10-88-195 linux-3.10.0-693.el7]#
通常到這一步內核的編譯安裝就能夠結束來, 經過VNC選擇要啓動的內核便可
因爲測試機器是跑在一臺物理機上的虛擬機, 這裏經過virsh vncdisplay查看虛擬機的VNC鏈接, 前提是已經安裝VNC server
continue
登錄並reboot
按ESC進入到啓動菜單選擇
選擇本身編譯的內核
進入經過運行uname -a
發現已是新內核了
設置IPVS debug level, 先確保ip_vs模塊已經被加載了, 沒加載的話是沒有/proc/sys/net/ipv4/vs
這個目錄的
加載ip_vs模塊, 能夠直接經過modprobe, 也能夠直接經過運行ipvsadm加載, 經過lsmod能夠發現ip_vs模塊已經被加載了
[root@10-10-88-195 linux-3.10.0-693.el7]# modprobe ip_vs [root@10-10-88-195 linux-3.10.0-693.el7]# lsmod | grep ip_vs ip_vs 181385 0 nf_conntrack 133387 6 ip_vs,nf_nat,nf_nat_ipv4,xt_conntrack,nf_nat_masquerade_ipv4,nf_conntrack_ipv4 libcrc32c 12644 4 xfs,ip_vs,nf_nat,nf_conntrack [root@10-10-88-195 linux-3.10.0-693.el7]#
能夠看到已經有/proc/sys/net/ipv4/vs
這個目錄了, 咱們須要修改的是/proc/sys/net/ipv4/vs/debug_level
默認debug level爲0
[root@10-10-88-195 linux-3.10.0-693.el7]# cat /proc/sys/net/ipv4/vs/debug_level 0 [root@10-10-88-195 linux-3.10.0-693.el7]#
能夠設置的debug level範圍爲[0-12], 通常設置debug level爲8就差很少了, 再往上的話會把具體每一個鏈接的信息都打印出來
[root@10-10-88-195 linux-3.10.0-693.el7]# echo 8 > /proc/sys/net/ipv4/vs/debug_level [root@10-10-88-195 linux-3.10.0-693.el7]# cat /proc/sys/net/ipv4/vs/debug_level 8 [root@10-10-88-195 linux-3.10.0-693.el7]#
再經過sysctl驗證設置是否生效, 能夠看到net.ipv4.vs.debug_level已經被設置爲8了
[root@10-10-88-195 linux-3.10.0-693.el7]# sysctl -a | grep debug_level sysctl: reading key "net.ipv6.conf.all.stable_secret" sysctl: reading key "net.ipv6.conf.default.stable_secret" sysctl: reading key "net.ipv6.conf.docker0.stable_secret" sysctl: reading key "net.ipv6.conf.eth0.stable_secret" sysctl: reading key "net.ipv6.conf.eth1.stable_secret" sysctl: reading key "net.ipv6.conf.lo.stable_secret" net.ipv4.vs.debug_level = 8 [root@10-10-88-195 linux-3.10.0-693.el7]#
經過dmesg查看內核輸出信息(IPVS日誌)
dmesg具體參數用法能夠經過dmesg -h查看, 示例爲 -H (human readable) -e (show local time and time delta in readable format) -w (follow / wait for new message)
[root@10-10-88-195 linux-3.10.0-693.el7]# dmesg -Hew
啓動keepalived測試一下
[root@10-10-88-195 linux-3.10.0-693.el7]# systemctl start keepalived [root@10-10-88-195 linux-3.10.0-693.el7]#
能夠看到debug信息已經多了很多
https://www.linux.com/learn/intro-to-linux/2018/4/how-compile-linux-kernel-0
http://kozlex.blogspot.com/2015/05/build-redhat-7-custom-kernel.html