CentOS6 mininial 安装KVM 详细教程
初始化设置
## 关闭防火墙和SELINUX
/etc/rc.d/init.d/iptables stop
/etc/rc.d/init.d/ip6tables stop
chkconfig iptables off
chkconfig ip6tables off
sed -i 's/enforcing/disabled/' /etc/selinux/config
setenforce 0
## 关闭不必要的服务
/etc/rc.d/init.d/netfs stop
chkconfig netfs off
## 更新系统
yum -y install yum-plugin-fastestmirror
yum -y update
## 添加EPEL源
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
## 定时任务设置
yum -y install cronie-noanacron
# yum remove cronie-anacron -y
## 配置vim
yum -y install vim-enhanced lrzsz
#echo " alias vi='vim' " >> /etc/profile
echo "alias vi='vim' " >> ~/.bashrc
#source /etc/profile
source ~/.bashrc
## 添加用户
useradd yunwei
echo anwg123. | passwd --stdin yunwei
安装依赖包
[root@sh-kvm-1 ~]# yum -y install qemu-kvm libvirt python-virtinst bridge-utils
[root@kvm-1 ~]# lsmod | grep kvm
kvm_intel 54285 0
kvm 333172 1 kvm_intel
[root@sh-kvm-1 ~]# /etc/rc.d/init.d/libvirtd start
Starting libvirtd daemon: [ OK ]
[root@sh-kvm-1 ~]# /etc/rc.d/init.d/messagebus start
Starting system message bus: [ OK ]
[root@sh-kvm-1 ~]# chkconfig libvirtd on
[root@sh-kvm-1 ~]# chkconfig messagebus on
配置桥接网络
# 网桥网卡配置
[root@sh-kvm-1 ~]# cp /etc/sysconfig/network-scripts/ifcfg-em1 /etc/sysconfig/network-scripts/ifcfg-br0
[root@sh-kvm-1 ~]# vi /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
HWADDR=14:18:77:40:29:D3
TYPE=Bridge
UUID=9e8e7f89-cfe9-40c6-b547-a08ee6da0864
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=192.168.1.125
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=114.114.114.114
# em1网卡配置
[root@sh-kvm-1 ~]# vi /etc/sysconfig/network-scripts/ifcfg-em1
# create new
DEVICE=em1
TYPE=Ethernet
ONBOOT=yes
BRIDGE=br0
[root@sh-kvm-1 ~]# /etc/rc.d/init.d/network restart
- 查看网桥配置状态
[root@sh-kvm-1 ~]# ifconfig
br0 Link encap:Ethernet HWaddr 14:18:77:40:29:D3
inet addr:192.168.1.125 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::1618:77ff:fe40:29d3/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:52655 errors:0 dropped:0 overruns:0 frame:0
TX packets:20216 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:49670413 (47.3 MiB) TX bytes:1665453 (1.5 MiB)
em1 Link encap:Ethernet HWaddr 14:18:77:40:29:D3
inet6 addr: fe80::1618:77ff:fe40:29d3/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:302969 errors:0 dropped:0 overruns:0 frame:0
TX packets:96324 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:427674107 (407.8 MiB) TX bytes:7173701 (6.8 MiB)
Interrupt:41
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:7 errors:0 dropped:0 overruns:0 frame:0
TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:608 (608.0 b) TX bytes:608 (608.0 b)
virbr0 Link encap:Ethernet HWaddr 52:54:00:68:65:A2
inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
vnet0 Link encap:Ethernet HWaddr FE:54:00:08:94:EC
inet6 addr: fe80::fc54:ff:fe08:94ec/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:19 errors:0 dropped:0 overruns:0 frame:0
TX packets:3443 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:500
RX bytes:1243 (1.2 KiB) TX bytes:381667 (372.7 KiB)
创建虚拟机kvm-1
# 创建挂载卷
lvcreate -n kvm-1 -L 20G vg_shkvm1
# 安装虚拟机
virt-install \
--name kvm-1 \
--ram 2048 \
--disk path=/dev/vg_shkvm1/kvm-1 \
--vcpus 2 \
--os-type linux \
--os-variant rhel6 \
--network bridge=br0 \
--graphics none \
--console pty,target_type=serial \
--location 'http://mirrors.aliyun.com/centos/6.9/os/x86_64/' \
--extra-args 'console=ttyS0,115200n8 serial'
图形安装教程
- 选择安装语言
- 设置网络配置,使用静态IP
配置静态ip,忘记截图,按照上面网桥ip,设置相同局域网ip即可
- 静态ip配置成功,如下图会加载安装镜像:
- 选择使用文本方式安装,即命令行模式
- Re-initialize all 初始化磁盘
这里选择初始化全部硬盘,还有一种情况是如果在重装虚拟机的时候,当前lvm卷上面已经存在系统,可以选择替换当前系统的方式安装,这样会保留原来lvm卷上系统的完整信息。
- 选择时区,上海
- 设置root密码
- 安装系统安装位置
- 初始化磁盘
- 开始安装系统包文件
等待系统安装包安装完成,重启系统。
- 参考虚拟机kvm-1的安装,安装kvm-2
安装过程中报错解决
配置桥接时报错:can't create bridge with the same name,#本次安装故障原因是br0网卡配置是name没有改,导致重启时重启创建em1报错
# 使用brctl 解决
[root@sh-kvm-1 ~]# brctl
Usage: brctl [commands]
commands:
addbr <bridge> add bridge
delbr <bridge> delete bridge
addif <bridge> <device> add interface to bridge
delif <bridge> <device> delete interface from bridge
setageing <bridge> <time> set ageing time
setbridgeprio <bridge> <prio> set bridge priority
setfd <bridge> <time> set bridge forward delay
sethello <bridge> <time> set hello time
setmaxage <bridge> <time> set max message age
sethashel <bridge> <int> set hash elasticity
sethashmax <bridge> <int> set hash max
setmclmc <bridge> <int> set multicast last member count
setmcrouter <bridge> <int> set multicast router
setmcsnoop <bridge> <int> set multicast snooping
setmcsqc <bridge> <int> set multicast startup query count
setmclmi <bridge> <time> set multicast last member interval
setmcmi <bridge> <time> set multicast membership interval
setmcqpi <bridge> <time> set multicast querier interval
setmcqi <bridge> <time> set multicast query interval
setmcqri <bridge> <time> set multicast query response interval
setmcqri <bridge> <time> set multicast startup query interval
setpathcost <bridge> <port> <cost> set path cost
setportprio <bridge> <port> <prio> set port priority
setportmcrouter <bridge> <port> <int> set port multicast router
show [ <bridge> ] show a list of bridges
showmacs <bridge> show a list of mac addrs
showstp <bridge> show bridge stp info
stp <bridge> {on|off} turn stp on/off
# 查看当前网桥配置
[root@sh-kvm-1 ~]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.1418774029d3 no em1
vnet0
virbr0 8000.5254006865a2 yes virbr0-nic
# 删除刚刚重启网络时创建的网桥
[root@sh-kvm-1 ~]# brctl delbr br0
# 修改正确的网桥br0配置,然后重启网络成功,因此配置网桥的时候特别注意