# CentOS6 最小化安装完成后初始化
## 关闭防火墙和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
# 修改hosts文件
[root@sh-kvm-1 ~]# yum update -y
[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
TYPE=Bridge
ONBOOT=yes
BOOTPROTO=none
IPADDR=192.168.0.67
NETMASK=255.255.255.0
GATEWAY=192.168.0.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
HWADDR=14:18:77:40:29:D3
UUID=d2e2265d-f891-4574-918f-c76a4dd6f2eb
# 配置网桥这里注意
# bro网卡配置里面不需要em1的mac地址和UUID,em1网卡的mac地址和UUID跟着em1网卡走。 不然重启网络时会报错,报错在文章末尾。
[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)
# 创建挂载卷
lvcreate -n kvm-1 -L 20G vg_shkvm1
# 安装虚拟机
virt-install \
--name kvm-2 \
--ram 4096 \
--disk path=/dev/vg_shkvm2/kvm-2 \
--vcpus 4 \
--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即可
这里选择初始化全部硬盘,还有一种情况是如果在重装虚拟机的时候,当前lvm卷上面已经存在系统,可以选择替换当前系统的方式安装,这样会保留原来lvm卷上系统的完整信息。
等待系统安装包安装完成,重启系统。
# 创建挂载卷
lvcreate -n kvm-2 -L 20G vg_shkvm1
# 安装虚拟机
virt-install \
--name kvm-2 \
--ram 2048 \
--disk path=/dev/vg_shkvm1/kvm-2 \
--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'
配置桥接时报错:device em1 does not seem to be present delaying initialization ;device br0 already exists,can’t create bridge with the same name,#本次安装故障原因是br0网卡配置是name没有改,导致重启时重启创建em1报错
> 删除/etc/udev/rules.d/70-persistent-net.rules这个文件
将ifcfg-br0文件中的mac地址和UUID这两行内容注释掉
start_udev
重启服务器,网卡恢复正常。
如果还是无法启动,查看新产生的/etc/udev/rules.d/70-persistent-net.rules内容,并将网卡的配置文件改成相应的内容