IT评测·应用市场-qidao123.com

标题: ARM架构服务器安装部署KVM捏造化情况 [打印本页]

作者: 杀鸡焉用牛刀    时间: 2024-6-15 02:39
标题: ARM架构服务器安装部署KVM捏造化情况
文章目次
一、主流的捏造化方案简介
二、查察内核是否支持KVM捏造化
三、关闭Selinux
四、关闭防火墙
五、设置网桥br0和静态IP
六、安装GNOME桌面情况
七、安装KVM及所需组件
八、修改sshd 设置文件
九、启动libvirt并设置开机自启动
十、创建镜像目次和磁盘文件目次
十一、创建捏造机的磁盘文件
十二、创建捏造机
十三、设置捏造机的网络
十四、KVM捏造机常见管理下令(在宿主机中实行)
十五、常见问题

   硬件情况:
  
  软件情况:
  
  一、主流的捏造化方案简介


               
           KVM捏造化                二、查察内核是否支持KVM捏造化

  针对ARM架构服务器,若/dev/kvm 和 /sys/module/kvm恣意一个不存在,都说明内核不支持KVM捏造化。 
  1. [root@localhost ~]# ls -l /dev/kvm
  2. crw-rw----+ 1 root kvm 10, 232 May  6 09:18 /dev/kvm
  3. [root@localhost ~]# ls /sys/module/kvm
  4. parameters  uevent
复制代码
扩展说明:
针对X86服务器,查察是否支持KVM捏造化的下令如下:
  1. #若是intel cpu,命令执行结果是vmx;若是amd cpu,命令执行结果是svm;
  2. [root@localhost ~]# egrep -o 'vmx|svm' /proc/cpuinfo
复制代码
三、关闭Selinux


  1. [root@localhost ~]# sed -i 's/enforcing/disabled/' /etc/selinux/config 
复制代码

  1. [root@localhost ~]# setenforce 0 
复制代码

  1. [root@localhost ~]# getenforce 
复制代码
四、关闭防火墙

   说明:为了顺遂完成KVM捏造化情况的安装部署,先关闭防火墙。待安装部署完成后,再启用防火墙,并进行相关设置(具体设置可以详见:Linux系统中设置防火墙-CSDN博客)。
  
  1. [root@localhost ~]# systemctl stop firewalld
复制代码

  1. [root@localhost ~]# systemctl disable firewalld
复制代码

  1. [root@localhost ~]# systemctl stop iptables
复制代码

  1. [root@localhost ~]# systemctl disable iptables
复制代码
五、设置网桥br0和静态IP

   留意:每台物理服务器的下令实行结果以及必要设置的静态IP大概不一样,请基于实际情况来进行设置。
  
  1. [root@localhost ~]# ip ad
  2. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
  3.     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  4.     inet 127.0.0.1/8 scope host lo
  5.        valid_lft forever preferred_lft forever
  6.     inet6 ::1/128 scope host 
  7.        valid_lft forever preferred_lft forever
  8. 2: enp125s0f0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
  9.     link/ether b0:4f:a6:3d:44:9c brd ff:ff:ff:ff:ff:ff
  10. 3: enp125s0f1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
  11.     link/ether b0:4f:a6:3d:44:9d brd ff:ff:ff:ff:ff:ff
  12. 4: enp125s0f2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
  13.     link/ether b0:4f:a6:3d:44:9e brd ff:ff:ff:ff:ff:ff
  14. 5: enp125s0f3: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
  15.     link/ether b0:4f:a6:3d:44:9f brd ff:ff:ff:ff:ff:ff
复制代码
从下令实行结果可知,当前处于UP状态的网卡是enp125s0f0(如有多个网卡都处于state UP,则任选一个来进行设置。留意,不要选lo,这是127.0.0.1专用的)

  1. [root@localhost ~]# cp /etc/sysconfig/network-scripts/ifcfg-enp125s0f0 \
  2.                     /etc/sysconfig/network-scripts/ifcfg-br0
