cat /proc/cpuinfo | egrep 'vmx|svm'
注:如果是在vmware上跑的话,需要勾选虚拟化引擎:
setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=permissive/g" /etc/selinux/config
systemctl stop firewalld
systemctl disable firewalld
systemctl stop iptables
systemctl disable iptables
(1) 宿主机桥接工具
yum -y install bridge-utils
(2) 增加宿主机的br0网络配置
cat >/etc/sysconfig/network-scripts/ifcfg-br0<
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_AUTOCONF=no
IPV6_DEFROUTE=no
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=br0
DEVICE=br0
ONBOOT=yes
USERCTL=no
EOF
# 说明:这个br0设备大多数情况是没有的,需要自己创建,同时这个设备是可以有网址的,作为宿主机的网卡使用。
(3) 编辑修改网络设备脚本文件,修改网卡设备eth0(或ens33),增加:
vim /etc/sysconfig/network-scripts/ifcfg-ens33
BRIDGE=br0
(4) 重启网络,
systemctl restart network
(5) 校验桥接接口,并查看br0的IP地址
[root@localhost ~]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.000c29931680 no ens33
[root@localhost ~]# ifconfig
br0: flags=4163
inet 172.17.203.92 netmask 255.255.255.0 broadcast 172.17.203.255
inet6 fe80::1872:9ff:fe97:c85e prefixlen 64 scopeid 0x20
ether 00:0c:29:93:16:80 txqueuelen 1000 (Ethernet)
RX packets 796 bytes 74825 (73.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 302 bytes 31828 (31.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens33: flags=4163
ether 00:0c:29:93:16:80 txqueuelen 1000 (Ethernet)
RX packets 10987 bytes 12441197 (11.8 MiB)
RX errors 0 dropped 6 overruns 0 frame 0
TX packets 4218 bytes 367445 (358.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 1000 (Local Loopback)
RX packets 51 bytes 15740 (15.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 51 bytes 15740 (15.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
yum -y install qemu-kvm python-virtinst libvirt libvirt-python virt-manager libguestfs-tools virt-install
kvm相关安装包及其作用:
systemctl enable libvirtd
systemctl start libvirtd
grubby --update-kernel=ALL --args="console=ttyS0"
reboot
在kvm libvirt 中,有两个工具用来安装虚拟客户机,virt-manager 和 virt-install;前者是通过图形界面安装,后者则是通过命令行的形式进行安装虚拟客户机 。本节主要记录下通过 virt-install 安装客户机的步骤。
执行命令:
qemu-img create -f qcow2 /var/lib/libvirt/images/centos7-1.qcow2 10G
说明:qemu-img 主要用来创建虚拟客户机所需的磁盘, create 表示创建,-f qcow2 表示创建一个格式为 qcow2 的磁盘, /var/lib/libvirt/images/centos7-1.qcow2 表示创建的磁盘名称及磁盘文件,10G 表示该磁盘可用大小。
virt-install --virt-type=kvm --name=centos7-1 --vcpus=2 --memory=1024 --location=/home/CentOS-7-x86_64-Minimal-1908.iso --disk path=/var/lib/libvirt/images/centos7-1.qcow2,size=10,format=qcow2 --network bridge=br0 --graphics none --extra-args='console=ttyS0' --force
注意:.iso镜像文件一定放到/home 或者根目录重新创建目录,不然会因为权限报错,无法创建虚拟机。
命令说明:
virt-install \
--virt-type=kvm \ 虚拟机类型
--name=centos7-1 \ 表示虚拟客户机名称
--vcpus=2 \ 表示给虚拟客户机分配的虚拟CPU数量
--memory=1024 \ 内存大小
--location=/home/data/CentOS-7-x86_64-Minimal-1908.iso \ 指定客户机安装镜像文件路径
--disk path=/var/lib/libvirt/images/centos7-1.qcow2,size=15,format=qcow2 \ 客户端磁盘的位置及格式
--network bridge=br0 \ 客户端网卡配置(机器默认会有virbr0,这里的br0为上一章节中配置过的)
--graphics none \ 不用图像配置界面
--extra-args='console=ttyS0' \ 表示使用 console ttyS0 进行管理
--force
上面创建虚拟机命令最终需要你配置系统基础设置,带 [!] 基本都是要配置的,按照顺序往下配置,按对用的数字以此进行设置。
基本设置如下:
最后,按下b开始安装过程。
注:图形化VNC安装可参考:CentOS 7 使用 virt-install + vnc 图形界面 创建虚拟机_一直被模仿,从未被超越-CSDN博客
# virsh list --all
# virsh console centos7-1
退出命令:
# ctrl + ]
# virsh start centos7-1 # 虚拟机开启(启动):
# virsh reboot centos7-1 # 虚拟机重新启动
# virsh shutdown centos7-1 # 虚拟机关机
# virsh destroy centos7-1 # 强制关机(强制断电)
# virsh suspend centos7-1 # 暂停(挂起)KVM 虚拟机
# virsh resume centos7-1 # 恢复被挂起的 KVM 虚拟机
# virsh undefine centos7-1 # 该方法只删除配置文件,磁盘文件未删除
# virsh autostart centos7-1 # 随物理机启动而启动(开机启动)
# virsh autostart --disable centos7-1 # 取消标记为自动开始(取消开机启动)
# virsh shutdown centos7-1
# virt-clone -o centos7-1 -n centos7-2 -f /data/centos7-2.qcow2
-o 要克隆的原虚拟机名字
-n 克隆后新虚拟机的名字
-f 新虚拟机磁盘镜像文件的存储位置
# virsh list --all //列出所有虚拟机
# virsh shutdown centos7-5 //关闭centos7-5虚拟机
# virsh snapshot-create-as centos7-5 centos7-5-s1 //为虚拟机centos7-5创建快照centos7-5-s1
# virsh snapshot-list centos7-5 //列出虚拟机test1的所有快照
# virsh snapshot-info centos7-5 centos7-5-s1 //查看快照的详细信息
# virsh snapshot-delete centos7-5 centos7-5-s1 //删除虚拟机centos7-5的快照centos7-5-s1
// 恢复快照
# virsh shutdown centos7-5
# virsh snapshot-revert centos7-5 centos7-5-s1
# virsh start centos7-5
[root@localhost ~]# virsh list --all
Id Name State
----------------------------------------------------
1 centos7-2 running
- centos7-0 shut off
- centos7-3 shut off
- centos7-4 shut off
- centos7-5 shut off
- centos7-6 shut off
- centos7-7 shut off
[root@localhost ~]# virsh dumpxml centos7-2 | grep mac
/machine
hvm
[root@localhost ~]# arp -a | grep 52:54:00:df:08:22
? (192.168.122.110) at 52:54:00:df:08:22 [ether] on virbr0
或者
[root@localhost ~]# virsh domifaddr centos7-0
Name MAC address Protocol Address
-------------------------------------------------------------------------------
vnet0 52:54:00:bd:bd:5b ipv4 192.168.122.94/24
(1) 安装基础依赖
yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install git python-pip libvirt-python libxml2-python python-websockify supervisor nginx
yum install apt install -y python3-pip
yum install -y gcc make autoconf automake git python3-pip python3-requests python3-mock gettext pkgconf xsltproc python3-dev pep8 pyflakes python3-yaml
yum install -y systemd logrotate python3-psutil python3-ldap python3-lxml python3-websockify python3-jsonschema openssl nginx python3-cherrypy3 python3-cheetah python3-pampy python-m2crypto gettext python3-openssl
(2) 安装wok和kimchi
wget https://github.com/kimchi-project/kimchi/releases/download/2.5.0/wok-2.5.0-0.el7.centos.noarch.rpm
yum install -y ./wok-2.5.0-0.el7.centos.noarch.rpm
wget https://github.com/kimchi-project/kimchi/releases/download/2.5.0/kimchi-2.5.0-0.el7.centos.noarch.rpm
yum install -y ./kimchi-2.5.0-0.el7.centos.noarch.rpm
(3) 启动服务
systemctl start nginx
systemctl enable nginx
systemctl start wokd
systemctl enable wokd
(4) 浏览器访问
https://172.17.203.92:8001/login.html
(必须加https不让无法登陆)
账号和密码为主机root的密码和账号