oVirt专题:Hosted Engine之Engine Appliance制作

http://blkart.blog.51cto.com/1142352/1558647

oVirt v3.4开始支持Hosted Engine。什么是Hosted Engine呢?很简单,以前的管理节点是部署在一台物理机器上的,现在我们将管理节点部署到一台虚拟机中,并且这台虚拟机运行在oVirt虚拟化环境中的计算节点上。以前是先部署管理节点,然后部署计算节点,最后把计算节点注册到管理节点,这时通过WEB管理平台可以在计算节点上运行虚拟机。现在的需要先部署计算节点,然后在计算节点上起虚机部署管理节点。先后顺序有了变化。

前面提到需要将管理节点部署在一台虚拟机中,既然是虚拟机,那么我们可以提前制作一个管理节点虚拟机模板——Engine Appliance,提前在虚拟机中安装好系统及管理节点需要的软件包,在部署oVirt虚拟化环境时直接基于该模板创建一台虚拟机,在虚拟机中执行engine-setup命令进行配置即可完成管理节点部署。这样我们可以节约管理节点部署的时间,实现虚拟化环境的快速部署。


Engine Appliance如何制作?oVirt社区ovirt-appliance项目为我们提供了制作工具。下面介绍下基于该工具制作Engine Appliance的方法:

一、环境准备

需要准备一台能够连接互联网的机器(需要开启CPU虚拟化支持),内存需要大于5G,磁盘可用空间大于10G;准备CentOS7(6中缺少必要的lorax包)的安装介质。

二、制作环境搭建

(1)安装CentOS7系统

(2)安装依赖包(需要配置epel7的软件源)

1
2
# yum -y install lorax pykickstart virt-install libguestfs-tools imagefactory oz
# yum -y groupinstall Virtualization Host

(3)将SELinux设置为Permissive模式

1
2
# setenforce 0
# sed -i "s/^SELINUX.*/SELINUX=permissive/g" /etc/sysconfig/selinux

三、制作appliance

(1)下载ovirt-appliance包,准备appliance制作环境

1
2
3
4
5
# cd /tmp/
# git clone git://gerrit.ovirt.org/ovirt-appliance
# cd ovirt-appliance
# git submodule update --init
# cd engine-appliance

(2)制作appliance

(2.1)raw格式(输出文件为ovirt-appliance-fedora.raw)

1
# make ovirt-appliance-fedora.raw

(2.2)ova格式(输出文件为ovirt-appliance-fedora.ova)

1
# make

Note:此时我们就可以得到raw或ova格式的Engine Appliance文件,该文件可以在Hosted Engine部署时作为管理节点虚拟机模板来使用。

常见错误解决办法:

(1)导入Version模块错误,如下:

1
2
3
4
5
6
7
8
9
10
11
Traceback (most recent call last):
   File  "scripts/create_ova.py" , line 4,  in  <module>
     from imagefactory_plugins.ovfcommon.ovfcommon  import  RHEVOVFPackage
   File  "/tmp/ovirt-appliance/engine-appliance/imagefactory/imagefactory_plugins/ovfcommon/ovfcommon.py" , line 28,  in  <module>
     from imgfac.PersistentImageManager  import  PersistentImageManager
   File  "/tmp/ovirt-appliance/engine-appliance/imagefactory/imgfac/PersistentImageManager.py" , line 17,  in  <module>
     from ApplicationConfiguration  import  ApplicationConfiguration
   File  "/tmp/ovirt-appliance/engine-appliance/imagefactory/imgfac/ApplicationConfiguration.py" , line 25,  in  <module>
     from imgfac.Version  import  VERSION as VERSION
ImportError: No module named Version
make : *** [ovirt-appliance-fedora.ova] 错误 1

解决办法:

1
# cp /usr/lib/python2.7/site-packages/imgfac/Version.py /tmp/ovirt-appliance/engine-appliance/imagefactory/imgfac/

(2)没有找到qemu-kvm命令,如下

1
2
3
kill  $( cat  spawned_pids)
/bin/bash :行1: qemu-kvm: 未找到命令
make [1]: 离开目录“ /tmp/ovirt-appliance/engine-appliance

解决办法:

1
ln  -s  /usr/libexec/qemu-kvm  /bin/

Engine Appliance制作工具分析:

通过上面的制作方法我们可以了解到,Engine Appliance的制作方法是完全自动化的,如果我们想要对Engine Appliance做一些自定义的配置,应该如何实现呢?

首先介绍下工具的工作流程:

执行make命令-->调用MakeFile(定义变量,嵌套第二个make)-->make -f imgbased/data/images/poor-mans-lmc.makefile(定义变量,执行run-install)-->run-install(定义变量,调用qemu-kvm命令,读取ks文件,安装一个系统,制作qcow2格式的文件)-->返回第一个make继续调用scripts/create_ova.py脚本制作ova文件