复制代码

  1. [root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-br0
  2. #Type使用桥接
  3. TYPE=Bridge
  4. #IP分配协议改为静态分配
  5. BOOTPROTO=static
  6. #修改NAME为br0
  7. NAME=br0
  8. #修改DEVICE为br0
  9. DEVICE=br0
  10. ONBOOT=yes
  11. #宿主机的静态IP
  12. IPADDR=192.168.112.56
  13. #子网掩码
  14. PREFIX=24
  15. #网关
  16. GATEWAY=192.168.112.1
  17. #DNS
  18. DNS1=114.114.114.114
复制代码

  1. [root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-enp125s0f0
  2. #Type使用Ethernet
  3. TYPE=Ethernet
  4. #IP分配协议改为静态分配
  5. BOOTPROTO=static
  6. NAME=enp125s0f0
  7. DEVICE=enp125s0f0
  8. ONBOOT=yes
  9. #指定桥接设备为br0
  10. BRIDGE=br0
复制代码

  1. #华为openeuler系统使用该命令,其他linux系统可以使用systemctl restart network
  2. [root@localhost ~]# nmcli con reload; nmcli con up enp125s0f0  
复制代码

  1. ##如果配置成功,会有以下输出:
  2. [root@localhost ~]# brctl show
  3. bridge name     bridge id               STP enabled     interfaces
  4. br0             8000.b04fa63d449c       no              enp125s0f0
  5. docker0         8000.0242ca5f6b53       no              veth0f04dc2
  6.                                                         veth6148d75
  7.                                                         veth7ee782c
  8.                                                         veth88dc0dd
  9.                                                         vethc335d89
  10.                                                         vethf19fe4a
  11. virbr0          8000.525400112ec1       yes             virbr0-nic
复制代码

  1. ##修改内核参数
  2. [root@localhost ~]# vi /etc/sysctl.conf
  3. net.ipv4.ip_forward=1
  4. ##执行生效
  5. ##加载指定的文件配置内核参数,-p后通常接一个文件路径
  6. ##若为空,默认加载/etc/sysctl.conf中的内核参数
  7. [root@localhost ~]# sysctl -p  
  8.     
  9. ##显示所有的内核参数      
  10. [root@localhost ~]# sysctl -a    
  11.  
  12. ##若只是临时修改内核参数的值,可以执行如下命令,但是重启后失效        
  13. [root@localhost ~]# net.ipv4.ip_forward=1
  14.  
  15. ##加载/etc/sysctl.d/目录下所有conf文件(包括/etc/sysctl.conf文件)中的内核参数
  16. [root@localhost ~]# sysctl --system  
复制代码
六、安装GNOME桌面情况

   GNOME简介
  
  1. ##更新系统
  2. [root@localhost ~]# yum update -y   
  3. ##安装字库
  4. [root@localhost ~]# yum install dejavu-fonts liberation-fonts \
  5.                     gnu-*-fonts google-*-fonts -y
  6. ##安装Xorg
  7. [root@localhost ~]# yum install xorg-* -y
  8. ##这可能会安装很多没用的包,可以使用下面的命令安装必要的xorg相关包
  9. [root@localhost ~]# yum install xorg-x11-apps xorg-x11-drivers xorg-x11-drv-ati \
  10.     xorg-x11-drv-dummy xorg-x11-drv-evdev xorg-x11-drv-fbdev xorg-x11-drv-intel \
  11.     xorg-x11-drv-libinput xorg-x11-drv-nouveau xorg-x11-drv-qxl \
  12.     xorg-x11-drv-synaptics-legacy xorg-x11-drv-v4l xorg-x11-drv-vesa \
  13.     xorg-x11-drv-vmware xorg-x11-drv-wacom xorg-x11-fonts xorg-x11-fonts-others \
  14.     xorg-x11-font-utils xorg-x11-server xorg-x11-server-utils xorg-x11-server-Xephyr \
  15.     xorg-x11-server-Xspice xorg-x11-util-macros xorg-x11-utils xorg-x11-xauth \
  16.     xorg-x11-xbitmaps xorg-x11-xinit xorg-x11-xkb-utils -y
  17. ##安装GNOME及组件
  18. [root@localhost ~]# yum install adwaita-icon-theme atk atkmm at-spi2-atk \
  19.     at-spi2-core baobab \
  20.     abattis-cantarell-fonts cheese clutter clutter-gst3 clutter-gtk cogl dconf \
  21.     dconf-editor devhelp eog epiphany evince evolution-data-server file-roller folks \
  22.     gcab gcr gdk-pixbuf2 gdm gedit geocode-glib gfbgraph gjs glib2 glibmm24 \
  23.     glib-networking gmime30 gnome-autoar gnome-backgrounds gnome-bluetooth \
  24.     gnome-builder gnome-calculator gnome-calendar gnome-characters \
  25.     gnome-clocks gnome-color-manager gnome-contacts gnome-control-center \
  26.     gnome-desktop3 gnome-disk-utility gnome-font-viewer gnome-getting-started-docs \
  27.     gnome-initial-setup gnome-keyring gnome-logs gnome-menus gnome-music \
  28.     gnome-online-accounts gnome-online-miners gnome-photos gnome-remote-desktop \
  29.     gnome-screenshot gnome-session gnome-settings-daemon gnome-shell \
  30.     gnome-shell-extensions gnome-software gnome-system-monitor gnome-terminal \
  31.     gnome-tour gnome-user-docs gnome-user-share gnome-video-effects \
  32.     gnome-weather gobject-introspection gom grilo grilo-plugins \
  33.     gsettings-desktop-schemas gsound gspell gssdp gtk3 gtk4 gtk-doc gtkmm30 \
  34.     gtksourceview4 gtk-vnc2 gupnp gupnp-av gupnp-dlna gvfs json-glib libchamplain \
  35.     libdazzle libgdata libgee libgnomekbd libgsf libgtop2 libgweather libgxps libhandy \
  36.     libmediaart libnma libnotify libpeas librsvg2 libsecret libsigc++20 libsoup \
  37.     mm-common mutter nautilus orca pango pangomm libphodav python3-pyatspi \
  38.     python3-gobject rest rygel simple-scan sushi sysprof tepl totem totem-pl-parser \
  39.     tracker3 tracker3-miners vala vte291 yelp yelp-tools \
  40.     yelp-xsl zenity -y
  41. ##启动gdm显示管理器
  42. [root@localhost ~]# systemctl enable gdm
  43. ##设置系统默认以图形界面登录
  44. [root@localhost ~]# systemctl set-default graphical.target
  45. ##查询当前开机运行级别
  46. [root@localhost ~]# systemctl get-default  
  47. ##重启生效
  48. [root@localhost ~]# reboot
复制代码
七、安装KVM及所需组件

   说明:如果宿主机没有安装图形桌面,则无需安装virt-manager。virt-manager(Virtual Machine Manager)是图形化虚机管理器,类似于Esxi的Web Console管理页面。
  1. ##安装KVM及所需组件
  2. [root@localhost ~]# yum install virt-manager virt-install bridge-utils \
  3.                     libvirt qemu-kvm virt-viewer libcanberra-gtk2  libiscsi  \
  4.                     dbus-devel  virt-clone dejavu-lgc-sans-fonts qemu-img \
  5.                     libvirt-client virt-v2v libguestfs-tools xorg-x11-xauth -y
  6. ##查看virt-manager版本号
  7. [root@localhost ~]# virt-manager --version
  8. 2.1.0
  9. ##查看virsh版本号
  10. [root@localhost ~]# virsh --version    
  11. 6.2.0
  12. ##查看qemu-img版本号
  13. [root@localhost ~]# qemu-img --version
  14. qemu-img version 6.2.0 (qemu-6.2.0-86.oe2203)
  15. ##查看virt-install版本号
  16. [root@localhost ~]# virt-install --version
  17. 2.1.0
复制代码
八、修改sshd 设置文件

  1. [root@localhost ~]# sudo vi /etc/ssh/sshd_config
  2. ##确保该配置文件有如下内容
  3. X11Forwarding yes
  4. X11DisplayOffset 10
  5. X11UseLocalhost no
  6. PermitTunnel yes
  7. ##重启 sshd 服务
  8. [root@localhost ~]# systemctl restart sshd
复制代码
九、启动libvirt并设置开机自启动

  1. ##启动
  2. [root@localhost ~]# systemctl start libvirtd
  3. ##设置开机自启
  4. [root@localhost ~]# systemctl enable libvirtd
  5. ##查看libvirt服务是否启动成功
  6. ##若服务处于running状态,说明服务启动成功
  7. ##可以正常使用libvirt提供的virsh命令行工具
  8. [root@localhost ~]# systemctl status libvirtd
复制代码
十、创建镜像目次和磁盘文件目次

  1. ##查看物理机磁盘空间
  2. ##通过df -hT发现/home目录空间最大
  3. [root@localhost ~]# df -hT
  4. Filesystem                 Type      Size  Used Avail Use% Mounted on
  5. devtmpfs                   devtmpfs  4.0M     0  4.0M   0% /dev
  6. tmpfs                      tmpfs     220G     0  220G   0% /dev/shm
  7. tmpfs                      tmpfs      88G   60M   88G   1% /run
  8. tmpfs                      tmpfs     4.0M     0  4.0M   0% /sys/fs/cgroup
  9. /dev/mapper/openeuler-root ext4       69G   15G   51G  23% /
  10. tmpfs                      tmpfs     220G     0  220G   0% /tmp
  11. /dev/sda2                  ext4      974M  204M  704M  23% /boot
  12. /dev/sda1                  vfat      599M  6.0M  593M   2% /boot/efi
  13. /dev/mapper/openeuler-home ext4      1.7T  174G  1.5T  11% /home
  14. tmpfs                      tmpfs      44G   72K   44G   1% /run/user/1003
  15. ##建立目录用来存放iso镜像文件
  16. [root@localhost ~]# mkdir /home/iso
  17. ##建立目录用来存放qcow2磁盘文件
  18. [root@localhost ~]# mkdir /home/qcow2
复制代码
十一、创建捏造机的磁盘文件

   说明:通过下令行方式创建一个捏造机前,必要创建该捏造机的磁盘文件。
  1. ##进入磁盘文件目录
  2. [root@localhost ~]# cd /home/qcow2
  3. ##创建虚拟机的磁盘文件
  4. ##这里创建了一个名为vm1.qcow2,空间为400GB的动态扩展的qcow2格式的磁盘
  5. ##这里的400GB只是磁盘的最大值,没有被写入数据前只有不到200KB大小
  6. [root@localhost ~]# qemu-img create -f qcow2 vm1.qcow2 400G
  7. Formatting 'vm1.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=429496729600 lazy_refcounts=off refcount_bits=16 cache=writeback
  8. ##查看磁盘文件vm1.qcow2的卷信息,里面disk size是其实际占用的宿主机磁盘大小
  9. ##上面的400GB只是磁盘的最大值,这里可以看到,没有被写入数据前只有200KB大小
  10. [root@localhost ~]# qemu-img info vm1.qcow2
  11. image: vm1.qcow2
  12. file format: qcow2
  13. virtual size: 400 GiB (429496729600 bytes)
  14. disk size: 200 KiB
  15. cluster_size: 65536
  16. Format specific information:
  17.     compat: 1.1
  18.     compression type: zlib
  19.     lazy refcounts: false
  20.     refcount bits: 16
  21.     corrupt: false
  22.     extended l2: false
复制代码
十二、创建捏造机

1)方法一:下令行基于iso镜像文件创建捏造机

  1. ##创建一个CPU8核、内存16GB、磁盘空间400GB的虚拟机
  2. [root@localhost ~]# virt-install --name vm1 --ram=16384 --vcpus=8 \
  3.                     --location=/home/iso/openEuler-22.03-LTS-SP1-aarch64-dvd.iso \
  4.                     --disk path=/home/qcow2/vm1.qcow2,size=400 --bridge=br0 \
  5.                     --graphics=none --console=pty,target_type=serial \
  6.                     --extra-args="console=ttyAMA0 console=ttyS0" --autostart
复制代码
  参数说明:
  
    
  开始安装,设置语言、时区、安装源、网络、暗码等信息。
  1. Installation
  2. 1) [x] Language settings                 2) [x] Time settings
  3.        (English (United States))                (Asia/Shanghai timezone)
  4. 3) [!] Installation source               4) [!] Software selection
  5.        (Processing...)                          (Processing...)
  6. 5) [!] Installation Destination          6) [!] Network configuration
  7.        (Processing...)                          (Not connected)
  8. 7) [!] Root password                     8) [!] User creation
  9.        (Root account is disabled)               (No user will be created)
  10. Please make a selection from the above ['b' to begin installation, 'q' to quit,
  11. 'r' to refresh]: 5 <=======输入5然后按Enter键,设置安装目录
  12. Probing storage...
  13. ================================================================================
  14. ================================================================================
  15. Installation Destination
  16. 1) [x] QEMU HARDDISK: 400 GiB (sda)
  17. 1 disk selected; 400 GiB capacity; 400 GiB free
  18. Please make a selection from the above ['c' to continue, 'q' to quit, 'r' to
  19. refresh]: c <=======输入c继续
  20. ================================================================================
  21. ================================================================================
  22. Partitioning Options
  23. 1) [ ] Replace Existing Linux system(s)
  24. 2) [x] Use All Space
  25. 3) [ ] Use Free Space
  26. 4) [ ] Manually assign mount points
  27. Installation requires partitioning of your hard drive. Select what space to use
  28. for the install target or manually assign mount points.
  29. Please make a selection from the above ['c' to continue, 'q' to quit, 'r' to
  30. refresh]: c <=======输入c继续
  31. ================================================================================
  32. ================================================================================
  33. Partition Scheme Options
  34. 1) [ ] Standard Partition
  35. 2) [ ] Btrfs
  36. 3) [x] LVM
  37. 4) [ ] LVM Thin Provisioning
  38. Select a partition scheme configuration.
  39. Please make a selection from the above ['c' to continue, 'q' to quit, 'r' to
  40. refresh]: 1 <=======输入1然后按Enter键,选择Standard Partition
  41. ================================================================================
  42. ================================================================================
  43. Partition Scheme Options
  44. 1) [x] Standard Partition
  45. 2) [ ] Btrfs
  46. 3) [ ] LVM
  47. 4) [ ] LVM Thin Provisioning
  48. Select a partition scheme configuration.
  49. Please make a selection from the above ['c' to continue, 'q' to quit, 'r' to
  50. refresh]: c <=======输入c继续
  51. ================================================================================
  52. ================================================================================
  53. Installation
  54. 1) [x] Language settings                 2) [x] Time settings
  55.        (English (United States))                (Asia/Shanghai timezone)
  56. 3) [x] Installation source               4) [x] Software selection
  57.        (Local media)                            (Minimal Install)
  58. 5) [x] Installation Destination          6) [ ] Network configuration
  59.        (Automatic partitioning                  (Not connected)
  60.        selected)
  61. 7) [!] Root password                     8) [!] User creation
  62.        (Root account is disabled)               (No user will be created)
  63. Please make a selection from the above ['b' to begin installation, 'q' to quit,
  64. 'r' to refresh]: 7 <=======输入7然后按Enter键,设置root账号的密码
  65. ================================================================================
  66. ================================================================================
  67. Root password
  68. 1) [ ] SM3 encrypt
  69. Please make a selection from the above ['c' to continue, 'q' to quit, 'r' to
  70. refresh]: 1 <=======输入1然后按Enter键,选择SM3加密方式
  71. ================================================================================
  72. ================================================================================
  73. Root password
  74. 1) [x] SM3 encrypt
  75. Please make a selection from the above ['c' to continue, 'q' to quit, 'r' to
  76. refresh]: c <=======输入c继续
  77. ================================================================================
  78. ================================================================================
  79. Root password
  80. Please select new root password. You will have to type it twice.
  81. Password: <=======输入密码然后按Enter键,这里不会反显
  82. Password (confirm): <=======再次输入确认密码,然后按Enter键,这里也不会反显
  83. ================================================================================
  84. ================================================================================
  85. Installation
  86. 1) [x] Language settings                 2) [x] Time settings
  87.        (English (United States))                (Asia/Shanghai timezone)
  88. 3) [x] Installation source               4) [x] Software selection
  89.        (Local media)                            (Minimal Install)
  90. 5) [x] Installation Destination          6) [ ] Network configuration
  91.        (Automatic partitioning                  (Not connected)
  92.        selected)
  93. 7) [x] Root password                     8) [ ] User creation
  94.        (Root password is set)                   (No user will be created)
  95. Please make a selection from the above ['b' to begin installation, 'q' to quit,
  96. 'r' to refresh]: b <=======输入b然后按Enter键就开始安装
  97. ================================================================================
  98. ================================================================================
  99. ......
  100. ......
  101. Installation complete
  102. Use of this product is subject to the license agreement found at:
  103. /usr/share/openEuler-release/EULA
  104. Installation complete. Press ENTER to quit:<=======安装完成,按Enter键重启虚拟机
  105. 重启后就进入到虚拟机的登录界面
  106. ......
  107. [  OK  ] Finished OpenEuler Security Tool.
  108. [FAILED] Failed to start Network Manager Wait Online.  <======= 该问题可以忽略,登陆虚拟机,配置网络后即可解决
  109. See 'systemctl status NetworkManager-wait-online.service' for details.
  110. [  OK  ] Reached target Network is Online.
  111.          Starting Crash recovery kernel arming...
  112.          Starting Notify NFS peers of a restart...
  113.          Starting System Logging Service...
  114. [  OK  ] Started Notify NFS peers of a restart.
  115. [  OK  ] Started System Logging Service.
  116. [  OK  ] Reached target Multi-User System.
  117.          Starting Record Runlevel Change in UTMP...
  118. [  OK  ] Finished Record Runlevel Change in UTMP.
  119. [  OK  ] Finished Crash recovery kernel arming.
  120. localhost login: 
  121. 登录成功后,这时,如果要退出虚拟机,按 Ctrl + ] 即可。
