tongsiying

阅读|运动|自律

0%

BlockStorage-kvm

# 001-搭建kvm网桥
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
注释:bond0
[root@host102442554 network-scripts]# vi ifcfg-bond0
DEVICE="bond0"
BOOTPROTO="none"
ONBOOT="yes"
TYPE=Bond
#TYPE=Ethernet
BONDING_OPTS="mode=4 miimon=100"
#IPADDR=10.244.25.54
#GATEWAY=10.244.25.126
#NETMASK=255.255.255.128
BRIDGE=ovirtmgmt


[root@host102442554 network-scripts]# vi ifcfg-ovirtmgmt
DEVICE=ovirtmgmt
ONBOOT=yes
TYPE=bridge
BOOTPROTO=none
IPADDR=10.244.25.54
GATEWAY=10.244.25.126
NETMASK=255.255.255.128

然后重启网络

002-搭建kvm

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
6.创建虚机:
①安装KVM
yum install vir*

②查看是否已经安装kvm
lsmod |grep kvm,有下面类似输出,则表明KVM安装完成。
kvm_amd(或者kvm_intel) 50380 0
kvm 305081 1 kvm_amd(或者kvm_intel)

③启动libvirt进程
rm -rf /var/run/libvirtd.pid 
libvirtd -d
④查看libvirt进程
ps -le | grep libvirt*
5 S 0 4300 1 6 80 0 - 153177 poll_s ? 00:00:00 libvirtd


yum upgrade device-mapper-libs
systemctl start virtlogd.socket

003-kvm创建虚机

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
1. 10.27.38.241~2444台物理机,在上面共搭建9台虚机,配置(2c4g 100GB),ip:10.27.38.41~49
suning@123
dev-42-data.qcow2
2.VNC闪屏解决方法
依次点Option-->Advanced-->Expert找到ColourLevel,默认值是pal8,修改为rgb222或full

3.虚机 用户名root,密码cloud@123

在物理机上建立虚机步骤:
一、查看虚机是否存在
virsh list --all 查看已存在的虚机
[root@pptvtest241 ~]# virsh list --all
Id Name State
----------------------------------------------------
2 dev-01 running
3 dev-05 running
4 dev-09 running
5 dev-13 running
6 dev-17 running
7 dev-21 running
8 dev-25 running
10 dev-33 running
13 dev-29 running
23 centos73-34 running
30 dev-41 running

二、拷贝/mnt/data1/moban路径下RHEL6U3_64bit_75G_20150512_APP.qcow2文件到/mnt/data1或者data2里面,并重命名为dev-42-data.qcow2

curl -O -u vuser:suning@123 ftp://10.104.249.195/soft/iso/rhel63.qcow2
 curl -O -u vuser:suning@123 ftp://10.104.249.195/soft/iso/rhel63.xml

cp moban/RHEL6U3_64bit_75G_20150512_APP.qcow2 dev-sys-05.qcow2
cp /mnt/data1/moban/rhel63.xml /etc/libvirt/qemu/[主机名].xml

三、创建一个数据盘100G
qemu-img create -f qcow2 dev-42-data.qcow2 100G

[root@pptvtest242 data1]# qemu-img create -f qcow2 dev-42-data.qcow2 100G
Formatting 'dev-41-data.qcow2', fmt=qcow2 size=107374182400 encryption=off cluster_size=65536

四、
virsh define /etc/libvirt/qemu/dev-42.xml

004-redhat

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/etc/ssh/sshd_config
1、下载镜像文件
cd /mnt/data1/moban
curl -O -u vuser:suning@123 ftp://10.104.249.195/soft/iso/rhel63.qcow2
curl -O -u vuser:suning@123 ftp://10.104.249.195/soft/iso/rhel63.xml

2、将镜像文件重命名
cd /mnt/data2
cp /mnt/data1/moban/CentOS7U3.qcow2 /mnt/data2/dev-55.qcow2
cp /mnt/data1/moban/centos73-34.xml /etc/libvirt/qemu/dev-55.xml

3、设置虚机磁盘大小
qemu-img create -f qcow2 dev-55-data.qcow2 800G

4、修改xml文件
vi /etc/libvirt/qemu/dev-55.xml

5、执行xml文件
virsh define /etc/libvirt/qemu/dev-55.xml

6、启动虚机
virsh start dev-55
virsh list --all

7、查看虚机端口
virsh vncdisplay dev-55 查看端口

8、登录vnc进行虚机的ip等配置
vnc登录:

