根據(jù)開發(fā)組同事反應,通過VCenter對RHEL6.0以下版本的系統(tǒng)進行克隆的時候,無法使用高級選項進行IP的指定操作,從而通過CloudStack對新的實例指定IP也是不能實現(xiàn)的,而且,不能夠使用DHCP服務器解決該問題,否則會導致新虛擬機IP地址跟指定IP的不一致,也可能導致整個系統(tǒng)中IP地址分配的混亂。
解決思路:
給RHEL6.0以下系統(tǒng)制作的模板均指定一個固定的保留IP地址,比如192.168.3.0/24網(wǎng)段中,保留192.168.3.240~192.168.3.250給此類模板系統(tǒng)。
不管是通過VCenter克隆虛擬機還是CloudStack新建實例,只要是通過該固定IP地址啟動的所有虛擬機,均會成功以原有IP地址啟動,并正常跟網(wǎng)段內(nèi)其他IP地址通訊,需要保證同一時間不允許同一IP地址的模板同時啟動。
下文以模板固定IP為:10.196.18.250的系統(tǒng),在控制節(jié)點,如cloudstackmanagement節(jié)點上面/etc/hosts中進行解析:
10.196.18.250 vm250
1.啟動vm250 ,通過檢測機制判斷其啟動成功,程序中去對10.196.18.250進行簡單的連接測試,ping 通即可。
2.在啟動實例的過程中,同時將IP地址信息寫入本地目錄中,按照如下格式保存:
假設(shè)文件名為:ifcfg-eth0.001,內(nèi)容為如下
DEVICE=eth0
ONBOOT=on
BOOTPROTO=static
IPADDR=10.196.28.208
NETMASK=255.255.255.0
GATEWAY=10.196.28.254
3.調(diào)用腳本文件:ChangeIP.sh ,該腳本文件完成兩項任務:
【1】將ifcfg-eth0.Id 拷貝到vmId指定目錄中,重命名為ifcfg-eth0
【2】通過cloudstack management 登陸vmId,重啟網(wǎng)絡(luò)服務,使得新的網(wǎng)絡(luò)配置文件生效。
使用方法:./ChangeIP.sh id_of_ifcfg-eth0 id_of_vm
如: ./ChangeIP.sh 001 250 ,將ifcfg-eth0.001 文件拷貝紙vm250系統(tǒng)中,并重新啟動網(wǎng)絡(luò)服務,使得新實例的最終IP地址為10.196.28.208
雙擊代碼全選
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#!/bin/bash #description: change ip on instances #Usage: ./ChangeIP.sh fileId vmId # flush the caches of remote hosts >~/.ssh/known_hosts #define the network configfile location dist=http://www.3lian.com/etc/sysconfig/network-scripts/ifcfg-eth0 # define a function which copy the new ifcfg-eth0 file # from cloudstack management or from other host to new # instance boot from vm_fixip without interactive function scp_file(){ expect -c " set timeout -1 spawn -noecho scp $1 $2 expect "yes/no" send "yesr" expect "password:" send "passwordr" expect eof " } scp_file ifcfg-eth0.$1 root@vm$2:$dist # this function named res_new means restart network # on new instance loading from new network config file # without interactive function res_net(){ expect -c " set timeout -1 spawn -noecho ssh $1 $2 expect "password:" send "passwordr" expect eof " } res_net root@vm$2 "service network restart > /dev/null 2>&1 &"