Openstack之制作Windows_server_2008镜像

Openstack之制作Windows_server_2008镜像

(CentOS6.5+Windows_server_2008+)

1、在镜像制作服务器,安装qemu libvirtd 及Windows virt驱动以及依赖

制作一个名为Cloud_windows_server_2008_64bit镜像,C盘大小为50G,预装Office和Ecplise,配置Java环境(配置用户CloudUser,密码为cloudpasswd)

(1)

[root@controllerShaowenhua opt]# yum install qemu-kvm libvirt libvirt-python libguestfs-tools virt-install guestfish
[root@controllerShaowenhua opt]# yum install qemu-kvm*
[root@controllerShaowenhua tmp]# yum -y install virt* --skip-broken
#--skip-broken版本原因

(2)需要手动下载virtio驱动

2、下载光盘镜像

找官网下载下三个文件:https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/

[root@controllerShaowenhua opt]# ll
total 3452548
-rw-r--r--. 1 qemu qemu 3368839168 Apr 26 11:14 cn_windows_server_2008_r2_standard_enterprise_datacenter_and_web_with_sp1_x64_dvd_617598.iso
-rw-r--r--. 1 root root    2949120 Apr 29 18:39 virtio-win-0.1.96_amd64.vfd
-rw-r--r--. 1 root root  160659456 Apr 29 17:59 virtio-win-0.1.96.iso

3、配置、/etc/libvirt/qemu.conf

[root@controllerShaowenhua opt]# cat /etc/libvirt/qemu.conf
# Master configuration file for the QEMU driver.
# All settings described here are optional - if omitted, sensible
# defaults are used.

# VNC is configured to listen on 127.0.0.1 by default.
# To make it listen on all public interfaces, uncomment
# this next option.
#
# NB, strong recommendation to enable TLS + x509 certificate
# verification when allowing public access
#
vnc_listen = "0.0.0.0"
#取消vnc_listen = "0.0.0.0"的注释

4、重启libvirtd

[root@controllerShaowenhua opt]# service libvirtd restart
Stopping libvirtd daemon:                                  [  OK  ]
Starting libvirtd daemon:                                  [  OK  ]

5、防火墙设置:后面要开发5901端口

[root@controllerShaowenhua tmp]# /etc/init.d/iptables stop
iptables: Setting chains to policy ACCEPT: nat mangle filte[  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
[root@controllerShaowenhua tmp]# service iptables status
iptables: Firewall is not running.
[root@controllerShaowenhua tmp]# setenforce 0

6、审计一下

[root@controllerShaowenhua tmp]# rpm -qa | grep libvirt
libvirt-python-0.10.2-29.el6.x86_64
libvirt-0.10.2-29.el6.x86_64
libvirt-client-0.10.2-29.el6.x86_64
[root@controllerShaowenhua tmp]# service libvirtd status
libvirtd (pid  9291) is running...
[root@controllerShaowenhua tmp]# lsmod | grep kvm
kvm_intel              54285  0
kvm                   333172  1 kvm_intel

7、开启主机设备虚拟化功能

image-20240429201502001

8、制作镜像文件

[root@controllerShaowenhua opt]# cd /tmp/
#创建一个空的磁盘文件
[root@controllerShaowenhua tmp]# qemu-img create -f raw Cloud_windows_server_2008_64bit.img 50G
Formatting 'Cloud_windows_server_2008_64bit.img', fmt=raw size=53687091200
[root@controllerShaowenhua tmp]# qemu-img info Cloud_windows_server_2008_64bit.img
image: Cloud_windows_server_2008_64bit.img
file format: raw
virtual size: 50G (53687091200 bytes)
disk size: 0
[root@controllerShaowenhua tmp]# virt-install --name Cloud_windows_server_2008_64bit --ram 2048 --vcpus 2 --network network=default,model=virtio \
--disk=Cloud_windows_server_2008_64bit.img,format=raw,device=disk,bus=virtio \
--cdrom=/opt/cn_windows_server_2008_r2_standard_enterprise_datacenter_and_web_with_sp1_x64_dvd_617598.iso \
--disk=/opt/virtio-win-0.1.96.iso \
--disk=/opt/virtio-win-0.1.96_amd64.vfd,device=floppy \
--vnc --vncport=5901 --vnclisten=0.0.0.0 --video qxl --channel spicevmc --os-type windows --os-variant win2k8 --force

执行完此条命令后,(版本原因)可能会显示如下信息:先把他放一边(课本就是垃圾)【执行过程中删掉> 符号】

[root@controllerShaowenhua tmp]# virt-install --name Cloud_windows_server_2008_64bit --ram 2048 --vcpus 2 --network network=default,model=virtio \
> --disk=Cloud_windows_server_2008_64bit.img,format=raw,device=disk,bus=virtio \
> --cdrom=/opt/cn_windows_server_2008_r2_standard_enterprise_datacenter_and_web_with_sp1_x64_dvd_617598.iso \
> --disk=/opt/virtio-win-0.1.96.iso \
> --disk=/opt/virtio-win-0.1.96_amd64.vfd,device=floppy \
> --vnc --vncport=5901 --vnclisten=0.0.0.0 --video qxl --channel spicevmc --os-type windows --os-variant win2k8 --force

Starting install...
Creating domain...                                                                                                                                         |    0 B     00:01     
Cannot open display:
Run 'virt-viewer --help' to see a full list of available command line options
Domain installation still in progress. Waiting for installation to complete.
Domain has shutdown. Continuing.
Starting domain...

9、下载Windows版:VNC

链接:https://www.realvnc.com/en/connect/download/vnc/

(1)下载完后的界面

image-20240429203308247

(2)点击File,new连接,这有个前提,在宿主机上开启VNC选项

image-20240429203130832

这里显示5900,我后面改的5901

(3)连接虚拟机(可能会闪几下(30s以上),只需等待即可),如果长时间不出现如下界面

image-20240429203552139

就需要在宿主机停止安装:CTRL+C,检查日志信息以及上述步骤是否执行到位,再执行以下操作:(如见)

[root@controllerShaowenhua tmp]# virsh destroy Cloud_windows_server_2008_64bit
Domain Cloud_windows_server_2008_64bit destroyed

[root@controllerShaowenhua tmp]# virsh undefine Cloud_windows_server_2008_64bit
Domain Cloud_windows_server_2008_64bit has been undefined

(4)选择与自己版本相符的操作系统

image-20240429204315764

(5)自定义,然后选择加载驱动程序

image-20240429204459435

(6)R2的选这个

image-20240429204713319

(7)选择盘1并下一步

image-20240429204807480

(8)设置密码,登录

image-20240429204955291

10、补充

虚拟机的状态:
1.运行(Running):虚拟机正在正常运行,执行其操作系统和应用程序。
2.暂停(Paused):虚拟机被暂停,所有的执行活动都停止了,但虚拟机的内存状态被保留,以便稍后恢复。
3.关机(Shutdown):虚拟机已经正常关闭,所有的应用程序和系统服务都已经停止运行。
4.崩溃(Crashed):虚拟机由于某种原因(如操作系统错误或硬件故障)突然停止运行,可能需要重新启动。
5.电源关闭(Power Off):虚拟机的电源被关闭,类似于物理机器的断电状态。在这种状态下,虚拟机没有运行,并且任何未保存的数据都可能丢失。
vish命令
virsh list --all 显示所有虚拟机
virsh list 显示开机的虚拟机
vish install 安装虚拟机

参考链接:https://opengers.github.io/virtualization/kvm-libvirt-qemu-2/

posted @ 2024-04-29 21:18  朝暮青丝  阅读(27)  评论(0编辑  收藏  举报