9、修改ip
vi /etc/sysconfig/network-scripts/ifcfg-eth0
service network restart

10、修改hostname
vi /etc/sysconfig/network
vi /etc/hosts
[root@dev-50 conf]# cat /etc/hosts
127.0.0.1 localhost dev-50 localhost4 localhost4.localdomain4
::1 localhost dev-50 localhost6 localhost6.localdomain6

vi /etc/hostname

11、修改sshd, 修改ssh为永不超时
vi /etc/ssh/sshd_config
注释如下两行
#ClientAliveInterval 0
#ClientAliveCountMax 3
重启sshd服务
# service sshd restart

12、删除cloud相关的rpm包
rpm -qa |grep cloud |xargs rpm -e --nodeps

13、reboot

14、划分硬盘空间
xfs分区:(df -Th可以看到xfs分区情况)
df -Th
lsblk
lsblk -f
pvcreate /dev/vdb
vgs
vgextend systemvg /dev/vdb
vgs
lvcreate -L 100G -n lv01 systemvg
lsblk

mkdir -p /data/osd.0
mkfs -t xfs /dev/mapper/systemvg-lv01 ## 格式化
mount -o rw,noatime,attr2 /dev/mapper/systemvg-lv01 /data/osd.0 ##挂载
vi /etc/fstab
# Created by anaconda on Tue Sep 19 09:16:19 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/systemvg-rootlv / xfs defaults 0 0
UUID=d4016770-faee-4562-b9e0-bcc6ba417fce /boot xfs defaults 0 0
/dev/mapper/systemvg-homelv /home xfs defaults 0 0
/dev/mapper/systemvg-optlv /opt xfs defaults 0 0
/dev/mapper/systemvg-tmplv /tmp xfs defaults 0 0
/dev/mapper/systemvg-usrlv /usr xfs defaults 0 0
/dev/mapper/systemvg-varlv /var xfs defaults 0 0
/dev/mapper/systemvg-swaplv swap swap defaults 0 0
/dev/mapper/systemvg-lv01 /data/osd.0 xfs rw,noatime,attr2,inode64,noquota 0 0
/dev/mapper/systemvg-lv02 /data/osd.1 xfs rw,noatime,attr2,inode64,noquota 0 0
/dev/mapper/systemvg-lv03 /data/osd.2 xfs rw,noatime,attr2,inode64,noquota 0 0
/dev/mapper/systemvg-lv04 /data/osd.3 xfs rw,noatime,attr2,inode64,noquota 0 0
/dev/mapper/systemvg-lv05 /data/osd.4 xfs rw,noatime,attr2,inode64,noquota 0 0
/dev/mapper/systemvg-lv06 /data/osd.5 xfs rw,noatime,attr2,inode64,noquota 0 0
/dev/mapper/systemvg-lv07 /data/osd.6 xfs rw,noatime,attr2,inode64,noquota 0 0
/dev/mapper/systemvg-lv08 /data/osd.7 xfs rw,noatime,attr2,inode64,noquota 0 0
sudo mount -a
reboot




ext4:分区:(df -Th可以看到xfs分区情况)
df -Th
lsblk
lsblk -f
pvcreate /dev/vdb
vgs
vgextend systemvg /dev/vdb
vgs
lvcreate -L 100G -n lv01 systemvg
lsblk

mkdir -p /mnt
mkfs -t ext4 /dev/mapper/systemvg-lv01 格式化
mount -t ext4 -o rw,noatime,user_xattr /dev/mapper/systemvg-lv01 /mnt
vi /etc/fstab
[root@ceph1 ~]# vi /etc/fstab
/dev/mapper/systemvg-lv01 /mnt ext4 rw,noatime,user_xattr 1 2

sudo mount -a
reboot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
红帽子xml
[root@pptvtest244 data2]# cat /etc/libvirt/qemu/dev-48.xml
<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
virsh edit dev-48
or other application using the libvirt API.
-->

