在centos7安装KVM及使用图形化界面生成与管理虚机

时间:2024-03-08 08:49:40

一、VMware虚拟机上的CPU开启支持虚拟化

 二、Virsh的安装

      1)安装kvm和libvirted

#yum install  -y qemu-kvm openssl  #安装虚拟化工具软件包和远程连接 
#
yum install -y libvirt #安装virt-install工具,用来创建虚拟机
#yum install -y virt-manager #安装KVM 图形化管理工具

     2)  启动libvirtd,并将它设为开机启动    

#systemctl start libvirtd && systemctl enable libvirtd

     3) 启动后使用ifconfig查看,发现会多出来一块virbr0的网卡说明libvirtd启动成功,如果默认没有ifconfig命令,使用yum install -y net-tools安装,如果能看见virbr0,就表示成功 

#yum install -y net-tools
#ifconfig
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.129  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::20c:29ff:fef9:6739  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:f9:67:39  txqueuelen 1000  (Ethernet)
        RX packets 13022  bytes 15452626 (14.7 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5237  bytes 568995 (555.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 00:00:00:00:00:00  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

      4) SecureCRT通过virt-manager启用图形化界面

         1、windows安装Xming 
           下载地址:https://sourceforge.net/projects/xming/ 
           下载完安装好启动就行了。 

          2、设置一下SecureCRT的会话选项   

                     

 

             3. vi /etc/ssh/sshd_config,确定下图的设置为yes 

 

                       

 

              4、CentOS7.2最小化安装后(不用安装GUI),需要安装支持图形几个X11的rpm包,其中xorg-x11-server-utils是图形化主安装包,而xorg-x11-apps则包含了测试要用的的xclock命令。     

[root@localhost ~]# yum install -y xorg-x11-server-utils xorg-x11-apps xorg-x11-utils

              5、Windows主机上双击运行Xmanager - Passive,会在任务栏中出现Xmanager - Passive的图标,鼠标悬浮其上会显示图形化监听的设备为[:0.0]

         

            6、在linux主机上以root用户执行xhost +命令打开x-window的访问权限(会提示xhost:  unable to open display "",不用管它)。如果服务器是图形化界面启动的,xhost +命令可以不用执行,如果不是,则运行下面的命令

[root@localhost ~]# xhost +
access control disabled, clients can connect from any host

            7、切换到其他需要执行图形化命令的用户,如virt-manager,定义图形化显示的地址变量,其中ip地址为运行CRT的windows主机地址,监听设备为上面Xmanager - Passive的监听的设备

[root@localhost ~]$  export DISPLAY=192.168.2.11:0.0

           8、启用virt-manager命令

#virt-manager

     

   

 报错汇总:

 错误一:        

# virt-manager 

Unable to initialize GTK: could not open display

    确保有安装xorg-x11-xauth

    #yum -y install xorg-x11-xauth

   退出secureCRT后从新登录,然后再调用virt-manager即可。

 错误二:

# virt-manager 

process 2827: D-Bus library appears to be incorrectly set up; failed to read machine uuid: Failed to open "/var/lib/dbus/machine-id": No such file or directory

See the manual page for dbus-uuidgen to correct this issue.

  D-Bus not built with -rdynamic so unable to print a backtrace

确保libvirtd开启状态:

# /etc/init.d/libvirtd status libvirtd is stopped # /etc/init.d/libvirtd start

 

 三、新建一台KVM虚机