复制代码
  留意:
  
  2)方法二:下令行基于基础qcow2磁盘文件(镜像模板),比如方法一中安装设置好的捏造机vm1的磁盘文件vm1.qcow2,创建捏造机。参考:重新构建KVM捏造机基础镜像

   说明:
  这里,我们基于方法一中安装设置好的捏造机vm1的磁盘文件vm1.qcow2作为镜像模板来创建捏造机vm2。
  
  为了制止和捏造机vm1的磁盘文件vm1.qcow2冲突,我们复制vm1.qcow2,并改名为vm2.qcow2。
  1. ##进入磁盘文件目录
  2. [root@localhost ~]# cd /home/qcow2
  3. ##复制vm1.qcow2,并改名为vm2.qcow2
  4. [root@localhost ~]# cp vm1.qcow2 vm2.qcow2
复制代码

  1. [root@localhost ~]# virt-install --name vm2 --ram=16384 --vcpus=8 \
  2.                     --disk path=/home/qcow2/vm2.qcow2,bus=virtio \
  3.                     --network bridge=br0,model=virtio --graphics=none \
  4.                     --console=pty,target_type=serial --hvm --virt-type kvm \
  5.                     --noautoconsole --import --autostart
复制代码
  参数说明:
  
  3)方法三:在一台Windows呆板上,通过VNC客户端,远程毗连宿主机上的VNC服务端,登录进入GNOME桌面情况后,在terminal下令窗口中输入virt-manager下令打开Virtual Machine Manager客户端,就可以通过图形化界面的方式进行捏造机管理了(包罗:创建/修改/删除捏造机等操作)。详见:VNC的安装部署-CSDN博客
   留意:条件条件是在宿主机系统中安装了图形化桌面情况。详见本文:六、安装OpenEuler GNOME桌面情况。
  十三、设置捏造机的网络


  1. [root@localhost ~]# virsh console vm1
  2. Connected to domain vm1
  3. Escape character is ^]