<domain type='kvm'>
<name>dev-48</name>
<uuid>89753b02-8c16-e9a1-35b3-9febf876e4f0</uuid>
<memory unit='KiB'>4194304</memory>
<currentMemory unit='KiB'>4194304</currentMemory>
<vcpu placement='static'>2</vcpu>
<os>
<type arch='x86_64' machine='rhel6.5.0'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2' cache='none'/>
<source file='/mnt/data2/dev-48.qcow2'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
</disk>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2' cache='none'/>
<source file='/mnt/data2/dev-48-data.qcow2'/>
<target dev='vdb' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
</disk>
<controller type='usb' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
</controller>
<controller type='pci' index='0' model='pci-root'/>
<interface type='bridge'>
<mac address='52:54:00:d9:78:8c'/>
<source bridge='br0'/>
<model type='e1000'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<serial type='pty'>
<target port='0'/>
</serial>
<console type='pty'>
<target type='serial' port='0'/>
</console>
<input type='tablet' bus='usb'/>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'>
<listen type='address' address='0.0.0.0'/>
</graphics>
<sound model='ac97'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</sound>
<video>
<model type='cirrus' vram='9216' heads='1'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
</memballoon>
</devices>
</domain>

005-centos

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
1、centos虚机搭建和红帽子差不多,只是xml不一样
2、centos镜像地址:ftp://10.102.141.120/image/centos73/20180404imageaddiptables/CentOS7U3_GLOBAL_64bit_75G_20180404_APP.qcow2

hostname修改:
在centos7中设置hostname碰到了一个巨坑,就是安照网上的方法修改后怎么都是原来的hostname,根本无效。所以在centos7中除了修改hosts文件和network文件后,还需修改etc/hostname文件,具体步骤如下
第一步:修改/etc/sysconfig/network文件
        #>vi /etc/sysconfig/network
        添加或修改:
                NETWORKING=yes
                HOSTNAME=slave3
第二步:修改/etc/hosts文件
        #>vi /etc/hosts
        修改 127.0.0.1这行中的 localhost.localdomain为 slave3
        修改 ::1这行中的localhost.localdomain 为slave3
第三步 :修改/etc/hostname文件(此步不操作,怎么修改都没有用)
        删除文件中的所有文字,在第一行添加slave3
第四步:重启并验证
       #>reboot -f 
       #> hostnamectl


修改ip:


3、xfs分区:(df -Th可以看到xfs分区情况)
df -Th
lsblk
lsblk -f
pvcreate /dev/vdb
vgs
vgextend systemvg /dev/vdb
vgs
lvcreate -L 100G -n lv01 systemvg
lsblk

mkdir -p /data/osd.0
mkfs -t xfs /dev/mapper/systemvg-lv01 格式化
mount -o rw,noatime,attr2 /dev/mapper/systemvg-lv01 /data/osd.0 挂载
vi /etc/fstab
# Created by anaconda on Tue Sep 19 09:16:19 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/systemvg-rootlv / xfs defaults 0 0
UUID=d4016770-faee-4562-b9e0-bcc6ba417fce /boot xfs defaults 0 0
/dev/mapper/systemvg-homelv /home xfs defaults 0 0
/dev/mapper/systemvg-optlv /opt xfs defaults 0 0
/dev/mapper/systemvg-tmplv /tmp xfs defaults 0 0
/dev/mapper/systemvg-usrlv /usr xfs defaults 0 0
/dev/mapper/systemvg-varlv /var xfs defaults 0 0
/dev/mapper/systemvg-swaplv swap swap defaults 0 0
/dev/mapper/systemvg-lv01 /data/osd.0 xfs rw,noatime,attr2,inode64,noquota 0 0
/dev/mapper/systemvg-lv02 /data/osd.1 xfs rw,noatime,attr2,inode64,noquota 0 0
/dev/mapper/systemvg-lv03 /data/osd.2 xfs rw,noatime,attr2,inode64,noquota 0 0
/dev/mapper/systemvg-lv04 /data/osd.3 xfs rw,noatime,attr2,inode64,noquota 0 0
/dev/mapper/systemvg-lv05 /data/osd.4 xfs rw,noatime,attr2,inode64,noquota 0 0
/dev/mapper/systemvg-lv06 /data/osd.5 xfs rw,noatime,attr2,inode64,noquota 0 0
/dev/mapper/systemvg-lv07 /data/osd.6 xfs rw,noatime,attr2,inode64,noquota 0 0
/dev/mapper/systemvg-lv08 /data/osd.7 xfs rw,noatime,attr2,inode64,noquota 0 0

sudo mount -a
reboot




ext4:分区:(df -Th可以看到xfs分区情况)
df -Th
lsblk
lsblk -f
pvcreate /dev/vdb
vgs
vgextend systemvg /dev/vdb
vgs
lvcreate -L 100G -n lv01 systemvg
lsblk

