forked from magenx/Magento-2-server-installation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
magenx.install.8.sh
1844 lines (1719 loc) · 67.5 KB
/
magenx.install.8.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
#=================================================================================#
# MagenX e-commerce stack for Magento 2 #
# Copyright (C) 2013-2020 [email protected] #
# All rights reserved. #
#=================================================================================#
SELF=$(basename $0)
MAGENX_VER="2.8.240.1"
# Config path
MAGENX_CONFIG_PATH="/opt/magenx/config"
###################################################################################
### DEFINE LINKS AND PACKAGES ###
###################################################################################
# CentOS version lock
CENTOS_VERSION="8"
# ELK version lock
ELKREPO="7.x"
# Magento
MAGE_VERSION="2"
MAGE_VERSION_FULL=$(curl -s https://api.github.com/repos/magento/magento${MAGE_VERSION}/tags 2>&1 | head -3 | grep -oP '(?<=")\d.*(?=")')
REPO_MAGE="composer create-project --repository-url=https://repo.magento.com/magento/project-community-edition"
# Repositories
REPO_PERCONA="https://repo.percona.com/yum/percona-release-latest.noarch.rpm"
REPO_REMI="http://rpms.famillecollet.com/enterprise/remi-release-${CENTOS_VERSION}.rpm"
# WebStack Packages
EXTRA_PACKAGES="autoconf automake dejavu-fonts-common dejavu-sans-fonts libtidy libpcap gettext-devel recode gflags tbb ed lz4 libyaml libdwarf bind-utils e2fsprogs svn screen gcc iptraf inotify-tools iptables smartmontools net-tools mlocate unzip vim wget curl sudo bc mailx clamav-filesystem clamav-server clamav-update clamav-milter-systemd clamav-data clamav-server-systemd clamav-scanner-systemd clamav clamav-milter clamav-lib logrotate git patch ipset strace rsyslog ncurses-devel GeoIP GeoIP-devel geoipupdate openssl-devel ImageMagick libjpeg-turbo-utils pngcrush jpegoptim moreutils lsof net-snmp net-snmp-utils xinetd python3-virtualenv python3-wheel-wheel python3-pip python3-devel ncftp postfix augeas-libs libffi-devel mod_ssl dnf-automatic sysstat libuuid-devel uuid-devel attr iotop expect unixODBC gcc-c++"
PHP_PACKAGES=(cli common fpm opcache gd curl mbstring bcmath soap mcrypt mysqlnd pdo xml xmlrpc intl gmp gettext-gettext phpseclib recode symfony-class-loader symfony-common tcpdf tcpdf-dejavu-sans-fonts tidy snappy lz4)
PHP_PECL_PACKAGES=(pecl-redis pecl-lzf pecl-geoip pecl-zip pecl-memcache pecl-oauth)
PERL_MODULES=(LWP-Protocol-https Config-IniFiles libwww-perl CPAN Template-Toolkit Time-HiRes ExtUtils-CBuilder ExtUtils-Embed ExtUtils-MakeMaker TermReadKey DBI DBD-MySQL Digest-HMAC Digest-SHA1 Test-Simple Moose Net-SSLeay devel)
# Nginx extra configuration
REPO_MAGENX_TMP="https://raw.githubusercontent.com/wigman/Magento-2-server-installation/master/"
NGINX_VERSION=$(curl -s http://nginx.org/en/download.html | grep -oP '(?<=gz">nginx-).*?(?=</a>)' | head -1)
NGINX_BASE="https://raw.githubusercontent.com/magenx/Magento-nginx-config/master/"
GITHUB_REPO_API_URL="https://api.github.com/repos/magenx/Magento-nginx-config/contents/magento2"
# Debug Tools
MYSQL_TUNER="https://raw.githubusercontent.com/major/MySQLTuner-perl/master/mysqltuner.pl"
MYSQL_TOP="https://raw.githubusercontent.com/magenx/Magento-mysql/master/mytop"
###################################################################################
### COLORS ###
###################################################################################
RED="\e[31;40m"
GREEN="\e[32;40m"
YELLOW="\e[33;40m"
WHITE="\e[37;40m"
BLUE="\e[0;34m"
### Background
DGREYBG=" \e[100m"
BLUEBG=" \e[1;44m"
REDBG=" \e[41m"
### Styles
BOLD="\e[1m"
### Reset
RESET="\e[0m"
###################################################################################
### ECHO MESSAGES DESIGN ###
###################################################################################
function WHITETXT() {
MESSAGE=${@:-"${RESET}Error: No message passed"}
echo -e " ${WHITE}${MESSAGE}${RESET}"
}
function BLUETXT() {
MESSAGE=${@:-"${RESET}Error: No message passed"}
echo -e " ${BLUE}${MESSAGE}${RESET}"
}
function REDTXT() {
MESSAGE=${@:-"${RESET}Error: No message passed"}
echo -e " ${RED}${MESSAGE}${RESET}"
}
function GREENTXT() {
MESSAGE=${@:-"${RESET}Error: No message passed"}
echo -e " ${GREEN}${MESSAGE}${RESET}"
}
function YELLOWTXT() {
MESSAGE=${@:-"${RESET}Error: No message passed"}
echo -e " ${YELLOW}${MESSAGE}${RESET}"
}
function BLUEBG() {
MESSAGE=${@:-"${RESET}Error: No message passed"}
echo -e "${BLUEBG}${MESSAGE}${RESET}"
}
###################################################################################
### PROGRESS BAR AND PAUSE ###
###################################################################################
function pause() {
read -p " $*"
}
function start_progress {
while true
do
echo -ne "#"
sleep 1
done
}
function quick_progress {
while true
do
echo -ne "#"
sleep 0.05
done
}
function long_progress {
while true
do
echo -ne "#"
sleep 3
done
}
function stop_progress {
kill $1
wait $1 2>/dev/null
echo -en "\n"
}
include_config () {
[[ -f "$1" ]] && . "$1"
}
_echo () {
echo -en " $@"
}
###################################################################################
### ARROW KEYS UP/DOWN MENU ###
###################################################################################
updown_menu () {
i=1;for items in $(echo $1); do item[$i]="${items}"; let i=$i+1; done
i=1
echo -e "\n---> Use up/down arrow keys then press Enter to select $2"
while [ 0 ]; do
if [ "$i" -eq 0 ]; then i=1; fi
if [ ! "${item[$i]}" ]; then let i=i-1; fi
echo -en "\r "
echo -en "\r${item[$i]}"
read -sn 1 selector
case "${selector}" in
"B") let i=i+1;;
"A") let i=i-1;;
"") echo; read -sn 1 -p "To confirm [ ${item[$i]} ] press y or n for new selection" confirm
if [[ "${confirm}" =~ ^[Yy]$ ]]; then
printf -v "$2" '%s' "${item[$i]}"
break
else
echo
echo -e "\n---> Use up/down arrow keys then press Enter to select $2"
fi
;;
esac
done }
clear
###################################################################################
### CHECK IF WE CAN RUN IT ###
###################################################################################
echo
echo
# root?
if [[ ${EUID} -ne 0 ]]; then
echo
REDTXT "[!] THIS SCRIPT MUST BE RUN AS ROOT!"
YELLOWTXT "[!] USE SUPER-USER PRIVILEGES."
exit 1
else
GREENTXT "PASS: ROOT!"
fi
# some selinux, sir?
if [ ! -f "${MAGENX_CONFIG_PATH}/selinux" ]; then
mkdir -p ${MAGENX_CONFIG_PATH}
SELINUX=$(awk -F "=" '/^SELINUX=/ {print $2}' /etc/selinux/config)
if [[ ! "${SELINUX}" =~ (disabled|permissive) ]]; then
echo
REDTXT "[!] SELINUX IS NOT DISABLED OR PERMISSIVE"
YELLOWTXT "[!] PLEASE CHECK YOUR SELINUX SETTINGS"
echo
echo " [!] System will be configured with SELinux if you answer 'n'"
echo
_echo "[?] Would you like to disable SELinux and reboot ? [y/n][y]:"
read selinux_disable
if [ "${selinux_disable}" == "y" ];then
sed -i "s/SELINUX=${SELINUX}/SELINUX=disabled/" /etc/selinux/config
echo "disabled" > ${MAGENX_CONFIG_PATH}/selinux
reboot
else
echo
GREENTXT "PASS: SELINUX IS ${SELINUX^^}"
echo "${SELINUX}" > ${MAGENX_CONFIG_PATH}/selinux
## selinux
if grep -q "enforcing" ${MAGENX_CONFIG_PATH}/selinux >/dev/null 2>&1 ; then
## selinux config
setsebool -P httpd_can_network_connect true
setsebool -P httpd_setrlimit true
setsebool -P httpd_enable_homedirs true
setsebool -P httpd_can_sendmail true
setsebool -P httpd_execmem true
fi
fi
fi
fi
# network is up?
host1=google.com
host2=github.com
RESULT=$(((ping -w3 -c2 ${host1} || ping -w3 -c2 ${host2}) > /dev/null 2>&1) && echo "up" || (echo "down" && exit 1))
if [[ ${RESULT} == up ]]; then
GREENTXT "PASS: NETWORK IS UP. GREAT, LETS START!"
else
echo
REDTXT "[!] NETWORK IS DOWN ?"
YELLOWTXT "[!] PLEASE CHECK YOUR NETWORK SETTINGS."
echo
echo
exit 1
fi
# do we have CentOS?
if grep "CentOS.* ${CENTOS_VERSION}\." /etc/centos-release > /dev/null 2>&1; then
GREENTXT "PASS: CENTOS RELEASE ${CENTOS_VERSION}"
else
echo
REDTXT "[!] UNABLE TO FIND CENTOS ${CENTOS_VERSION}"
YELLOWTXT "[!] THIS CONFIGURATION FOR CENTOS ${CENTOS_VERSION}"
echo
exit 1
fi
# check if x64. if not, beat it...
ARCH=$(uname -m)
if [ "${ARCH}" = "x86_64" ]; then
GREENTXT "PASS: 64-BIT"
else
echo
REDTXT "[!] 32-BIT SYSTEM?"
YELLOWTXT "[!] CONFIGURATION FOR 64-BIT ONLY."
echo
exit 1
fi
# check if memory is enough
TOTALMEM=$(awk '/MemTotal/ { print $2 }' /proc/meminfo)
if [ "${TOTALMEM}" -gt "3000000" ]; then
GREENTXT "PASS: YOU HAVE ${TOTALMEM} Kb OF RAM"
else
echo
REDTXT "[!] YOU HAVE LESS THAN 3Gb OF RAM"
YELLOWTXT "[!] TO PROPERLY RUN COMPLETE STACK YOU NEED 4Gb+"
echo
fi
# check if webstack is clean
if ! grep -q "webstack_is_clean" ${MAGENX_CONFIG_PATH}/webstack >/dev/null 2>&1 ; then
installed_packages="$(rpm -qa --qf '%{name} ' 'mysqld?|firewalld|Percona*|maria*|php-?|nginx*|*ftp*|varnish*|certbot*|redis*|webmin')"
if [ ! -z "$installed_packages" ]; then
REDTXT "[!] WEBSTACK PACKAGES ALREADY INSTALLED"
YELLOWTXT "[!] YOU NEED TO REMOVE THEM OR RE-INSTALL MINIMAL OS VERSION"
echo
echo -e "\t\t dnf remove ${installed_packages} --noautoremove"
echo
echo
exit 1
else
mkdir -p ${MAGENX_CONFIG_PATH}
echo "webstack_is_clean" > ${MAGENX_CONFIG_PATH}/webstack
fi
fi
GREENTXT "PATH: ${PATH}"
echo
if ! grep -q "yes" ${MAGENX_CONFIG_PATH}/systest >/dev/null 2>&1 ; then
echo
BLUEBG "~ QUICK SYSTEM TEST ~"
WHITETXT "-------------------------------------------------------------------------------------"
echo
dnf -y install epel-release > /dev/null 2>&1
dnf -y install time bzip2 tar > /dev/null 2>&1
test_file=vpsbench__$$
tar_file=tarfile
now=$(date +"%m/%d/%Y")
cname=$( awk -F: '/model name/ {name=$2} END {print name}' /proc/cpuinfo )
cores=$( awk -F: '/model name/ {core++} END {print core}' /proc/cpuinfo )
freq=$( awk -F: ' /cpu MHz/ {freq=$2} END {print freq}' /proc/cpuinfo )
tram=$( free -m | awk 'NR==2 {print $2}' )
echo
echo -n " PROCESSING I/O PERFORMANCE "
start_progress &
pid="$!"
io=$( ( dd if=/dev/zero of=$test_file bs=64k count=16k conv=fdatasync && rm -f $test_file ) 2>&1 | awk -F, '{io=$NF} END { print io}' )
stop_progress "$pid"
echo -n " PROCESSING CPU PERFORMANCE "
dd if=/dev/urandom of=$tar_file bs=1024 count=25000 >>/dev/null 2>&1
start_progress &
pid="$!"
tf=$( (/usr/bin/time -f "%es" tar cfj $tar_file.bz2 $tar_file) 2>&1 )
stop_progress "$pid"
rm -f tarfile*
echo
echo
if [ ${io% *} -ge 250 ] ; then
IO_COLOR="${GREEN}$io - excellent result"
elif [ ${io% *} -ge 200 ] ; then
IO_COLOR="${YELLOW}$io - average result"
else
IO_COLOR="${RED}$io - very bad result"
fi
if [ ${tf%.*} -ge 10 ] ; then
CPU_COLOR="${RED}$tf - very bad result"
elif [ ${tf%.*} -ge 5 ] ; then
CPU_COLOR="${YELLOW}$tf - average result"
else
CPU_COLOR="${GREEN}$tf - excellent result"
fi
WHITETXT "${BOLD}SYSTEM DETAILS"
WHITETXT "CPU model: $cname"
WHITETXT "Number of cores: $cores"
WHITETXT "CPU frequency: $freq MHz"
WHITETXT "Total amount of RAM: $tram MB"
echo
WHITETXT "${BOLD}BENCHMARKS RESULTS"
WHITETXT "[I/O speed]: ${IO_COLOR}"
WHITETXT "[CPU Time]: ${CPU_COLOR}"
echo
mkdir -p ${MAGENX_CONFIG_PATH} && echo "yes" > ${MAGENX_CONFIG_PATH}/systest
echo
pause "[] Press [Enter] key to proceed"
echo
fi
echo
# ssh test
if ! grep -q "yes" ${MAGENX_CONFIG_PATH}/sshport >/dev/null 2>&1 ; then
touch ${MAGENX_CONFIG_PATH}/sshport
echo
sed -i "s/.*LoginGraceTime.*/LoginGraceTime 30/" /etc/ssh/sshd_config
sed -i "s/.*MaxAuthTries.*/MaxAuthTries 6/" /etc/ssh/sshd_config
sed -i "s/.*X11Forwarding.*/X11Forwarding no/" /etc/ssh/sshd_config
sed -i "s/.*PrintLastLog.*/PrintLastLog yes/" /etc/ssh/sshd_config
sed -i "s/.*TCPKeepAlive.*/TCPKeepAlive yes/" /etc/ssh/sshd_config
sed -i "s/.*ClientAliveInterval.*/ClientAliveInterval 600/" /etc/ssh/sshd_config
sed -i "s/.*ClientAliveCountMax.*/ClientAliveCountMax 3/" /etc/ssh/sshd_config
sed -i "s/.*UseDNS.*/UseDNS no/" /etc/ssh/sshd_config
sed -i "s/.*PrintMotd.*/PrintMotd yes/" /etc/ssh/sshd_config
echo
SSH_PORT="$(awk '/#?Port [0-9]/ {print $2}' /etc/ssh/sshd_config)"
if [ "${SSH_PORT}" == "22" ]; then
REDTXT "[!] DEFAULT SSH PORT :22 DETECTED"
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.BACK
SSH_PORT_NEW=$(shuf -i 9537-9554 -n 1)
sed -i "s/.*Port 22/Port ${SSH_PORT_NEW}/g" /etc/ssh/sshd_config
SSH_PORT=${SSH_PORT_NEW}
fi
SFTP_PORT=$(shuf -i 5121-5132 -n 1)
sed -i "/^Port ${SSH_PORT}/a Port ${SFTP_PORT}" /etc/ssh/sshd_config
cat >> /etc/ssh/sshd_config <<END
# SFTP port configuration
Match LocalPort ${SFTP_PORT} User *,!root
ChrootDirectory %h
ForceCommand internal-sftp -u 0007 -l VERBOSE
PasswordAuthentication no
AllowTCPForwarding no
X11Forwarding no
END
echo
GREENTXT "SSH PORT AND SETTINGS WERE UPDATED - OK"
echo
GREENTXT "[!] SSH MAIN PORT: ${SSH_PORT}"
echo
if grep -q "enforcing" ${MAGENX_CONFIG_PATH}/selinux >/dev/null 2>&1 ; then
## selinux config
semanage port -a -t ssh_port_t -p tcp ${SSH_PORT}
semanage port -a -t ssh_port_t -p tcp ${SFTP_PORT}
fi
systemctl restart sshd.service
ss -tlp | grep sshd
echo
echo
REDTXT "[!] IMPORTANT: NOW OPEN NEW SSH SESSION WITH THE NEW PORT!"
REDTXT "[!] IMPORTANT: DO NOT CLOSE YOUR CURRENT SESSION!"
echo
_echo "[?] Have you logged in another session? [y/n][n]:"
read ssh_test
if [ "${ssh_test}" == "y" ];then
echo
GREENTXT "[!] SSH MAIN PORT: ${SSH_PORT}"
GREENTXT "[!] SFTP+CHROOT PORT: ${SFTP_PORT}"
echo
echo "# yes" > ${MAGENX_CONFIG_PATH}/sshport
echo "SSH_PORT=${SSH_PORT}" >> ${MAGENX_CONFIG_PATH}/sshport
echo "SFTP_PORT=${SFTP_PORT}" >> ${MAGENX_CONFIG_PATH}/sshport
echo
echo
pause "[] Press [Enter] key to proceed"
else
echo
mv /etc/ssh/sshd_config.BACK /etc/ssh/sshd_config
REDTXT "RESTORING sshd_config FILE BACK TO DEFAULTS ${GREEN} [ok]"
systemctl restart sshd.service
echo
GREENTXT "SSH PORT HAS BEEN RESTORED - OK"
if grep -q "enforcing" ${MAGENX_CONFIG_PATH}/selinux >/dev/null 2>&1 ; then
## selinux config
semanage port -d -p tcp ${SSH_PORT}
semanage port -d -p tcp ${SFTP_PORT}
fi
ss -tlp | grep sshd
fi
fi
echo
echo
###################################################################################
### AGREEMENT ###
###################################################################################
echo
if ! grep -q "yes" ${MAGENX_CONFIG_PATH}/terms >/dev/null 2>&1 ; then
printf "\033c"
echo
YELLOWTXT "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo
YELLOWTXT "BY INSTALLING THIS SOFTWARE AND BY USING ANY AND ALL SOFTWARE"
YELLOWTXT "YOU ACKNOWLEDGE AND AGREE:"
echo
YELLOWTXT "THIS SOFTWARE AND ALL SOFTWARE PROVIDED IS PROVIDED AS IS"
YELLOWTXT "UNSUPPORTED AND WE ARE NOT RESPONSIBLE FOR ANY DAMAGE"
echo
YELLOWTXT "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo
echo
_echo "[?] Do you agree to these terms ? [y/n][y]:"
read terms_agree
if [ "${terms_agree}" == "y" ];then
echo "yes" > ${MAGENX_CONFIG_PATH}/terms
else
REDTXT "Going out. EXIT"
echo
exit 1
fi
fi
###################################################################################
### MAIN MENU ###
###################################################################################
showMenu () {
printf "\033c"
echo
echo
echo -e "${DGREYBG}${BOLD} MAGENTO SERVER CONFIGURATION v.${MAGENX_VER} ${RESET}"
BLUETXT ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo
WHITETXT "[-] Install repository and LEMP packages : ${YELLOW}\tlemp"
WHITETXT "[-] Download Magento latest packages : ${YELLOW}\tmagento"
WHITETXT "[-] Setup Magento database : ${YELLOW}\tdatabase"
WHITETXT "[-] Install Magento no sample data : ${YELLOW}\tinstall"
WHITETXT "[-] Post-Install configuration : ${YELLOW}\tconfig"
echo
BLUETXT ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo
WHITETXT "[-] Install CSF Firewall or Fail2Ban : ${YELLOW}\tfirewall"
WHITETXT "[-] Install Webmin control panel : ${YELLOW}\twebmin"
echo
BLUETXT ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo
WHITETXT "[-] To quit and exit : ${RED}\texit"
echo
echo
}
while [ 1 ]
do
showMenu
read CHOICE
case "${CHOICE}" in
"lemp")
echo
echo
###################################################################################
### SYSTEM UPGRADE ###
###################################################################################
if ! grep -q "yes" ${MAGENX_CONFIG_PATH}/sysupdate >/dev/null 2>&1 ; then
## install all extra packages
echo
BLUEBG "[~] SYSTEM UPDATE AND PACKAGES INSTALLATION [~]"
WHITETXT "-------------------------------------------------------------------------------------"
echo
dnf install -y dnf-utils >/dev/null 2>&1
dnf module enable -y perl:5.26 >/dev/null 2>&1
dnf config-manager --set-enabled PowerTools >/dev/null 2>&1
dnf -y install ${EXTRA_PACKAGES} ${PERL_MODULES[@]/#/perl-}
## disable some module
dnf -y module disable nginx php redis varnish >/dev/null 2>&1
dnf -y upgrade --nobest
echo
curl -o /etc/motd -s ${REPO_MAGENX_TMP}motd
sed -i "s/MAGE_VERSION_FULL/${MAGE_VERSION_FULL}/" /etc/motd
sed -i "s/MAGENX_VER/${MAGENX_VER}/" /etc/motd
echo "yes" > ${MAGENX_CONFIG_PATH}/sysupdate
echo
fi
echo
echo
BLUEBG "[~] REPOSITORIES AND PACKAGES INSTALLATION [~]"
WHITETXT "-------------------------------------------------------------------------------------"
echo
echo
_echo "[?] Install Percona 8.0 database ? [y/n][n]:"
read repo_percona_install
if [ "${repo_percona_install}" == "y" ];then
echo
_echo "PROCESSING "
long_progress &
pid="$!"
dnf install -y -q ${REPO_PERCONA} >/dev/null 2>&1
stop_progress "$pid"
rpm --quiet -q percona-release
if [ "$?" = 0 ] # if repository installed then install package
then
echo
GREENTXT "REPOSITORY INSTALLED - OK"
echo
echo
GREENTXT "Percona 8.0 database installation:"
echo
_echo "PROCESSING "
long_progress &
pid="$!"
dnf module disable -y mysql >/dev/null 2>&1
percona-release setup ps80 -y >/dev/null 2>&1
dnf install -y percona-server-server percona-server-client >/dev/null 2>&1
stop_progress "$pid"
rpm --quiet -q percona-server-server percona-server-client
if [ "$?" = 0 ] # if package installed then configure
then
echo
GREENTXT "DATABASE INSTALLED - OK"
echo
systemctl enable mysqld >/dev/null 2>&1
rpm -qa 'percona*' | awk '{print " Installed: ",$1}'
echo
WHITETXT "Downloading my.cnf file from MagenX Github repository"
wget -qO /etc/my.cnf https://raw.githubusercontent.com/magenx/magento-mysql/master/my.cnf/my.cnf
echo
echo
WHITETXT "Calculating innodb_buffer_pool_size"
rpm -qa | grep -qw bc || dnf -q -y install bc >/dev/null 2>&1
IBPS=$(echo "0.5*$(awk '/MemTotal/ { print $2 / (1024*1024)}' /proc/meminfo | cut -d'.' -f1)" | bc | xargs printf "%1.0f")
sed -i "s/innodb_buffer_pool_size = 4G/innodb_buffer_pool_size = ${IBPS}G/" /etc/my.cnf
sed -i "s/innodb_buffer_pool_instances = 4/innodb_buffer_pool_instances = ${IBPS}/" /etc/my.cnf
echo
YELLOWTXT "innodb_buffer_pool_size = ${IBPS}G"
YELLOWTXT "innodb_buffer_pool_instances = ${IBPS}"
echo
else
echo
REDTXT "DATABASE INSTALLATION ERROR"
exit # if package is not installed then exit
fi
else
echo
REDTXT "REPOSITORY INSTALLATION ERROR"
exit # if repository is not installed then exit
fi
else
echo
YELLOWTXT "Percona repository installation was skipped by the user. Next step"
fi
echo
WHITETXT "============================================================================="
echo
_echo "[?] Install Nginx ${NGINX_VERSION} ? [y/n][n]:"
read repo_nginx_install
if [ "${repo_nginx_install}" == "y" ];then
echo
cat > /etc/yum.repos.d/nginx.repo <<END
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/\$releasever/\$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
END
echo
GREENTXT "REPOSITORY INSTALLED - OK"
echo
GREENTXT "Nginx package installation:"
echo
_echo "PROCESSING "
start_progress &
pid="$!"
dnf -y -q install nginx nginx-module-perl >/dev/null 2>&1
stop_progress "$pid"
rpm --quiet -q nginx
if [ "$?" = 0 ]
then
echo
GREENTXT "NGINX INSTALLED - OK"
echo
systemctl enable nginx >/dev/null 2>&1
rpm -qa 'nginx*' | awk '{print " Installed: ",$1}'
else
echo
REDTXT "NGINX INSTALLATION ERROR"
exit
fi
else
echo
YELLOWTXT "Nginx repository installation was skipped by the user. Next step"
fi
echo
WHITETXT "============================================================================="
echo
_echo "[?] Install PHP 7.4 ? [y/n][n]:"
read repo_remi_install
if [ "${repo_remi_install}" == "y" ];then
echo
GREENTXT "Remi repository installation:"
echo
read -e -p " [?] Enter required PHP version: " -i "7.4" PHP_VERSION
echo
_echo "PROCESSING "
long_progress &
pid="$!"
dnf install -y ${REPO_REMI} >/dev/null 2>&1
dnf -y module enable php:remi-${PHP_VERSION} >/dev/null 2>&1
dnf config-manager --set-enabled remi >/dev/null 2>&1
stop_progress "$pid"
rpm --quiet -q remi-release
if [ "$?" = 0 ]
then
echo
GREENTXT "REPOSITORY INSTALLED - OK"
echo
echo
GREENTXT "PHP ${PHP_VERSION} installation:"
echo
_echo "PROCESSING "
long_progress &
pid="$!"
dnf -y -q install php composer ${PHP_PACKAGES[@]/#/php-} ${PHP_PECL_PACKAGES[@]/#/php-} >/dev/null 2>&1
stop_progress "$pid"
rpm --quiet -q php
if [ "$?" = 0 ]
then
echo
GREENTXT "PHP ${PHP_VERSION} INSTALLED - OK"
systemctl enable php-fpm >/dev/null 2>&1
systemctl disable httpd >/dev/null 2>&1
echo
rpm -qa 'php*' | awk '{print " Installed: ",$1}'
else
echo
REDTXT "PHP INSTALLATION ERROR"
exit # if package is not installed then exit
fi
else
echo
REDTXT "REPOSITORY INSTALLATION ERROR"
exit # if repository is not installed then exit
fi
else
echo
YELLOWTXT "Remi repository installation was skipped by the user. Next step"
fi
echo
echo
WHITETXT "============================================================================="
echo
_echo "[?] Install Redis 6 ? [y/n][n]:"
read redis_install
if [ "${redis_install}" == "y" ];then
echo
GREENTXT "Redis installation:"
echo
_echo "PROCESSING "
start_progress &
pid="$!"
dnf -y -q module install redis:remi-6.0 >/dev/null 2>&1
stop_progress "$pid"
rpm --quiet -q redis
if [ "$?" = 0 ]
then
echo
GREENTXT "REDIS INSTALLED OK"
systemctl disable redis >/dev/null 2>&1
echo
rpm -qa 'redis*' | awk '{print " Installed: ",$1}'
echo
cat > /etc/systemd/system/[email protected] <<END
[Unit]
Description=Redis %i
After=network.target
PartOf=redis.target
[Service]
Type=simple
User=redis
Group=redis
PrivateTmp=true
PIDFile=/var/run/redis-%i.pid
ExecStart=/usr/bin/redis-server /etc/redis-%i.conf
Restart=on-failure
[Install]
WantedBy=multi-user.target redis.target
END
cat > /etc/systemd/system/redis.target <<END
[Unit]
Description=Redis start/stop all [email protected] instances
END
for REDISPORT in 6379 6380
do
mkdir -p /var/lib/redis-${REDISPORT}
chmod 755 /var/lib/redis-${REDISPORT}
chown redis /var/lib/redis-${REDISPORT}
cp -rf /etc/redis.conf /etc/redis-${REDISPORT}.conf
chmod 644 /etc/redis-${REDISPORT}.conf
sed -i "s/^bind 127.0.0.1.*/bind 127.0.0.1/" /etc/redis-${REDISPORT}.conf
sed -i "s/^dir.*/dir \/var\/lib\/redis-${REDISPORT}\//" /etc/redis-${REDISPORT}.conf
sed -i "s/^logfile.*/logfile \/var\/log\/redis\/redis-${REDISPORT}.log/" /etc/redis-${REDISPORT}.conf
sed -i "s/^pidfile.*/pidfile \/var\/run\/redis-${REDISPORT}.pid/" /etc/redis-${REDISPORT}.conf
sed -i "s/^port.*/port ${REDISPORT}/" /etc/redis-${REDISPORT}.conf
sed -i "s/dump.rdb/dump-${REDISPORT}.rdb/" /etc/redis-${REDISPORT}.conf
sed -i "/save [0-9]0/d" /etc/redis-${REDISPORT}.conf
sed -i 's/^#.*save ""/save ""/' /etc/redis-${REDISPORT}.conf
sed -i '/^# rename-command CONFIG ""/a\
rename-command SLAVEOF "" \
rename-command CONFIG "" \
rename-command PUBLISH "" \
rename-command SAVE "" \
rename-command SHUTDOWN "" \
rename-command DEBUG "" \
rename-command BGSAVE "" \
rename-command BGREWRITEAOF ""
' /etc/redis-${REDISPORT}.conf
done
echo
systemctl daemon-reload
systemctl enable redis@6379 >/dev/null 2>&1
systemctl enable redis@6380 >/dev/null 2>&1
else
echo
REDTXT "REDIS INSTALLATION ERROR"
exit
fi
else
echo
REDTXT "REPOSITORY INSTALLATION ERROR"
exit
fi
echo
WHITETXT "============================================================================="
echo
echo
_echo "[?] Install Varnish Cache ? [y/n][n]:"
read varnish_install
if [ "${varnish_install}" == "y" ];then
cat > /etc/yum.repos.d/varnish6.repo <<END
[varnishcache_varnish64]
name=varnishcache_varnish64
baseurl=https://packagecloud.io/varnishcache/varnish64/el/8/\$basearch
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/varnishcache/varnish64/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300
[varnishcache_varnish64-source]
name=varnishcache_varnish64-source
baseurl=https://packagecloud.io/varnishcache/varnish64/el/8/SRPMS
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/varnishcache/varnish64/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300
END
echo
_echo "PROCESSING "
start_progress &
pid="$!"
dnf -y -q install varnish >/dev/null 2>&1
stop_progress "$pid"
rpm --quiet -q varnish
if [ "$?" = 0 ]
then
echo
wget -qO /etc/systemd/system/varnish.service ${REPO_MAGENX_TMP}varnish.service
wget -qO /etc/varnish/varnish.params ${REPO_MAGENX_TMP}varnish.params
uuidgen > /etc/varnish/secret
systemctl daemon-reload >/dev/null 2>&1
GREENTXT "VARNISH INSTALLED - OK"
echo
rpm -qa 'varnish*' | awk '{print " Installed: ",$1}'
else
echo
REDTXT "VARNISH INSTALLATION ERROR"
fi
else
echo
YELLOWTXT "Varnish installation was skipped by the user. Next step"
fi
echo
WHITETXT "============================================================================="
echo
_echo "[?] Install ElasticSearch ${ELKREPO} ? [y/n][n]:"
read elastic_install
if [ "${elastic_install}" == "y" ];then
echo
GREENTXT "JAVA JDK installation:"
dnf -y install java >/dev/null 2>&1
echo
GREENTXT "Elasticsearch installation:"
echo
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
cat > /etc/yum.repos.d/elastic.repo << EOF
[elasticsearch-${ELKREPO}]
name=Elasticsearch repository for ${ELKREPO} packages
baseurl=https://artifacts.elastic.co/packages/${ELKREPO}/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
EOF
echo
_echo "PROCESSING "
start_progress &
pid="$!"
dnf -y -q install --enablerepo=elasticsearch-${ELKREPO} elasticsearch kibana >/dev/null 2>&1
stop_progress "$pid"
rpm --quiet -q elasticsearch
if [ "$?" = 0 ]
then
echo
echo "discovery.type: single-node" >> /etc/elasticsearch/elasticsearch.yml
echo "xpack.security.enabled: true" >> /etc/elasticsearch/elasticsearch.yml
sed -i "s/.*cluster.name.*/cluster.name: magento/" /etc/elasticsearch/elasticsearch.yml
sed -i "s/.*node.name.*/node.name: magento-node1/" /etc/elasticsearch/elasticsearch.yml
sed -i "s/.*network.host.*/network.host: 127.0.0.1/" /etc/elasticsearch/elasticsearch.yml
sed -i "s/.*http.port.*/http.port: 9200/" /etc/elasticsearch/elasticsearch.yml
sed -i "s/-Xms.*/-Xms512m/" /etc/elasticsearch/jvm.options
sed -i "s/-Xmx.*/-Xmx512m/" /etc/elasticsearch/jvm.options
chown -R :elasticsearch /etc/elasticsearch/*
systemctl daemon-reload
systemctl enable elasticsearch.service
systemctl restart elasticsearch.service
/usr/share/elasticsearch/bin/elasticsearch-setup-passwords auto -b > /tmp/elasticsearch
cat > ${MAGENX_CONFIG_PATH}/elasticsearch <<END
APM_SYSTEM_PASSWORD="$(awk '/PASSWORD apm_system/ { print $4 }' /tmp/elasticsearch)"
KIBANA_SYSTEM_PASSWORD="$(awk '/PASSWORD kibana_system/ { print $4 }' /tmp/elasticsearch)"
KIBANA_PASSWORD="$(awk '/PASSWORD kibana =/ { print $4 }' /tmp/elasticsearch)"
LOGSTASH_SYSTEM_PASSWORD="$(awk '/PASSWORD logstash_system/ { print $4 }' /tmp/elasticsearch)"
BEATS_SYSTEM_PASSWORD="$(awk '/PASSWORD beats_system/ { print $4 }' /tmp/elasticsearch)"
REMOTE_MONITORING_USER_PASSWORD="$(awk '/PASSWORD remote_monitoring_user/ { print $4 }' /tmp/elasticsearch)"
ELASTIC_PASSWORD="$(awk '/PASSWORD elastic/ { print $4 }' /tmp/elasticsearch)"
END
echo
echo
GREENTXT "ELASTCSEARCH ${ELKVER} INSTALLED - OK"
echo
rpm -qa 'elasticsearch*' | awk '{print " Installed: ",$1}'
else
echo
REDTXT "ELASTCSEARCH INSTALLATION ERROR"
fi
else
echo
YELLOWTXT "ElasticSearch installation was skipped by the user. Next step"
fi
echo
echo
GREENTXT "~ REPOSITORIES AND PACKAGES INSTALLATION IS COMPLETED ~"
WHITETXT "-------------------------------------------------------------------------------------"
echo
echo
pause '[] Press [Enter] key to show the menu'
printf "\033c"
;;
###################################################################################
### MAGENTO DOWNLOAD ###
###################################################################################
"magento")
echo
echo
BLUEBG "[~] DOWNLOAD MAGENTO ${MAGE_VERSION} (${MAGE_VERSION_FULL}) [~]"
WHITETXT "-------------------------------------------------------------------------------------"
echo
echo
read -e -p " [?] ENTER YOUR DOMAIN OR IP ADDRESS: " -i "storedomain.net" MAGE_DOMAIN
read -e -p " [?] ENTER MAGENTO FILES OWNER NAME: " -i "example" MAGE_OWNER
MAGE_WEB_ROOT_PATH="/home/${MAGE_OWNER}/public_html"
echo
_echo "[!] MAGENTO ${MAGE_VERSION} (${MAGE_VERSION_FULL}) WILL BE DOWNLOADED TO ${MAGE_WEB_ROOT_PATH}"
echo
userdel -r centos >/dev/null 2>&1
mkdir -p ${MAGE_WEB_ROOT_PATH} && cd $_
## create root user
useradd -d ${MAGE_WEB_ROOT_PATH%/*} -s /bin/bash ${MAGE_OWNER} >/dev/null 2>&1
## create root php user
MAGE_PHP_USER="php-${MAGE_OWNER}"
useradd -M -s /sbin/nologin -d ${MAGE_WEB_ROOT_PATH%/*} ${MAGE_PHP_USER} >/dev/null 2>&1
usermod -g ${MAGE_PHP_USER} ${MAGE_OWNER}
chmod 711 ${MAGE_WEB_ROOT_PATH%/*}
mkdir -p ${MAGE_WEB_ROOT_PATH%/*}/{.config,.cache,.local}
chown -R ${MAGE_OWNER}:${MAGE_PHP_USER} ${MAGE_WEB_ROOT_PATH} ${MAGE_WEB_ROOT_PATH%/*}/{.config,.cache,.local}
chmod 2770 ${MAGE_WEB_ROOT_PATH}
echo
MAGE_MINIMAL_OPT="MINIMAL SET OF PACKAGES"
GREENTXT "${MAGE_MINIMAL_OPT} INSTALLATION"
echo
GREENTXT "Benefits of removing bloatware packages:"
WHITETXT "[!] Faster backend/frontend operations!"
WHITETXT "[!] Less maintenance work!"
WHITETXT "[!] Less security risks and dependencies!"
echo
pause '[] Press [Enter] key to start'
echo
su ${MAGE_OWNER} -s /bin/bash -c "${REPO_MAGE} . --no-install"
curl -sO https://raw.githubusercontent.com/magenx/Magento-2-server-installation/master/composer_replace
##replace?
sed -i '/"conflict":/ {
r composer_replace
N
}' composer.json
##replace?
su ${MAGE_OWNER} -s /bin/bash -c "php -d memory_limit=-1 /usr/bin/composer install"
echo
echo
GREENTXT "[~] MAGENTO ${MAGE_MINIMAL_OPT} DOWNLOADED AND READY FOR SETUP [~]"
WHITETXT "--------------------------------------------------------------------"
echo
su ${MAGE_OWNER} -s /bin/bash -c "echo 007 > magento_umask"
mkdir -p ${MAGENX_CONFIG_PATH}
cat > ${MAGENX_CONFIG_PATH}/magento <<END
# ${MAGE_MINIMAL_OPT}
MAGE_VERSION="2"
MAGE_VERSION_FULL="${MAGE_VERSION_FULL}"
MAGE_DOMAIN="${MAGE_DOMAIN}"
MAGE_OWNER="${MAGE_OWNER}"
MAGE_PHP_USER="${MAGE_PHP_USER}"
MAGE_WEB_ROOT_PATH="${MAGE_WEB_ROOT_PATH}"
END
echo
pause '[] Press [Enter] key to show menu'
printf "\033c"
;;
###################################################################################
### DATABASE SETUP ###
###################################################################################
"database")
printf "\033c"
echo
BLUEBG "[~] CREATE MYSQL USER AND DATABASE [~]"
WHITETXT "-------------------------------------------------------------------------------------"
if [ ! -f /root/.my.cnf ]; then
systemctl start mysqld.service
MYSQL_ROOT_PASSWORD_GEN=$(head -c 500 /dev/urandom | tr -dc 'a-zA-Z0-9@%^&?=+_[]{}()<>-' | fold -w 15 | head -n 1)