server端
安裝qemu, kvm
yum install qemu毕谴,qemu-kvm
安裝libvirt
yum install libvirt
systemctl enable libvirtd.service
systemctl start libvirtd.service
安裝virt-install
yum install virt-install
下載centos的mirror鏡像
wget http://mirror.pregi.net/centos/7.3.1611/isos/x86_64/CentOS-7-x86_64-Minimal-1611.iso
創(chuàng)建qcow2鏡像
qemu-img create -f qcow2 /home/images/centos.qcow2 10G
啟動(dòng)虛擬機(jī)
virt-install --virt-type kvm --name centos --ram 1024
--disk /home/images/centos.qcow2,format=qcow2
--network network=default
--graphics vnc,listen=0.0.0.0 --noautoconsole
--os-type=linux --os-variant=rhel7
--location=/home/images/CentOS-7-x86_64-Minimal-1611.iso
查看vnc端口
[root@controller01 images]# virsh list
Id Name State
1 centos running
[root@controller01 images]# virsh vncdisplay centos
:0
0代表是5900窍株,大于0的從5900之后遞增。例如解滓,顯示:1,則代表5901
Client 端
windows安裝vnc-veriewer
連接到創(chuàng)建的虛擬機(jī)
如出現(xiàn)連上后閃退問題筝家,解決方案如下圖
http://blog.licess.com/vnc-viewer-shantui/
連接成功后洼裤,選擇語言,選擇Continue
選擇網(wǎng)絡(luò)和主機(jī)名配置溪王,打開自動(dòng)獲取id地址腮鞍,配置完成后選擇Done
選擇installation source,設(shè)置鏡像源值骇,done
磁盤分區(qū),按實(shí)際需求分區(qū)移国,這里我選擇默認(rèn)吱瘩。
點(diǎn)擊安裝。
設(shè)置密碼迹缀,設(shè)置完后選擇Done使碾。
安裝完之后重啟。
如果沒有啟動(dòng)成功裹芝,可以在server端 執(zhí)行virsh reboot centos 命令部逮。
再連接,安裝acpi嫂易。acpid服務(wù)是用于可以讓hypervisior可以重啟或關(guān)閉虛擬機(jī)
yum install acpid
systemctl enable acpid
安裝cloud-init兄朋。用于啟動(dòng)虛擬機(jī)時(shí)候nova-meatdata服務(wù)進(jìn)行密鑰注入到虛擬機(jī)。
yum install epel-release.noarch
yum install cloud-init
修改cloud-init啟動(dòng)模塊加載resolv-conf怜械。
/etc/cloud/cloud.cfg
cloud_init_modules屬性下添加
- resolv-conf
安裝 cloud-utils-growpart颅和。該然間是支持虛擬機(jī)磁盤擴(kuò)容。
yum install cloud-utils-growpart
如果上面步驟不能安裝cloud-init缕允,則可以在/etc/rc.d/rc.local文件中峡扩,在touch /var/lock/subsys/local這行前加入以下腳本
if [ ! -d /root/.ssh ]; then
mkdir -p /root/.ssh
chmod 700 /root/.ssh
fi
# Fetch public key using HTTP
ATTEMPTS=30
FAILED=0
while [ ! -f /root/.ssh/authorized_keys ]; do
curl -f http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key \
> /tmp/metadata-key 2>/dev/null
if [ \$? -eq 0 ]; then
cat /tmp/metadata-key >> /root/.ssh/authorized_keys
chmod 0600 /root/.ssh/authorized_keys
restorecon /root/.ssh/authorized_keys
rm -f /tmp/metadata-key
echo "Successfully retrieved public key from instance metadata"
echo "*****************"
echo "AUTHORIZED KEYS"
echo "*****************"
cat /root/.ssh/authorized_keys
echo "*****************"
fi
done
關(guān)閉zeroconf route
echo "NOZEROCONF=yes" >> /etc/sysconfig/network
配置console,為了確闭媳荆控制臺(tái)的信息出現(xiàn)在 dashboard 的日志標(biāo)簽頁中教届,以及 nova console-log 輸出中。
修改/etc/default/grub的配置GRUB_CMDLINE_LINUX選項(xiàng). 刪除 rhgb quiet 添加 console=tty0 console=ttyS0,115200n8驾霜。
例子:
GRUB_CMDLINE_LINUX="crashkernel=auto console=tty0 console=ttyS0,115200n8
更新grub配置
grub2-mkconfig -o /boot/grub2/grub.cfg
關(guān)閉虛擬機(jī)
shutdown -h now
Server端
安裝 libguestfs-tools
yum install libguestfs-tools
清理鏡像MAC地址
virt-sysprep -d centos
清除虛擬機(jī)
virsh undefine centos
鏡像制作完成案训,可以上傳到openstack,鏡像為 /home/images/centos.qcow2文件。