看到linode都由xen转移到kvm,刚好最近新买了台服务器,就不用xen了,记录一下安装centos 7安装KVM。
新安装的centos 7怎么初始化就不说,但是要禁止selinux。
1 | sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config |
yum安装KVM
1 | yum install kvm virt-manager libvirt virt-install qemu-kvm |
接着就是桥接网卡,将/etc/sysconfig/network-scripts/ifcfg-eth0 改为
1 2 3 4 5 6 | DEVICE=eth0 TYPE=Ethernet ONBOOT=yes BOOTPROTO=none BRIDGE=br0 IPV6INIT=yes |
新建/etc/sysconfig/network-scripts/ifcfg-br0文件,内容如下
1 2 3 4 5 6 7 8 9 10 11 12 | DEVICE=br0 TYPE=Bridge ONBOOT=yes BOOTPROTO=static IPADDR=服务器外网IP GATEWAY=服务器网关 NETMASK=255.255.255.0 DNS1=8.8.8.8 IPV6INIT=yes IPV6_AUTOCONF=no IPV6ADDR=服务器IP6地址 DELAY=0 |
最后重启网络服务 service network restart,看到br0网卡启动,桥接就成功了。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | [root@pandora qemu]# ifconfig br0: flags=4163<up ,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet xxx.xx.xx.xx netmask 255.255.255.0 broadcast xxx.xx.xx.xx inet6 fe80::21e:67ff:fee3:c0cc prefixlen 64 scopeid 0x20<link /> inet6 xxx.xx.xx.xx prefixlen 64 scopeid 0x0<global> ether 00:1e:67:e3:c0:cc txqueuelen 0 (Ethernet) RX packets 4548273 bytes 2978437532 (2.7 GiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 281319 bytes 26960851 (25.7 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth0: flags=4163<up ,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet6 fe80::21e:67ff:fee3:c0cc prefixlen 64 scopeid 0x20<link /> ether 00:1e:67:e3:c0:cc txqueuelen 1000 (Ethernet) RX packets 6321262 bytes 3169347733 (2.9 GiB) RX errors 0 dropped 999 overruns 0 frame 0 TX packets 286078 bytes 27317934 (26.0 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 device memory 0xc1200000-c127ffff lo: flags=73</up><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 6 bytes 276 (276.0 B) RX errors 0 dropped 0 overruns 0 frame 0 </host></up></global></up> |
最后就是安装虚拟机了。
1 2 3 4 5 6 7 8 9 10 11 | virt-install \ --accelerate \ --name=centos7 \ --controller type=scsi,model=virtio-scsi \ --disk path=/home/data/centos7.qcow2,format=qcow2,size=300,sparse=true,cache=none,bus=scsi \ --cdrom=/home/iso/CentOS-7-x86_64-Minimal-1503-01.iso \ --graphics vnc,listen=0.0.0.0,port=5900,password=123456\ --network bridge=br0,mac=02:00:00:fd:5f:0f \ --vcpus=8 --ram=16384 \ --os-type=linux \ --os-variant=rhel7 |
–name 虚拟机名称
–disk 磁盘位置,格式为qcow2,size为300G
–cdrom 安装ISO的位置
–graphics vnc连接地址端口密码
–vcpus=8 –ram=16384 设置cpu 8个核心,内存16G
另外centos 7创建虚拟机的时候,可能会出现Failed to create chardev错误,解决办法在上一篇说了。
centos7创建KVM虚拟机提示错误Failed to create chardev