forked from fviatool/host
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtangtoc.sh
2121 lines (1821 loc) · 68.2 KB
/
tangtoc.sh
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
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# @author: VLT PRO
# @website: https://wptangtoc.com
# @email: giatuan@wptangtoc.com
# @since: 2023
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
read -p "Nhập domain hoặc subdomain bạn muốn thêm
(ví dụ: Domain.com ...) [Enter = Bỏ Qua]: " NAME
#chuyển đổi viết hoa thành chữ thường điều kiện
if [[ $NAME = '' ]];then
NAME='Host'
fi
NAME=$(echo $NAME | tr '[:upper:]' '[:lower:]')
check_root=$(who | awk -F ' ' '{print $1}'| head -1)
if [[ "$check_root" != "root" ]]; then
if [[ -f /home/$check_root/.bashrc ]]; then
check_root_2=$(whoami)
if [[ $check_root_2 != 'root' ]];then
echo "Vui lòng sử dụng tài khoản root để cài đặt chương trình hosting"
echo "Vui lòng chuyển sang user Root. Vui lòng chạy lại lệnh cài đặt."
rm -f wptangtoc-ols
exit
fi
fi
fi
check_phan_vung_home_gioi_han=$(df -TH | grep '/dev/mapper/centos-home')
if [[ $check_phan_vung_home_gioi_han ]];then
echo "Vui lòng liên hệ với nhà cung cấp VPS, máy chủ của bạn cài hệ điều hành linux theo dạng nhánh gốc /"
echo "Hiện tại hệ điều hành của bạn đang được phân quyền theo dạng home dung lượng lớn và nhánh gốc / dung lượng nhỏ"
echo "Không phù hợp với cấu trúc Hosting
rm -f wptangtoc-ols
exit
fi
wordpress=$1
if [ "$NAME" = '' ]; then
clear
echo "Bạn chưa nhập tên miền, vui lòng nhập tên miền của bạn."
exit
fi
if [ "$NAME" = "${NAME/./}" ]; then
clear
echo "Domain bạn nhập không đúng định dạng. hãy nhập ví dụ: domain.com..."
rm -f wptangtoc-ols
exit
fi
if [[ $(echo $NAME | grep '://') ]];then
NAME=$(echo $NAME | cut -f3 -d '/')
fi
if [[ $(echo $NAME | grep '^www\.') ]];then
NAME=$(echo $NAME | sed 's/^www.//g')
fi
#check CPU ARM báo lỗi
if [[ $(uname -m | grep 'arm') ]];then
echo "Hiện tại wptangtoc ols chỉ hỗ trợ CPU x86_64 không hỗ trợ CPU ARM"
echo "Để sử dụng hosting hãy lựa chọn CPU x86_64"
rm -f wptangtoc-ols
exit
fi
if [ -f /var/cpanel/cpanel.config ]; then
clear
echo "webserver của bạn đã được cài đặt WHM/Cpanel, nếu muốn sử dụng hosting"
echo "Hãy reinstall lại hệ điều hành CentOS 7 - 64 bit, rồi mới có thể cài đặt hosting"
rm -f wptangtoc-ols
exit
fi
if [[ -d /usr/local/lscp ]];then
echo "webserver của bạn đã được cài đặt Cyberpanel, nếu muốn sử dụng hosting"
echo "Hãy reinstall lại hệ điều hành CentOS 7 - 64 bit, rồi mới có thể cài đặt hosting"
rm -f wptangtoc-ols
exit
fi
if [ -f /etc/psa/.psa.shadow ]; then
clear
echo "webserver của bạn đã được cài đặt Plesk, nếu muốn sử dụng hosting"
echo "Hãy reinstall lại hệ điều hành CentOS 7 - 64 bit, rồi mới có thể cài đặt hosting"
rm -f wptangtoc-ols
exit
fi
if [ -f /etc/wptt/.wptt.conf ]; then
clear
echo "webserver của bạn đã được cài đặt hosting trước đó rồi"
echo "Cảm ơn bạn đã lựa chọn sử dụng hosting"
echo "Yêu cầu hỗ trợ: VLT PRO - Email: giatuan@wptangtoc.com"
rm -f wptangtoc-ols
exit
fi
if [ -f /etc/init.d/directadmin ]; then
clear
echo "webserver của bạn đã được cài đặt DirectAdmin, nếu muốn sử dụng hosting"
echo "Hãy reinstall lại hệ điều hành CentOS 7 - 64 bit, rồi mới có thể cài đặt hosting"
rm -f wptangtoc-ols
exit
fi
if [ -f /etc/init.d/webmin ]; then
clear
echo "webserver của bạn đã được cài đặt webmin, nếu muốn sử dụng hosting"
echo "Hãy reinstall lại hệ điều hành CentOS 7 - 64 bit, rồi mới có thể cài đặt hosting"
rm -f wptangtoc-ols
exit
fi
sentora="/root/passwords.txt"
hocvps="/etc/hocvps/scripts.conf"
eev3="/usr/local/bin/ee"
wordops="/usr/local/bin/wo"
kusanagi="/home/kusanagi"
cwpsrv="/usr/local/cwpsrv"
vestacp="/usr/local/vesta/"
eev4="/opt/easyengine"
vpssim="/home/vpssim.conf"
larvps="/etc/larvps/.larvps.conf"
tino="/opt/tinopanel"
hostvn="/var/hostvn/hostvn.conf"
if [ -f "${larvps}" ]; then
echo "webserver của bạn đã được cài đặt Larvps, nếu muốn sử dụng hosting"
echo "Hãy reinstall lại hệ điều hành CentOS 7 - 64 bit, rồi mới có thể cài đặt hosting"
rm -f wptangtoc-ols
exit
fi
if [[ -f "${sentora}" || -f "${hocvps}" || -f "${eev3}" || -f "${wordops}" || -f "${kusanagi}" || -f "${cwpsrv}" || -f "${vestacp}" || -f "${eev4}" || -f "${vpssim}" || -f "${tino}" || -f "${hostvn}" ]]; then
echo "Bạn đã sử dụng các bảng điều khiển khác vui lòng reintall lại VPS để có thể sử dụng Hosting"
echo "Hãy reinstall lại hệ điều hành CentOS 7 - 64 bit, rồi mới có thể cài đặt hosting"
rm -f wptangtoc-ols
exit
fi
if [[ -d /usr/local/lsws || -d /home/lsws ]]; then
echo "webserver của bạn đã được cài đặt LiteSpeed Webserver, nếu muốn sử dụng hosting"
echo "Hãy reinstall lại hệ điều hành CentOS 7 - 64 bit, rồi mới có thể cài đặt hosting"
rm -f wptangtoc-ols
exit
fi
work_cpucore='1024'
cpucore=$(grep -c ^processor /proc/cpuinfo)
max_client=$(expr $work_cpucore \* $cpucore \* 2)
max_client_max=$(expr $work_cpucore \* $cpucore \* 3)
max_client_php=$(expr $work_cpucore \* $cpucore \/ 8)
tong_ram_byte=$(awk '/MemTotal/ {print $2}' /proc/meminfo)
rong_ram_mb=$(echo "scale=0;${tong_ram_byte}/1024" | bc)
gioi_han_tien_trinh_bao_loi_503=$(expr $max_client \/ 8)
if [[ "$rong_ram_mb" = "" ]]; then
rong_ram_mb="2048"
fi
tong_ram_mb_db=$(echo "scale=0;${rong_ram_mb}/4" | bc)
if [[ $tong_ram_mb_db = '' ]];then
tong_ram_mb_db="2048"
fi
tong_ram_gb=$(expr ${rong_ram_mb} / 1024)
db_table_size=$(expr $tong_ram_gb \* 64 )
buffer_db=$(expr $rong_ram_mb / 6)
wptangtocols_version=$(curl -s https://wptangtoc.com/share/version-wptangtoc-ols.txt?domain-install=$NAME)
if [[ $wptangtocols_version = "" ]];then
wptangtocols_version=$(curl -s https://github.com/wptangtoc/wptangtoc-ols/blob/main/version-wptangtoc-ols.txt | grep 'LC1' | cut -f2 -d '>' | sed 's:</td::g')
fi
Server_OS_Version=$(grep VERSION_ID /etc/os-release | awk -F[=,] '{print $2}' | tr -d \" | head -c2 | tr -d .)
if [[ "$Server_OS_Version" != "7" ]]; then
echo "Phần mềm này hiện tại chỉ phát triển trên centos 7 vui lòng sử dụng hệ điều hành linux centos 7"
rm -f wptangtoc-ols
exit
fi
clear
#chon version php cho function luu tru
function chon_version_php(){
echo "Bạn hãy lựa chọn phiên bản PHP muốn sử dụng: "
prompt="Nhap vao lua chon cua ban [1-4]: "
php_version="8.1"
options=("Phien ban PHP 8.1" "Phien ban PHP 8.0" "Phien ban PHP 7.4" "Phien ban PHP 7.3")
PS3="$prompt"
select opt in "${options[@]}"; do
case "$REPLY" in
1)
php_version="8.1"
break
;;
2)
php_version="8.0"
break
;;
3)
php_version="7.4"
break
;;
4)
php_version="7.3"
break
;;
$((${#options[@]} + 1)))
printf "\nHe thong se cai dat PHP 7.4\n"
break
;;
*)
printf "Ban nhap sai, he thong cai dat PHP 7.4\n"
break
;;
esac
done
}
#set mặc định php 8.1 là WordPress mặc định
php_version="8.1"
clear
echo "Bạn hãy lựa chọn phiên bản Maria Database muốn sử dụng: "
prompt="Nhập vào lựa chọn của bạn [1-4]: "
mariadb_version="10.6"
options=("Phien ban: 10.11" "Phien ban: 10.6" "Phien ban: 10.5" "Phien ban: 10.4")
PS3="$prompt"
select opt in "${options[@]}"; do
case "$REPLY" in
1)
mariadb_version="10.11"
break
;;
2)
mariadb_version="10.6"
break
;;
3)
mariadb_version="10.5"
break
;;
4)
mariadb_version="10.4"
break
;;
$((${#options[@]} + 1)))
printf "\nHe thong se cai dat maria database 10.5\n"
break
;;
*)
printf "Ban nhap sai, he thong cai dat maria database 10.5\n"
break
;;
esac
done
clear
# tuong thich vps hệ thống nhỏ dưới 1GB
if (( $rong_ram_mb > 1024 ));then
echo "Bạn hãy lựa chọn object cache bạn muốn sử dụng: "
prompt="Nhập vào lựa chọn của bạn [1-4]: "
object_cache="lsmemcached"
options=("Redis" "Lsmemcached" "Memcached" "Khong su dung")
PS3="$prompt"
select opt in "${options[@]}"; do
case "$REPLY" in
1)
object_cache="redis"
break
;;
2)
object_cache="lsmemcached"
break
;;
3)
object_cache="memcache"
break
;;
4)
object_cache="khong_su_dung_object_cache"
break
;;
$((${#options[@]} + 1)))
printf "\nHe thong se cai dat lsmemcached\n"
break
;;
*)
printf "Ban nhap sai, he thong cai dat lsmemcached\n"
break
;;
esac
done
clear
else
object_cache="khong_su_dung_object_cache"
fi
if [[ $php_version = "" ]];then
php_version="7.4"
fi
if [[ $mariadb_version = "" ]];then
mariadb_version="10.6"
fi
if [[ $object_cache = "" ]];then
object_cache="khong_su_dung_object_cache"
fi
echo "Bạn có muốn thay đổi Port SSH? để nâng cao bảo mật"
read -p "Nhập port SSH mới, bỏ qua nhấn (Enter): " port_ssh
if [[ "$wordpress" = "wp" ]]; then
clear
read -p "Xac nhan ban muon thiet lap wp-config ngay tai day khong. (y/n): " dongyconfig
if [[ "$dongyconfig" = "y" ]]; then
read -p "1. Ten tieu de Website wordpress cua ban muon : " SiteTitle
read -p "2. Nhap id dang nhap wordpress: " idusername
read -sp "3. Nhap password wordpress:
Luu y: hay nhap wordpress it nhat 26 ky tu de nang cao bao mat (Password khi gõ sẽ ẩn): " mypassword
echo ""
read -p "4. Nhap Email ban cua website $NAME
vi du abc@gmail.com, giatuan@wptangtoc.com: " emailwp
if [ "$emailwp" = "${emailwp/@/}" ]; then
clear
echo "Email khong dung dinh dang."
echo
exit
fi
tien_to_db=$(
date +%s | sha256sum | base64 | head -c 6
echo
)
fi
fi
RED='\033[0;31m'
NC='\033[0m'
echo -e "${RED}
.:..........................
.::::::::::::::::::::::::::::..
..:::::::::::::::::::::::::::::.
...:::::::::.
.:::::::.
.:::::::. . .:::::::
.::::::::::::::::::::.. :::::::
::::::::::::::::::::::::. ::::::.
.::::::::::::::::::::::::::. .:::::.
.:::::::::::::::::::::::::::: .:::::.
.::::::::::::::::::::::::::. .:::::.
::::::::::::::::::::::::. ::::::.
.:::::: .:::::::::::::::::::::. ::::::.
.:::::::. .:::::::
::::::::::::. .:::::::.
......:::::::::... ...:::::::::.
.:::::::::::::::::::::::.
..............::::::::::::::::::..
.:::::::::::::................. ${NC}"
echo ""
echo -e "${RED}-------------------------------------------------------------------------"
echo ""
echo " 0 0 000000 0000000 0000000 "
echo " 0 0 0 0 0 0 00 0 0 0000 0 0000 0000 "
echo " 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 "
echo " 0 0 0 000000 0 0 0 0 0 0 0 0 0 0 0 "
echo -e "${NC} 0 0 0 0 0 000000 0 0 0 0 000 0 0 0 0 "
echo " 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 "
echo " 00 00 0 0 0 0 0 0 0000 0 0000 0000 "
echo ""
echo " 00000 0 00000 "
echo " 0 0 0 0 0 "
echo " 0 0 0 0 "
echo -e "${RED} 0 0 0 00000 "
echo " 0 0 0 0 "
echo " 0 0 0 0 0 "
echo " 00000 000000 00000 "
echo -e "--------------------------------------------------------------------------${NC}"
sleep 2
clear
function box_out() {
local s=("$@") b w
for l in "${s[@]}"; do
((w < ${#l})) && {
b="$l"
w="${#l}"
}
done
tput setaf 7
echo " -${b//?/-}-
| ${b//?/ } |"
for l in "${s[@]}"; do
printf '| %s%*s%s |\n' "$(tput setaf 7)" "-$w" "$l" "$(tput setaf 3)"
done
echo "| ${b//?/ } |
-${b//?/-}-"
tput sgr 0
}
if [[ $NAME != 'wptangtoc-ols.com' ]];then
box_out "Xin chào $NAME" "Chào mừng bạn đến với Hosting version $wptangtocols_version"
else
box_out "Chào mừng bạn đến với Hosting version $wptangtocols_version"
fi
sleep 2
clear
echo ""
echo "Đang chuẩn bị tiến hành cài đặt hosting $wptangtocols_version"
sleep 1
echo ""
echo "Cảm ơn bạn đã lựa chọn sử dụng hosting ..."
sleep 2
echo "
.:..
..:-------.
.:::.......:::::.
:--. ..........:::.
:::.. ........:::.
...--::..........:.:::
:=+++=-:........:::::
:+*****==:... ......:.
==+*###***=-===+=:.:
=-::=********###%*==
-*+=-=+*+=-:-=*##%*+#=
+####*####*+++*##%***.
+*+**#%%###%%%%##%#+.
:+=++*###**####%#-:
==-+++***++*###:
.-====----:::::--+==++++++***#.
.-===------==-----:=**++*##***#+
:-----=------==----:-+++*******##.
.-----=---------------==+=++******+-:
:----------=--------:.:+******+++=--==-
----------------------:::=***+===--====--:
----:------------------::-:-::..-===-===-==:
---::--------------------=-:---::-=-====--=++-:.
"
echo ""
echo "Phần mềm phát triển bởi VLT PRO"
sleep 4
clear
yum install epel-release -y
yum clean all && yum update -y
function kernel_tcp_toi_uu(){
LIMITSCONFCHECK=$(grep '* hard nofile 524288' /etc/security/limits.conf)
if [[ -z $LIMITSCONFCHECK ]]; then #check LIMITSCONFCHECK
# Set VPS hard/soft limits
echo "* soft nofile 524288" >>/etc/security/limits.conf
echo "* hard nofile 524288" >>/etc/security/limits.conf
if [[ ! -f /etc/rc.d/rc.local ]]; then #check khong co rc.local
cat > /usr/lib/systemd/system/rc-local.service <<EOF
# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.d/rc.local is executable.
[Unit]
Description=/etc/rc.d/rc.local Compatibility
ConditionFileIsExecutable=/etc/rc.d/rc.local
After=network.target
[Service]
Type=forking
ExecStart=/etc/rc.d/rc.local start
TimeoutSec=0
RemainAfterExit=yes
EOF
cat > /etc/rc.d/rc.local <<EOF
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
EOF
# remove non-standard centos 7 service file if detected
if [ -f /etc/systemd/system/rc-local.service ]; then
echo "cat /etc/systemd/system/rc-local.service"
cat /etc/systemd/system/rc-local.service
echo
rm -rf /etc/systemd/system/rc-local.service
rm -rf /var/lock/subsys/local
systemctl daemon-reload
systemctl stop rc-local.service
fi
chmod +x /etc/rc.d/rc.local
pushd /etc; ln -s rc.d/rc.local /etc/rc.local; popd
systemctl daemon-reload
systemctl start rc-local.service
systemctl status rc-local.service
fi #check khong co rc.local
ulimit -n 524288
echo "ulimit -n 524288" >> /etc/rc.local
fi #check LIMITSCONFCHECK
if [[ -f /etc/security/limits.d/20-nproc.conf ]]; then
cat > "/etc/security/limits.d/20-nproc.conf" <<EOF
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.
* soft nproc 8192
* hard nproc 8192
nobody soft nproc 32278
nobody hard nproc 32278
root soft nproc unlimited
EOF
fi
if [[ ! -f /proc/user_beancounters ]]; then #check dieu kien ao hoa 1 phan skip
if [ -d /etc/sysctl.d ]; then #check kernel toan phan
if [[ "$(grep 'wptangtoc-ols' /etc/sysctl.d/101-sysctl.conf >/dev/null 2>&1; echo $?)" != '0' ]]; then #check da add wptangtoc ols mod kernel
touch /etc/sysctl.d/101-sysctl.conf
echo 65536 > /sys/module/nf_conntrack/parameters/hashsize
if [[ "$(grep 'hashsize' /etc/rc.local >/dev/null 2>&1; echo $?)" != '0' ]]; then
echo "echo 65536 > /sys/module/nf_conntrack/parameters/hashsize" >> /etc/rc.local
fi
cat >> "/etc/sysctl.d/101-sysctl.conf" <<EOF
# wptangtoc-ols
kernel.pid_max=65536
kernel.printk=4 1 1 7
fs.nr_open=12000000
fs.file-max=9000000
net.core.wmem_max=16777216
net.core.rmem_max=16777216
net.ipv4.tcp_rmem=8192 87380 16777216
net.ipv4.tcp_wmem=8192 65536 16777216
net.core.netdev_max_backlog=65536
net.core.somaxconn=65535
net.core.optmem_max=8192
net.ipv4.tcp_fin_timeout=10
net.ipv4.tcp_keepalive_intvl=30
net.ipv4.tcp_keepalive_probes=3
net.ipv4.tcp_keepalive_time=240
net.ipv4.tcp_max_syn_backlog=65536
net.ipv4.tcp_sack=1
net.ipv4.tcp_syn_retries=3
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_tw_recycle = 0
net.ipv4.tcp_tw_reuse = 0
net.ipv4.tcp_max_tw_buckets = 1440000
vm.swappiness=10
vm.min_free_kbytes=65536
net.ipv4.ip_local_port_range=1024 65535
net.ipv4.tcp_slow_start_after_idle=0
net.ipv4.tcp_limit_output_bytes=65536
net.ipv4.tcp_rfc1337=1
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.all.log_martians = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.all.secure_redirects = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.default.log_martians = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.secure_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.icmp_ignore_bogus_error_responses = 1
net.netfilter.nf_conntrack_helper=0
net.nf_conntrack_max = 524288
net.netfilter.nf_conntrack_tcp_timeout_established = 28800
net.netfilter.nf_conntrack_generic_timeout = 60
net.ipv4.tcp_challenge_ack_limit = 999999999
net.ipv4.tcp_mtu_probing = 1
net.ipv4.tcp_base_mss = 1024
net.unix.max_dgram_qlen = 4096
EOF
if [[ "$(grep -o 'AMD EPYC' /proc/cpuinfo | sort -u)" = 'AMD EPYC' ]]; then #check cpu amd
echo "kernel.watchdog_thresh = 20" >> /etc/sysctl.d/101-sysctl.conf
fi #check cpu amd
if [[ -f /usr/lib/tuned/virtual-guest/tuned.conf ]];then
sed -i '/vm.swappiness/d' /usr/lib/tuned/virtual-guest/tuned.conf
echo 'vm.swappiness = 10' >> /usr/lib/tuned/virtual-guest/tuned.conf
fi
/sbin/sysctl --system
fi #check da add wptangtoc ols mod kernel
fi #check kernel toan phan
#ép xung, xung nhịp đơn nhân cpu lên tối đa high performance for centos 7 và tắt cơ chế tiết kiệm điện ktune, tối ưu i/o
if [[ $(which tuned-adm) ]];then
tuned-adm profile latency-performance
fi
# tuned-adm profile throughput-performance
fi #check dieu kien ao hoa 1 phan skip
}
kernel_tcp_toi_uu
function kernel_update(){
echo "Cap nhat update kernel linux core"
echo ':::::::::::::. ..:::::::::::::
:::::::::::: : ::::::::::::
:::::::::::. :::::::::::
::::::::::: -+- .++*. .::::::::::
:::::::::::.+.*-+* *= .::::::::::
::::::::::- -**%%#*#. .::::::::::
::::::::::-.:*******: : :-::::::::
::::::::::: =#++*#%@%: :::::::::
:::::::::. +@@@%@@@@@@ .:::::::
:::::::: -@@@@@@@@@%@+ ::::::
::::::: .%@@@@@@@@@@@@* . :::::
::::::. .%@@@@@@@@@@@@@@+ .. ::::
::::-: *@@@@@@@@@@@@@@@% . .:::
----: .@@@@@@@@@@@@@@@@@ . :::
:::::==-#@@@@@@@@@@@@@@@# ...-::
-===*###-:*@@@@@@@@@@@%*#. =*::-
-########= +@@@@@@@@@#*#*=+*##+-:
-*########+:+@@@@@@@@*:+########*=
=##########*##%%%%#=. .*#####**+=-
-=++****###*: .. :+***+=--:::
::::----===-:-::::--::::----::::--
'
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
yum --enablerepo=elrepo-kernel install -y kernel-lt
grub2-set-default 0
grub2-mkconfig -o /boot/grub2/grub.cfg
echo "Hoan tat qua trinh update kernel LTS linux core"
}
#tat selinux
if [[ -f /etc/sysconfig/selinux ]];then
setenforce 0
sed -i 's/=enforcing/=disabled/g' /etc/sysconfig/selinux
fi
rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install nano wget zip unzip curl git certbot bind-utils firewalld gcc gcc-c++ make autoconf glibc rcs bc -y
yum remove postfix chrony acpid Sendmail Xfs Autofs Isdn Nfslock Apmd nginx yum-cron -y
echo '[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/'$mariadb_version'/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1' >/etc/yum.repos.d/MariaDB.repo
yum clean all
yum update -y
echo '@@@@@@@@@@@@@@@@@@@@@@@@@#*+=:#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@=. -@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@%. +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@* =@@@#=@@@@*=@@@@@@@@@@@@@@%+@@@@@@@@@+*****@@%+#*#*#@
@@@@@@@@@@@@@@@@%#=. @@@@ :@@* +@%==++=%@=++**:@%==++=%@.*@@%#:%*.###*.@
@@@@@@@@@@%#+=:. +@@@= @::# #+ @ .@@* #% =%@= @ :@@+ #@.%@@@@.*#:###*:#
@@@@@@@@+: -@@@@.+@@: *@@.+*:+*= %% #@@* *+:+*= %@:+#**=+@*:####-#
@##%%%+ .. :-*@@@@@@@@@@@@@@@@@@%%@@@@@@@@@@@@@%%@@@@@%%%%@@@@@%%%%@@
@+ .=#%@@@%%##= =@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@#:-+#@@@@@@@@@@#-+%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'
box_out "Tiến hành cài đặt Maria Database $mariadb_version"
yum install MariaDB-server MariaDB-client -y
if [[ ! -d /var/lib/mysql ]];then
#thay repo mariadb
echo '[mariadb]
name = MariaDB
baseurl = https://mirror.rackspace.com/mariadb/yum/'$mariadb_version'/rhel7-amd64
gpgkey = https://mirror.rackspace.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
module_hotfixes=1' >/etc/yum.repos.d/MariaDB.repo
yum clean all
yum install MariaDB-server MariaDB-client -y
#trả repo về vị trí cũ
echo '[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/'$mariadb_version'/rhel7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
module_hotfixes=1' >/etc/yum.repos.d/MariaDB.repo
fi
systemctl start mariadb.service
systemctl enable mariadb.service
echo "Chung minh thay database user root bang wordpressadmin de nang cao bao mat"
db_root_password=$(
date +%s | sha256sum | base64 | head -c 32
echo
)
mysql <<EOF
use mysql;
FLUSH PRIVILEGES;
CREATE USER 'wordpressadmin'@'localhost' IDENTIFIED BY '$db_root_password';
GRANT ALL PRIVILEGES ON *.* TO 'wordpressadmin'@'localhost' WITH GRANT OPTION;
DROP USER 'root'@'localhost';
FLUSH PRIVILEGES;
EOF
box_out "Hoàn tất quá trình cài đặt Maria database"
systemctl restart mariadb.service
systemctl start firewalld
systemctl enable firewalld
systemctl stop httpd
systemctl disable httpd
systemctl mask httpd
# chuyen doi tuong thich iptables sang firewalld
checktuonglua=$(systemctl status firewalld | grep "masked")
if [[ "$checktuonglua" ]];then
systemctl unmask firewalld
systemctl start firewalld
systemctl enable firewalld
systemctl mask ip6tables
systemctl mask iptables
systemctl disable iptables
systemctl disable ip6tables
systemctl stop iptables
systemctl stop ip6tables
fi
mkdir -p /etc/wptt/
mkdir -p /etc/wptt/vhost
mkdir -p /etc/wptt-user
rpm -Uvh http://rpms.litespeedtech.com/centos/litespeed-repo-1.3-1.el7.noarch.rpm
echo '[litespeed]
name=LiteSpeed Tech Repository for CentOS $releasever - $basearch
baseurl=http://rpms.litespeedtech.com/centos/$releasever/$basearch/
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-litespeed
[litespeed-update]
name=LiteSpeed Tech Update Repository for CentOS $releasever - $basearch
baseurl=http://rpms.litespeedtech.com/centos/$releasever/update/$basearch/
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-litespeed
[litespeed-edge]
name=LiteSpeed Tech Edge Repository for CentOS $releasever - $basearch
baseurl=http://rpms.litespeedtech.com/edge/centos/$releasever/$basearch/
failovermethod=priority
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-litespeed
[litespeed-edge-update]
name=LiteSpeed Tech Edge Update Repository for CentOS $releasever - $basearch
baseurl=http://rpms.litespeedtech.com/edge/centos/$releasever/update/$basearch/
failovermethod=priority
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-litespeed
' >/etc/yum.repos.d/litespeed.repo
echo ' -#-
-#@@-
-#@@%%- -.
-#@@%@@@: :+*-
-#@@@@@%*==*%+
-#@@@@@#+=+#%*:.
-#@@@@%*==*#%%-.=++:
-#@@@%#==+#%%%*:-+++++=:
-#@@@%@*.#%%%%%- :++++++++=:
-#@@@@@@@%--#%%%%+ -++++++++=:
+@@%@@@@@@- .*##%%#: -+++++++++:
.=%@@%@@@@%=. =####%= .=++++++++=.
.+%@@%@@@@%=. -#####*.=++++++=.
.+%@@@@%@@-:*####+=:=++++=.
.+%@@@*:=###*=--=++++=.
.+#--###+---+++++=.
.+#*=--=+++++=.
=#+:.=++++++=.
.+=. :+++++=.
:+++=.
:+=.
.:
'
yum install openlitespeed -y
#kiểm tra openlitespeed đã được cài đặt chưa, fix lỗi nếu Repository của litespeed bị lỗi thì dùng Repository dự phòng
#nếu chưa cài đặt thì dùng Repository dự phòng ip khác thay vì dùng 208.167.239.232 ip dns gốc sẽ dùng 89.208.248.38 dự phòng của litespeed
if [[ ! -d /usr/local/lsws ]];then
sed -i '/rpms.litespeedtech.com/d' /etc/hosts
echo $'\n89.208.248.38 rpms.litespeedtech.com\n' >> /etc/hosts
yum clean all
rpm -Uvh http://rpms.litespeedtech.com/centos/litespeed-repo-1.3-1.el7.noarch.rpm
yum install openlitespeed -y
su_dung_repo_du_phong=1
fi
box_out "Hoàn tất cài đặt OpenLiteSpeed"
USER=${NAME//[-._]/wp}
check_ky_tu=$(echo $USER | wc -c)
if (( $check_ky_tu > 32 ));then
USER=$(echo $USER | cut -c 1-30)
fi
# useradd $USER -p -m -d /home/$USER >/dev/null 2>&1
useradd -p -m -d /usr/local/lsws/$NAME $USER >/dev/null 2>&1
if [[ $(cat /etc/passwd | cut -f1 -d ':' | grep -w $USER) = '' ]];then
random=$(
date +%s | sha256sum | base64 | head -c 2
echo
)
USER=${NAME//[-._]/$random}
check_ky_tu2=$(echo $USER | wc -c)
if (( $check_ky_tu2 > 32 ));then
USER=$(echo $USER | cut -c 1-30)
fi
# useradd "$USER" -p -m -d /home/"$USER" >/dev/null 2>&1
useradd -p -m -d /usr/local/lsws/$NAME $USER >/dev/null 2>&1
fi
groupadd wptangtoc-ols >/dev/null 2>&1
php_ver_chon=${php_version//[-._]/}
yum install lsphp${php_ver_chon} lsphp${php_ver_chon}-json lsphp${php_ver_chon}-common lsphp${php_ver_chon}-gd lsphp${php_ver_chon}-pecl-imagick lsphp${php_ver_chon}-process lsphp${php_ver_chon}-mbstring lsphp${php_ver_chon}-mysqlnd lsphp${php_ver_chon}-xml lsphp${php_ver_chon}-opcache lsphp${php_ver_chon}-mcrypt lsphp${php_ver_chon}-pdo lsphp${php_ver_chon}-imap lsphp${php_ver_chon}-bcmath lsphp${php_ver_chon}-intl -y
if [[ $su_dung_repo_du_phong = '1' ]];then
#cho quay tro lai sử dụng repo gốc
sed -i '/rpms.litespeedtech.com/d' /etc/hosts
fi
#centos7 khong ho tro zip truc tiep cai he dieu hanh moi hon thi them zip vao thang lscache
# yum install lsphp${php_ver_chon}-zip -y
ln -sf /usr/local/lsws/lsphp${php_ver_chon}/bin/lsphp /usr/local/lsws/fcgi-bin/lsphp${php_ver_chon}
ln -sf /usr/local/lsws/lsphp${php_ver_chon}/bin/lsphp /usr/local/lsws/fcgi-bin/lsphp5
ln -sf /usr/local/lsws/lsphp${php_ver_chon}/bin/php /usr/bin/php
#cai dat zip theo cach khac]
# yum install lsphp${php_ver_chon}-pear lsphp${php_ver_chon}-devel -y
# yum install -y http://packages.psychotic.ninja/7/plus/x86_64/RPMS/libzip-0.11.2-6.el7.psychotic.x86_64.rpm
# yum install -y http://packages.psychotic.ninja/7/plus/x86_64/RPMS/libzip-devel-0.11.2-6.el7.psychotic.x86_64.rpm
# /usr/local/lsws/lsphp${php_ver_chon}/bin/pecl install zip
# echo "extension=zip.so" > /usr/local/lsws/lsphp${php_ver_chon}/etc/php.d/20-zip.ini
blue='\033[1;34m'
NC='\033[0m'
echo -e "${blue}
...::::--------------:::...
.:--===++++===========================--:..
:-=+++++++===========+++++++===========+++=======-:.
.-+++++=============+===+*. *+=========+===============-:.
.=+*++====++++++++++++===+=*- :#=+++++===+=+++++++++++++==+==-:
:+*++====+=++===========+++==* :======+++==*+===========+++==++=-:
=*+===++==+=#. .=*++ -*+* .-*====++=.
.++==++======++ +=====: -%. -+=+=+- =#= +=====: -*=+===++:
++==+======+=*: :#=+++=#: .# *+++=+* *#. -#=++++#. .#=+=====+:
:+===========+* ++====+* =- :*=++=*: :#+ ++====+* =*=+=====+=
:+=========+=*= #++++++. :# ++===+* =#- :#++++++. :*========+=
=+========+=* :.... .=#= .#=++=*= ** :.... .=*=========+:
==========++ .......:-+*+*:...+*=++=#:...-#= .......:-+*+========++:
:==+===+=#: =*+++++++++==++++++=====++++++#: -#+++++++++==+=====++=.
.-===+=+* *+=========++================+* *+=========+====++=-:
:-==++---=*=+===++=====++++++=====++++=+*---=*=+=========+++==-:
:-=++++=+============================+++++========++====-:.
.:-=======+++=========================+++=======-:.
.::--===============================--::.
...:::-------------::::..
${NC}"
box_out "Hoàn tất cài đặt LSPHP phiên bản $php_version"
echo ""
box_out "Kích hoạt LiteSpeed webserver"
systemctl enable lsws
systemctl start lsws
/usr/local/lsws/bin/lswsctrl start
firewall-cmd --zone=public --add-service=http --add-service=https --permanent
firewall-cmd --zone=public --add-port=443/udp --permanent
firewall-cmd --reload
function Post_Install_Regenerate_Webadmin_Console_Passwd() {
Webadmin_Pass=$(
head /dev/urandom | tr -dc A-Za-z0-9 | head -c 36
echo ''
)
id_ols_admin=$(
date +%s | sha256sum | base64 | head -c 24
echo
)
Encrypt_string=$(/usr/local/lsws/admin/fcgi-bin/admin_php -q /usr/local/lsws/admin/misc/htpasswd.php "${Webadmin_Pass}")
echo "" >/usr/local/lsws/admin/conf/htpasswd
echo "$id_ols_admin:$Encrypt_string" >/usr/local/lsws/admin/conf/htpasswd
echo "tai khoan ols webgui username/password da cap nhat thanh cong!"
}
Post_Install_Regenerate_Webadmin_Console_Passwd
echo "#
# PLAIN TEXT CONFIGURATION FILE
#
#It not set, will use host name as serverName
serverName
httpdWorkers $cpucore
user nobody
group nobody
priority 0
autoRestart 1
chrootPath /
cpuAffinity $cpucore
enableLVE 0
inMemBufSize 60M
swappingDir /tmp/lshttpd/swap
autoFix503 1
gracefulRestartTimeout 300
mime conf/mime.properties
showVersionNumber 0
adminEmails root@localhost
errorlog logs/error.log {
logLevel ERROR
debugLevel 0
rollingSize 10M
keepDays 30
compressArchive 1
enableStderrLog 0
}
accesslog logs/access.log {
rollingSize 10M
keepDays 10
compressArchive 0
}
indexFiles index.html, index.php
expires {
enableExpires 1
expiresByType image/*=A31536000, text/css=A31536000, application/x-javascript=A31536000, application/javascript=A31536000, font/*=A31536000, application/x-font-ttf=A31536000
}
autoLoadHtaccess 1