為了測試集群,在安裝了初始虛擬機之后,我采用虛擬機clone方式來部署虛擬服務器。
但是,虛擬機clone之后,發(fā)現(xiàn)其中的新虛擬網(wǎng)卡被系統(tǒng)識別為eth3
eth4
和 eth5
,而不是預期的eth0
eth1
和 eth2
。這對管理服務器配置帶來一些麻煩。所以還是查詢了一些資料,解決了這個問題,記錄如下。
參考
- LogicalInterfaceNames 提供了多種設置網(wǎng)卡邏輯名稱的方法
說明
現(xiàn)代的Linux操作系統(tǒng)都可以采用udev方式來對加入系統(tǒng)的硬件設備進行命名,這也是推薦的方法。udev根據(jù)設置的規(guī)則可以確保加入系統(tǒng)的硬件設備命名一致,不會因為系統(tǒng)重啟而導致硬件設備識別為其他名稱。這對于類似集群系統(tǒng)對共享存儲的識別尤為重要,否則會導致集群運行不正常。
設置udev規(guī)則配置文件對網(wǎng)卡命名
可以采用如下方法設置網(wǎng)卡:
- 在
/etc/udev/rules.d
添加10_netinterfaces.rules
配置文件
1 2 3 | KERNEL=="eth?", SYSFS{address}=="00:16:36:18:14:51", NAME="eth0" KERNEL=="eth?", SYSFS{address}=="00:16:36:84:02:29", NAME="eth1" KERNEL=="eth?", SYSFS{address}=="00:16:36:63:ef:de", NAME="eth2" |
- 重啟系統(tǒng)后系統(tǒng)將根據(jù)MAC地址來識別設備命名。
實際的解決方法
以上方法雖然可行,但是在重啟系統(tǒng)后,仍然發(fā)現(xiàn)網(wǎng)卡被識別為 eth3
eth4
和 eth5
。并且/var/log/messages
中有如下信息
Sep 11 02:28:33 glusterfs-1 kernel: udev: renamed network interface eth0 to eth3Sep 11 02:28:33 glusterfs-1 kernel: udev: renamed network interface eth1 to eth4Sep 11 02:28:33 glusterfs-1 kernel: udev: renamed network interface eth2 to eth5
這說明啟動時系統(tǒng)是識別這三塊網(wǎng)卡為 eth0
eth1
和 eth2
,但是隨后被udev規(guī)則設置所改變。
仔細檢查了 /etc/udev/rules.d
目錄下,發(fā)現(xiàn)還有一個 70-persistent-net.rules
規(guī)則文件,內容如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | # This file was automatically generated by the /lib/udev/write_net_rules # program, run by the persistent-net-generator.rules rules file. # # You can modify it, as long as you keep each rule on a single # line, and change only the value of the NAME= key. # PCI device 0x10ec:0x8139 (8139cp) (custom name provided by external tool) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:db:6b:b0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0" # PCI device 0x10ec:0x8139 (8139cp) (custom name provided by external tool) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:32:ed:8d", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1" # PCI device 0x10ec:0x8139 (8139cp) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:eb:f5:b9", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2" # PCI device 0x10ec:0x8139 (8139cp) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:16:36:18:14:51", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth3" # PCI device 0x10ec:0x8139 (8139cp) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:16:36:84:02:29", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth4" # PCI device 0x10ec:0x8139 (8139cp) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:16:36:63:ef:de", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth5" |
這個配置文件是 /lib/udev/write_net_rules
腳本自動生成的,是系統(tǒng)識別新硬件時候添加的配置文件。這樣可以確保每個添加的硬件(內核驅動相同)不會判別為相同命名。
所以,在這種情況下,應該修改 70-persistent-net.rules
,去除不需要的配置,并修改為合適的命名。
1 2 3 4 5 6 7 8 | # PCI device 0x10ec:0x8139 (8139cp) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:16:36:18:14:51", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0" # PCI device 0x10ec:0x8139 (8139cp) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:16:36:84:02:29", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1" # PCI device 0x10ec:0x8139 (8139cp) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:16:36:63:ef:de", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2" |
當然,移除這個70-persistent-net.rules
,改為采用前述的 10_netinterfaces.rules
規(guī)則配置文件也能起到同樣作用。