Centos 安装 KVM虚拟化工具 超云服务器 VMware

需求:在裸机(超云服务器)上安装centos7,并在centos7上安装虚拟化工具,且再建三个虚拟机(centos/windows)

目录

需求:在裸机(超云服务器)上安装centos7,并在centos7上安装虚拟化工具,且再建三个虚拟机(centos/windows)

准备工作

安装centos7

启动需要安装系统的服务器并安装centos7

安装KVM

KVM常用命令


准备工作

  1. 8G或8G以上的空U盘一个(U盘作为启动盘)

  2. Fedora Media Writer制作系统启动盘工具

  3. C.centos镜像文件一个(建议到官网下载:https://www.centos.org/download/),此处我下载的是CentOS-7-x86_64-DVD-1708.iso

    安装centos7

安装centos7

  1. 将U盘插入电脑,制作U盘启动盘
    1. 等待文件写入完成,启动盘就做好了。

启动需要安装系统的服务器并安装centos7

  1. 给磁盘做好raid(根据实际需求来,做raid是更好的管理好硬盘,在做raid之前,确保里面没东西或者提前做好备份)
    1. 启动服务器长按DEL键,看到屏幕上有打印信息,按Ctrl+R进入raid设置
    2. (若需要重新做raid)若已做好raid,先删除所有的raid,操作步骤:选中根节点按F2 》选中remove ...config..》回车即可。
    3. 创建raid(根据需求来,我这里只做raid0,可做多个raid),确定好那些磁盘要合并,选中需要合并的磁盘回车(单个操作),后面就可以看到序号,然后按方向键“↓”,进入Advanced 高级设置,将Initialize勾选上,注意!!!注意!!!注意!!!已勾选里面会显示"X",设置完成后保存,回到Advanced 按钮的地方,点击旁边的OK, raid0设置好了下图仅供参考
    4. 初始化raid0,选中刚做好的raid0,按下F2,设置fast init  初始化(格式化),保存。重启服务器。
    5. 重启按住DEL键,根据提示进入BIOS界面,进入Boot设置启动方式的顺序。第一个设置为从U盘启动。第二个设置为从硬盘启动。保存退出即可完成设置。重启,不需要做任何操作。直接会进入安装步骤。
    6. 正式开始安装centos7
  2. 安装KVM

    1. 查看cpu是否支持虚拟化

      [root@localhost ~]# grep -E '(vmx|svm)' /proc/cpuinfo **

    2. 安装qemu-kvm(用户态管理工具),libvirt(命令行管理工具),virt-install(安装kvm工具),bridge-utils(桥接设备管理工具)

      [root@localhost ~]# yum install -y qemu-kvm libvirt virt-install bridge-utils

    3.  

       确保加载kvm模块

      [root@localhost ~]# lsmod |grep kvm
      kvm_intel             174841  0
      kvm                   578518  1 kvm_intel
      irqbypass              13503  1 kvm

    4.  

       

      #如果没有加载,运行一下命令
      [root@localhost ~]# modprobe kvm
      [root@localhost ~]# modprobe kvm-intel
    5.  

       

      启动libvirtd服务

      [root@localhost ~]# systemctl enable libvirtd
      [root@localhost ~]# systemctl start  libvirtd
      [root@localhost ~]# systemctl status  libvirtd

    6.  

       

       

      由于要用virt-manager图形化安装虚拟机,所以还需要安装桌面

      [root@localhost ~]# yum grouplist
      [root@localhost ~]# yum groupinstall "GNOME Desktop" -y

    7.  

      配置中文桌面   vim /etc/profile  添加以下语句

      grep -E "^[ \t]*export[ \t]+LANG[ \t]*=" /etc/profile&& y="yes" || y="no"
      if [[ "$y" = "yes" ]]; then
      sed -r -i -e '/^[ \t]*export[ \t]+LANG[ \t]*=/c\export LANG="zh_CN.UTF-8"' /etc/profile
      else
      echo 'export LANG="zh_CN.UTF-8"'
      fi
      执行此命令使它生效:source /etc/profile

    8. 安装virt-manager

      [root@localhost ~]# yum -y install virt-manager

    9.  

      xshell链接

       

       

      [root@localhost ~]# virt-manager
    10. 提前将ISO系统镜像存放到服务器的一个目录里,比如/data/iso

      [root@localhost ~]# mkdir -p /data/{iso,kvmstorage}
      [root@localhost ~]# cd /data/iso/
      [root@localhost iso]# ll
      总用量 4217748
      -rw-r--r-- 1 root root  950009856 11月 22 15:24 CentOS-7-x86_64-Minimal-1804.iso
      -rw-r--r-- 1 root root 3368962048 3月  23 2012 cn_windows_server_2008_r2.iso

    11. 新建虚拟机

    12.  

      KVM安装完成!

KVM常用命令

KVM虚拟机的管理主要是通过virsh命令对虚拟机进行管理

命令帮助
[root@localhost ~]# virsh --help
查看虚拟机状态
[root@localhost ~]# virsh list --all
 Id    名称                         状态
----------------------------------------------------
 4     win2k8r2                       running

关机
[root@localhost ~]# virsh shutdown win2k8r2

强制关闭电源
[root@localhost ~]# virsh destroy win2k8r2

通过配置文件创建虚拟机
[root@localhost ~]# virsh create /etc/libvirt/qemu/win2k8r2.xml

设置虚拟机开机自启
[root@localhost ~]# virsh autostart win2k8r2
[root@localhost ~]# ll /etc/libvirt/qemu/autostart/
总用量 0
lrwxrwxrwx 1 root root 30 1月  24 13:06 win2k8r2.xml -> /etc/libvirt/qemu/win2k8r2.xml

到处虚拟机配置文件
[root@localhost ~]# virsh dumpxml win2k8r2 > /etc/libvirt/qemu/win2k8r2_bak.xml

删除虚拟机(该命令只删除配置文件,并不删除磁盘文件)
[root@localhost ~]# virsh undefine win2k8r2

通过导出备份的配置文件恢复原KVM虚拟机的定义,并重新定义虚拟机。
[root@localhost ~]# mv /etc/libvirt/qemu/win2k8r2_bak.xml /etc/libvirt/qemu/win2k8r2.xml
[root@localhost ~]# virsh define /etc/libvirt/qemu/win2k8r2.xml

编辑配置文件
[root@localhost ~]# virsh edit win2k8r2

挂起
[root@localhost ~]# virsh suspend win2k8r2

恢复
[root@localhost ~]# virsh resume win2k8r2

 

猜你喜欢

转载自blog.csdn.net/qq_33415990/article/details/112279504
今日推荐