目前市場上稍微有些實力的交換機廠商,均支持自動化的批量開局部署,雖然具體實現有些區別,但實現原理基本一致。以下圖:
linux
# dhcp server: udp 67 # dhcp client: udp 68 vim /etc/sysconfig/iptables -A INPUT -p udp -m state --state NEW -m udp --dport 67 -j ACCEPT -A INPUT -p udp -m state --state NEW -m udp --dport 68 -j ACCEPT # 重啓服務 service iptables restart
# 安裝 yum install dhcp -y # 範例:/usr/share/doc/dhcp-4.2.5/dhcpd.conf.example cat /etc/dhcp/dhcpd.conf ddns-update-style none; # interim爲DNS互動更新模式,ad-hoc爲特殊DNS更新模式,none爲不支持動態更新模式 ignore client-updates; # 忽略客戶端更新 # option domain-name "centos.org"; # 默認搜索域 # option domain-name-servers 100.64.191.11; # option ntp-servers 100.64.191.25; option time-offset -18000; # Eastern Standard Time default-lease-time 21600; # The default is 43200 seconds max-lease-time 43200; # If not defined, the default maximum lease time is 86400 #allow booting; # The booting flag is used to tell dhcpd whether or not to respond to queries from a particular client. This keyword only has meaning when it appears in a host declaration. By default, booting is allowed, but if it is disabled for a particular client, then that client will not be able to get an address from the DHCP server. #allow bootp; # The bootp flag is used to tell dhcpd whether or not to respond to bootp queries. Bootp queries are allowed by default. option tftp-server-address code 150 = ip-address; # isc-dhcp-server中並無"tftp-server-address"的option參數,須要提起指定 subnet 100.64.191.0 netmask 255.255.255.0 { range 100.64.191.101 100.64.191.200; # option subnet-mask 255.255.255.0; option routers 100.64.191.1; # 若是在二層網絡下操做,是否設置網關並不重要 # next-server 100.64.191.10; # 通常操做系統的自動安裝使用option66指向tftp服務器 # filename "/pxelinux.0"; # tftp根目錄下的啓動引導文件 option tftp-server-address 100.64.191.10; # 通常交換機的自動配置使用option150指向tftp服務器,務必提早確認;另外centec交換機固定讀取 "smartdeploy.xml" 文件,不用特別指定並傳遞中間文件名 # we want the nameserver to appear at a fixed address # host ns { # hardware ethernet 00:1C:25:80:F4:58; # 特殊設備網卡mac # fixed-address 100.64.191.11; #} } # 啓動 systemctl enable dhcpd ; systemctl restart dhcpd # client獲取地址後,可在server端查看租約 cat /var/lib/dhcpd/dhcpd.leases
# tcftp server: udp 69 vim /etc/sysconfig/iptables -A INPUT -p udp -m state --state NEW -m udp --dport 69 -j ACCEPT # 重啓服務 service iptables restart
# 安裝 yum install xinetd tftp-server tftp -y # 建立tftp根目錄; # 若是有權限問題,可執行"chmod 777 /tftp" mkdir -p /tftp # 配置,默認無tftp配置文件; cat << EOF > /etc/xinetd.d/tftp # default: off # description: The tftp server serves files using the trivial file transfer # protocol. The tftp protocol is often used to boot diskless # workstations, download configuration files to network-aware printers, # and to start the installation process for some operating systems. service tftp { socket_type = dgram protocol = udp wait = yes user = root server = /usr/sbin/in.tftpd server_args = -u nobody -s /tftp # -s指定tftp根目錄 disable = no # 默認yes per_source = 11 cps = 100 2 flags = IPv4 } EOF # 啓動服務 systemctl enable xinetd ; systemctl restart xinetd
Centec交換機的初始化配置特性爲"SmartConfig"。vim
SmartConfig流程梳理:centos
SmartConfig具體實現步驟以下:服務器
# "initial-switch-deployment"顯示爲"on"爲使能狀態,"off"爲關閉狀態; # 若是爲關閉狀態,在配置模式下使用"smart-config initial-switch-deployment"命令可打開smart-config功能,此命令重啓設備後生效; # 默認狀況下,smart-config處於使能狀態 E580# show smart-config config Smart-Config config: initial-switch-deployment: on hostname-prefix: on Send log message to console: on
cat ~/smartdeploy.xml <SmartDeploy> <ftype>init</ftype> # 不可修改 <hostprefix>E580</hostprefix> # 此處設置E580的hostname的前綴,完整的hastname爲該前綴加上相應設備(非帶外管理口)的MAC地址的後六位,如E580的MAC地址爲00:1e:08:a9:cc:6d,那麼hostname爲:"E580A9.CC6D" # 此段編輯默認匹配項,就是若是有MAC\Productid\SN都不匹配的交換機,則使用這段條目裏設置的image和配置文件 <defItem> <option>disable</option> #"enable"啓用默認匹配,"disable"關閉默認匹配 <image>centecOS-e580-v6.2.26.r.bin</image> # 根據實際狀況修改,若是已"disable"默認匹配,設置與否並不重要 <config>startup-config-default.conf</config> # 根據實際狀況修改,若是已"disable"默認匹配,設置與否並不重要 </defItem> # 三種匹配方式:設備MAC地址、設備Product-ID、以及設備序列號,只需任意匹配到其中一條,就能夠用匹配到的條目下的image及配置啓動交換機; # 此段爲使用序列號匹配的範例,若是不須要換image,則將image字段的內容部分刪除,如"<image></image>"; # 注意事項:(1). 若是指定了更換image,下載image與配置文件後,設備會再次重啓; # (2). 只指定配置文件,不指定更換image的狀況下,爲了不設備再次重啓,可在配置文件中的管理網口的配置前面,添加「no management ip address dhcp"與"no interface vlan 1"兩句配置,具體可參考"配置文件示例" <groups> <Item> <type>MAC</type> # 不用修改 <value></value> # 根據實際狀況修改,若是不採用MAC匹配,建議不設置 <image></image> # 根據實際狀況修改,若是不採用MAC匹配,建議不設置 <config></config> # 根據實際狀況修改,若是不採用MAC匹配,建議不設置 </Item> <Item> <type>productid</type> # 不用修改 <value></value> # 根據實際狀況修改,若是不採用Product-ID匹配,建議不設置 <image></image> # 根據實際狀況修改,若是不採用Product-ID匹配,建議不設置 <config></config> # 根據實際狀況修改,若是不採用Product-ID匹配,建議不設置 </Item> <Item> <type>SN</type> # 不用修改 <value>E163GD172018</value> # 根據實際狀況修改 <image></image> # 根據實際狀況修改 <config>startup-config-test.conf</config> # 根據實際狀況修改 </Item> </groups> </SmartDeploy>
注意事項: 只指定配置文件,不指定更換image的狀況下,爲了不設備再次重啓,在配置文件中的管理網口的配置前面,添加「no management ip address dhcp"與"no interface vlan 1"兩句配置。網絡
# 注意配置文件名與"smartdeploy.xml"中定義的config文件名一致 cat ~/startup-config-test.conf no service password-encryption ! username admin privilege 4 password 8 7834ed73c1ee2c999338cd31aaed88ce ! no management ip address dhcp no interface vlan 1 ! management ip address 100.64.191.201/24 management route add gateway 100.64.191.1 ! vlan database vlan 10 ! interface eth-0-1 ! interface eth-0-2 ! interface eth-0-3 ! interface eth-0-4 ! interface eth-0-5 ! interface eth-0-6 ! interface eth-0-7 ! interface eth-0-8 ! interface eth-0-9 ! interface eth-0-10 ! interface eth-0-11 ! interface eth-0-12 ! interface eth-0-13 ! interface eth-0-14 ! interface eth-0-15 ! interface eth-0-16 ! interface eth-0-17 ! interface eth-0-18 ! interface eth-0-19 ! interface eth-0-20 ! interface eth-0-21 ! interface eth-0-22 ! interface eth-0-23 ! interface eth-0-24 ! interface eth-0-25 ! interface eth-0-26 ! interface eth-0-27 ! interface eth-0-28 ! interface eth-0-29 ! interface eth-0-30 ! interface eth-0-31 ! interface eth-0-32 ! interface eth-0-33 ! interface eth-0-34 ! interface eth-0-35 ! interface eth-0-36 ! interface eth-0-37 ! interface eth-0-38 ! interface eth-0-39 ! interface eth-0-40 ! interface eth-0-41 ! interface eth-0-42 ! interface eth-0-43 ! interface eth-0-44 ! interface eth-0-45 ! interface eth-0-46 ! interface eth-0-47 ! interface eth-0-48 ! interface eth-0-49 ! interface eth-0-50 ! interface eth-0-51 ! interface eth-0-52 ! line con 0 no line-password no login line vty 0 7 exec-timeout 35791 0 privilege level 4 transport input ssh no line-password login local ! end
SmartConfig特性已定義從tftp服務獲取中間文件及配置文件,image等的路徑,嚴格按其預約義的路徑存放相關文件便可。app
# 在tftp根目錄下建立相關目錄 mkdir -p /tftp/smartconfig/{conf,image} # 放置文件 mv ~/smartdeploy.xml /tftp/smartconfig/ mv ~/startup-config-test.conf /tftp/smartconfig/conf/ # 查看目錄結構 tree /tftp/ /tftp/ └── smartconfig ├── conf │ └── startup-config-test.conf ├── images └── smartdeploy.xml
具體配置請見2.1.2 DHCP服務器安裝配置章節,注意事項:less
觸發SmartConfig工做的必要條件是:dom
# 若是測試或者已保存過配置的設備,可在特權模式下刪除startup-config.conf文件 E580# delete flash:/startup-config.conf
若是smart-config未生效,可經過以下方式troubleshooting:
設備在沒有startup-config.conf文件重啓後,smart-config會自動加載一套默認配置給設備,此默認配置中,管理網口工做在DHCP模式下,可在特權模式下使用show dhcp client verbose指令查看管理網口是否已經從DHCP Server獲取到管理IP與TFTP Server IP。ssh
# 重點關注"Allocated IP" 與 "TFTP server addresses" 兩個參數 Switch# show dhcp client verbose DHCP client informations: ============================================================ Management interface DHCP client information: Current state: BOUND Allocated IP: 100.64.191.101 255.255.255.0 Lease/renewal/rebinding: 714/71/564 seconds Lease from 2019-04-09 15:26:57 to 2019-04-09 15:46:57 Will Renewal in 0 days 0 hours 1 minutes 11 seconds DHCP server: 100.64.191.10 Transaction ID: 0x16d35160 Default router: 100.64.191.1 TFTP server addresses: 100.64.191.10 # 若是未獲取到TFTP地址,則不顯示此行 Client ID: switch-001e:08a9:cc:6c-management # 管理網口MAC不一樣於設備板卡的MAC地址