[lianhua@host ~]$ time qemu-img create -f raw lianhua_demo.img -o preallocation=off 10G
Formatting 'lianhua_demo.img', fmt=raw size=10737418240 preallocation=off
real 0m0.040s
user 0m0.015s
sys 0m0.015s
[lianhua@host ~]$ qemu-img info lianhua_demo.img
image: lianhua_demo.img
file format: raw
virtual size: 10G (10737418240 bytes)
disk size: 0
如上所示,创建了一个名为 lianhua_demo.img 的格式为 raw 的镜像,该镜像大小为 10G。但是,使用 info 查看镜像信息时,镜像的实际大小为 0(disk size)。这是由于 raw 格式的镜像可以指定自己为稀疏文件,如果是稀疏文件,那么只在写数据到镜像的时候才会真正为其分配空间。
[lianhua@host ~]$ /usr/libexec/qemu-kvm -m 1024 -smp 2 -hda lianhua_demo_falloc.img -monitor stdio
WARNING: Image format was not specified for'lianhua_demo_falloc.img' and probing guessed raw.
Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
Specify the 'raw' format explicitly to remove the restrictions.
QEMU 2.6.0 monitor - type 'help'formore information
(qemu) VNC server running on '::1;5900'
(qemu) info pci
Bus 0, device 0, function0:
Host bridge: PCI device 8086:1237id""
Bus 0, device 1, function1:
IDE controller: PCI device 8086:7010
BAR4: I/O at 0xc040 [0xc04f].
id""
Bus 0, device 1, function3:
Bridge: PCI device 8086:7113
IRQ 9.
id""
Bus 0, device 3, function0:
Ethernet controller: PCI device 8086:100e
IRQ 11.
BAR0: 32 bit memory at 0xfebc0000 [0xfebdffff].
BAR1: I/O at 0xc000 [0xc03f].
BAR6: 32 bit memory at 0xffffffffffffffff [0x0003fffe].
id""
可以看出,镜像在虚拟机中的 pci 号为 00:01:1,且该设备为 IDE 设备。qemu-kvm 的 -hda 选项将镜像文件作为虚拟机的第一个 IDE 设备,在虚拟机中表现为 /dev/hda 设备或 /dev/sda 设备(驱动不同,表现的设备名称不同),更多磁盘选项配置可以查看 qemu-kvm 的 man 文档。
[root@host ~]# pvdisplay
--- Physical volume ---
PV Name /dev/loop2
VG Name cinder-volumes
PV Size 602.34 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 154199
Free PE 146519
Allocated PE 7680
PV UUID pTkQ5Z-zNdc-LRrn-qWAX-13D6-bhbG-DdcGFD
[root@host ~]# vgdisplay
--- Volume group ---
VG Name cinder-volumes
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 1447
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 602.34 GiB
PE Size 4.00 MiB
Total PE 154199
Alloc PE / Size 7680 / 30.00 GiB
Free PE / Size 146519 / 572.34 GiB
VG UUID Mrrh1r-qKQw-bCgW-0WXi-d5Bd-OiVV-cTBrg5
[root@host ~]# lvdisplay
--- Logical volume ---
LV Path /dev/cinder-volumes/volume-c34555f0-fd26-42fe-a3b2-86098b590be2
LV Name volume-c34555f0-fd26-42fe-a3b2-86098b590be2
VG Name cinder-volumes
LV UUID n81Af6-cWEe-LvAm-wjA3-vgKD-RxgV-qMtIq6
LV Write Access read/write
LV Creation host, time host.localdomain, 2020-08-0200:47:30 +0800
LV Status available
# open 1
LV Size 26.00 GiB
Current LE 6656
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
(看这里详细了解 LVM)
volume 创建成功后将 volume attach 到虚拟机上作为虚拟机的磁盘:
[root@host ~]# openstack volume list
+--------------------------------------+--------------------------------------------+--------+------+---------------------------------------------+
| ID | Display Name | Status | Size | Attached to |
+--------------------------------------+--------------------------------------------+--------+------+---------------------------------------------+
| c34555f0-fd26-42fe-a3b2-86098b590be2 | lianhua-vm1-vol | in-use | 26 | Attached to lianhua-vm1-vol on /dev/vdb |
+--------------------------------------+--------------------------------------------+--------+------+---------------------------------------------+
[root@lianhua-vm1:/home/robot]
# fdisk -l | grep vd
Disk /dev/vda: 40 GiB, 42949672960 bytes, 83886080 sectors # 这里 vda 的磁盘容量为 40G
/dev/vda1 * 20488388604683883999 40G 83 Linux
Disk /dev/vdb: 26 GiB, 27917287424 bytes, 54525952 sectors
[root@lianhua-vm1:/home/robot]
# lspci | grep block
00:06.0 SCSI storage controller: Red Hat, Inc. Virtio block device
00:0b.0 SCSI storage controller: Red Hat, Inc. Virtio block device
虚拟机中成功分配磁盘设备,且从 vda 中分出磁盘分区 vda1 给操作系统的文件系统使用。
2) 查看虚拟机内磁盘设备 vdb 分割的 lv volume:
[root@lianhua-vm1:/home/robot]
# pvdisplay
--- Physical volume ---
PV Name /dev/vdb
VG Name lianhua-vm1-vol
PV Size 26.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 6655
Free PE 1405
Allocated PE 5250
PV UUID OqdKmO-PspN-0ZKe-M0l4-0vGD-cY7k-VjZvTJ
[root@lianhua-vm1:/home/robot]
# vgdisplay
--- Volume group ---
VG Name lianhua-vm1-vol
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 7
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 6
Open LV 6
Max PV 0
Cur PV 1
Act PV 1
VG Size <26.00 GiB
PE Size 4.00 MiB
Total PE 6655
Alloc PE / Size 5250 / <20.51 GiB
Free PE / Size 1405 / <5.49 GiB
VG UUID JcVrao-YnJ7-mRpK-8Rxc-i07i-WVH4-aVgAoD
[root@lianhua-vm1:/home/robot]
# lvdisplay
--- Logical volume ---
LV Path /dev/lianhua-vm1-vol/provider_sys
LV Name provider_sys
VG Name lianhua-vm1-vol
LV UUID C6byt7-5cby-h2RT-xcLg-OJU0-Qq1E-27G6jB
LV Write Access read/write
LV Creation host, time lianhua-vm1, 2020-08-0200:50:11 +0800
LV Status available
# open 1
LV Size <9.77 GiB
Current LE 2500
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:0
--- Logical volume ---
LV Path /dev/lianhua-vm1-vol/provider_lianhua
LV Name provider_lianhua
VG Name lianhua-vm1-vol
LV UUID vfeZg8-PKVR-kKxv-yidf-rQqp-A7De-CvXqws
LV Write Access read/write
LV Creation host, time lianhua-vm1, 2020-08-0200:50:11 +0800
LV Status available
# open 1
LV Size 4.88 GiB
Current LE 1250
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:1
--- Logical volume ---
LV Path /dev/lianhua-vm1-vol/provider_log
LV Name provider_log
VG Name lianhua-vm1-vol
LV UUID mHdD60-QjSy-sRlz-GLmK-CFIM-l42c-QGthXa
LV Write Access read/write
LV Creation host, time lianhua-vm1, 2020-08-0200:50:12 +0800
LV Status available
# open 1
LV Size 1000.00 MiB
Current LE 250
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:2
[root@lianhua-vm2:/mnt/log]
# ls
[root@lianhua-vm2:/mnt/log]
# mkdir lianhua
[root@lianhua-vm2:/mnt/log]
# ls
lianhua
[root@lianhua-vm1:/mnt/log]
# ls
lianhua
视图控制层代码demo如下:
@Controller
@RequestMapping("/")
public class MessageController {
private final MessageRepository messageRepository;
@Autowired
public MessageController(Mes
作为一名
Linux SA,日常运维中很多地方都会用到脚本,而服务器的ip一般采用静态ip或者MAC绑定,当然后者比较操作起来相对繁琐,而前者我们可以设置主机名、ip信息、网关等配置。修改成特定的主机名在维护和管理方面也比较方便。如下脚本用途为:修改ip和主机名等相关信息,可以根据实际需求修改,举一反三!
#!/bin/sh
#auto Change ip netmask ga