9.1 使用后端文件新建前端盘
[root@room8pc205 images]# qemu-img create -b node.qcow2 -f qcow2 node2.img
Formatting 'node2.img', fmt=qcow2 size=17179869184 backing_file='node.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off
9.2 利用模板编写node2.xml文件
[root@room8pc205 ~]# sed 's,demo,node2,' demo.xml >/etc/libvirt/qemu/node2.xml
9.3 定义虚拟机
[root@room8pc205 ~]# virsh define /etc/libvirt/qemu/node2.xml
定义域 node2(从 /etc/libvirt/qemu/node2.xml)
9.4 用virsh查看node2,并启动他
[root@room8pc205 ~]# virsh list --all
Id 名称 状态
----------------------------------------------------
8 node1 running
- node2 关闭
[root@room8pc205 ~]# virsh start node2
域 node2 已开始
[root@room8pc205 ~]# virsh console node2
CentOS Linux 7 (Core)
Kernel 3.10.0-693.el7.x86_64 on an x86_64
localhost login: root
密码:
Last login: Mon Jul 19 12:58:32 from 192.168.0.254
[root@localhost ~]#
注:按 ctrl+] 组合键退出virsh console
[root@room8pc205 ~]# virsh shutdown node2
域 node2 被关闭
9.5 修改模板文件为node2增加一块网卡
9.5.1 更改配置文件
[root@room8pc205 ~]# cd /etc/libvirt/qemu/
[root@room8pc205 qemu]# cp node2.xml node2.xml.bak
[root@room8pc205 qemu]# vim node2.xml #复制网卡信息做更改如下。
<interface type='bridge'>
<source bridge='private1'/>
<target dev='vnet0'/>
<model type='virtio'/>
</interface>
更改完成后保存
9.5.2 网卡信息的查看
[root@node2 ~]# ip link show #这个时候我们查看是没有增加网卡信息的需要重启一下
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 52:54:00:dd:62:af brd ff:ff:ff:ff:ff:ff
[root@node2 ~]# poweroff -p #注重启不能用reboot
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 52:54:00:dd:62:af brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
link/ether 52:54:00:40:e0:a5 brd ff:ff:ff:ff:ff:ff
网卡添加成功
#这是我们用ifconfig查看没有eth1 发现eth1不存在,原因eth1没有启动
[root@node2 network-scripts]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.167 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::5054:ff:fedd:62af prefixlen 64 scopeid 0x20<link>
ether 52:54:00:dd:62:af txqueuelen 1000 (Ethernet)
RX packets 442 bytes 25470 (24.8 KiB)
RX errors 0 dropped 6 overruns 0 frame 0
TX packets 91 bytes 7464 (7.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@node2 network-scripts]# ifconfig -a
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.167 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::5054:ff:fedd:62af prefixlen 64 scopeid 0x20<link>
ether 52:54:00:dd:62:af txqueuelen 1000 (Ethernet)
RX packets 503 bytes 28840 (28.1 KiB)
RX errors 0 dropped 6 overruns 0 frame 0
TX packets 101 bytes 8220 (8.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

eth1: flags=4098<BROADCAST,MULTICAST> mtu 1500
ether 52:54:00:40:e0:a5 txqueuelen 1000 (Ethernet)
RX packets 371 bytes 19330 (18.8 KiB)
RX errors 0 dropped 365 overruns 0 frame 0
TX packets 9 bytes 1262 (1.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
9.5.3 给eth1配置网卡
[root@node2 network-scripts]# cd /etc/sysconfig/network-scripts/
[root@node2 network-scripts]# cp ifcfg-eth0 ifcfg-eth1
[root@node2 network-scripts]# vim ifcfg-eth1
# Generated by dracut initrd
DEVICE="eth1"
ONBOOT="yes"
IPV6INIT="no"
BOOTPROTO="static"
TYPE="Ethernet"
IPADDR="192.168.4.10"
NETMASK="255.255.255.0"
GATEWAY="192.168.4.254"
[root@node2 network-scripts]# ifdown eth1;ifup eth1
[root@node2 network-scripts]# ifconfig eth1 | awk '/inet /{print}'
inet 192.168.4.10 netmask 255.255.255.0 broadcast 192.168.4.255
[root@node2 network-scripts]# ping 192.168.4.254
PING 192.168.4.254 (192.168.4.254) 56(84) bytes of data.
64 bytes from 192.168.4.254: icmp_seq=1 ttl=64 time=0.212 ms
64 bytes from 192.168.4.254: icmp_seq=2 ttl=64 time=0.195 ms

--- 192.168.4.254 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.195/0.203/0.212/0.016 ms
9.6 给node2新增硬盘
9.6.1 创建新的镜像盘文件
[root@room8pc205 images]# qemu-img create -f qcow2 node2-1.img 20G
Formatting 'node2-1.img', fmt=qcow2 size=21474836480 encryption=off cluster_size=65536 lazy_refcounts=off
9.6.2 更改xml配置文件
[root@room8pc205 images]# cd /etc/libvirt/qemu/
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/var/lib/libvirt/images/node2-1.img'/>
<target dev='vdb' bus='virtio'/>
</disk>
更改完成后重启node1生效
[root@node2 ~]# poweroff -p
[root@room8pc205 qemu]# virsh start node2
域 node2 已开始
[root@room8pc205 qemu]# virsh console node2
[root@node2 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 253:0 0 16G 0 disk
└─vda1 253:1 0 16G 0 part /
vdb 253:16 0 20G 0 disk