相关文件分析:

(1)MakeFile

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
MAIN_NAME ?= ovirt-appliance-fedora     #定义文件名
 
VM_CPUS ?= 2     #定义虚拟机CPU数量
VM_RAM ?= 4096     #定义虚拟机RAM大小(M)
VM_DISK ?= 8000     #定义虚拟机DISK大小(M)
 
OVA_RAM ?= 4096     #定义OVA模板RAM大小(M)
OVA_CPUS ?= $(VM_CPUS)     #定义OVA模板CPU数量
 
ARCH := x86_64     #定义架构
RELEASEVER := 7     #定义版本
 
PYTHON ?= PYTHONPATH= "$(PWD)/imagefactory/"  python     #定义Python环境变量
CURL ?= curl     #定义CURL工具
 
.SECONDARY:
.PHONY:$(MAIN_NAME).ks.tpl     #定义ks模板文件名称
.INTERMEDIATE: hda.qcow2     #定义虚拟机磁盘文件名
 
all: $(MAIN_NAME).ova
         echo  "$(MAIN_NAME)"  appliance  done
 
%.ks: %.ks.tpl     #基于ks模板,拼合生成ks文件(修改一些ks文件信息)
         ksflatten $< > $@
         sed  -i \
                 -e  "/^[-]/ d"  \
                 -e  "/^text/ d"  \
                 -e  "s/^part .*/part \/ --size $(VM_DISK) --fstype ext4 --fsoptions discard/"  \
                 -e  "s/^network .*/network --activate/"  \
                 -e  "s/^%packages.*/%packages --ignoremissing/"  \
                 -e  "/default\.target/ s/^/#/"  \
                 -e  "/RUN_FIRSTBOOT/ s/^/#/"  \
                 -e  "/remove authconfig/ s/^/#/"  \
                 -e  "/remove linux-firmware/ s/^/#/"  \
                 -e  "/remove firewalld/ s/^/#/"  \
                 -e  "/^bootloader/ s/bootloader .*/bootloader --location=mbr --timeout=1/"  \
                 -e  "/rawhide/ s/^/#/"  \
                 -e  "/^reboot/ s/reboot/poweroff/"  \
                 -e  "/^services/ s/sshd/sshd,initial-setup-text/"  \
                 -e  "/^firstboot/ s/$$/ --reconfig/"  \
                 -e  "s#\$$basearch#$(ARCH)#g"  \
                 -e  "s#\$$releasever#$(RELEASEVER)#g"  \
                 $@
 
 
%.qcow2: %.ks     #制作qcow2格式模板文件
         make  -f imgbased /data/images/poor-mans-lmc .makefile \     #执行第二次make
                 KICKSTART= "$<"  \
                 RELEASEVER=$(RELEASEVER) \
                 QEMU_APPEND= "cmdline $(QEMU_APPEND)"  \
                 DISK_SIZE=$$(( $(VM_DISK) / 1000 ))G \
                 run- install     #执行run-install,制作hda.qcow2文件
         qemu-img convert -O qcow2 hda.qcow2  "$@"     #将hda.qcow2文件转换为qcow2格式并重新命名    
         rm  -f hda.qcow2     #删除hda.qcow2文件(该文件为中间文件,此后已不需要)
 
%.ova: %.qcow2     #调用scripts/create_ova.py,制作ova格式模板文件
         $(SUDO) $(PYTHON) scripts /create_ova .py -m $(OVA_RAM) -c $(OVA_CPUS)  "$*.qcow2"  "$@"
 
 
clean: clean-log     #清除log
         echo
 
clean-log:
         rm  -f *.log     #删除log文件

(2)poor-mans-lmc.makefile

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
KICKSTART = kickstarts /runtime-layout .ks     #需要再研究下文件是否会被调用
 
DISK_NAME = hda.qcow2     #定义虚拟机磁盘文件名
DISK_SIZE = 10G     #定义虚拟机磁盘大小
 
VM_RAM = 2048     #定义虚拟机内存
VM_SMP = 4
 
QEMU = qemu-kvm     #定义QEMU工具
QEMU_APPEND =     #QEMU附加信息
CURL = curl -L -O     #CURL命令附加选项
 
FEDORA_RELEASEVER = 7     #定义版本
FEDORA_ANACONDA_RELEASEVER = 7     #定义Anaconda版本
FEDORA_URL = http: //192 .168.3.239 /mirrors/Fedora/19/os/x86_64/     #定义FEDORA dvd镜像URL
FEDORA_ANACONDA_URL = $(FEDORA_URL)     #定义Anaconda URL
 
ifneq ($(FEDORA_RELEASEVER), $(FEDORA_ANACONDA_RELEASEVER))
FEDORA_ANACONDA_URL = http: //192 .168.3.239 /mirrors/Fedora/19/os/x86_64/
endif
 