mkdir -p /mnt
mkfs -t ext4 /dev/mapper/systemvg-lv01 格式化
mount -t ext4 -o rw,noatime,user_xattr /dev/mapper/systemvg-lv01 /mnt
vi /etc/fstab
sudo mount -a
reboot

centos的xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
修改方法和红帽子一致:
- <!-- WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
virsh edit centos73-34
or other application using the libvirt API.
  -->
- <domain type="kvm">
  <name>centos73-34</name>
  <uuid>e12767b1-290d-8149-d1fb-477da52bfadc</uuid>
  <memory unit="KiB">2097152</memory>
  <currentMemory unit="KiB">2097152</currentMemory>
  <vcpu placement="static">2</vcpu>
- <os>
  <type arch="x86_64" machine="rhel6.5.0">hvm</type>
  <boot dev="hd" />
  </os>
- <features>
  <acpi />
  <apic />
  <pae />
  </features>
  <clock offset="utc" />
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
- <devices>
  <emulator>/usr/libexec/qemu-kvm</emulator>
- <disk type="file" device="disk">
  <driver name="qemu" type="qcow2" cache="none" />
  <source file="/mnt/data1/centos73-34.qcow2" />
  <target dev="vda" bus="virtio" />
  <address type="pci" domain="0x0000" bus="0x00" slot="0x05" function="0x0" />
  </disk>
- <disk type="file" device="disk">
  <driver name="qemu" type="qcow2" cache="none" />
  <source file="/mnt/data1/centos-data-34.qcow2" />
  <target dev="vdb" bus="virtio" />
  <address type="pci" domain="0x0000" bus="0x00" slot="0x07" function="0x0" />
  </disk>
- <controller type="usb" index="0">
  <address type="pci" domain="0x0000" bus="0x00" slot="0x01" function="0x2" />
  </controller>
  <controller type="pci" index="0" model="pci-root" />
- <interface type="bridge">
  <mac address="52:54:00:bb:61:70" />
  <source bridge="br0" />
  <model type="e1000" />
  <address type="pci" domain="0x0000" bus="0x00" slot="0x03" function="0x0" />
  </interface>
- <serial type="pty">
  <target port="0" />
  </serial>
- <console type="pty">
  <target type="serial" port="0" />
  </console>
  <input type="tablet" bus="usb" />
  <input type="mouse" bus="ps2" />
  <input type="keyboard" bus="ps2" />
- <graphics type="vnc" port="-1" autoport="yes" listen="0.0.0.0">
  <listen type="address" address="0.0.0.0" />
  </graphics>
- <sound model="ich6">
  <address type="pci" domain="0x0000" bus="0x00" slot="0x04" function="0x0" />
  </sound>
- <video>
  <model type="cirrus" vram="9216" heads="1" />
  <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x0" />
  </video>
- <memballoon model="virtio">
  <address type="pci" domain="0x0000" bus="0x00" slot="0x06" function="0x0" />
  </memballoon>
  </devices>
  </domain>

006-mysql的xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
[root@pptvtest241 qemu]# cat dev-01.xml
<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
virsh edit dev-01
or other application using the libvirt API.
-->

<domain type='kvm'>
<name>dev-01</name>
<uuid>89753b02-8c16-e9a1-35b3-9febf876a5f1</uuid>
<memory unit='KiB'>4194304</memory>
<currentMemory unit='KiB'>4194304</currentMemory>
<vcpu placement='static'>2</vcpu>
<os>
<type arch='x86_64' machine='rhel6.5.0'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2' cache='none'/>
<source file='/mnt/data1/dev-sys-01.qcow2'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
</disk>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2' cache='none'/>
<source file='/mnt/data1/dev-mysql-01.qcow2'/>
<target dev='vdb' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
</disk>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2' cache='none'/>
<source file='/mnt/data1/dev-data-01.qcow2'/>
<target dev='vdc' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
</disk>
<controller type='usb' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
</controller>
<controller type='pci' index='0' model='pci-root'/>
<interface type='bridge'>
<mac address='52:54:00:da:98:7a'/>
<source bridge='br0'/>
<model type='e1000'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<serial type='pty'>
<target port='0'/>
</serial>
<console type='pty'>
<target type='serial' port='0'/>
</console>
<input type='tablet' bus='usb'/>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'>
<listen type='address' address='0.0.0.0'/>
</graphics>
<sound model='ac97'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</sound>
<video>
<model type='cirrus' vram='9216' heads='1'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
</memballoon>
</devices>
</domain>

007-虚机扩容

