rhel7.2使用lvm安装虚拟机
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了rhel7.2使用lvm安装虚拟机相关的知识,希望对你有一定的参考价值。
当前物理机OS为RHEL7.2
本篇文章使用的是物理上的块设备(逻辑卷)来建立kvm虚拟机。这样比使用文件来建立虚拟机的效率要高的多
step1:准备工作
当前物理机的网络配置为:物理机有一个网卡em1,我创建了一个网桥br0,用来作为虚拟机连接到物理机的桥接通道
[[email protected] qemu]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.549f35121014 no em1
virbr0 8000.52540002a17b yes virbr0-nic
br0用于桥接到物理网卡
virbr0用于做NAT
注意:br0需要你自己添加,virbr0不需要,系统自带的
[[email protected] network-scripts]# more ifcfg-br0
BOOTPROTO=static
#DEVICE=virbr0
DEVICE=br0
ONBOOT=yes
TYPE=Bridge ##类型是bridge
NAME=br0
IPADDR=192.168.107.105
NETMASK=255.255.255.0
GATEWAY=192.168.107.1
DEFROUTE=yes
[[email protected] network-scripts]# more ifcfg-em1
# Generated by parse-kickstart
BOOTPROTO=none
DEVICE=em1
ONBOOT=yes
UUID=9244d816-622e-41e5-a357-3ca0f00e8ad5
TYPE=Ethernet
NAME=em1
NM_CONTROLLED=no ##该网卡不在NetworkManager服务的管理下,并且之后关闭该服务。
#IPADDR=192.168.107.105
#NETMASK=255.255.255.0
#GATEWAY=192.168.107.1
BRIDGE=br0 ##em1网卡桥接到br0
注意:需要将NetworkManager 关闭掉才可以,如果不关的话可能会导致物理机无法ping通虚拟机
systemctl stop NetworkManager
systemctl disable NetworkManager
systemctl is-enable NetworkManager
查看存储池的配置:
[[email protected] ~]# virsh pool-info storage1 ##这里的storage1 存储池是我之前在virt-manager图形界面建立的
Name: storage1
UUID: 3aacbac0-07ec-4c3d-b5ae-d33a4b980279
State: running
Persistent: yes
Autostart: yes
Capacity: 930.69 GiB
Allocation: 238.00 GiB
Available: 692.69 GiB
创建用于安装虚拟机的lvm
[[email protected] ~]# lvcreate -L 20G -n rhel7.2_test server
Logical volume "rhel7.2_test" created.
[[email protected] ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
rhel7.2_oracle server -wi-ao---- 60.00g
rhel7.2_test server -wi-a----- 20.00g
root server -wi-ao---- 20.00g
storage server -wi-ao---- 100.00g
swap server -wi-ao---- 8.00g
u01 server -wi-ao---- 50.00g
[[email protected] ~]# mkfs.xfs /dev/mapper/server-rhel7.2_test
必须格式化,不然在创建虚拟机的时候看不到卷,就无法使用卷
step2:新建虚拟机,采用NAT方式连接
virt-manager-->新建虚拟机
左侧的storage1是新建的storage pool,右侧的rhel7.2_test卷是上边lvcreate创建的,如果之前不格式化的话,在这里看不到该卷
选择rhel7.2_test卷作为这次虚拟机安装的存储设备
在网络这里选择NAT方式连接
给这台虚拟机配置个名字
之后就是虚拟机安装过程了,分区如下,其他步骤就不截屏了
附:当前物理机及虚拟机的网络配置
1 桥接方式
我的第一台虚拟机使用的是桥接方式,配置如下:
2 NAT方式
我这里新建的虚拟机是NAT方式连接,配置如下:
此时物理机的ip如下
[[email protected] ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> 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: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master br0 state UP qlen 1000
link/ether 54:9f:35:12:10:14 brd ff:ff:ff:ff:ff:ff
inet6 fe80::569f:35ff:fe12:1014/64 scope link
valid_lft forever preferred_lft forever
3: em2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
link/ether 54:9f:35:12:10:15 brd ff:ff:ff:ff:ff:ff
4: em3: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
link/ether 54:9f:35:12:10:16 brd ff:ff:ff:ff:ff:ff
5: em4: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
link/ether 54:9f:35:12:10:17 brd ff:ff:ff:ff:ff:ff
6: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
link/ether 54:9f:35:12:10:14 brd ff:ff:ff:ff:ff:ff
inet 192.168.107.105/24 brd 192.168.107.255 scope global br0
valid_lft forever preferred_lft forever
inet6 fe80::569f:35ff:fe12:1014/64 scope link
valid_lft forever preferred_lft forever
7: virbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
link/ether 52:54:00:02:a1:7b 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
8: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 500
link/ether 52:54:00:02:a1:7b brd ff:ff:ff:ff:ff:ff
9: vnet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UNKNOWN qlen 500
link/ether fe:54:00:0b:6e:99 brd ff:ff:ff:ff:ff:ff
inet6 fe80::fc54:ff:fe0b:6e99/64 scope link
valid_lft forever preferred_lft forever
11: vnet1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master virbr0 state UNKNOWN qlen 500
link/ether fe:54:00:f9:51:af brd ff:ff:ff:ff:ff:ff
inet6 fe80::fc54:ff:fef9:51af/64 scope link
valid_lft forever preferred_lft forever
新安装的nat网络中的vm如下:
注:此图是另外一台nat虚拟机的信息,效果是一样的,MAC不同
在主机上ping虚拟机ip
[[email protected] ~]# ping 192.168.122.165
PING 192.168.122.165 (192.168.122.165) 56(84) bytes of data.
64 bytes from 192.168.122.165: icmp_seq=1 ttl=64 time=0.338 ms
64 bytes from 192.168.122.165: icmp_seq=2 ttl=64 time=0.322 ms
64 bytes from 192.168.122.165: icmp_seq=3 ttl=64 time=0.322 ms
以上是关于rhel7.2使用lvm安装虚拟机的主要内容,如果未能解决你的问题,请参考以下文章