新弄了一批機器,為了準備切換到萬兆環(huán)境烁巫,給機器配了雙千兆和雙萬兆混合的4接口網卡,然后就出了一點問題
centos 7 引入了網絡一致化命名規(guī)則,具體可以看紅帽的聯(lián)網指南
主要部分摘抄如下
------------引用專用分割線----------------------------
8.1.?命名方案層級結構
默認情況下风纠,systemd?會使用以下策略,采用支持的命名方案為接口命名:
方案 1:如果固件或 BIOS 信息適用且可用牢贸,則使用整合了為板載設備提供索引號的固件或 BIOS 的名稱(例如:eno1)竹观,否則請使用方案 2。
方案 2:如果固件或 BIOS 信息適用且可用潜索,則使用整合了為 PCI 快速熱插拔插槽提供索引號的固件或 BIOS 名稱(例如?ens1)臭增,否則請使用方案 3。
方案 3:如果硬件連接器物理位置信息可用竹习,則使用整合了該信息的名稱(例如:enp2s0)誊抛,否則請使用方案 5。
方案 4:?默認不使用整合接口 MAC 地址的名稱(例如:enx78e7d1ea46da)整陌,但用戶可選擇使用此方案拗窃。
方案 5:傳統(tǒng)的不可預測的內核命名方案瞎领,在其他方法均失敗后使用(例如:?eth0)。
這個策略(如上所述)是默認策略随夸。如果該系統(tǒng)已啟用?biosdevname九默,則會使用該方案。注:啟用?biosdevname?需要添加?biosdevname=1?作為命令行參數(Dell 系統(tǒng)除外)宾毒,此時只要安裝?biosdevname驼修,就會默認使用該方案。如果用戶已添加?udev?規(guī)則诈铛,該規(guī)則會更高內核設備名稱邪锌,則會優(yōu)先使用這些規(guī)則。
設備命名過程如下:
/usr/lib/udev/rules.d/60-net.rules?文件中的規(guī)則會讓?udev?幫助工具?/lib/udev/rename_device?查看所有?/etc/sysconfig/network-scripts/ifcfg-suffix?文件癌瘾。如果發(fā)現包含?HWADDR?條目的?ifcfg?文件與某個接口的 MAC 地址匹配觅丰,它會將該接口重命名為?ifcfg?文件中由?DEVICE?指令給出的名稱。
/usr/lib/udev/rules.d/71-biosdevname.rules?中的規(guī)則讓?biosdevname?根據其命名策略重命名該接口妨退,即在上一步中沒有重命名該接口妇萄、已安裝?biosdevname、且在 boot 命令行中將?biosdevname=0?作為內核命令給出咬荷。
/lib/udev/rules.d/75-net-description.rules?中的規(guī)則讓?udev?通過檢查網絡接口設備冠句,填寫內部?udev?設備屬性值 ID_NET_NAME_ONBOARD、ID_NET_NAME_SLOT幸乒、ID_NET_NAME_PATH懦底。注:有些設備屬性可能處于未定義狀態(tài)。
/usr/lib/udev/rules.d/80-net-name-slot.rules?中的規(guī)則讓?udev?重命名該接口罕扎,優(yōu)先順序如下:ID_NET_NAME_ONBOARD聚唐、ID_NET_NAME_SLOT、ID_NET_NAME_PATH腔召。并提供如下信息:沒有在步驟 1 或 2 中重命名該接口杆查,同時未給出內核參數?net.ifnames=0。如果一個參數未設定臀蛛,則會按列表的順序設定下一個亲桦。如果沒有設定任何參數,則不會重命名該接口浊仆。
-----------以上是紅帽的聯(lián)網指南-------
其實簡述上面的信息就是首先看內核參數是否啟用了biosdevname=1 (默認是啟用)客峭,如果bios提供了設備的名稱就使用bios提供的名稱
如果沒有,就根據網卡配置中 device=eth抡柿,em舔琅,xyz 的名字來命名這個網卡,但是如果這樣命名的話沙绝,必須在配置里寫死網卡的mac地址
作為網卡的識別標志搏明,對單網卡當然沒什么問題鼠锈,但是如果在集群環(huán)境里闪檬,HA星著,以及bonding環(huán)境里,為了快速切換網絡流量粗悯,往往要屏蔽mac虚循,
使用虛擬mac,或者多塊網卡使用一個mac地址样傍,這個時候需要在配置文件里屏蔽mac地址横缔,因此就需要區(qū)改udev的配置文件來解決
我所遇到的問題是,使用了biosdevname=0和?net.ifnames=0 參數后衫哥,(因為以前有大量的centos6的機器茎刚,為了移植方便,不使用一致性命名規(guī)則撤逢,網卡名依然是eth0膛锭,eth1.。蚊荣。初狰。)安裝服務器時一切正常,但啟動系統(tǒng)后互例,發(fā)現系統(tǒng)將插在第一個端口的網卡認為是eth2奢入,和預期不符,本能的認為udev可以解決問題媳叨,于是添加了udev的規(guī)則
```
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="24:6e:96:ac:a1:xa", ATTR{type}=="1", KERNEL=="*", NAME="eth0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="24:6e:96:ac:a1:xb", ATTR{type}=="1", KERNEL=="*", NAME="eth1"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="24:6e:96:ac:a1:xc", ATTR{type}=="1", KERNEL=="*", NAME="eth2"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="24:6e:96:ac:a1:xd", ATTR{type}=="1", KERNEL=="*", NAME="eth3"
```
發(fā)現不起作用腥光,,難道寫錯了糊秆?換個規(guī)則柴我,用pci設備號去綁定
SUBSYSTEM=="net", ACTION=="add", KERNEL=="eth*", SUBSYSTEM=="pci", KERNELS===="0000:01:00.0", NAME="eth0"
依然沒用
用下面的命令debug一下
udevadm test /sys/class/net/eth0
結果縮略如下
rules contain 49152 bytes tokens (4096 * 12 bytes), 13451 bytes strings
2076 strings (25677 bytes), 1399 de-duplicated (12904 bytes), 678 trie nodes used
NAME 'eth2' /etc/udev/rules.d/60-net.rules:6
IMPORT builtin 'net_id' /usr/lib/udev/rules.d/75-net-description.rules:6
IMPORT builtin 'hwdb' /usr/lib/udev/rules.d/75-net-description.rules:12
IMPORT builtin 'path_id' /usr/lib/udev/rules.d/80-net-setup-link.rules:5
IMPORT builtin 'net_setup_link' /usr/lib/udev/rules.d/80-net-setup-link.rules:9
No matching link configuration found.
RUN '/usr/lib/systemd/systemd-sysctl --prefix=/net/ipv4/conf/$name --prefix=/net/ipv4/neigh/$name --prefix=/net/ipv6/conf/$name --prefix=/net/ipv6/neigh/$name' /usr/lib/udev/rules.d/99-systemd.rules:55
Error changing net interface name 'eth0' to 'eth2': File exists
could not rename interface '2' from 'eth0' to 'eth2': File exists
created db file '/run/udev/data/n2' for '/devices/pci0000:00/0000:00:1c.4/0000:06:00.0/net/eth0'
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:1c.4/0000:06:00.0/net/eth0
ID_BUS=pci
ID_MODEL_FROM_DATABASE=I350 Gigabit Network Connection (Gigabit 4P X540/I350 rNDC)
粗體看到原來是設備已經存在,無法重命名扩然,于是想到的重新加載驅動
modprobe -rv igb
modprobe -rv ixgbe
然后按順序加載驅動
modprobe?ixgbe
modprobe? igb
終于可以看到效果了艘儒,不過重啟就完蛋了
于是想是否可以調整驅動加載順序?
找了半天文檔夫偶,發(fā)現可以通過重新打包內核啟動文件和編譯內核兩條路實現界睁,不過這顯然又增加了很多麻煩,總不能升級一次內核兵拢,就重新打一次包吧
看看其他方法翻斟。最好發(fā)現簡單的方法就是修改啟動內核的參數 將 biosdevname=0和net.ifnames=0 改為?biosdevname=0和net.ifnames=1 ,這樣系統(tǒng)啟動時说铃,會按照上述一致性命名規(guī)則访惜,重新命名網卡嘹履,可以預期的是,已dell板載網卡為例债热,網卡會依次命名為eno1砾嫉,eno4,等等窒篱,然后再加載udev規(guī)則焕刮,按照udev規(guī)則,再次重新命名為我們期望的eth0墙杯,eth1配并,等等
當然配置文件可以用ansible搞定,我這里的模版內容就是
ifcfg-eth0.j2
------
NAME="eth0"
DEVICE="eth0"
ONBOOT=yes
HWADDR="{{ hostvars[inventory_hostname].ansible_eth1.macaddress }}"
NETBOOT=yes
IPV6INIT=no
BOOTPROTO=static
TYPE=Ethernet
----------
這樣udev 規(guī)則就生效了高镐,其實就是啟動過程中溉旋,當上述兩個參數全為0時,網絡設備只能叫ethx嫉髓,先加載的驅動搶占了eth0和eth1時观腊,(我這里是千兆的設備驅動 igb先啟動)后起的設備想按udev規(guī)則rname時,發(fā)現eth0岩喷,和eth1 已經被占據了恕沫,因此命名失敗,所以深入理解啟動順序和動作其實還是蠻重要的
參考鏈接? https://access.redhat.com/documentation/zh-cn/red_hat_enterprise_linux/7/html/networking_guide/sec-understanding_the_device_renaming_procedure
紅帽知識庫文章引用如下
Why RHEL7 system is failing in renaming the interfaces with error "systemd-udevd: error changing net interface name ethX to ethY: File exists" ??
SOLUTION 已驗證?- 已更新?2015年四月23日19:40?-?English?
環(huán)境Red Hat Enterprise Linux 7.1udevd
問題
In RHEL 7 system NIC naming has been changed to?ethX?style by adding?net.ifnames=0?and?biosdevname=0?to grub file. After doing that and rebooting the system when system boots up,?MAC?address mapping to?NIC?names are as?eth0 - 8c:dc:d4:b7:xx:xx?and?eth1 - 8c:dc:d4:33:yy:yyNow the requiremet is NIC port whose?MAC?is?8c:dc:d4:b7:xx:xx?should be named as?eth1?and the NIC port whose?MAC?is?8c:dc:d4:33:yy:yy?should be named as?eth0.So to achieve that have tried adding?HWADDR?accordingly in the respective?ifcfg-ethN?files and then after reboot interfaces are coming up in the same way as that as that of original mapping.In logs can see below error at the time when?udev?tried renaming the interfaces:RawApr 20 05:32:38 HOSTNAME systemd-udevd: error changing net interface name eth0 to eth1: File existsApr 20 05:32:38 HOSTNAME systemd-udevd: error changing net interface name eth1 to eth0: File exists
決議There is no fixed supported way to achieve this particular type of interface renaming.There were couple of bugs raised-?#1184167?,?#1048399?to achieve that type of interface renaming, but all got closed with status as "CLOSED CANTFIX"Workaround is to change the?net.ifnames=1?, then after rebuilding the?grub?and rebooting the system , renaming as per requirement?may be?achieved. This may happen because?udev?running from the?initramfs?will rename the interfaces to their Consistent Device Names. Then when the root file system will be mounted?udev?will run again and this time it finds the?DEVICE/HWADDR?pairs in the?ifcfg-ethX?files and renaming might happen accordingly.If the?NIC?drivers didn't load until after the root file system was mounted, this would break. Its hard to expect this workaround to always work 100% in all cases, If the timing changes the behaviour could be different.
根源
There is no fixed supported way to achieve this particular type of interface renaming. When the system boots and the?NIC?modules are loaded, before any renaming or naming scheme takes place, the interfaces will be named?eth0, eth1, eth2, etc as the NIC modules and interfaces are created.Further the requirement of renaming?eth0?to?eth1?and?eth1?to?eth0?could not be achieved because system cannot rename a device to some other name that is already in use.
診斷步驟
Check NIC configuration , booting logs how interface came up etc.Can refer to?Red Hat Documentation?on renaming the interfaces in RHEL7.
簡書不會插入代碼框啊纱意,發(fā)現發(fā)布完了都錯行了婶溯,找時間學習學習編輯器