1
2
3
4
5
6
7
1、查看虚机磁盘大小
qemu-img info dev-56-data.qcow2
2、停止运行虚机
virsh destroy dev-56
3、停止后进行扩容操作
qemu-img resize -f qcow2 dev-56-data.qcow2 +500G
4、virsh start dev-56

008-虚机新增磁盘

1
2
3
4
5
6
7
8
9
10
qemu-img  create -f qcow2 /mnt/data2/dev-test-21.qcow2 40G
chown qemu:qemu /mnt/data2/dev-test-21.qcow2
chmod 644 /mnt/data2/dev-test-21.qcow2

virsh attach-disk dev-21 /mnt/data2/dev-test-21.qcow2  vdc  --subdriver qcow2   --persistent



胡正川 2018-08-01 11:07:09
virsh是支持在线挂盘到vm里面的

009-直接拷贝已存在的镜像,无法重启网卡

1
2
3
直接拷贝已存在的镜像,无法重启网卡
解决:
echo "" >>/etc/udev/rules.d/70-persistent-net.rules;rm -f /etc/udev/rules.d/70-persistent-net.rule;

010-保存已在使用的镜像文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
8.1执行关机前操作
校正时间!!!

将镜像网卡配置文件参数BOOTPROTO由原来的dhcp更换为none(避免该网卡接受dhcp配置ip方式)
注释/sbin/dhclient-script脚本调用函数make_resolv_conf,禁止dhlient-script自动设置dns
清理/var/cache目录
清理yum目录
# yum clean all
# rm -rf /etc/udev/rules.d/70-persistent-*
# rm -rf /var/lib/dhclient/dhclient-eth0.leases
# rm -rf /var/log/*


# echo > /etc/resolv.conf (如果是雨花ice环境使用的虚拟机使用dns 192.168.131.20)
# echo > .bash_history
# history -c
# shutdown –h now
关闭虚拟机

011-qcow2转raw

1
2
3
4
5
6
7
8
qemu-img convert -f qcow2  CentOS7U3_GLOBAL_64bit_75G_20180404_APP.qcow2 -O raw CentOS7U3.raw

qcw2镜像转化为raw镜像文件
#yum install  qemu-img
#qemu-img convert -f qcow2 CentOS7U3_GLOBAL_64bit_75G_20180404_APP.qcow2 -O raw CentOS7U3.raw

raw镜像转化为qcw2镜像文件
#qemu-img convert -f qcow2  win7.raw  -O  raw  win7.qcow2

012-系统坏块修复

1
2
3
4
5
@王星童 vnc:10.244.25.48:0 这台虚机你试下
centos6 系列的坏块修复fsck -y /dev/mapper/systemvg-optlv
centos7 系列的坏块修复 xfs_repair -L  xxx

e2fsck -fy /dev/mapper/datavg-datalv

013-xml文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
SNBS之后按照这一种方式来
<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
virsh edit dev-21
or other application using the libvirt API.
-->

<domain type='kvm'>
<name>dev-21</name>
<uuid>89753b02-8c16-e9a1-35b3-9febf8364571</uuid>
<memory unit='KiB'>4194304</memory>
<currentMemory unit='KiB'>4194304</currentMemory>
<vcpu placement='static'>2</vcpu>
<os>
<type arch='x86_64' machine='rhel6.5.0'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='block' device='disk'>
<driver name='qemu' type='raw' cache='none'/>
<source dev='/dev/disk/by-path/ip-10.243.0.130:3260-iscsi-iqn.1012-00.com.example:storage.disk2.amiens.sys1.xyz-lun-1'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
</disk>
<disk type='block' device='disk'>
<driver name='qemu' type='raw' cache='none'/>
<source dev='/dev/disk/by-path/ip-10.243.0.130:3260-iscsi-iqn.1012-00.com.example:storage.disk2.amiens.sys1.xyz-lun-1'/>
<target dev='vdb' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x10' function='0x0'/>
</disk>
<controller type='usb' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
</controller>
<controller type='pci' index='0' model='pci-root'/>
<controller type='scsi' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
</controller>
<interface type='bridge'>
<mac address='52:54:01:a9:71:4b'/>
<source bridge='ovirtmgmt'/>
<model type='e1000'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<serial type='pty'>
<target port='0'/>
</serial>
<console type='pty'>
<target type='serial' port='0'/>
</console>
<input type='tablet' bus='usb'>
<address type='usb' bus='0' port='1'/>
</input>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'>
<listen type='address' address='0.0.0.0'/>
</graphics>
<sound model='ac97'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</sound>
<video>
<model type='cirrus' vram='16384' heads='1' primary='yes'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
</memballoon>
</devices>
</domain>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
virsh edit dev-21
or other application using the libvirt API.
-->