SHELL =  /bin/bash
 
 
.INTERMEDIATE: spawned_pids
 
vmlinuz:     #定义vmlinuz文件位置
         $(CURL) $(FEDORA_ANACONDA_URL) /isolinux/vmlinuz
 
initrd.img:     #定义initrd.img文件位置
         $(CURL) $(FEDORA_ANACONDA_URL) /isolinux/initrd .img
 
squashfs.img:     #定义squashfs.img文件位置
         $(CURL) $(FEDORA_ANACONDA_URL) /LiveOS/squashfs .img
 
define TREEINFO     #定义TreeInfo信息
[general]
name = Fedora-$(FEDORA_RELEASEVER)
family = Fedora
variant = Fedora
version = $(FEDORA_RELEASEVER)
packagedir =
arch = x86_64
 
[stage2]
mainimage = squashfs.img
 
[images-x86_64]
kernel = vmlinuz
initrd = initrd.img
endef
 
.PHONY: .treeinfo
export  TREEINFO
.treeinfo:
         echo  -e  "$$TREEINFO"  > $@
 
run- install : PYPORT:=$(shell  echo  $$(( 50000 + $$RANDOM % 15000 )) )
run- install : vmlinuz initrd.img squashfs.img .treeinfo $(KICKSTART)
         python -m SimpleHTTPServer $(PYPORT) &  echo  $$! > spawned_pids
         qemu-img create -f qcow2 $(DISK_NAME) $(DISK_SIZE)
         $(QEMU) \     #调用qemu-kvm启动虚拟机,根据ks文件配置自动安装系统并进行相关配置
                 -vnc 0.0.0.0:7 \
                 -serial stdio \
                 -smp $(VM_SMP) -m $(VM_RAM) \
                 -hda $(DISK_NAME) \
                 -kernel vmlinuz \
                 -initrd initrd.img \
                 -append  "console=ttyS0 inst.repo=$(FEDORA_URL) inst.ks=http://10.0.2.2:$(PYPORT)/$(KICKSTART) inst.stage2=http://10.0.2.2:$(PYPORT)/ quiet $(QEMU_APPEND)"  ; \
         kill  $$( cat  spawned_pids)

下面来分析下自动安装虚机时用到的ks文件:

默认情况下,整个自动安装过程会涉及到4个ks文件,但是我们可以根据我们的实际情况及需求进行灵活调整。

(1)ovirt-appliance-fedora.ks.tpl

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
**导入fedora-cloud-base.ks文件内容**
%include fedora-spin-kickstarts /fedora-cloud-base .ks
 
#
# Repos
#
# baseurl variant
#url --url=http://download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Fedora/$basearch/os/
#repo --name="fedora" --baseurl=http://download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Fedora/$basearch/os/
#repo --name="updates" --baseurl=http://download.fedoraproject.org/pub/fedora/linux/updates/$releasever/$basearch/
 
**定义安装源及YUM源**
# mirrorlist variant
url --mirrorlist=http: //mirrors .fedoraproject.org /mirrorlist ?repo=fedora-$releasever&arch=$basearch
repo --name= "updates"  --mirrorlist=http: //mirrors .fedoraproject.org /mirrorlist ?repo=updates-released-f$releasever&arch=$basearch
 
#
# Configuration
#
**设置SELinux为permissive模式**
selinux --permissive
**重新配置firstboot**
firstboot --reconfig
**锁定root用户密码**
rootpw --plaintext none --lock
**系统安装完成后关闭电源**
poweroff
**添加一个名为admin的用户,加入到wheel组中**
user --name=admin --plaintext --password=none -- groups =wheel
 
#
# Packages
#
**定义要安装的包**
%packages
**初始配置工具,centos6.5中没有**
initial-setup(The initial-setup utility runs after installation.  It guides the user through a series of steps that allows  for  easier configuration of the machine.)
**重写磁盘分区表的工具**
dracut-modules-growroot(This dracut module will re-write the partition table of a disk so that the root partition has as much space as possible, bumping it up to the edge of the disk, or the edge of the next partition.)
%end
 
**安装后执行的任务**
%post --erroronfail
#
**准备initial-setup工具**
echo  "Preparing initial-setup"
#
**安装软件包**
yum  install  -y initial-setup plymouth(Plymouth provides an attractive graphical boot animation  in  place of the text messages that normally get shown.  Text messages are instead redirected to a log  file  for  viewing after boot.)
**系统启动时initial-setup-text服务发现该文件时确认需要初始化配置系统**
touch  /etc/reconfigSys
**设置initial-setup-text(字符界面)服务随系统启动**
systemctl  enable  initial-setup-text.service
**禁止initial-setup-graphical(图形界面)服务随系统启动**
systemctl disable initial-setup-graphical.service
 
 
# Default tty is ttyS0, to display initial-setup on tty0 we need to set this explicitly
sed  -i \
**设置initial-setup在tty0显示**
   -e  "/^StandardOutput/ a TTYPath=/dev/tty0"  \
   -e  "/^Description/ a Before=cloud-init-local.service cloud-init.service"  \
   /usr/lib/systemd/system/initial-setup-text .service