复制代码

  1. [root@localhost ~]# ip ad  
  2. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
  3.     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  4.     inet 127.0.0.1/8 scope host lo
  5.        valid_lft forever preferred_lft forever
  6.     inet6 ::1/128 scope host 
  7.        valid_lft forever preferred_lft forever
  8. 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
  9.     link/ether 52:54:00:65:d3:3f brd ff:ff:ff:ff:ff:ff
复制代码

  1. [root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
  2. TYPE=Ethernet
  3. PROXY_METHOD=none
  4. BROWSER_ONLY=no
  5. BOOTPROTO=static
  6. DEFROUTE=yes
  7. IPV4_FAILURE_FATAL=no
  8. IPV6INIT=yes
  9. IPV6_AUTOCONF=yes
  10. IPV6_DEFROUTE=yes
  11. IPV6_FAILURE_FATAL=no
  12. NAME=enp1s0
  13. UUID=009a3243-b57b-4845-a43b-2045ca7aa79a
  14. DEVICE=enp1s0
  15. ONBOOT=yes
  16. IPADDR=192.168.112.61
  17. PREFIX=24
  18. GATEWAY=192.168.112.1
  19. DNS1=114.114.114.114
复制代码

  1. #华为openeuler系统使用该命令,其他linux系统可以使用systemctl restart network 
  2. [root@localhost network-scripts]# nmcli con reload; nmcli con up eth0
复制代码
十四、KVM捏造机常见管理下令(在宿主机中实行)

   参考:KVM-捏造化管理工具 - 知乎
  1. ## 从虚拟机退出到宿主机
  2. [root@localhost ~]# Ctrl + ]
  3. ## 查看KVM进程 
  4. [root@localhost ~]# ps axu |grep kvm      
  5. ## 查看libvirt的版本信息                 
  6. [root@localhost ~]# virsh version  
  7. ## 列出当前有多少个虚拟机,以及其状态                         
  8. [root@localhost ~]# virsh list    
  9. ## 列出当前有多少个虚拟机,包括关机状态的虚拟机                          
  10. [root@localhost ~]# virsh list --all          
  11. ## 进入指定的虚拟机,进入的时候还需要按一下回车             
  12. [root@localhost ~]# virsh console vm1                    
  13. ## 编辑虚拟机的配置    
  14. [root@localhost ~]# virsh edit vm1      
  15. ## 使用XML文件创建一个虚拟机                   
  16. [root@localhost ~]# virsh create vm1.xml            
  17. ## 使用XML文件定义一个虚拟机,但是不启动
  18. [root@localhost ~]# virsh define vm1.xml    
  19. ## 启动虚拟机
  20. [root@localhost ~]# virsh start vm1                          
  21. ## 重启虚拟机
  22. [root@localhost ~]# virsh reboot vm1      
  23. ## 关闭虚拟机,比较优雅地做法,按部就班的关闭虚拟机
  24. [root@localhost ~]# virsh shutdown vm1                    
  25. ## 强制停止虚拟机,是比较暴力的做法,相当于物理机的直接关闭电源
  26. [root@localhost ~]# virsh destroy vm1                        
  27. ## 彻底销毁虚拟机,会删除虚拟机配置文件,但不会删除虚拟磁盘
  28. [root@localhost ~]# virsh undefine vm1 --nvram              
  29. ## 设置宿主机开机时该虚拟机也开机
  30. [root@localhost ~]# virsh autostart vm1      
  31. ## 解除开机启动
  32. [root@localhost ~]# virsh autostart --disable vm1      
  33. ## 列出开机自动启动的虚拟机
  34. [root@localhost ~]# virsh list --autostart        
  35. ## 挂起虚拟机
  36. [root@localhost ~]# virsh suspend vm1                    
  37. ## 恢复挂起的虚拟机
  38. [root@localhost ~]# virsh resume vm1                        
  39. ## 当机器是运行状态时,卸载虚拟磁盘命令(只是当前有效,重启后又回来了)
  40. [root@localhost ~]# virsh detach-disk vm1 sdb        
  41. ## 永久添加磁盘
  42. [root@localhost ~]# virsh attach-disk vm1 \
  43.                     /var/lib/libvirt/images/disk1/additional/vm1/file1 sdb \
  44.                     --subdriver=qcow2 --config --live --persistent                                                
  45. ## 查看虚拟机有几块网卡 
  46. [root@localhost ~]# virsh domiflist vm1          
  47. ## 查看虚拟机的磁盘
  48. [root@localhost ~]# virsh domblklist vm1                    
  49. ## 查看虚拟机的cpu数量
  50. [root@localhost ~]# virsh vcpucount vm1  
复制代码
十五、常见问题

【问题一】
问题形貌:在ARM服务器上,virt-install利用下令行模式安装捏造机时,若--extra-args加入console=tty0,创建捏造机将失败,下令实行某个阶段,就会卡死无法继续运行。
解决办法:可以把console=tty0改为console=ttyS0或者console=ttyAMA0。只要没有console=tty0就好了。
【问题二】
问题形貌:
KVM创建快照失败 “Operation not supported: internal snapshots of a VM with pflash based firmware are not supported”
解决办法:
目前没有办法创建内部快照,官方没有修复方法。唯一的办法是利用外部快照。
参考URL:
https://unix.stackexchange.com/questions/663372/error-creating-snapshot-operation-not-supported-internal-snapshots-of-a-vm-wit
https://fabianlee.org/2021/01/10/kvm-creating-and-reverting-libvirt-external-snapshots/
【问题三】
问题形貌:cannot undefine domain with nvram
解决办法:
[root@localhost ~]# virsh undefine vm1 --nvram   #添加--nvram参数即可

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 IT评测·应用市场-qidao123.com (https://dis.qidao123.com/) Powered by Discuz! X3.4