centos7安装kvm

centos7安装kvm



由于centos 7较之前的版本有了很大的变化,目前测试了centos 7 环境下kvm的安装与搭建,具体如下。


一、安装kvm 软件

由于之前已做过较详细的 kvm 的安装与总结,这里只大致列下步骤:


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

[root@zw ~]# lsmod | grep kvm # make sure modules are loaded

kvm_intel             148081  0 

kvm                   461126  1 kvm_intel


 vnc监听 宿主的任何ip 

echo 'vnc_listen = "0.0.0.0"'>> /etc/libvirt/qemu.conf


[root@zw ~]# systemctl start libvirtd

[root@zw ~]# systemctl enable libvirtd

 


注:centos7上服务的管理方式换成了systemctl 。


 


二、配置网卡桥接


centos7上默认已不再是eth0、eth1 ,我的pc server上安装好的第一块网卡变成了enp3s0 ,修改步骤和centos 6上没有区别,如下


 

[root@zw ~]# cd /etc/sysconfig/network-scripts/

[root@zw network-scripts]# cat ifcfg-br0

TYPE=Bridge

BOOTPROTO=none

DEVICE=br0

ONBOOT=yes

IPADDR0=10.10.33.17

PREFIX0=24

GATEWAY0=10.10.33.1


[root@zw network-scripts]# cat ifcfg-enp3s0

DEVICE=enp3s0

TYPE=Ethernet

ONBOOT=yes

BRIDGE=br0


[root@zw ~]reboot

[root@zw network-scripts]# ifconfig

br0: flags=4163 mtu 1500

inet 10.10.33.17 netmask 255.255.255.0 broadcast 10.10.33.255

inet6 fe80::7a24:afff:fe46:ca60 prefixlen 64 scopeid 0x20

ether 78:24:af:46:ca:60 txqueuelen 0 (Ethernet)

RX packets 129 bytes 14676 (14.3 KiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 148 bytes 21994 (21.4 KiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

enp3s0: flags=4163 mtu 1500

ether 78:24:af:46:ca:60 txqueuelen 1000 (Ethernet)

RX packets 129 bytes 16482 (16.0 KiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 148 bytes 21994 (21.4 KiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73 mtu 65536

inet 127.0.0.1 netmask 255.0.0.0

inet6 ::1 prefixlen 128 scopeid 0x10

loop txqueuelen 0 (Local Loopback)

RX packets 9 bytes 728 (728.0 B)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 9 bytes 728 (728.0 B)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

virbr0: flags=4099 mtu 1500

inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255

ether a6:88:9f:14:b2:66 txqueuelen 0 (Ethernet)

RX packets 0 bytes 0 (0.0 B)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 1 bytes 90 (90.0 B)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0


[root@zw network-scripts]# ip add show

1: lo: mtu 65536 qdisc noqueue state UNKNOWN

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: enp3s0: mtu 1500 qdisc pfifo_fast master br0 state UP qlen 1000

link/ether 78:24:af:46:ca:60 brd ff:ff:ff:ff:ff:ff

3: br0: mtu 1500 qdisc noqueue state UP

link/ether 78:24:af:46:ca:60 brd ff:ff:ff:ff:ff:ff

inet 10.10.33.17/24 brd 10.10.33.255 scope global br0

valid_lft forever preferred_lft forever

inet6 fe80::7a24:afff:fe46:ca60/64 scope link

valid_lft forever preferred_lft forever

4: virbr0: mtu 1500 qdisc noqueue state DOWN

link/ether a6:88:9f:14:b2:66 brd ff:ff:ff:ff:ff:ff

inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0

valid_lft forever preferred_lft forever

 


注:由于ip 命令属于iproute2软件包中的工具,由于代替旧的ifconfig命令,尽可能的习惯使用新的命令和工具包来淘汰老的软件和工具。


 



三、selinux防火墙关闭


# setenforce 0

# sed -i 's/=enforcing/=disabled/g' /etc/selinux/config



四、创建虚拟机:

# cd /data

# mkdir 10.10.33.200

# cd 10.10.33.200

创建虚拟磁盘

qemu-img create -f qcow2 system.qcow2 100G(自定义)


创建虚拟机(定义cpu/内存/网卡/系统安装方式)

virt-install --name=10.10.33.200 --ram 2048 --vcpus=2 --arch=x86_64 --os-type=linux --os-variant='rhel6' --disk path=/data/10.10.33.200/system.qcow2,device=disk,bus=virtio,format=qcow2 --accelerate --pxe --graphics vnc,password=123456 --network bridge=br1   --force --autostart


常用命令:

virsh list    查看虚拟机状态


Id    Name                           State

----------------------------------------------------

 2     10.10.33.200                   running


virsh vncdisplay  虚拟机名称    (查看虚拟机vnc端口号)

:0


virsh destroy 10.10.33.200     强制关闭虚拟机


virsh start 10.10.33.200     开启虚拟机

你可能感兴趣的:(kvm)