kvm创建虚拟机,特别注意.iso镜像文件一定放到/home,/tmp 或者根目录重新创建目录,不然会因为权限报错,无法创建虚拟机。
下载镜像 wget mv CentOS-7-x86_64-Minimal-2003.iso /tmp/ 安装虚拟机 mkdir /var/kvm/images/ -p virt-install \ --name test1 \ --ram 2096 \ --disk path=http://www.likecs.com/var/kvm/images/test.img,size=8 \ --vcpus 1 \ --os-type linux \ --os-variant rhel7 \ --network bridge=virbr0 \ --graphics none \ --console pty,target_type=serial \ --location /tmp/CentOS-7-x86_64-Minimal-2003.iso \ --extra-args 'console=ttyS0,115200n8 serial' virt-install \ --name test2 \ --ram 2096 \ --disk path=http://www.likecs.com/var/kvm/images/test2.img,size=8 \ --vcpus 1 \ --os-type linux \ --os-variant rhel7 \ --network bridge=virbr0 \ --graphics none \ --console pty,target_type=serial \ --location /tmp/CentOS-7-x86_64-Minimal-2003.iso \ --extra-args 'console=ttyS0,115200n8 serial'参数介绍
命令行配置系统上面创建虚拟机命令最终需要你配置系统基础设置,带 [!] 基本都是要配置的,按照顺序往下配置,按对用的数字以此进行设置。
命令行操作界面
Installation 1) [x] Language settings 2) [!] Time settings (English (United States)) (Timezone is not set.) 3) [!] Installation source 4) [!] Software selection (Processing...) (Processing...) 5) [!] Installation Destination 6) [x] Kdump (No disks selected) (Kdump is enabled) 7) [ ] Network configuration 8) [!] Root password (Not connected) (Password is not set.) 9) [!] User creation (No user will be created) Please make your choice from above ['q' to quit | 'b' to begin installation | 'r' to refresh]:1.Time settings设置时区
Installation Destination 安装磁盘
按b进入安装, 等待几分钟安装完成即可
连接虚拟机通过 virsh console <虚拟机名称> 命令来连接虚拟机
# 查看虚拟机 virsh list # 查看在运行的虚拟机 virsh list --all # 查看所有虚拟机 Id Name State ---------------------------------------------------- 7 centos72 running连接虚拟机
virsh console centos72退出虚拟机
`exit 退出系统到登录界面` `快捷键: ctrl+]` `ctrl +5` `从虚拟机登录页面,退出到宿主机命令行页面` `control +]` 配置网络 配置虚拟机网络 [root@kvm-47 ~]# virsh console test2 Connected to domain test2 Escape character is ^] CentOS Linux 7 (Core) Kernel 3.10.0-1127.el7.x86_64 on an x86_64 localhost login: root Password: Last login: Wed Nov 4 14:20:45 on ttyS0 [root@localhost ~]# dhclient eth0 [root@localhost ~]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 52:54:00:40:16:b0 brd ff:ff:ff:ff:ff:ff inet 192.168.122.59/24 brd 192.168.122.255 scope global dynamic eth0 valid_lft 3522sec preferred_lft 3522sec [root@localhost ~]# yum install -y net-tools [root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 TYPE=Ethernet TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=dhcp DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=eth0 UUID=55bac306-da97-49f8-9838-450002d702dc DEVICE=eth0 // 此处修改为yes ONBOOT=yes [root@localhost ~]# systemctl restart network