注意事项
安装kvm
curl -o /etc/yum.repos.d/Centos-7.repo http://mirrors.aliyun.com/repo/Centos-7.repo
systemctl stop firewalld.service
systemctl disable firewalld.service
yum install autoconf gcc gcc-c++ automake libtool glib* zlib* -y
yum -y group install virtualization-platform virtualization-client
yum -y install tigervnc-server tigervnc vnc vnc-server
yum install qemu-kvm -y
yum install qemu-img -y
yum -y install qemu-kvm-tools
yum -y install virt-install
yum -y install bridge-utils
yum -y install libvirt
systemctl start libvirtd
systemctl enable libvirtd
yum install libguestfs-tools -y
yum install libvirt-python python-virtinst libvirt-client virt-install virt-viewer –y
lsmod | grep kvm
绑定网卡
ip add
virsh iface-bridge br0 enp3s0
ip add
brctl show
brctl addif br0 enp3s0
systemctl restart network
systemctl disable NetworkManager
systemctl stop NetworkManager
systemctl restart network
service network restart
ip add
这样桥接网卡成功, 安装aliyun linux cloud, 官网:https://help.aliyun.com/document_detail/215519.html
参照官网下载好镜像,我使用的是 qcow2, uname -a 看cpu 架构, 我的是x86_64
master.xml
<domain type='kvm'>
<name>master</name>
<memory>3145728</memory><!-- 3 GB内存。 -->
<vcpu>2</vcpu>
<cpu mode='host-passthrough'><!-- 需要在对应架构的服务器上启动实例。 -->
</cpu>
<os>
<type arch='x86_64'>hvm</type><!-- 如果是ARM64架构的服务器,则需设置为arch='aarch64'。 -->
<boot dev='hd'/>
</os>
<clock sync="localtime"/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator><!-- 请根据不同的操作系统设置对应的kvm路径。例如:Ubuntu对应的kvm路径是/usr/bin/kvm。 -->
<disk type='file' device='disk'><!-- 请根据镜像格式设置下面的type参数:qcow2对应type='qcow2'、vhd对应type='vpc'。 -->
<driver name='qemu' type='qcow2' cache='none' dataplane='on' io='native'/> <!-- 如果要创建qcow2快照,需要关闭dataplane。 -->
<source file='/vm/master.qcow2'/> <!-- 填写Alibaba Cloud Linux 3镜像的绝对路径。 -->
<target dev='vda' bus='virtio'/>
</disk>
<!-- 加入seed.img的信息。 -->
<disk type='file' device='disk'>
<driver name='qemu' type='raw'/>
<source file='/vm/seed.img'/> <!-- 填写seed镜像的绝对路径。 -->
<target dev='vdb' bus='virtio'/>
</disk>
<interface type='bridge'>
<source bridge='br0'/>
<model type='virtio'/>
</interface>
<console type='pty'>
<target type='virtio' port='0'/>
</console>
<video>
<model type='cirrus' vram='9216' heads='1'/>
<alias name='video0'/>
</video>
<input type='tablet' bus='usb'/>
<input type='mouse' bus='ps2'/>
<graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'/>
</devices>
</domain>
部署虚拟机,并启动
virsh define master.xml
virsh start master
virsh console master
sudo passwd root
su root
vim /etc/ssh/sshd_config
PasswordAuthentication yes
systemctl restart sshd
谢谢观看
end