by hyc
1.Cloud-init安裝
已有了一個安裝好系統的鏡像。
鏡像名:ubuntu-test-14.04-server-amd64.img
用戶名:user
密碼:1
主機名:ubuntu
在ip為192.168.29.80的服務器上執行命令:
sudo kvm -m 2048 -drive file=/openstack_img/iso/ubuntu-14.04.2-server-amd64.iso,index=1,media=cdrom -drive file=/openstack_img/img/ubuntu-test-14.04-server-amd64.img,if=virtio -drive file=/openstack_img/driver/virtio-win.iso,index=3,media=cdrom -net nic,model=virtio -net user -nographic -vnc :9 -usbdevice tablet
登錄后,執行以下命令安裝必要的軟件包:
# sudo apt-get -y update
# sudo apt-get -y upgrade
# sudo apt-get install curl
# curl http://mirror.rightscale.com/rightlink/rightscale.pub | apt-key add -
# echo "deb [arch=amd64] http://mirror.rightscale.com/rightscale_software_ubuntu/latest trusty main" > /etc/apt/sources.list.d/rightscale_extra.sources.list
# sudo apt-get -y --force-yes install cloud-init
# sudo apt-get -y install cloud-utils
參考資料:http://docs.rightscale.com/rl10/reference/rl10_cloud_init_installation.html
安裝結束后,上傳到ip為192.168.29.94的服務器上
# scp ubuntu-test-14.04-server-amd64.img user@192.168.29.94:/home/user
2.Cloud-init使用
登錄192.168.29.94服務器后,將鏡像上傳到OpenStack上。
# glance image-create --name "ubuntu-server-14.04-0711" --is-public true --disk-format qcow2 --container-format bare --file ubuntu-test-14.04-server-amd64.img --progress
上傳結束后,返回數據:
登錄OpenStack控制台,點擊“實例”。
再點擊“啟動雲主機”后,設置雲主機名稱為“ubuntu-test-server”,雲主機啟動源選擇“從鏡像啟動”,鏡像名稱選擇剛剛上傳的“ubuntu-server-14.04-0711”。界面顯示如下:
選擇網絡:
配置雲主機:
選擇“創建后”,選擇“直接輸入”。
#!/bin/sh
# 修改用戶的密碼
passwd ubuntu<<EOF
psd
psd
EOF
# 修改Liunx系統主機名
sed -i 's/ubuntu-test-server/hostnametest/g' /etc/hostname
sed -i 's/ubuntu/hostnametest/g' /etc/hosts
reboot
點擊“運行”,則立即創建實例。等待一會創建成功。
用vnc連接進去后。用戶名為“ubuntu”,密碼為“psd”登錄進去后。
查看主機名,已改為你設置的。
查看/etc/hostname文件,主機名也改為了“hostnametest”。
查看/etc/hosts文件,安裝系統后是ubuntu,現在改為了“hostnametest”。
注:
1.也可以用你安裝系統時設置的用戶名“user”和密碼“1”登錄。
2.主機名的設置可以在啟動雲主機后的“詳情”里“雲主機名名稱”設置主機名,也可以在“創建后”用Shell命令設置主機名。
3./etc/hosts文件里的主機名也可以不修改,在用命令sudo可以正常執行,但是會彈出警告信息“sudo: unable to resolve host hostnametest”而這只是機器在反解上的問題, 所以就用命令對/etc/hosts文件進行設定(sed -i 's/ubuntu/hostnametest/g' /etc/hosts), 讓hostnametest(hostname) 可以解回127.0.0.1 的IP 即可。