%end
 
%post --erroronfail
#
**预安装ovirt-engine及ovirt-guest-agent包**
echo  "Pre-Installing oVirt stuff"
#
yum  install  -y http: //resources .ovirt.org /pub/yum-repo/ovirt-release35 .rpm
yum  install  -y ovirt-engine ovirt-guest-agent
 
#
**生成ovirt-engine的应答文件**
echo  "Creating a partial answer file"
#
cat  /root/ovirt-engine-answers  <<__EOF__
[environment:default]
OVESETUP_CORE /engineStop =none:None
OVESETUP_DIALOG /confirmSettings =bool:True
OVESETUP_DB /database =str:engine
OVESETUP_DB /fixDbViolations =none:None
OVESETUP_DB /secured =bool:False
OVESETUP_DB /securedHostValidation =bool:False
OVESETUP_DB /host =str:localhost
OVESETUP_DB /user =str:engine
OVESETUP_DB /port =int:5432
OVESETUP_SYSTEM /nfsConfigEnabled =bool:False
OVESETUP_CONFIG /applicationMode =str:virt
OVESETUP_CONFIG /firewallManager =str:firewalld
OVESETUP_CONFIG /websocketProxyConfig =none:True
OVESETUP_CONFIG /storageType =str:nfs
OVESETUP_PROVISIONING /postgresProvisioningEnabled =bool:True
OVESETUP_APACHE /configureRootRedirection =bool:True
OVESETUP_APACHE /configureSsl =bool:True
OSETUP_RPMDISTRO /requireRollback =none:None
OSETUP_RPMDISTRO /enableUpgrade =none:None
__EOF__
 
%end
 
%post --erroronfail
#
**启用wheels组的 sudo 权限**
echo  "Enabling sudo for wheels"
#
**注释掉关于wheel组中用户不输入密码即可使用 sudo 提升权限的配置行,删除root用户密码并配置密码过期**
sed  -i  "/%wheel.*NOPASSWD/ s/^#//"  /etc/sudoers
passwd  --delete root
passwd  --expire root
%end

(2)fedora-cloud-base.ks

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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# This is a basic Fedora 21 spin designed to work in OpenStack and other
# private cloud environments. It's configured with cloud-init so it will
# take advantage of ec2-compatible metadata services for provisioning ssh
# keys. Cloud-init creates a user account named "fedora" with passwordless
# sudo access. The root password is empty and locked by default.
#
# Note that unlike the standard F20 install, this image has /tmp on disk
# rather than in tmpfs, since memory is usually at a premium.
#
# This kickstart file is designed to be used with appliance-creator and
# may need slight modification for use with actual anaconda or other tools.
# We intend to target anaconda-in-a-vm style image building for F20.
 
**设置文本模式安装**
text
**设置语言及编码类型**
lang en_US.UTF-8
**设置键盘类型**
keyboard us
**设置日期显示类型**
timezone --utc Etc /UTC
 
**设置系统验证信息**
auth --useshadow --enablemd5
**设置SELinux为强制模式**
selinux --enforcing
**锁定root用户密码 /root 用户密码加密**
rootpw --lock --iscrypted locked
**添加一个名为none的用户**
user --name=none
 
**禁用防火墙**
firewall --disabled
 
**bootloader设置,待确认具体参数功能**
bootloader --timeout=1 --append= "no_timer_check console=tty1 console=ttyS0,115200n8"  --extlinux
 
**设置eth0网卡通过dhcp进行网络参数配置,激活/启用该网卡**
network --bootproto=dhcp --device=eth0 --activate --onboot=on
**设置这些服务随系统启动**
services --enabled=network,sshd,rsyslog,cloud-init,cloud-init- local ,cloud-config,cloud-final
 
**清空mbr**
zerombr
**清空所有分区**
clearpart --all
**设置根分区大小为3000M,格式化为ext4文件系统**
part / --size 3000 --fstype ext4
 
**导入fedora-repo.ks文件,导入最新源信息,可注释掉**
%include fedora-repo.ks
 
**系统安装完后重启**
reboot
 
**要安装的包列表**
# Package list.
%packages
kernel-core(centos6.5无该包)
@core
grubby
 
# cloud-init does magical things with EC2 metadata, including provisioning
# a user account with ssh keys.
cloud-init(Cloud-init is a  set  of init scripts  for  cloud instances.  Cloud instances need special scripts to run during initialization to retrieve and  install  ssh  keys and to  let  the user run various scripts.)
 