<domain type='kvm'>
<name>dev-21</name>
<uuid>89753b02-8c16-e9a1-35b3-9febf8364571</uuid>
<memory unit='KiB'>4194304</memory>
<currentMemory unit='KiB'>4194304</currentMemory>
<vcpu placement='static'>2</vcpu>
<os>
<type arch='x86_64' machine='rhel6.5.0'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='network' device='disk'>
<driver name='qemu' type='raw'/>
<source protocol='iscsi' name='iqn.1012-00.com.example:storage.disk2.amiens.sys1.xyz/1'>
<host name='10.243.0.130' port='3260'/>
</source>
<target dev='vdd' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
</disk>
<disk type='block' device='lun'>
<driver name='qemu' type='raw'/>
<source dev='/dev/sdn'/>
<target dev='sdn' bus='scsi'/>
<address type='drive' controller='0' bus='0' target='112' unit='0'/>
</disk>
<controller type='usb' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
</controller>
<controller type='pci' index='0' model='pci-root'/>
<controller type='scsi' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
</controller>
<interface type='bridge'>
<mac address='52:54:01:a9:71:4b'/>
<source bridge='ovirtmgmt'/>
<model type='e1000'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<serial type='pty'>
<target port='0'/>
</serial>
<console type='pty'>
<target type='serial' port='0'/>
</console>
<input type='tablet' bus='usb'>
<address type='usb' bus='0' port='1'/>
</input>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'>
<listen type='address' address='0.0.0.0'/>
</graphics>
<sound model='ac97'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</sound>
<video>
<model type='cirrus' vram='16384' heads='1' primary='yes'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
</memballoon>
</devices>
</domain>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
virsh edit dev-21
or other application using the libvirt API.
-->

<domain type='kvm'>
<name>dev-21</name>
<uuid>89753b02-8c16-e9a1-35b3-9febf8364571</uuid>
<memory unit='KiB'>4194304</memory>
<currentMemory unit='KiB'>4194304</currentMemory>
<vcpu placement='static'>2</vcpu>
<os>
<type arch='x86_64' machine='rhel6.5.0'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='block' device='lun'>
<driver name='qemu' type='raw'/>
<source dev='/dev/sdd'/>
<target dev='sdd' bus='scsi'/>
<address type='drive' controller='0' bus='0' target='12' unit='0'/>
</disk>
<disk type='block' device='lun'>
<driver name='qemu' type='raw'/>
<source dev='/dev/sdn'/>
<target dev='sdn' bus='scsi'/>
<address type='drive' controller='0' bus='0' target='112' unit='0'/>
</disk>
<controller type='usb' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
</controller>
<controller type='pci' index='0' model='pci-root'/>
<controller type='scsi' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
</controller>
<interface type='bridge'>
<mac address='52:54:01:a9:71:4b'/>
<source bridge='ovirtmgmt'/>
<model type='e1000'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<serial type='pty'>
<target port='0'/>
</serial>
<console type='pty'>
<target type='serial' port='0'/>
</console>
<input type='tablet' bus='usb'>
<address type='usb' bus='0' port='1'/>
</input>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'>
<listen type='address' address='0.0.0.0'/>
</graphics>
<sound model='ac97'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</sound>
<video>
<model type='cirrus' vram='16384' heads='1' primary='yes'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
</memballoon>
</devices>
</domain>

014-BMC

1
2
3
4
5
6
7
8
查看设备的BMC地址:
ipmitool lan print |grep "IP Address"

华为BMC:
Administrator
Admin@9000

root/Huawei12#$

015-qemu-img

1
2
3
4
5
6
7
8
9
10
1.yum install  qemu-img

2.qcw2镜像转化为raw镜像文件
qemu-img convert -f qcow2 CentOS7U3_GLOBAL_64bit_75G_20180404_APP.qcow2 -O raw CentOS7U3.raw

3.raw镜像转化为qcw2镜像文件
qemu-img convert -f qcow2  win7.raw  -O  raw  win7.qcow2

4.压测环境上传:
time qemu-img convert -S 8k -f qcow2 -O raw /os_data/RHEL6U3_GLOBAL_64bit_75G_20180109_APP.qcow2 /mnt/snbsfuse/snpool001/fusetest
赞赏一下吧~