-
Notifications
You must be signed in to change notification settings - Fork 1
/
CentOS-7-EFI-kickstart.cfg
649 lines (550 loc) · 25.4 KB
/
CentOS-7-EFI-kickstart.cfg
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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
# Kickstart for CentOS 7.5.1804 x86_64
# platform=x86, AMD64, 或 Intel EM64T
# version=RHEL7
# Firewall configuration
firewall --disabled
# SELinux configuration
selinux --disabled
# Installation logging level
logging --level=info
services --enabled="sshd,chronyd,iptables,"
services --disabled="auditd,kdump,messagebus,wpa_supplicant,abrt-ccpp,abrt-oops,abrt-vmcore,abrt-xorg,abrtd,avahi-daemon,NetworkManager,NetworkManager-dispatcher.service,NetworkManager.service,NetworkManager-wait-online"
install
#url --url=http://ftp.sakura.ad.jp/pub/linux/centos/7/os/x86_64/
url --mirrorlist="http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock"
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
#lang C
lang zh_CN.utf8
# System authorization information
auth --enableshadow --passalgo=sha512
# Root password
rootpw --iscrypted $6$hMQrGfWmyGaNCD.2$AaRLHlTXZBvjOKX1wJofdzgssJE6SfDkji6KwnG7xzhaBvq3j054fJn99IJPe/n6U0WYl/aSTv0vVgWZiRKB50
#rootpw lookback
#密码是lookback
selinux --disabled
text
# System timezone
timezone Asia/Shanghai --isUtc
eula --agreed
#poweroff
reboot --eject
repo --name=base --mirrorlist="http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra" --cost=100
repo --name=updates --mirrorlist="http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra" --cost=1000
repo --name=extras --mirrorlist="http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra" --cost=1005
repo --name=epel --mirrorlist="https://mirrors.fedoraproject.org/mirrorlist?repo=epel-$releasever&arch=$basearch"
repo --name=elrepo-kernel --baseurl=http://elrepo.org/linux/kernel/el7/x86_64/
repo --name=elrepo-release --baseurl=http://elrepo.org/linux/elrepo/el7/x86_64/
repo --name=elrepo-extras --baseurl=http://elrepo.org/linux/extras/el7/x86_64/
repo --name=zabbix --baseurl=http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/ --cost=1030
#repo --name=base --baseurl=http://10.10.10.250/centos/7/os/x86_64 --cost=100
#repo --name=updates --baseurl=http://10.10.10.250/centos/7/updates/x86_64 --cost=1000
#repo --name=extras --baseurl=http://10.10.10.250/centos/7/extras/x86_64 --cost=1005
#repo --name=epel --baseurl=http://10.10.10.250/epel/7/x86_64 --cost=1010
#repo --name=elrepo-kernel --baseurl=http://10.10.10.250/elrepo/kernel/el7/x86_64/ --cost=1015
#repo --name=elrepo-release --baseurl=http://10.10.10.250/elrepo/elrepo/el7/x86_64/ --cost=1020
#repo --name=elrepo-extras --baseurl=http://10.10.10.250/elrepo/extras/el7/x86_64/ --cost=1025
#repo --name=zabbix --baseurl=http://10.10.10.250/zabbix/zabbix/3.4/rhel/7/x86_64/ --cost=1030
#repo --name=base --baseurl=http://ftp.sakura.ad.jp/pub/linux/centos/7/os/x86_64 --cost=100
#repo --name=updates --baseurl=http://ftp.sakura.ad.jp/pub/linux/centos/7/updates/x86_64 --cost=1000
#repo --name=epel --baseurl=http://ftp.jaist.ac.jp/pub/Linux/Fedora/epel/7/x86_64/
%include /tmp/part-include
%pre
#!/bin/bash
#yum update -y
b2G=1073741824
disk_name=$(lsblk -d | awk '$1~/^((h|s|x?v)da|nvme.*1)$/{print $1}')
disk_size=$(lsblk -bd | awk '$1~/^((h|s|x?v)da|nvme.*1)$/{print $4}')
Disk_Size=$( expr $disk_size / $b2G )
echo "# Clear the Master Boot Record" > /tmp/part-include
echo "zerombr" >> /tmp/part-include
echo "# Partition clearing information" >> /tmp/part-include
echo "#clearpart --all" >> /tmp/part-include
echo "clearpart --drives=$disk_name --all" >> /tmp/part-include
echo "# Partition" >> /tmp/part-include
echo "bootloader --append='crashkernel=auto' --location=mbr --boot-drive=$disk_name" >> /tmp/part-include
echo -e "\n\n\n\n" >> /tmp/part-include
if [[ "$disk_size" -ge "10737418240" ]] && [[ "$disk_size" -lt "21474836480" ]]; then
echo "#partitioning $disk_name in %pre for 10G <= X < 20G" >> /tmp/part-include
echo "clearpart --all --initlabel --drives=$disk_name" >> /tmp/part-include
echo "# Disk partitioning information UEFI" >> /tmp/part-include
echo "part /boot --fstype="xfs" --ondisk=$disk_name --size=1024" >> /tmp/part-include
echo "part /boot/efi --fstype='efi' --ondisk=$disk_name --size=200 --fsoptions='umask=0077,shortname=winnt'" >> /tmp/part-include
echo "part pv.218 --fstype='lvmpv' --ondisk=$disk_name --size=8200 --grow" >> /tmp/part-include
echo "volgroup LBVG --pesize=4096 pv.218" >> /tmp/part-include
echo "logvol swap --fstype='swap' --size=1024 --name=swap --vgname=LBVG" >> /tmp/part-include
echo "logvol / --fstype='xfs' --percent=90 --name=root --vgname=LBVG" >> /tmp/part-include
elif [[ "$disk_size" -ge "21474836480" ]] && [[ "$disk_size" -lt "107374182400" ]]; then
echo "#partitioning $disk_name in %pre for 20G <= X < 100G" >> /tmp/part-include
echo "clearpart --all --initlabel --drives=$disk_name" >> /tmp/part-include
echo "# Disk partitioning information UEFI" >> /tmp/part-include
echo "part /boot --fstype="xfs" --ondisk=$disk_name --size=1024" >> /tmp/part-include
echo "part /boot/efi --fstype='efi' --ondisk=$disk_name --size=200 --fsoptions='umask=0077,shortname=winnt'" >> /tmp/part-include
echo "part pv.218 --fstype='lvmpv' --ondisk=$disk_name --size=18432 --grow" >> /tmp/part-include
echo "volgroup LBVG --pesize=4096 pv.218" >> /tmp/part-include
echo "logvol swap --fstype='swap' --size=2048 --name=swap --vgname=LBVG" >> /tmp/part-include
echo "logvol / --fstype='xfs' --percent=95 --name=root --vgname=LBVG" >> /tmp/part-include
elif [[ "$disk_size" -ge "107374182400" ]]; then
echo "#partitioning $disk_name in %pre for 100G <= X" >> /tmp/part-include
echo "clearpart --all --initlabel --drives=$disk_name" >> /tmp/part-include
echo "# Disk partitioning information UEFI" >> /tmp/part-include
echo "part /boot --fstype="xfs" --ondisk=$disk_name --size=1024" >> /tmp/part-include
echo "part /boot/efi --fstype='efi' --ondisk=$disk_name --size=200 --fsoptions='umask=0077,shortname=winnt'" >> /tmp/part-include
echo "part pv.218 --fstype='lvmpv' --ondisk=$disk_name --size=34820 --grow" >> /tmp/part-include
echo "volgroup LBVG --pesize=4096 pv.218" >> /tmp/part-include
echo "logvol swap --fstype='swap' --size=4096 --name=swap --vgname=LBVG" >> /tmp/part-include
echo "logvol / --fstype='xfs' --name=root --vgname=LBVG --size=30720 --grow" >> /tmp/part-include
#echo "logvol / --fstype='xfs' --name=root --vgname=LBVG --size=30720 --grow --percent=90" >> /tmp/part-include
fi
%end
%packages --ignoremissing --excludedocs
@ Development Tools
#@ fonts
-microcode_ctl
-rdma
#-kernel
-kernel-headers
-kernel-tools
#@X Window System
#xorg-x11-xauth
#xorg-x11-fonts-*
#xorg-x11-utils
epel-release
elrepo-release-7.0
zabbix-release-3.4
kernel-ml
kernel-ml-devel
kernel-ml-tools
kernel-ml-tools-libs
kernel-ml-headers
kernel-ml-doc
kernel-ml-tools-libs-devel
perf
python-perf
zabbix-agent
zabbix-sender
lshw
vim
tree
ntpdate
bash-completion
bash-completion-extras
yum-plugin-fastestmirror
git
xterm
gettext
vnstat
man
screen
tmux
crontabs
wget
curl
axel
iproute
mtr
gdisk
iotop
iftop
htop
bind-utils
tcpdump
traceroute
net-tools
bridge-utils
iptables-devel
iptables-services
iptables
tar
ipmitool
nss
libcurl
#fail2ban
chrony
%end
%post --log=/tmp/ks-post-1.log --interpreter=/usr/bin/bash
#Web_Status_Code=$(curl -Lkso /dev/null -w "%{http_code}" 10.10.10.250/centos)
#if [ $Web_Status_Code = '0' ]; then
# if ! grep -q git.ds.com /etc/hosts; then sed -i '/^::1/a \\n10.0.1.179 git.ds.com' /etc/hosts;fi
# if ! grep -q mirrors.ds.com /etc/hosts; then sed -i '/^::1/a \\n10.10.10.250 mirrors.ds.com' /etc/hosts;fi
# curl -Lk http://git.ds.com/lookback/private-mirrors/raw/master/CentOS-Base.repo > /etc/yum.repos.d/CentOS-Base.repo
# curl -Lk http://git.ds.com/lookback/private-mirrors/raw/master/epel.repo > /etc/yum.repos.d/epel.repo
# curl -Lk http://git.ds.com/lookback/private-mirrors/raw/master/elrepo.repo > /etc/yum.repos.d/elrepo.repo
#fi
# network
cat << 'EOF' > /etc/sysconfig/network
NETWORKING=yes
#NETWORKING_IPV6=yes
HOSTNAME=localhost.localdomain
EOF
Interface_No=$(ip a|awk '$2~/^e(n|t)/{sum+=1;}END{print sum-1}')
for i in $(seq 0 ${Interface_No});do
cat << EOF > /etc/sysconfig/network-scripts/ifcfg-eth$i
TYPE="Ethernet"
DEVICE="eth$i"
NAME="eth$i"
BOOTPROTO="dhcp"
ONBOOT="yes"
DEFROUTE="yes"
#METRIC=
#GATEWAY=
#NETMASK=
#IPADDR=
#DNS1=
#HWADDR=
EOF
done
if [[ "${Interface_No}" -ge "0" ]]; then
eth0_mac=$(ip a|awk '$2~/^e(n|t)/{getline;print $2}')
sed -i "s/#HWADDR=/HWADDR=${eth0_mac}/" /etc/sysconfig/network-scripts/ifcfg-eth0
fi
cat << 'EOF' > /etc/resolv.conf
nameserver 139.99.18.82
nameserver 139.99.115.58
nameserver 139.99.18.83
#nameserver 2403:3a00::1
EOF
cat >> /etc/sysctl.conf <<-EOF
# Do not accept RA
#net.ipv6.conf.default.accept_ra=0
#net.ipv6.conf.all.accept_ra=0
#net.ipv6.conf.eth0.accept_ra=0
fs.file-max=65535
net.ipv4.tcp_max_tw_buckets = 60000
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304
net.ipv4.tcp_max_syn_backlog = 65536
net.core.netdev_max_backlog = 32768
net.core.somaxconn = 32768
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
#net.ipv4.tcp_tw_recycle = 1
#net.ipv4.tcp_tw_len = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.ip_local_port_range = 1024 65000
net.nf_conntrack_max = 6553500
net.netfilter.nf_conntrack_max = 6553500
net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60
net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120
net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120
net.netfilter.nf_conntrack_tcp_timeout_established = 3600
net.ipv4.conf.all.rp_filter = 2
net.ipv4.ip_forward = 1
EOF
# iptables
cat <<'EOF' > /etc/sysconfig/iptables
# Simple static firewall loaded by iptables.service. Replace
# this with your own custom rules, run lokkit, or switch to
# shorewall or firewalld as your needs dictate.
*filter
:INPUT DROP [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -s 180.150.139.135/32 -p tcp -m tcp -m state --state NEW,ESTABLISHED -m multiport --dports 22,22992 -m comment --comment "RACK-Firewall-Anyconnect-VPN-SSH_PORT" -j ACCEPT
-A INPUT -s 172.30.200.249/32 -p tcp -m tcp -m state --state NEW,ESTABLISHED -m multiport --dports 22,22992 -m comment --comment "RACK-Anyconnect-VPN-SSH_PORT" -j ACCEPT
-A INPUT -s 172.25.200.200/32 -p tcp -m tcp -m state --state NEW,ESTABLISHED -m multiport --dports 22,22992 -m comment --comment "RACK-Anyconnect-VPN-SSH_PORT" -j ACCEPT
-A INPUT -s 172.20.200.200/32 -p tcp -m tcp -m state --state NEW,ESTABLISHED -m multiport --dports 22,22992 -m comment --comment "RACK-Anyconnect-VPN-SSH_PORT" -j ACCEPT
-A INPUT -s 172.19.3.200/32 -p tcp -m tcp -m state --state NEW,ESTABLISHED -m multiport --dports 22,22992 -m comment --comment "RACK-Anyconnect-VPN-SSH_PORT" -j ACCEPT
-A INPUT -s 203.60.15.113/32 -p tcp -m tcp -m state --state NEW,ESTABLISHED -m multiport --dports 22,22992 -m comment --comment "RACK-Anyconnect-VPN-SSH_PORT" -j ACCEPT
-A INPUT -p tcp -m tcp -m state --state NEW,ESTABLISHED -m multiport --dports 22,22992 -m comment --comment "SSH_PORT" -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
EOF
# Add elrepo&epel&zabbix Repository
#yum install -y http://elrepo.org/linux/kernel/el7/x86_64/RPMS/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
#yum install -y http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
#perl -pi.orig -e 's/^(mirrorlist=)/#$1/; s/^#(baseurl=)/$1/' /etc/yum.repos.d/CentOS-Base.repo
#perl -pi -e 's/^(baseurl=http:\/\/mirror.centos.org)/baseurl=http:\/\/ftp.sakura.ad.jp\/pub\/linux/' /etc/yum.repos.d/CentOS-Base.repo
# sshd
sed -ri 's/^(#)?Port 22$/Port 22/;/^Port/a Port 22992' /etc/ssh/sshd_config
sed -i -e "/\#MaxSessions 10$/a #AllowUsers\nDenyUsers toor administrator administrateur admin adm test guest info mysql user oracle" /etc/ssh/sshd_config
sed -i -e '/GSSAPIAuthentication yes$/d' /etc/ssh/sshd_config
sed -i -e '/^GSSAPICleanupCredentials yes$/d' /etc/ssh/sshd_config
[[ "$(awk '/^UseDNS/{print $2}' /etc/ssh/sshd_config)" =~ ^[nN][oO]$ ]] || { echo 'UseDNS no' >> /etc/ssh/sshd_config; }
# docker
curl -Lk get.docker.com|bash
curl -Lk onekey.sh/docker-compose|bash
curl -L https://github.com/docker/compose/releases/download/v2.17.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
mkdir -p /etc/docker
cat <<'EOL' > /etc/docker/daemon.json
{
"bip": "172.31.0.1/16"
}
EOL
# selinux
[ -f /etc/sysconfig/selinux ] && { sed -i 's/^SELINUX=.*/#&/;s/^SELINUXTYPE=.*/#&/;/SELINUX=.*/a SELINUX=disabled' /etc/sysconfig/selinux; /usr/sbin/setenforce 0; }
[ -f /etc/selinux/config ] && { sed -i 's/^SELINUX=.*/#&/;s/^SELINUXTYPE=.*/#&/;/SELINUX=.*/a SELINUX=disabled' /etc/selinux/config; /usr/sbin/setenforce 0; }
# ntp
if ! ping ntp.dtops.cc -c1 >/dev/null 2>&1; then
echo '172.25.0.254 ntp.dtops.cc' >> /etc/hosts
fi
[ -x /usr/sbin/ntpdate ] || yum install ntpdate -y
if ! grep -q ntpdate /var/spool/cron/root; then
echo -e "*/5 * * * * /usr/sbin/ntpdate -u ntp.dtops.cc >/dev/null 2>&1" >> /var/spool/cron/root
else
sed -i '/ntpdate/d' /var/spool/cron/root; echo -e "*/5 * * * * /usr/sbin/ntpdate -u ntp.dtops.cc >/dev/null 2>&1" >> /var/spool/cron/root
fi
# add_yum_pulgins
curl -4Lk https://github.com/xiaoyawl/centos_init/raw/master/yum_plugins/axelget.conf > /etc/yum/pluginconf.d/axelget.conf
curl -4Lk https://github.com/xiaoyawl/centos_init/raw/master/yum_plugins/axelget.py > /usr/lib/yum-plugins/axelget.py
## fail2ban
#touch /var/log/fail2ban.log
#sed -i -E 's/^(logtarget =).*/\1 \/var\/log\/fail2ban.log/' /etc/fail2ban/fail2ban.conf
#
## fail2ban 00-firewalld.conf
#sed -ri 's/firewallcmd-ipset/iptables-multiport/' /etc/fail2ban/jail.d/00-firewalld.conf
#
## fail2ban local.conf
#cat <<'EOL' >/etc/fail2ban/jail.d/local.conf
#[DEFAULT]
#banaction = iptables-multiport
#backend = systemd
#
#[sshd]
#enabled = true
#port = 22,22992
#EOL
#locale
cat <<'EOF' > /etc/locale.conf
LANG="zh_CN.UTF-8"
EOF
localectl set-locale LANG=zh_CN.utf8
localectl set-keymap cn
localectl set-x11-keymap cn
# postfix
sed -i -e 's/^#mynetworks_style = host$/mynetworks_style = host/' /etc/postfix/main.cf
# autofsck
echo 'AUTOFSCK_DEF_CHECK=yes' >> /etc/sysconfig/autofsck
#sgdisk -t 3:8300 /dev/vda
#gdisk -l /dev/vda
# root lock
#usermod -p '' root
# udev
rm -f /etc/udev/rules.d/70-persistent-net.rules
# ntp
cat <<'EOF' >/etc/ntp.conf
# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
driftfile /var/lib/ntp/drift
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict -4 default ignore
restrict -6 default ignore
restrict ntp.dtops.cc kod nomodify notrap nopeer noquery
#restrict -6 ntp1.sakura.ad.jp kod nomodify notrap nopeer noquery
disable monitor
# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict -4 127.0.0.1
restrict -6 ::1
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server ntp.dtops.cc iburst
#broadcast 192.168.1.255 autokey # broadcast server
#broadcastclient # broadcast client
#broadcast 224.0.1.1 autokey # multicast server
#multicastclient 224.0.1.1 # multicast client
#manycastserver 239.255.254.254 # manycast server
#manycastclient 239.255.254.254 autokey # manycast client
# Enable public key cryptography.
#crypto
includefile /etc/ntp/crypto/pw
# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys
# Specify the key identifiers which are trusted.
#trustedkey 4 8 42
# Specify the key identifier to use with the ntpdc utility.
#requestkey 8
# Specify the key identifier to use with the ntpq utility.
#controlkey 8
# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats
EOF
# chrony
cat <<'EOF' >/etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server ntp.dtops.cc iburst
# Ignore stratum in source selection.
stratumweight 0
# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift
# In first three updates step the system clock instead of slew
# if the adjustment is larger than 10 seconds.
makestep 10 3
# Enable kernel synchronization of the real-time clock (RTC).
rtcsync
# Allow NTP client access from local network.
#allow 192.168/16
# Listen for commands only on localhost.
bindcmdaddress 127.0.0.1
bindcmdaddress ::1
# Serve time even if not synchronized to any NTP server.
#local stratum 10
# Specify file containing keys for NTP and command authentication.
keyfile /etc/chrony.keys
# Specify key number for command authentication.
commandkey 1
# Generate new command key on start if missing.
generatecommandkey
# Disable logging of client accesses.
noclientlog
# Send message to syslog when clock adjustment is larger than 0.5 seconds.
logchange 0.5
# Specify directory for log files.
logdir /var/log/chrony
# Select which information is logged.
#log measurements statistics tracking
# This option allows you to configure the port on which chronyd will listen for NTP requests.
# The compiled in default is udp/123, the standard NTP port. If set to 0, chronyd will not open the server
# socket and will operate strictly in a client-only mode.
port 0
# User to which will chronyd switch on initialisation to drop root privileges.
user chrony
# Deny access to chronyc from other computers.
cmddeny all
# Lock chronyd into RAM so that it will never be paged out.
lock_all
EOF
%end
%post --log=/tmp/ks-post-2.log --interpreter=/usr/bin/bash
# disable_ipv6
if ! grep -q 'ipv6.disable=1' /etc/default/grub; then
sed -ri 's/^(GRUB_CMDLINE_LINUX.*)(")$/\1 ipv6.disable=1\2/' /etc/default/grub
fi
#grubby --update-kernel=ALL --args=ipv6.disable=1
# network name eth
if ! grep -q 'biosdevname=0' /etc/default/grub; then
sed -ri 's/^(GRUB_CMDLINE_LINUX.*)(")$/\1 biosdevname=0\2/' /etc/default/grub
fi
if ! grep -q 'net.ifnames=0' /etc/default/grub; then
sed -ri 's/^(GRUB_CMDLINE_LINUX.*)(")$/\1 net.ifnames=0\2/' /etc/default/grub
fi
#sed -ri 's/^(GRUB_CMDLINE_LINUX.*)(")$/\1 net.ifnames=0 biosdevname=0\2/' /etc/default/grub
#grubby --update-kernel=ALL --args=net.ifnames=0
#grubby --update-kernel=ALL --args=biosdevname=0
grub2-mkconfig -o /etc/grub2.cfg
grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
cat /usr/lib/udev/rules.d/60-net.rules > /etc/udev/rules.d/60-net.rules
sed -i 's/^/#/' /etc/udev/rules.d/60-net.rules
# ssh
[ -d /root/.ssh ] || mkdir -p /root/.ssh/
>/root/.ssh/authorized_keys2 && >/root/.ssh/authorized_keys
cat <<'EOF' >/root/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDfhGitgDKxQidZXLHS3DFalTvmzTwQ4UH3etQJUE7/iPNwLs6ZDzbR5pqTPfK1YdhUTuJOoNQZ71Fr9qwLtF6aLdgO+ybmK/8sNrMeTvGmKyr4YQ5k02vVIbBnQIEr08eXpV1y206CMWQ7FiiMlFvaeFZhj8trchiffhAUJdZOjl/BikzDJcYdp/sRXrFA4G21yXU0ffOn9aAAvqOqRBRoDhpLnSWaovGjd419Cy/pdhu4Vuispz1x834l975fLv4PIh+3nW9WMbhrmIXzWoTsxnc8OUbT4FnRdA33G8T3JXQc1n1UjX7H4BGfzKA6eax574rspAk51cslaydby2vX root@lookback
EOF
chmod 0700 /root/.ssh/
chmod 0600 /root/.ssh/{authorized_keys2,authorized_keys}
# zabbix
mkdir -p /etc/zabbix/scripts/
sed -ri "s/^(Server(Active)?=).*/\1180.150.154.122/" /etc/zabbix/zabbix_agentd.conf
pcip=${pcip:-$(ip addr | awk '$1=="inet" && $NF!="lo"{print $2;exit}'|sed -r 's/\/[0-9]{1,}//')}
HOSTNAME_ZBX=${HOSTNAME_ZBX:-$pcip}
sed -ri "s/^(Hostname=).*/\1${HOSTNAME_ZBX}/g" /etc/zabbix/zabbix_agentd.conf
curl -Lks4 https://raw.githubusercontent.com/xiaoyawl/centos_init/master/fdisk/disk.pl -o /etc/zabbix/scripts/disk.pl
curl -Lks4 https://raw.githubusercontent.com/xiaoyawl/centos_init/master/fdisk/disktcp.conf -o /etc/zabbix/zabbix_agentd.d/disktcp.conf
chmod +x /etc/zabbix/scripts/disk.pl
(crontab -l; echo -e "*/1 * * * * /usr/sbin/ss -tan|awk 'NR>1{++S[\$1]}END{for (a in S) print a,S[a]}' > /tmp/tcp-status.txt\n*/1 * * * * /usr/sbin/ss -o state established '( dport = :http or sport = :http)' |grep -v Netid > /tmp/httpNUB.txt") | crontab -
echo 'zabbix ALL=(root)NOPASSWD:/usr/bin/cksum /root/.ssh/authorized_keys' >> /etc/sudoers
echo 'zabbix ALL=(root)NOPASSWD:/usr/sbin/iptables,/usr/bin/cksum /etc/sysconfig/iptables' >>/etc/sudoers
echo "UserParameter=authorized_keys,sudo /usr/bin/cksum /root/.ssh/authorized_keys|awk '{print \$1}'" >> /etc/zabbix/zabbix_agentd.conf
echo "UserParameter=iptables_lins,/usr/bin/sudo iptables -S |md5sum|awk '{print \$1}'" >> /etc/zabbix/zabbix_agentd.conf
echo "UserParameter=iptables_file,/usr/bin/sudo /usr/bin/cksum /etc/sysconfig/iptables|awk '{print \$1}'" >> /etc/zabbix/zabbix_agentd.conf
# change kernel
sed -i '/\[main\]/a exclude=kernel*' /etc/yum.conf
# add_speedtest
curl -Lk 'https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py' > /usr/bin/speedtest-cli
chmod +x /usr/bin/speedtest-cli
# PS1
curl -Lks 'https://raw.githubusercontent.com/xiaoyawl/centos_init/master/PS1' >> /etc/profile
%end
%post --log=/tmp/ks-post-3.log --interpreter=/usr/bin/bash
#
[ -x /bin/systeminfo ] && break
curl -Lk http://git.dwhd.org/lookback/CentOS_INIT/raw/master/OS/securityremove > /bin/securityremove
curl -Lk http://git.dwhd.org/lookback/CentOS_INIT/raw/master/OS/lsmod > /bin/lsmod
curl -Lk http://git.dwhd.org/lookback/CentOS_INIT/raw/master/OS/systeminfo > /bin/systeminfo
curl -Lk http://git.dwhd.org/lookback/CentOS_INIT/raw/master/OS/vim.tar.gz | gunzip | tar x -C ~/
[ -e /root/.vim/syntax ] || mkdir -p /root/.vim/syntax
#curl http://www.vim.org/scripts/download_script.php?src_id=19394 -o ~/.vim/syntax/nginx.vim
curl -Lk https://raw.githubusercontent.com/xiaoyawl/centos_init/master/nginx.vim > /root/.vim/syntax/nginx.vim
sed -i "1i au BufRead,BufNewFile /etc/nginx/*,/usr/local/nginx/conf/*.conf if &ft == '' | setfiletype nginx | endif" /root/.vimrc
chmod +x /bin/{securityremove,lsmod,systeminfo}
test -f /etc/bash.bashrc && sed -i "/securityremove/d" /etc/bash.bashrc && echo 'alias rm="/bin/securityremove"' >> /etc/bash.bashrc && . /etc/bash.bashrc
test -f /etc/bashrc && sed -i "/securityremove/d" /etc/bashrc && echo 'alias rm="/bin/securityremove"' >> /etc/bashrc && . /etc/bashrc
test -f /root/.bashrc && sed -i "/alias rm/d" /root/.bashrc && echo 'alias rm="/bin/securityremove"' >> /root/.bashrc && . /root/.bashrc
echo -e '#alias ls="/bin/lsmod"\nalias ls="ls --color=auto"' >> ~/.bashrc && . ~/.bashrc
#tar xf vim.tar.gz -C /root/ && /bin/rm -rf vim.tar.gz
if ! grep "alias vi='vim'" /root/.bashrc &>/dev/null; then
cat >> /root/.bashrc <<-EOF
alias vi='vim'
alias last='last -i'
alias grep='grep --color=auto'
export VISUAL=vim
export EDITOR=vim
EOF
sed -i 's/.*set hlsearch.*/"&/' /etc/vimrc
fi
%end
%post --log=/tmp/ks-post-4.log --interpreter=/usr/bin/bash
set -x
# yum update
systemctl enable zabbix-agent.service docker.service
yum -y clean all
yum -y update
rm -rf /etc/sysconfig/network-scripts/ifcfg-en*
rm -rf /tmp/{yum*,vmware-root,systemd-private*}
cd /tmp && { for i in `ls`;do echo $i| grep -q ^ks || \rm -rf $i;done; } && cd -
mkdir -p /data
sed -i '1 i\MAILTO=""' /var/spool/cron/root
cat << 'EOF' > /etc/motd
■■■■ ■■■■■■ ■■■■ ■■■■■ ■■■■
■ ■ ■■ ■■ ■■ ■ ■■ ■■ ■■
■ ■■ ■■ ■ ■ ■ ■ ■ ■
■ ■ ■■ ■ ■ ■ ■ ■
■ ■ ■■ ■ ■ ■ ■ ■
■ ■ ■■ ■ ■ ■ ■■ ■■
■ ■ ■■ ■ ■ ■■■■■ ■■
■ ■ ■■ ■ ■ ■ ■ ■
■ ■■ ■■ ■ ■ ■ ■ ■
■ ■ ■■ ■■ ■■ ■ ■■ ■■
■■■■ ■■ ■■■■ ■ ■■■■
EOF
%end
%post --log=/tmp/ks-post-5.log --interpreter=/usr/bin/bash
set -x
restorecon -R /etc/yum.repos.d/
restorecon -R /var/spool/cron/root
#restorecon -R /etc/fail2ban/jail.d/
restorecon -R /etc/yum/pluginconf.d
restorecon -R /etc/default/grub
restorecon -R /etc/udev/rules.d/60-net.rules
restorecon -R /boot/efi/EFI/centos/grub.cfg
restorecon -R /root/.ssh/
restorecon -R /etc/zabbix
restorecon -R /usr/bin/speedtest-cli
restorecon -R /etc/profile
restorecon -R /bin/{securityremove,lsmod,systeminfo}
restorecon -R /root/{.bashrc,.vim,.vimrc}
restorecon -R /etc/{bashrc,vimrc}
restorecon -R /usr/lib/systemd/system/{zabbix-agent.service,docker.service}
restorecon -R /data /etc/motd
%end