# this is used by openstack's cloud orchestration framework (and it's small)
heat-cfntools(Tools required to be installed on Heat provisioned cloud instances)
 
# need this for growpart, because parted doesn't yet support resizepart
# https://bugzilla.redhat.com/show_bug.cgi?id=966993
cloud-utils-growpart(This package provides the growpart script  for  growing a partition. It is primarily used  in  cloud images  in  conjunction with the dracut-modules-growroot package to grow the root partition on first boot.)
 
# We need this image to be portable; also, rescue mode isn't useful here.
dracut-config-generic(centos6.5无该软件包)
-dracut-config-rescue
 
syslinux-extlinux(The EXTLINUX bootloader,  for  booting the  local  system, as well as all the SYSLINUX /PXELINUX  modules  in  /boot .)
 
**需要初始安装,后续会删除**
# Needed initially, but removed below.
firewalld
 
**挑选的一些会用到的包**
# cherry-pick a few things from @standard
tar
rsync
 
**删除@core包组中不需要的软件包**
# Some things from @core we can do without in a minimal install
-biosdevname
-plymouth
-NetworkManager
-iprutils
-kbd
-uboot-tools
-kernel
-grub2
 
%end
 
 
 
%post --erroronfail
 
**为EC2创建grub.conf文件**
# Create grub.conf for EC2. This used to be done by appliance creator but
# anaconda doesn't do it. And, in case appliance-creator is used, we're
# overriding it here so that both cases get the exact same file.
# Note that the console line is different -- that's because EC2 provides
# different virtual hardware, and this is a convenient way to act differently
echo  -n  "Creating grub.conf for pvgrub"
rootuuid=$(  awk  '$2=="/" { print $1 };'   /etc/fstab  )
mkdir  /boot/grub
 
 
echo  -e  'default=0\ntimeout=0\n\n'  /boot/grub/grub .conf
for  kv  in  $(  ls  -1v  /boot/vmlinuz * | grep  - v  rescue | sed  s/.*vmlinuz- //   );  do
   echo  "title Fedora ($kv)"  >>  /boot/grub/grub .conf
   echo  -e  "\troot (hd0)"  >>  /boot/grub/grub .conf
   echo  -e  "\tkernel /boot/vmlinuz-$kv ro root=$rootuuid no_timer_check console=hvc0 LANG=en_US.UTF-8"  >>  /boot/grub/grub .conf
   echo  -e  "\tinitrd /boot/initramfs-$kv.img"  >>  /boot/grub/grub .conf
   echo
done
 
**为ec2建立grub.conf的链接**
#link grub.conf to menu.lst for ec2 to work
echo  -n  "Linking menu.lst to old-style grub.conf for pv-grub"
ln  -sf grub.conf  /boot/grub/menu .lst
ln  -sf  /boot/grub/grub .conf  /etc/grub .conf
 
**老版本的livecd-tools工具中没有--lock,使用 passwd 锁定root用户密码**
# older versions of livecd-tools do not follow "rootpw --lock" line above
# https://bugzilla.redhat.com/show_bug.cgi?id=964299
passwd  -l root
# remove the user anaconda forces us to make
userdel -r none
 
**设置kickstart的超时时间为1秒**
# Kickstart specifies timeout in seconds; syslinux uses 10ths.
# 0 means wait forever, so instead we'll go with 1.
sed  -i  's/^timeout 10/timeout 1/'  /boot/extlinux/extlinux .conf
 
**设置systemd在正确的运行级别启动**
# setup systemd to boot to the right runlevel
echo  -n  "Setting default runlevel to multiuser text mode"
rm  -f  /etc/systemd/system/default .target
ln  -s  /lib/systemd/system/multi-user .target  /etc/systemd/system/default .target
echo  .
 
**如果你想删除rsyslog,只使用journald,需要注释掉这部分**
# If you want to remove rsyslog and just use journald, remove this!
echo  -n  "Disabling persistent journal"
rmdir  /var/log/journal/
echo  .
 
**删除虚拟机中不需要的包linux-firmware**
# this is installed by default but we don't need it in virt
echo  "Removing linux-firmware package."
yum -C -y remove linux-firmware
 
**删除firewalld包**
# Remove firewalld; was supposed to be optional in F18+, but is required to
# be present for install/image building.
echo  "Removing firewalld."
yum -C -y remove firewalld --setopt= "clean_requirements_on_remove=1"
 
**删除其它的一些只在系统安装时需要的包**
# Another one needed at install time but not after that, and it pulls
# in some unneeded deps (like, newt and slang)
echo  "Removing authconfig."
yum -C -y remove authconfig --setopt= "clean_requirements_on_remove=1"
 
**禁用串口控制台**
echo  -n  "Getty fixes"
# although we want console output going to the serial console, we don't
# actually have the opportunity to login there. FIX.
# we don't really need to auto-spawn _any_ gettys.
sed  -i '/^ #NAutoVTs=.*/ a\
NAutoVTs=0'  /etc/systemd/logind .conf
 
**初始配置脚本需要这个文件**
echo  -n  "Network fixes"
# initscripts don't like this file to be missing.
cat  /etc/sysconfig/network  << EOF
NETWORKING= yes
NOZEROCONF= yes
EOF
 
**删除udev中关于网卡的配置文件(文件中包含网卡的MAC信息,因此需要删除)**
# For cloud images, 'eth0' _is_ the predictable device name, since
# we don't want to be tied to specific virtual (!) hardware
rm  -f  /etc/udev/rules .d /70 *
ln  -s  /dev/null  /etc/udev/rules .d /80-net-name-slot .rules
 
**eth0网卡的基本配置信息**
# simple eth0 config, again not hard-coded to the build hardware
cat  /etc/sysconfig/network-scripts/ifcfg-eth0  << EOF
DEVICE= "eth0"
BOOTPROTO= "dhcp"
ONBOOT= "yes"
TYPE= "Ethernet"
PERSISTENT_DHCLIENT= "yes"
EOF
 
**生成localhost域名解析信息**
# generic localhost names
cat  /etc/hosts  << EOF
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
 
EOF
echo  .
 
 
**禁用将tmpfs挂载到 /tmp **
# Because memory is scarce resource in most cloud/virt environments,
# and because this impedes forensics, we are differing from the Fedora
# default of having /tmp on tmpfs.
echo  "Disabling tmpfs for /tmp."
systemctl mask tmp. mount
 
**确保firstboot不会在系统启动时配置系统**
# make sure firstboot doesn't start
echo  "RUN_FIRSTBOOT=NO"  /etc/sysconfig/firstboot
 
# Uncomment this if you want to use cloud init but suppress the creation
# of an "ec2-user" account. This will, in the absence of further config,
# cause the ssh key from a metadata source to be put in the root account.
#cat <<EOF > /etc/cloud/cloud.cfg.d/50_suppress_ec2-user_use_root.cfg
#users: []
#disable_root: 0
#EOF
 
**删除random-seed**
echo  "Removing random-seed so it's not the same in every image."
rm  -f  /var/lib/random-seed
 
**清空yum源缓存数据**
echo  "Cleaning old yum repodata."
yum  history  new
yum clean all
truncate -c -s 0  /var/log/yum .log
 
**导入RPM GPG key**
echo  "Import RPM GPG key"
releasever=$(rpm -q --qf  '%{version}\n'  fedora-release)
basearch=$( uname  -i)
rpm -- import  /etc/pki/rpm-gpg/RPM-GPG-KEY-fedora- $releasever-$basearch
 
**列出已经安装的软件包列表**
echo  "Packages within this cloud image:"
echo  "-----------------------------------------------------------------------"
rpm -qa
echo  "-----------------------------------------------------------------------"
# Note that running rpm recreates the rpm db files which aren't needed/wanted
rm  -f  /var/lib/rpm/__db *
 
**修复SELinux上下文**
echo  "Fixing SELinux contexts."
touch  /var/log/cron
touch  /var/log/boot .log
mkdir  -p  /var/cache/yum
chattr -i  /boot/extlinux/ldlinux .sys
/usr/sbin/fixfiles  -R -a restore
chattr +i  /boot/extlinux/ldlinux .sys
 
**用0填充空余空间**
echo  "Zeroing out empty space."
# This forces the filesystem to reclaim space from deleted files
dd  bs=1M  if = /dev/zero  of= /var/tmp/zeros  || :
rm  -f  /var/tmp/zeros
echo  "(Don't worry -- that out-of-space error was expected.)"
 
%end

(3)fedora-repo.ks(导入一些附加的repo源,该源最终会被注释掉)

1
2
3
4
5
6
7
8
9
# Include the appropriate repo definitions
 
# Exactly one of the following should be uncommented
 
# For the master branch the following should be uncommented
%include fedora-repo-rawhide.ks
 
# For non-master branches the following should be uncommented
# %include fedora-repo-not-rawhide.ks

(4)fedora-repo-rawhide.ks

1
repo --name=rawhide --mirrorlist=http: //mirrors .fedoraproject.org /mirrorlist ?repo=rawhide&arch=$basearch

前一篇中提到make过程中,这些ks文件会被拼接到一起,最后生成一个名为ovirt-appliance-fedora.ks的文件,该文件最终在虚拟机安装时被调用。


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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#version=DEVEL
#repo --name="rawhide" --mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=rawhide&arch=x86_64
repo --name= "updates"  --mirrorlist=http: //mirrors .fedoraproject.org /mirrorlist ?repo=updates-released-f19&arch=x86_64
# Keyboard layouts
keyboard  'us' # Shutdown after installation
shutdown
# Root password
rootpw --lock --plaintext none
# System timezone
timezone Etc /UTC  --isUtc
# Use network installation
url --mirrorlist= "http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-19&arch=x86_64"
# System language
lang en_US.UTF-8
user --name=none
user -- groups =wheel --name=admin --password=none
# Firewall configuration
firewall --disabled
# Network information
network --activate
# System authorization information
auth --useshadow --enablemd5
# Use text mode install
# Run the Setup Agent on first boot
firstboot --reconfig --reconfig
# SELinux configuration
selinux --permissive
 
# System services
services --enabled= "network,sshd,initial-setup-text,rsyslog,cloud-init,cloud-init-local,cloud-config,cloud-final"
# System bootloader configuration
bootloader --location=mbr --timeout=1
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all
# Disk partitioning information
part / --size 8000 --fstype ext4 --fsoptions discard
 
%post --erroronfail
 
# Create grub.conf for EC2. This used to be done by appliance creator but
# anaconda doesn't do it. And, in case appliance-creator is used, we're
# overriding it here so that both cases get the exact same file.
# Note that the console line is different -- that's because EC2 provides
# different virtual hardware, and this is a convenient way to act differently
echo  -n  "Creating grub.conf for pvgrub"
rootuuid=$(  awk  '$2=="/" { print $1 };'   /etc/fstab  )
mkdir  /boot/grub
echo  -e  'default=0\ntimeout=0\n\n'  /boot/grub/grub .conf
for  kv  in  $(  ls  -1v  /boot/vmlinuz * | grep  - v  rescue | sed  s/.*vmlinuz- //   );  do
   echo  "title Fedora ($kv)"  >>  /boot/grub/grub .conf
   echo  -e  "\troot (hd0)"  >>  /boot/grub/grub .conf
   echo  -e  "\tkernel /boot/vmlinuz-$kv ro root=$rootuuid no_timer_check console=hvc0 LANG=en_US.UTF-8"  >>  /boot/grub/grub .conf
   echo  -e  "\tinitrd /boot/initramfs-$kv.img"  >>  /boot/grub/grub .conf
   echo
done
 
 
#link grub.conf to menu.lst for ec2 to work
echo  -n  "Linking menu.lst to old-style grub.conf for pv-grub"
ln  -sf grub.conf  /boot/grub/menu .lst
ln  -sf  /boot/grub/grub .conf  /etc/grub .conf
 
# older versions of livecd-tools do not follow "rootpw --lock" line above
# https://bugzilla.redhat.com/show_bug.cgi?id=964299
passwd  -l root
# remove the user anaconda forces us to make
userdel -r none
 
# Kickstart specifies timeout in seconds; syslinux uses 10ths.
# 0 means wait forever, so instead we'll go with 1.
sed  -i  's/^timeout 10/timeout 1/'  /boot/extlinux/extlinux .conf
 
# setup systemd to boot to the right runlevel
echo  -n  "Setting default runlevel to multiuser text mode"
#rm -f /etc/systemd/system/default.target
#ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
echo  .
 
# If you want to remove rsyslog and just use journald, remove this!
echo  -n  "Disabling persistent journal"
rmdir  /var/log/journal/
echo  .
 
# this is installed by default but we don't need it in virt
echo  "Removing linux-firmware package."
#yum -C -y remove linux-firmware
 
# Remove firewalld; was supposed to be optional in F18+, but is required to
# be present for install/image building.
echo  "Removing firewalld."
#yum -C -y remove firewalld --setopt="clean_requirements_on_remove=1"
 
# Another one needed at install time but not after that, and it pulls
# in some unneeded deps (like, newt and slang)
echo  "Removing authconfig."
#yum -C -y remove authconfig --setopt="clean_requirements_on_remove=1"
 
echo  -n  "Getty fixes"
# although we want console output going to the serial console, we don't
# actually have the opportunity to login there. FIX.
# we don't really need to auto-spawn _any_ gettys.
sed  -i '/^ #NAutoVTs=.*/ a\
NAutoVTs=0'  /etc/systemd/logind .conf
 
echo  -n  "Network fixes"
# initscripts don't like this file to be missing.
cat  /etc/sysconfig/network  << EOF
NETWORKING= yes
NOZEROCONF= yes
EOF
 
# For cloud images, 'eth0' _is_ the predictable device name, since
# we don't want to be tied to specific virtual (!) hardware
rm  -f  /etc/udev/rules .d /70 *
ln  -s  /dev/null  /etc/udev/rules .d /80-net-name-slot .rules
 
# simple eth0 config, again not hard-coded to the build hardware
cat  /etc/sysconfig/network-scripts/ifcfg-eth0  << EOF
DEVICE= "eth0"
BOOTPROTO= "dhcp"
ONBOOT= "yes"
TYPE= "Ethernet"
PERSISTENT_DHCLIENT= "yes"
EOF
 
# generic localhost names
cat  /etc/hosts  << EOF
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
 
EOF
echo  .
 
 
# Because memory is scarce resource in most cloud/virt environments,
# and because this impedes forensics, we are differing from the Fedora
# default of having /tmp on tmpfs.
echo  "Disabling tmpfs for /tmp."
systemctl mask tmp. mount
 
# make sure firstboot doesn't start
#echo "RUN_FIRSTBOOT=NO" > /etc/sysconfig/firstboot
 
# Uncomment this if you want to use cloud init but suppress the creation
# of an "ec2-user" account. This will, in the absence of further config,
# cause the ssh key from a metadata source to be put in the root account.
#cat <<EOF > /etc/cloud/cloud.cfg.d/50_suppress_ec2-user_use_root.cfg
#users: []
#disable_root: 0
#EOF
 
echo  "Removing random-seed so it's not the same in every image."
rm  -f  /var/lib/random-seed
 
echo  "Cleaning old yum repodata."
yum  history  new
yum clean all
truncate -c -s 0  /var/log/yum .log
 
echo  "Import RPM GPG key"
releasever=$(rpm -q --qf  '%{version}\n'  fedora-release)
basearch=$( uname  -i)
rpm -- import  /etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-19-x86_64
 
echo  "Packages within this cloud image:"
echo  "-----------------------------------------------------------------------"
rpm -qa
echo  "-----------------------------------------------------------------------"
# Note that running rpm recreates the rpm db files which aren't needed/wanted
rm  -f  /var/lib/rpm/__db *
 
 
echo  "Fixing SELinux contexts."
touch  /var/log/cron
touch  /var/log/boot .log
mkdir  -p  /var/cache/yum
chattr -i  /boot/extlinux/ldlinux .sys
/usr/sbin/fixfiles  -R -a restore
chattr +i  /boot/extlinux/ldlinux .sys
 
echo  "Zeroing out empty space."
# This forces the filesystem to reclaim space from deleted files
dd  bs=1M  if = /dev/zero  of= /var/tmp/zeros  || :
rm  -f  /var/tmp/zeros
echo  "(Don't worry -- that out-of-space error was expected.)"
 
%end
 
%post --erroronfail
#
echo  "Preparing initial-setup"
#
yum  install  -y initial-setup plymouth
touch  /etc/reconfigSys
systemctl  enable  initial-setup-text.service
systemctl disable initial-setup-graphical.service
 
# Default tty is ttyS0, to display initial-setup on tty0 we need to set this explicitly
sed  -i \
   -e  "/^StandardOutput/ a TTYPath=/dev/tty0"  \
   -e  "/^Description/ a Before=cloud-init-local.service cloud-init.service"  \
   /usr/lib/systemd/system/initial-setup-text .service
%end
 
%post --erroronfail
#
echo  "Pre-Installing oVirt stuff"
#
yum  install  -y http: //resources .ovirt.org /pub/yum-repo/ovirt-release35 .rpm
yum  install  -y ovirt-engine ovirt-guest-agent
 
#
echo  "Creating a partial answer file"
#
cat  /root/ovirt-engine-answers  <<__EOF__
[environment:default]
OVESETUP_CORE /engineStop =none:None
OVESETUP_DIALOG /confirmSettings =bool:True
OVESETUP_DB /database =str:engine
OVESETUP_DB /fixDbViolations =none:None
OVESETUP_DB /secured =bool:False
OVESETUP_DB /securedHostValidation =bool:False
OVESETUP_DB /host =str:localhost
OVESETUP_DB /user =str:engine
OVESETUP_DB /port =int:5432
OVESETUP_SYSTEM /nfsConfigEnabled =bool:False
OVESETUP_CONFIG /applicationMode =str:virt
OVESETUP_CONFIG /firewallManager =str:firewalld
OVESETUP_CONFIG /websocketProxyConfig =none:True
OVESETUP_CONFIG /storageType =str:nfs
OVESETUP_PROVISIONING /postgresProvisioningEnabled =bool:True
OVESETUP_APACHE /configureRootRedirection =bool:True
OVESETUP_APACHE /configureSsl =bool:True
OSETUP_RPMDISTRO /requireRollback =none:None
OSETUP_RPMDISTRO /enableUpgrade =none:None
__EOF__
 
%end
 
%post --erroronfail
#
echo  "Enabling sudo for wheels"
#
sed  -i  "/%wheel.*NOPASSWD/ s/^#//"  /etc/sudoers
passwd  --delete root
passwd  --expire root
%end
 
%packages --ignoremissing
@core
cloud-init
cloud-utils-growpart
dracut-config-generic
dracut-modules-growroot
firewalld
grubby
heat-cfntools
initial-setup
kernel-core
rsync
syslinux-extlinux
tar
 
%end


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值