-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcustom-centos-image
More file actions
362 lines (251 loc) · 11.9 KB
/
custom-centos-image
File metadata and controls
362 lines (251 loc) · 11.9 KB
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
####Zstack 镜像和OpenStack差异主要在agent的安装和datastore。
####CentOS 8 和CentOS 7 差异,主要在升级内核的源,安装的包。
## CentOS 7.9 虚拟机,内核版本升级到5.4,这样virt 运行速度快很多。
yum install centos-release-openstack-train -y
yum install diskimage-builder -y
yum install libguestfs-tools-c libguestfs-tools libguestfs -y
#设置完成后,不需要使用virt都需要export
vi .bash_profile
export LIBGUESTFS_BACKEND=direct
export LANG="en_US.UTF-8"
### Zstack for CentOS 8
mkdir cloud-images
cd cloud-images
export image_name='CentOS-8-GenericCloud-8.4.2105-20210603.0.x86_64.qcow2'
#repo
virt-customize -a $image_name --run-command 'mkdir /etc/yum.repos.d/backup'
virt-customize -a $image_name --run-command 'mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/'
virt-customize -a $image_name --upload /root/cloud-images/CentOS-8-all.repo:/etc/yum.repos.d/CentOS-8-all.repo
# update kernel and tools
virt-customize -a $image_name --install kernel-lt,qemu-guest-agent,vim,wget
virt-customize -a $image_name --install unzip,jq,bash-completion,device-mapper-persistent-data,lvm2,iotop,iftop,nload,bridge-utils,bind-utils,nc,binutils,tree,psmisc,sysstat,nfs-utils
virt-customize -a $image_name --install socat,conntrack,ebtables,ipset
#enable service
virt-customize -a $image_name --run-command 'systemctl enable qemu-guest-agent'
# 设置时区
virt-customize -a $image_name --timezone "Asia/Shanghai"
#SSH服务
virt-customize -a $image_name --edit '/etc/ssh/sshd_config:s/GSS/#GSS/'
#环境变量
virt-customize -a $image_name --append-line '/etc/profile:alias vi=vim'
virt-customize -a $image_name --append-line '/etc/profile:alias c="clear"'
virt-customize -a $image_name --append-line '/etc/profile:unset MAILCHECK'
virt-customize -a $image_name --append-line '/root/.bash_profile:export LANG="en_US.UTF-8"'
#clean yum
virt-customize -a $image_name --run-command 'rm -rf /var/cache/dnf/*'
virt-customize -a $image_name --run-command 'rm -f /etc/issue.d/cockpit.issue /etc/motd.d/cockpit'
#inatall agent
virt-customize -a $image_name --run-command 'mkdir -p /var/lib/cloud/scripts/per-once'
virt-customize -a $image_name --upload /root/cloud-images/zstack.sh:/var/lib/cloud/scripts/per-once/zstack.sh
virt-customize -a $image_name --run-command 'chmod +x /var/lib/cloud/scripts/per-once/zstack.sh'
cd /root/
export DIB_LOCAL_IMAGE="/root/cloud-images/CentOS-8-GenericCloud-8.4.2105-20210603.0.x86_64.qcow2"
export DIB_RELEASE=8
export DIB_CLOUD_INIT_ALLOW_SSH_PWAUTH="yes"
export DIB_AVOID_PACKAGES_UPDATE=1
export image_name='CentOS-8.4-x86.qcow2'
#disk builder images
disk-image-create -a amd64 -o $image_name -x --image-size 80 vm base centos disable-selinux cloud-init dhcp-all-interfaces
### Zstack for CentOS 7
mkdir cloud-images
cd cloud-images
# CentOS 7.9 镜像
curl -O https://mirrors.ustc.edu.cn/centos-cloud/centos/7/images/CentOS-7-x86_64-GenericCloud-2009.qcow2
# pwd
/root/cloud-images
# 设置镜像变量
export image_name='CentOS-7-x86_64-GenericCloud-2009.qcow2'
#repo
virt-customize -a $image_name --run-command 'mkdir /etc/yum.repos.d/backup'
virt-customize -a $image_name --run-command 'mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/'
virt-customize -a $image_name --upload /root/cloud-images/CentOS-7-all.repo:/etc/yum.repos.d/CentOS-7-all.repo
##安装工具
virt-customize -a $image_name --install kernel,vim,qemu-guest-agent
virt-customize -a $image_name --install net-tools,wget,unzip,jq,bash-completion,yum-utils,device-mapper-persistent-data,lvm2,openssl,sysstat,iotop,iftop,nload,bridge-utils,bash-completion,bind-utils,nc,binutils,tree,psmisc,nfs-utils
virt-customize -a $image_name --install socat,conntrack,ebtables,ipset
#启动服务
virt-customize -a $image_name --run-command 'systemctl enable qemu-guest-agent'
# 设置时区
virt-customize -a $image_name --timezone "Asia/Shanghai"
#SSH服务
virt-customize -a $image_name --edit '/etc/ssh/sshd_config:s/GSS/#GSS/'
virt-customize -a $image_name --edit '/etc/ssh/sshd_config:s/#UseDNS yes/UseDNS no/'
#vim
virt-customize -a $image_name --append-line '/etc/profile:alias vi=vim'
virt-customize -a $image_name --append-line '/etc/profile:alias c="clear"'
virt-customize -a $image_name --append-line '/etc/profile:unset MAILCHECK'
virt-customize -a $image_name --append-line '/root/.bash_profile:export LANG="en_US.UTF-8"'
#inatall zstack agent
virt-customize -a $image_name --run-command 'mkdir -p /var/lib/cloud/scripts/per-once'
virt-customize -a $image_name --upload /root/cloud-images/zstack.sh:/var/lib/cloud/scripts/per-once/zstack.sh
virt-customize -a $image_name --run-command 'chmod +x var/lib/cloud/scripts/per-once/zstack.sh'
#clean yum,不能运行yum clean all,会导致镜像加大。这样就足够。最终镜像730M大小,
virt-customize -a $image_name --run-command 'rm -rf /var/cache/yum/*'
##DIB
#pwd
/root
export DIB_LOCAL_IMAGE="/root/cloud-images/CentOS-7-x86_64-GenericCloud-2009.qcow2"
export DIB_RELEASE=7
export DIB_CLOUD_INIT_ALLOW_SSH_PWAUTH="yes"
export DIB_AVOID_PACKAGES_UPDATE=1
export image_name='CentOS-7.9-x86.qcow2'
#disk builder images
disk-image-create -a amd64 -o $image_name -x --image-size 80 vm base centos disable-selinux cloud-init dhcp-all-interfaces
### OpenStack for CentOS 8
cd cloud-images
export image_name='CentOS-8-GenericCloud-8.4.2105-20210603.0.x86_64.qcow2'
#repo
virt-customize -a $image_name --run-command 'mkdir /etc/yum.repos.d/backup'
virt-customize -a $image_name --run-command 'mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/'
virt-customize -a $image_name --upload /root/cloud-images/CentOS-8-all.repo:/etc/yum.repos.d/CentOS-8-all.repo
# update kernel and tools
virt-customize -a $image_name --install kernel-lt,qemu-guest-agent,vim
virt-customize -a $image_name --install wget,unzip,jq,bash-completion,yum-utils,device-mapper-persistent-data,lvm2,openssl,sysstat,iotop,iftop,nload,bridge-utils,bash-completion,bind-utils,nc,binutils,tree,psmisc
virt-customize -a $image_name --install socat,conntrack,ebtables,ipset
#enable service
virt-customize -a $image_name --run-command 'systemctl enable qemu-guest-agent'
# 设置时区
virt-customize -a $image_name --timezone "Asia/Shanghai"
#SSH服务
virt-customize -a $image_name --edit '/etc/ssh/sshd_config:s/GSS/#GSS/'
#环境变量
virt-customize -a $image_name --append-line '/etc/profile:alias vi=vim'
virt-customize -a $image_name --append-line '/etc/profile:alias c="clear"'
virt-customize -a $image_name --append-line '/etc/profile:unset MAILCHECK'
virt-customize -a $image_name --append-line '/root/.bash_profile:export LANG="en_US.UTF-8"'
#clean yum
virt-customize -a $image_name --run-command 'rm -rf /var/cache/dnf/*'
##DIB
cd /root/
export LIBGUESTFS_BACKEND=direct
export DIB_LOCAL_IMAGE="/root/cloud-images/CentOS-8-GenericCloud-8.4.2105-20210603.0.x86_64.qcow2"
export DIB_RELEASE=8
export DIB_CLOUD_INIT_ALLOW_SSH_PWAUTH="yes"
export DIB_AVOID_PACKAGES_UPDATE=1
export image_name='CentOS-8.4-x86.qcow2'
DIB_CLOUD_INIT_DATASOURCES="ConfigDrive, OpenStack" disk-image-create -a amd64 -o $image_name -x --image-size 40 vm base centos disable-selinux cloud-init cloud-init-datasources dhcp-all-interfaces growroot
### OpenStack for CentOS 7
mkdir cloud-images
cd cloud-images
# CentOS 7.9 镜像
curl -O https://mirrors.ustc.edu.cn/centos-cloud/centos/7/images/CentOS-7-x86_64-GenericCloud-2009.qcow2
# pwd
/root/cloud-images
# 设置镜像变量
export image_name='CentOS-7-x86_64-GenericCloud-2009.qcow2'
#repo
virt-customize -a $image_name --run-command 'mkdir /etc/yum.repos.d/backup'
virt-customize -a $image_name --run-command 'mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/'
virt-customize -a $image_name --upload /root/cloud-images/CentOS-7-all.repo:/etc/yum.repos.d/CentOS-7-all.repo
#安装工具
virt-customize -a $image_name --install kernel,qemu-guest-agent,vim
virt-customize -a $image_name --install net-tools,wget,unzip,jq,bash-completion,yum-utils,device-mapper-persistent-data,lvm2,openssl,sysstat,iotop,iftop,nload,bridge-utils,bash-completion,bind-utils,nc,binutils,tree,psmisc
virt-customize -a $image_name --install socat,conntrack,ebtables,ipset
#启动服务
virt-customize -a $image_name --run-command 'systemctl enable qemu-guest-agent'
# 设置时区
virt-customize -a $image_name --timezone "Asia/Shanghai"
#SSH服务
virt-customize -a $image_name --edit '/etc/ssh/sshd_config:s/GSS/#GSS/'
virt-customize -a $image_name --edit '/etc/ssh/sshd_config:s/#UseDNS yes/UseDNS no/'
#vim
virt-customize -a $image_name --append-line '/etc/profile:alias vi=vim'
virt-customize -a $image_name --append-line '/etc/profile:alias c="clear"'
virt-customize -a $image_name --append-line '/etc/profile:unset MAILCHECK'
virt-customize -a $image_name --append-line '/root/.bash_profile:export LANG="en_US.UTF-8"'
#clean yum,不能运行yum clean all,会导致镜像加大。这样就足够。最终镜像730M大小,
virt-customize -a $image_name --run-command 'rm -rf /var/cache/yum/*'
##DIB
#pwd
/root
export DIB_LOCAL_IMAGE="/root/cloud-images/CentOS-7-x86_64-GenericCloud-2009.qcow2"
export DIB_RELEASE=7
export DIB_CLOUD_INIT_ALLOW_SSH_PWAUTH="yes"
export DIB_AVOID_PACKAGES_UPDATE=1
export image_name='CentOS-7.9-x86.qcow2'
##build image
DIB_CLOUD_INIT_DATASOURCES="ConfigDrive, OpenStack" disk-image-create -a amd64 -o $image_name -x --image-size 40 vm base centos disable-selinux cloud-init cloud-init-datasources dhcp-all-interfaces growroot
###附录
##修改密码
virt-customize -a $image_name --root-password password:chenshake
##替换repo
virt-customize -a $image_name --run-command ‘rm /etc/yum.repos.d/CentOS-7-all.repo'
virt-customize -a $image_name --run-command ‘wget -O /etc/yum.repos.d/all-huawei.repo https://raw.fastgit.org/shake/shell/main/CentOS7/all-huawei.repo'
# cat .pip/pip.conf
## Note, this file is written by cloud-init on first boot of an instance
## modifications made here will not survive a re-bundle.
###
[global]
index-url=http://mirrors.cloud.aliyuncs.com/pypi/simple/
[install]
trusted-host=mirrors.cloud.aliyuncs.com
##nexus upload and download file
curl -v -u admin:admin --upload-file get-pip.py https://hub.bj.sugon.tech:8443/repository/binary/tools/get-pip.py
curl -o get-pip.py https://hub.abc.tech:8443/repository/binary/tools/get-pip.py
## zstack install agent
cat cloud-images/zstack.sh
#!/bin/bash
/bin/bash -c "$(curl -s -S http://169.254.169.254/vm-tools.sh)"
sed -i 's/9100/9104/g' /usr/local/zstack/zwatch-vm-agent/conf.yaml
/bin/systemctl restart zwatch-vm-agent.service
## CentOS 7
[CentOS-Base]
name=CentOS Base
baseurl=https://hub.bj.sugon.tech:8443/repository/CentOS-7-Base/
enabled=1
gpgcheck=0
[CentOS-Updates]
name=CentOS Update
baseurl=https://hub.bj.sugon.tech:8443/repository/CentOS-7-Update/
enabled=1
gpgcheck=0
[CentOS-Extras]
name=CentOS Extras
baseurl=https://hub.bj.sugon.tech:8443/repository/CentOS-7-Extras/
enabled=1
gpgcheck=0
[EPEL]
name=CentOS EPEL
baseurl=https://hub.bj.sugon.tech:8443/repository/CentOS-7-EPEL/
enabled=1
gpgcheck=0
[CentOS-7-LTS-Kernels]
name=CentOS LTS Kernels
baseurl=https://hub.bj.sugon.tech:8443/repository/CentOS-7-LTS-Kernels/
enabled=1
gpgcheck=0
## CentOS 8
[BaseOS]
name=CentOS-8 - Base
baseurl=https://hub.bj.sugon.tech:8443/repository/CentOS-8-BaseOS/
enabled=1
gpgcheck=0
[AppStream]
name=CentOS-8 - AppStream
baseurl=https://hub.bj.sugon.tech:8443/repository/CentOS-8-AppStream/
enabled=1
gpgcheck=0
[PowerTools]
name=CentOS-8 - PowerTools
baseurl=https://hub.bj.sugon.tech:8443/repository/CentOS-8-PowerTools/
enabled=1
gpgcheck=0
[epel]
name=Extra Packages for Enterprise Linux 8
baseurl=https://hub.bj.sugon.tech:8443/repository/CentOS-8-EPEL/
enabled=1
gpgcheck=0
[elrepo-kernel]
name=ELRepo.org - el8
baseurl=https://hub.bj.sugon.tech:8443/repository/CentOS-8-elrepo-kernel/
enabled=1
gpgcheck=0
[docker-ce-stable]
name=Docker CE Stable
baseurl=https://hub.bj.sugon.tech:8443/repository/CentOS-8-Docker/
enabled=1
gpgcheck=0
##
echo $LANG
echo 'export LANG="en_US.UTF-8"' >> ~/.bash_profile
source ~/.bash_profile # 使文件生效