-
Notifications
You must be signed in to change notification settings - Fork 185
/
Copy path@initB
429 lines (388 loc) · 15.8 KB
/
@initB
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
#!/bin/bash
if [[ $(systemctl is-active swap.target) != "active" ]]; then
systemctl unmask swap.target >/dev/null 2>&1
systemctl start swap.target >/dev/null 2>&1
fi
if [[ $(free -m | awk 'NR==3{print$2}') = "0" ]] && [[ $virt_type != "container" ]]; then
if [[ $(df -T / | awk '{print$2}' | tail -n 1) = "btrfs" ]]; then
btrfs subvolume create /swap 2>/dev/null
btrfs filesystem mkswapfile --size 1g --uuid clear /swap/swapfile 2>/dev/null
swapon /swap/swapfile
sed -i "/swapfile/d" /etc/fstab
echo "/swap/swapfile none swap defaults 0 0" >>/etc/fstab
else
fallocate -l 1G /swapfile 2>/dev/null
dd if=/dev/zero of=/swapfile bs=1M count=1024 status=progress 2>/dev/null
chmod 600 /swapfile
mkswap -U clear /swapfile
swapon /swapfile
sed -i "/swapfile/d" /etc/fstab
echo "/swapfile none swap defaults 0 0" >>/etc/fstab
fi
echo "RESUME=" >/etc/initramfs-tools/conf.d/resume
fi
cat << EOF >/etc/apt/apt.conf.d/01InstallLess
APT::Get::Assume-Yes "true";
APT::Install-Recommends "false";
APT::Install-Suggests "false";
EOF
cat << EOF >/etc/apt/apt.conf.d/71debconf
Dpkg::Options {
"--force-confdef";
"--force-confold";
};
EOF
sed -i '/ulimit -SHn/d' /etc/profile
sed -i '/ulimit -c/d' /etc/profile
sed -i '/ulimit -d/d' /etc/profile
sed -i '/ulimit -f/d' /etc/profile
sed -i '/ulimit -m/d' /etc/profile
sed -i '/ulimit -s/d' /etc/profile
sed -i '/ulimit -t/d' /etc/profile
sed -i '/ulimit -u/d' /etc/profile
sed -i '/ulimit -v/d' /etc/profile
sed -i '/HISTCONTROL=/d' /etc/profile
sed -i '/alias reboot=/d' /etc/profile
cat << EOF >>/etc/profile
ulimit -SHn 1000000
ulimit -t 65536
ulimit -u 65536
ulimit -c 65536
ulimit -d unlimited
ulimit -f unlimited
ulimit -s unlimited
ulimit -v unlimited
HISTCONTROL=ignoredups
alias reboot="sudo systemctl reboot"
EOF
source /etc/profile
sed -i '/pam_limits.so/d' /etc/pam.d/common-session
echo "session required pam_limits.so" >>/etc/pam.d/common-session
cat << EOF >/etc/security/limits.conf
root soft nofile 1000000
root hard nofile 1000000
root soft nproc 1000000
root hard nproc 1000000
root soft core 1000000
root hard core 1000000
root hard memlock unlimited
root soft memlock unlimited
www-data soft nofile 1000000
www-data hard nofile 1000000
www-data soft nproc 1000000
www-data hard nproc 1000000
www-data soft core 1000000
www-data hard core 1000000
www-data hard memlock unlimited
www-data soft memlock unlimited
* soft nofile 1000000
* hard nofile 1000000
* soft nproc 1000000
* hard nproc 1000000
* soft core 1000000
* hard core 1000000
* hard memlock unlimited
* soft memlock unlimited
EOF
sed -i '/DefaultLimitCORE/d' /etc/systemd/system.conf
sed -i '/DefaultLimitNOFILE/d' /etc/systemd/system.conf
sed -i '/DefaultLimitNPROC/d' /etc/systemd/system.conf
cat << EOF >>/etc/systemd/system.conf
DefaultLimitCORE=1000000
DefaultLimitNOFILE=1000000
DefaultLimitNPROC=1000000
EOF
systemctl daemon-reload
sed -i '/nf_conntrack/d' /etc/modules-load.d/modules.conf
sed -i '/ifb/d' /etc/modules-load.d/modules.conf
cat << EOF >>/etc/modules-load.d/modules.conf
nf_conntrack
ifb
sch_cake
EOF
modprobe nf_conntrack
modprobe ifb
modprobe sch_cake
cat << EOF >/etc/sysctl.conf
vm.overcommit_memory = 1
vm.swappiness = 5
vm.dirty_ratio = 10
vm.dirty_background_ratio = 5
fs.file-max = 1000000
fs.inotify.max_user_instances = 819200
fs.inotify.max_queued_events = 32000
fs.inotify.max_user_watches = 64000
net.unix.max_dgram_qlen = 10240
net.netfilter.nf_conntrack_acct = 0
net.netfilter.nf_conntrack_checksum = 0
net.netfilter.nf_conntrack_events = 1
net.netfilter.nf_conntrack_timestamp = 0
net.netfilter.nf_conntrack_max = 1048576
net.netfilter.nf_conntrack_buckets = 65536
net.netfilter.nf_conntrack_tcp_loose = 1
net.netfilter.nf_conntrack_tcp_be_liberal = 1
net.netfilter.nf_conntrack_tcp_max_retrans = 3
net.netfilter.nf_conntrack_generic_timeout = 60
net.netfilter.nf_conntrack_tcp_timeout_unacknowledged = 30
net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 30
net.netfilter.nf_conntrack_tcp_timeout_time_wait = 30
net.netfilter.nf_conntrack_tcp_timeout_close_wait = 15
net.netfilter.nf_conntrack_tcp_timeout_close = 5
net.netfilter.nf_conntrack_tcp_timeout_last_ack = 30
net.netfilter.nf_conntrack_tcp_timeout_syn_recv = 30
net.netfilter.nf_conntrack_tcp_timeout_syn_sent = 30
net.netfilter.nf_conntrack_tcp_timeout_established = 3600
net.netfilter.nf_conntrack_sctp_timeout_established = 3600
net.netfilter.nf_conntrack_udp_timeout = 15
net.netfilter.nf_conntrack_udp_timeout_stream = 45
net.core.somaxconn = 65536
net.core.netdev_max_backlog = 262144
net.core.optmem_max = 262144
net.core.rmem_default = 262144
net.core.wmem_default = 262144
net.core.rmem_max = 33554432
net.core.wmem_max = 33554432
net.mptcp.enabled = 1
net.ipv4.conf.all.arp_accept = 0
net.ipv4.conf.default.arp_accept = 0
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.all.rp_filter = 0
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.all.secure_redirects = 0
net.ipv4.conf.default.secure_redirects = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.route_localnet = 1
net.ipv4.route.flush = 1
net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.ip_forward = 1
net.ipv4.conf.all.forwarding = 1
net.ipv4.conf.default.forwarding = 1
net.ipv4.ip_no_pmtu_disc = 0
net.ipv4.udp_rmem_min = 262144
net.ipv4.udp_wmem_min = 262144
net.ipv4.tcp_mem = 16384 131072 524288
net.ipv4.tcp_rmem = 8192 262144 16777216
net.ipv4.tcp_wmem = 8192 262144 16777216
net.ipv4.tcp_max_tw_buckets = 131072
net.ipv4.tcp_max_orphans = 131072
net.ipv4.tcp_max_syn_backlog = 32768
net.ipv4.tcp_limit_output_bytes = 1048576
net.ipv4.tcp_adv_win_scale = 1
net.ipv4.tcp_moderate_rcvbuf = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_workaround_signed_windows = 0
net.ipv4.tcp_mtu_probing = 0
net.ipv4.tcp_mtu_probe_floor = 48
net.ipv4.tcp_base_mss = 1024
net.ipv4.tcp_no_metrics_save = 0
net.ipv4.tcp_no_ssthresh_metrics_save = 1
net.ipv4.tcp_sack = 1
net.ipv4.tcp_dsack = 1
net.ipv4.tcp_frto = 0
net.ipv4.tcp_recovery = 1
net.ipv4.tcp_early_retrans = 3
net.ipv4.tcp_min_rtt_wlen = 120
net.ipv4.tcp_reordering = 3
net.ipv4.tcp_ecn = 0
net.ipv4.tcp_fin_timeout = 10
net.ipv4.tcp_fastopen = 3
net.ipv4.tcp_fastopen_blackhole_timeout_sec = 0
net.ipv4.tcp_fastopen_key = 00000000-00000000-00000000-00000000
net.ipv4.tcp_keepalive_time = 7200
net.ipv4.tcp_keepalive_intvl = 75
net.ipv4.tcp_keepalive_probes = 9
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_syncookies = 0
net.ipv4.tcp_tw_reuse = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_retries1 = 3
net.ipv4.tcp_retries2 = 8
net.ipv4.tcp_orphan_retries = 0
net.ipv4.tcp_challenge_ack_limit = 100000
net.ipv4.tcp_slow_start_after_idle = 0
net.ipv4.tcp_autocorking = 0
net.ipv4.tcp_rfc1337 = 1
net.core.default_qdisc = cake
EOF
sed -i '/net.ipv4.tcp_congestion_control/d' /etc/sysctl.conf
if [[ $(uname -r) =~ "bbrplus" ]]; then
echo "net.ipv4.tcp_congestion_control = bbrplus" >>/etc/sysctl.conf
else
echo "net.ipv4.tcp_congestion_control = bbr" >>/etc/sysctl.conf
fi
sync
sysctl -p >/dev/null 2>&1
dpkg --configure -a
cat << EOF >/etc/apt/sources.list
deb http://cloudfront.debian.net/debian buster main contrib non-free
deb http://cloudfront.debian.net/debian buster-updates main contrib non-free
deb http://cloudfront.debian.net/debian buster-backports main contrib non-free
deb http://cloudfront.debian.net/debian-security buster/updates main contrib non-free
EOF
apt update --fix-missing && apt upgrade --allow-downgrades -y
apt full-upgrade -y && apt --purge autoremove -y && apt clean -y && apt autoclean -y
[[ -n $(dpkg -l | awk '{print$2}' | grep '^os-prober$') ]] && apt remove --purge os-prober
[[ -n $(dpkg -l | awk '{print$2}' | grep '^systemd-timesyncd$') ]] && apt remove --purge systemd-timesyncd
unset aptPKG
[[ -z $(dpkg -l | awk '{print$2}' | grep '^sudo$') ]] && aptPKG+=(sudo)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^wget$') ]] && aptPKG+=(wget)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^curl$') ]] && aptPKG+=(curl)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^git$') ]] && aptPKG+=(git)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^locales$') ]] && aptPKG+=(locales)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^ethtool$') ]] && aptPKG+=(ethtool)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^ca-certificates$') ]] && aptPKG+=(ca-certificates)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^apt-transport-https$') ]] && aptPKG+=(apt-transport-https)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^gnupg2$') ]] && aptPKG+=(gnupg2)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^unzip$') ]] && aptPKG+=(unzip)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^jq$') ]] && aptPKG+=(jq)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^haveged$') ]] && aptPKG+=(haveged)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^chrony$') ]] && aptPKG+=(chrony)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^irqbalance$') ]] && [[ $(nproc --all) -gt 1 ]] && aptPKG+=(irqbalance)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^libjemalloc2') ]] && aptPKG+=(libjemalloc2)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^google-perftools') ]] && aptPKG+=(google-perftools)
[[ -n $aptPKG ]] && apt update && apt install $(echo ${aptPKG[@]})
[[ -f "/etc/ld.so.preload" ]] && sed -i "/libjemalloc/d" /etc/ld.so.preload
ldconfig
systemctl restart haveged
cat << EOF >/etc/chrony/chrony.conf
server time.cloud.tencent.com iburst
server time4.cloud.tencent.com iburst
server time5.cloud.tencent.com iburst
server ntp.aliyun.com iburst
server ntp6.aliyun.com iburst
server ntp7.aliyun.com iburst
driftfile /var/lib/chrony/chrony.drift
logdir /var/log/chrony
maxupdateskew 100.0
rtcsync
makestep 1 3
leapsectz right/UTC
EOF
systemctl restart chrony
systemctl enable chrony >/dev/null 2>&1
localeSet=`cat << EOF
LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8
EOF
`
if [[ -z $(locale -a | grep "en_US.utf8") ]]; then
echo "$localeSet" >/etc/default/locale
echo "en_US.UTF-8 UTF-8" >/etc/locale.gen
locale-gen "en_US.UTF-8"
update-locale LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8 LC_ALL=en_US.UTF-8
fi
[[ $(date +"%Z %z") != "CST +0800" ]] && timedatectl set-timezone "Asia/Shanghai"
timedatectl set-local-rtc 0 >/dev/null 2>&1
timedatectl set-ntp true
[[ -f "/etc/rc.local" ]] && rm -rf /etc/rc.local
if [[ -n $(systemctl list-unit-files --type=service | grep 'rc_online') ]]; then
systemctl stop rc_online
rm -rf /etc/systemd/system/rc_online.service
systemctl daemon-reload >/dev/null
fi
cat << EOF >/etc/rc_online.local
#!/bin/bash
echo madvise >/sys/kernel/mm/transparent_hugepage/enabled
$(which ip) route show table local | grep ' dev lo ' | while read line; do
line=\$(echo \$line | awk -F' mtu ' '{print\$1}')
$(which ip) route change \$line mtu 65520 initcwnd 1000 initrwnd 1000 fastopen_no_cookie 1 congctl lock cubic
done
NIC_local=\$($(which ip) route | grep -v 'scope link' | awk -F' dev ' '{print\$2}' | cut -d' ' -f1)
$(which ip) route show table local | grep " dev \$NIC_local " | while read line; do
line=\$(echo \$line | awk -F' mtu ' '{print\$1}')
$(which ip) route change \$line mtu 1500 fastopen_no_cookie 1 congctl lock $(sysctl net.ipv4.tcp_congestion_control | awk -F' = ' '{print$2}')
done
$(which ip) route | grep " dev \$NIC_local " | while read line; do
line=\$(echo \$line | awk -F' mtu ' '{print\$1}')
$(which ip) route change \$line mtu 1500 fastopen_no_cookie 1 congctl lock $(sysctl net.ipv4.tcp_congestion_control | awk -F' = ' '{print$2}')
done
NIC_device=\$(find /sys/class/net ! -type d | xargs --max-args=1 realpath | grep 'device')
for ifb in \$(echo \$NIC_device | xargs -n 1 | grep 'virtual' | awk -F'/' '{print\$NF}' | grep '^ifb'); do
$(which ip) link set \$ifb down
$(which ip) link delete \$ifb
done
$(which ip) link set lo qlen 1000000 mtu 65520
$(which tc) qdisc del dev lo root >/dev/null 2>&1
$(which tc) qdisc add dev lo root cake unlimited rtt 10us diffserv4 dual-srchost no-split-gso no-ack-filter raw egress
$(which ip) link add name ifb4lo type ifb >/dev/null 2>&1
$(which tc) qdisc del dev lo ingress >/dev/null 2>&1
$(which tc) qdisc add dev lo handle ffff: ingress
$(which tc) qdisc del dev ifb4lo root >/dev/null 2>&1
$(which tc) qdisc add dev ifb4lo root cake unlimited rtt 10us diffserv4 dual-dsthost no-split-gso no-ack-filter raw ingress
$(which ip) link set ifb4lo qlen 1000000 mtu 65520
$(which ip) link set ifb4lo up
$(which tc) filter add dev lo parent ffff: matchall action mirred egress redirect dev ifb4lo
echo \$NIC_device | xargs -n 1 | grep 'virtual' | awk -F'/' '{print\$NF}' | grep -v 'docker' | grep -v 'ifb' | grep -v '^lo\$' | while read line; do
MTU_NUM=\$(< /sys/class/net/\$line/mtu)
ifb4eth=\$(echo "ifb4\$line" | cut -c 1-15)
$(which ip) link set \$line qlen 4096 mtu \$MTU_NUM
$(which tc) qdisc del dev \$line root >/dev/null 2>&1
$(which tc) qdisc add dev \$line root cake unlimited rtt 10us diffserv4 dual-srchost nonat nowash no-split-gso ack-filter raw overhead 18 mpu 64 noatm egress
$(which ip) link add name \$ifb4eth type ifb >/dev/null 2>&1
$(which tc) qdisc del dev \$line ingress >/dev/null 2>&1
$(which tc) qdisc add dev \$line handle ffff: ingress
$(which tc) qdisc del dev \$ifb4eth root >/dev/null 2>&1
$(which tc) qdisc add dev \$ifb4eth root cake unlimited rtt 10us diffserv4 dual-dsthost nonat nowash no-split-gso ack-filter raw overhead 18 mpu 64 noatm ingress
$(which ip) link set \$ifb4eth qlen 4096 mtu \$MTU_NUM
$(which ip) link set \$ifb4eth up
$(which tc) filter add dev \$line parent ffff: matchall action mirred egress redirect dev \$ifb4eth
done
echo \$NIC_device | xargs -n 1 | grep -v 'virtual' | awk -F'/' '{print\$NF}' | while read line; do
MTU_NUM=\$(< /sys/class/net/\$line/mtu)
ifb4eth=\$(echo "ifb4\$line" | cut -c 1-15)
$(which ip) link set \$line qlen 4096 mtu \$MTU_NUM
$(which tc) qdisc del dev \$line root >/dev/null 2>&1
$(which tc) qdisc add dev \$line root cake unlimited rtt 1ms diffserv4 dual-srchost nonat nowash split-gso ack-filter ethernet egress
$(which ip) link add name \$ifb4eth type ifb >/dev/null 2>&1
$(which tc) qdisc del dev \$line ingress >/dev/null 2>&1
$(which tc) qdisc add dev \$line handle ffff: ingress
$(which tc) qdisc del dev \$ifb4eth root >/dev/null 2>&1
$(which tc) qdisc add dev \$ifb4eth root cake unlimited rtt 1ms diffserv4 dual-dsthost nonat nowash split-gso ack-filter ethernet ingress
$(which ip) link set \$ifb4eth qlen 4096 mtu \$MTU_NUM
$(which ip) link set \$ifb4eth up
$(which tc) filter add dev \$line parent ffff: matchall action mirred egress redirect dev \$ifb4eth
$(which ethtool) -s \$line duplex full >/dev/null 2>&1
$(which ethtool) -K \$line rx on rx-all on rx-gro on tx on sg on tso on gso on gro on >/dev/null 2>&1
done
$(which ip) tcp_metrics flush
$(which ip) route flush cache
EOF
chmod +x /etc/rc_online.local
mkdir -p /etc/systemd/system/networking.service.d/
cat << EOF >/etc/systemd/system/networking.service.d/override.conf
[Service]
ExecStartPost=/etc/rc_online.local
EOF
systemctl daemon-reload >/dev/null
/etc/rc_online.local
crontab -l 2>/dev/null >/tmp/now.cron
sed -i '/\/etc\/rc_online.local/d' /tmp/now.cron
cat << EOF >>/tmp/now.cron
EOF
crontab /tmp/now.cron
rm -rf /tmp/now.cron
date -s "$(wget -qSO- --max-redirect=0 aliyun.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z" | grep -v ' 08:00:00 '
[[ $? -ne "0" ]] && date -s "$(wget -qSO- --max-redirect=0 baidu.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"
hwclock -w