forked from pedro-garcia-interactiv4/MASC-M
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmascm.sh
1611 lines (1543 loc) · 52 KB
/
mascm.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
#KEY_OWNER=4f09fdcf5c89e32c6f712ecf90632615
#====================================================================#
# MagenX - Automated Server Configuration for Magento #
# Copyright (C) 2013 [email protected] #
# All rights reserved. #
#====================================================================#
SELF=$(basename $0)
MASCM_VER="3.0"
# The base md5sum location to cotrol license
#MASCM_BASE=http://www.magenx.com/mascm
# quick-n-dirty - color, indent, echo, pause, proggress bar settings
function cecho() {
COLOR='\033[01;37m' # bold gray
RESET='\033[00;00m' # normal white
MESSAGE=${@:-"${RESET}Error: No message passed"}
echo -e "${COLOR}${MESSAGE}${RESET}" | awk '{print " ",$0}'
}
function cinfo() {
COLOR='\033[01;34m' # bold blue
RESET='\033[00;00m' # normal white
MESSAGE=${@:-"${RESET}Error: No message passed"}
echo -e "${COLOR}${MESSAGE}${RESET}" | awk '{print " ",$0}'
}
function cwarn() {
COLOR='\033[01;31m' # bold red
RESET='\033[00;00m' # normal white
MESSAGE=${@:-"${RESET}Error: No message passed"}
echo -e "${COLOR}${MESSAGE}${RESET}" | awk '{print " ",$0}'
}
function cok() {
COLOR='\033[01;32m' # bold green
RESET='\033[00;00m' # normal white
MESSAGE=${@:-"${RESET}Error: No message passed"}
echo -e "${COLOR}${MESSAGE}${RESET}" | awk '{print " ",$0}'
}
function pause() {
read -p "$*"
}
function start_progress {
interval=1
while true
do
echo -ne "#"
sleep $interval
done
}
function quick_progress {
interval=0.05
while true
do
echo -ne "#"
sleep $interval
done
}
function long_progress {
interval=3
while true
do
echo -ne "#"
sleep $interval
done
}
function stop_progress {
kill $1
wait $1 2>/dev/null
echo -en "\n"
}
clear
###################################################################################
# START CHECKS #
###################################################################################
echo
echo
# Check licence key
# KEY_OUT=$(curl $MASCM_BASE/ver 2>&1 | grep $KEY_OWNER | awk '{print $2}')
# KEY_IN=$(echo $HOSTNAME | md5sum | awk '{print $1}')
# if [[ "$KEY_OUT" == "$KEY_IN" ]]; then
# cok "PASS: INTEGRITY CHECK FOR '$SELF' ON '$HOSTNAME' OK"
# elif [[ "$KEY_OUT" != "$KEY_IN" ]]; then
# cwarn "ERROR: INTEGRITY CHECK FAILED! MD5 MISMATCH!"
# cwarn "YOU CAN NOT RUN THIS SCRIPT WITHOUT A LICENCE KEY"
# echo "Local md5: $KEY_IN"
# echo "Remote md5: $KEY_OUT"
# echo
# echo "-----> NOTE: PLEASE REPORT IT TO: [email protected]"
# echo
# echo
# exit 1
#fi
# root?
if [[ $EUID -ne 0 ]]; then
cwarn "ERROR: THIS SCRIPT MUST BE RUN AS ROOT!"
echo "------> USE SUPER-USER PRIVILEGES."
exit 1
else
cok PASS: ROOT!
fi
# do we have CentOS 6?
if grep -q "CentOS release 6" /etc/redhat-release ; then
cok "PASS: CENTOS RELEASE 6"
else
cwarn "ERROR: UNABLE TO DETERMINE DISTRIBUTION TYPE."
echo "------> THIS CONFIGURATION FOR CENTOS 6."
echo
exit 1
fi
# check if x64. if not, beat it...
ARCH=$(uname -m)
if [ "$ARCH" = "x86_64" ]; then
cok "PASS: YOUR ARCHITECTURE IS 64-BIT"
else
cwarn "ERROR: YOUR ARCHITECTURE IS 32-BIT?"
echo "------> CONFIGURATION FOR 64-BIT ONLY."
echo
exit 1
fi
# check if memory is enough
UNITS=$(cat /proc/meminfo | grep MemTotal | awk '{print $3}')
TOTALMEM=$(cat /proc/meminfo | grep MemTotal | awk '{print $2}')
if [ "$TOTALMEM" -gt "1500000" ]; then
cok "PASS: YOU HAVE $TOTALMEM $UNITS OF RAM"
else
cwarn "WARNING: YOU HAVE LESS THAN 1GB OF RAM"
fi
# network is up?
host1=74.125.24.106
host2=208.80.154.225
RESULT=$(((ping -w3 -c2 $host1 || ping -w3 -c2 $host2) > /dev/null 2>&1) && echo "up" || (echo "down" && exit 1))
if [[ $RESULT == up ]]; then
cok "PASS: NETWORK IS UP. GREAT, LETS START!"
else
cwarn "ERROR: NETWORK IS DOWN?"
echo "------> PLEASE CHECK YOUR NETWORK SETTINGS."
echo
echo
exit 1
fi
echo
###################################################################################
# CHECKS END #
###################################################################################
echo
if grep -q "yes" ~/mascm/.terms >/dev/null 2>&1 ; then
echo "loading menu"
sleep 1
else
cecho "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo
cecho "BY INSTALLING THIS SOFTWARE AND BY USING ANY AND ALL SOFTWARE"
cecho "YOU ACKNOWLEDGE AND AGREE:"
echo
cecho "THIS SOFTWARE AND ALL SOFTWARE PROVIDED IS PROVIDED AS IS"
cecho "UNSUPPORTED AND WE ARE NOT RESPONSIBLE FOR ANY DAMAGE"
echo
cecho "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo
echo
echo -n "---> Do you agree to these terms? [y/n][y]:"
read terms_agree
if [ "$terms_agree" == "y" ];then
echo "yes" > ~/mascm/.terms
else
echo "Exiting"
echo
exit 1
fi
fi
###################################################################################
# HEADER MENU START #
###################################################################################
showMenu () {
printf "\033c"
echo
echo
cecho "Magento Server Configuration v.$MASCM_VER"
cecho :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo
cecho "- For repositories installation enter: \033[01;34m repo"
cecho "- For packages installation enter: \033[01;34m packages"
cecho "- To download latest Magento enter: \033[01;34m magento"
cecho "- To setup Magento database enter: \033[01;34m database"
cecho "- Install Magento (no sample data): \033[01;34m install"
echo
cecho :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo
cecho "- To configure system backup enter: \033[01;34m backup"
cecho "- To make your server secure enter: \033[01;34m protect"
cecho "- To install CSF firewall enter: \033[01;34m firewall"
echo
cecho :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo
cecho "- To quit enter: \033[01;34m exit"
echo
echo
}
while [ 1 ]
do
showMenu
read CHOICE
case "$CHOICE" in
"repo")
echo
echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
cwarn "secure /tmp and /var/tmp"
echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
echo
echo -n "---> Would you like to secure /tmp and /var/tmp? [y/n][n]:"
read secure_tmp
if [ "$secure_tmp" == "y" ];then
echo
cd
rm -rf /tmp
mkdir /tmp
mount -t tmpfs -o rw,noexec,nosuid tmpfs /tmp
chmod 1777 /tmp
echo "tmpfs /tmp tmpfs rw,noexec,nosuid 0 0" >> /etc/fstab
rm -rf /var/tmp
ln -s /tmp /var/tmp
echo
cok "tmp SECURED OK"
fi
echo
echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
cok NOW BEGIN REPOSITORIES INSTALLATION
echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
echo
cecho "============================================================================="
echo
echo -n "---> Start EPEL repository installation? [y/n][n]:"
read repoE_install
if [ "$repoE_install" == "y" ];then
echo
cok "Running Installation of Extra Packages for Enterprise Linux"
echo
echo -n " PROCESSING "
quick_progress &
pid="$!"
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm >/dev/null 2>&1
stop_progress "$pid"
rpm --quiet -q epel-release
if [ "$?" = 0 ]
then
cok "INSTALLED OK"
else
cwarn "ERROR"
exit
fi
else
cinfo "EPEL repository installation skipped. Next step"
fi
echo
cecho "============================================================================="
echo
echo -n "---> Start CentALT Repository installation? [y/n][n]:"
read repoC_install
if [ "$repoC_install" == "y" ];then
echo
cok "Running Installation of CentALT repository"
echo
echo -n " PROCESSING "
quick_progress &
pid="$!"
rpm -Uvh http://centos.alt.ru/pub/repository/centos/6/x86_64/centalt-release-6-1.noarch.rpm >/dev/null 2>&1
stop_progress "$pid"
rpm --quiet -q centalt-release
if [ "$?" = 0 ]
then
cok "INSTALLED OK"
else
cwarn "ERROR"
exit
fi
echo
cok "Locking CentALT only for Nginx and Memcached always latest build"
echo "includepkgs=nginx* memcached" >> /etc/yum.repos.d/centalt.repo
else
cinfo "CentALT repository installation skipped. Next step"
fi
echo
cecho "============================================================================="
echo
echo -n "---> Start Repoforge repository installation? [y/n][n]:"
read repoF_install
if [ "$repoF_install" == "y" ];then
echo
cok "Running Installation of Repoforge"
echo
echo -n " PROCESSING "
quick_progress &
pid="$!"
rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm >/dev/null 2>&1
stop_progress "$pid"
rpm --quiet -q rpmforge-release
if [ "$?" = 0 ]
then
cok "INSTALLED OK"
else
cwarn "ERROR"
exit
fi
echo
else
cinfo "Repoforge installation skipped. Next step"
fi
echo
cecho "============================================================================="
echo
echo -n "---> Start Percona repository installation? [y/n][n]:"
read repoP_install
if [ "$repoP_install" == "y" ];then
echo
cok "Running Installation of Percona repository"
echo
echo -n " PROCESSING "
quick_progress &
pid="$!"
rpm -Uhv http://www.percona.com/downloads/percona-release/percona-release-0.0-1.x86_64.rpm >/dev/null 2>&1
stop_progress "$pid"
rpm --quiet -q percona-release
if [ "$?" = 0 ]
then
cok "INSTALLED OK"
else
cwarn "ERROR"
exit
fi
echo
else
cinfo "Percona repository installation skipped. Next step"
fi
echo
cecho "============================================================================="
echo
echo -n "---> Start IUScommunity repository installation? [y/n][n]:"
read repoIU_install
if [ "$repoIU_install" == "y" ];then
echo
cok "Running Installation of IUScommunity repository "
echo
echo -n " PROCESSING "
quick_progress &
pid="$!"
rpm -Uvh http://dl.iuscommunity.org/pub/ius/stable/CentOS/6/x86_64/ius-release-1.0-11.ius.centos6.noarch.rpm >/dev/null 2>&1
stop_progress "$pid"
rpm --quiet -q ius-release
if [ "$?" = 0 ]
then
cok "INSTALLED OK"
else
cwarn "ERROR"
exit
fi
echo
else
cinfo "IUScommunity repository installation skipped. Next step"
fi
###################################################################################
# REPOSITORIES END #
###################################################################################
echo
cecho "============================================================================="
echo -n "---> Start System Update? [y/n][n]:"
read sys_update
if [ "$sys_update" == "y" ];then
cok "RUNNING SYSTEM UPDATE"
echo
echo -n " PROCESSING "
long_progress &
pid="$!"
yum -y -q update >/dev/null 2>&1
stop_progress "$pid"
cok "UPDATED OK"
echo
cok "INSTALLING ADDITIONAL PACKAGES:"
echo
echo -n " PROCESSING "
long_progress &
pid="$!"
yum -q -y install redis wget curl mcrypt sudo crontabs gcc vim mlocate unzip >/dev/null 2>&1
stop_progress "$pid"
cok "INSTALLED OK"
echo
else
cinfo "System Update skipped. Next step"
fi
echo
echo
echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
cok REPOSITORIES INSTALLATION FINISHED
echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
echo
echo
pause "---> Press [Enter] key to show menu"
printf "\033c"
;;
"packages")
echo
echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
cok NOW INSTALLING PHP, NGINX, PERCONA, VARNISH, MEMCACHED, REDIS, FAIL2BAN
echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
echo
echo
cecho "============================================================================="
echo
echo -n "---> Start Percona installation? [y/n][n]:"
read percona_install
if [ "$percona_install" == "y" ];then
echo
cok "Running Percona Installation"
echo
echo -n " PROCESSING "
long_progress &
pid="$!"
yum -y -q install Percona-Server-client-55 Percona-Server-server-55 >/dev/null 2>&1
stop_progress "$pid"
rpm --quiet -q Percona-Server-client-55 Percona-Server-server-55
if [ "$?" = 0 ]
then
cok "INSTALLED OK"
else
cwarn "ERROR"
exit
fi
echo
chkconfig mysql on
echo
cecho "Percona doesnt have its own my.cnf file"
cecho "Downloading from MagenX Github repository default config"
wget -O /etc/my.cnf_ -q https://raw.github.com/magenx/magento-mysql/master/my.cnf/my.cnf
echo
cok "my.cnf downloaded to /etc and saved as my.cnf_"
cecho "Please correct it according to your servers specs, rename and restart your mysql server"
wget -O /etc/mysqlreport.pl -q http://hackmysql.com/scripts/mysqlreport
wget -O /etc/mysqltuner.pl -q https://raw.github.com/rackerhacker/MySQLTuner-perl/master/mysqltuner.pl
cecho "Please use these tools to check and finetune your database"
cecho "perl /etc/mysqlreport.pl"
cecho "perl /etc/mysqltuner.pl"
else
cinfo "Percona installation skipped. Next step"
fi
echo
cecho "============================================================================="
echo
echo -n "---> Start PHP installation? [y/n][n]:"
read php_install
if [ "$php_install" == "y" ];then
echo
cok "Running PHP Installation"
echo
echo -n " PROCESSING "
long_progress &
pid="$!"
yum -y -q install php54 php54-cli php54-common php54-fpm php54-gd php54-curl php54-mbstring php54-bcmath php54-soap php54-mcrypt php54-mysql php54-pdo php54-xml php54-pecl-apc php54-pecl-memcache php54-pecl-redis >/dev/null 2>&1
stop_progress "$pid"
rpm --quiet -q php54
if [ "$?" = 0 ]
then
cok "INSTALLED OK"
yum list installed | grep php54 | awk '{print " ",$1}'
else
cwarn "ERROR"
exit
fi
echo
chkconfig php-fpm on
else
cinfo "PHP installation skipped. Next step"
fi
echo
cecho "============================================================================="
echo
echo -n "---> Start NGINX installation? [y/n][n]:"
read nginx_install
if [ "$nginx_install" == "y" ];then
echo
cok "Running NGINX Installation"
echo
echo -n " PROCESSING "
start_progress &
pid="$!"
yum -y -q install nginx >/dev/null 2>&1
stop_progress "$pid"
rpm --quiet -q nginx
if [ $? = 0 ]
then
cok "INSTALLED OK"
else
cwarn "ERROR"
exit
fi
echo
chkconfig nginx on
chkconfig redis on
chkconfig httpd off
else
cinfo "NGINX installation skipped. Next step"
fi
echo
cecho "============================================================================="
echo
echo -n "---> Start Varnish 3 installation? [y/n][n]:"
read varnish_install
if [ "$varnish_install" == "y" ];then
echo
cok "Running Varnish 3 Installation"
echo
echo -n " PROCESSING "
quick_progress &
pid="$!"
rpm -Uhv http://repo.varnish-cache.org/redhat/varnish-3.0/el6/x86_64/varnish/varnish-3.0.5-1.el6.x86_64.rpm http://repo.varnish-cache.org/redhat/varnish-3.0/el6/x86_64/varnish/varnish-libs-3.0.5-1.el6.x86_64.rpm >/dev/null 2>&1
stop_progress "$pid"
rpm --quiet -q varnish
if [ "$?" = 0 ]
then
cok "INSTALLED OK"
else
cwarn "ERROR"
exit
fi
echo
else
cinfo "Varnish 3 installation skipped. Next step"
fi
echo
cecho "============================================================================="
echo
echo -n "---> Start Memcached installation? [y/n][n]:"
read memd_install
if [ "$memd_install" == "y" ];then
echo
cok "Running Memcached Installation"
echo
echo -n " PROCESSING "
start_progress &
pid="$!"
yum -y -q install memcached >/dev/null 2>&1
stop_progress "$pid"
rpm --quiet -q memcached
if [ "$?" = 0 ]
then
cok "INSTALLED OK"
else
cwarn "ERROR"
exit
fi
echo
chkconfig memcached on
else
cinfo "Memcached installation skipped. Next step"
fi
echo
cecho "============================================================================="
echo
echo -n "---> Start Fail2Ban installation? [y/n][n]:"
read f2b_install
if [ "$f2b_install" == "y" ];then
echo
cok "Running Fail2Ban Installation"
echo
echo -n " PROCESSING "
start_progress &
pid="$!"
yum -y -q install fail2ban >/dev/null 2>&1
stop_progress "$pid"
rpm --quiet -q memcached
if [ "$?" = 0 ]
then
cok "INSTALLED OK"
else
cwarn "ERROR"
exit
fi
echo
chkconfig fail2ban on
cok "Writing nginx 403 filter"
cat > /etc/fail2ban/filter.d/nginx-403.conf <<END
[Definition]
failregex = directory index of .* is forbidden, client: <HOST>
^<HOST> .*"GET \/w00tw00t\.at\.ISC\.SANS\.DFind\:\).*".*
^<HOST> .*"GET .*phppath/php.*" 444 .*
^<HOST> .*"POST .*444 .*
^<HOST> .*"GET .*444 .*
^<HOST> .*"GET .*wp-login.php.*404.*
END
cok "Writing nginx 403 action"
cat > /etc/fail2ban/action.d/nginx-403.conf <<END
[Definition]
actionban = IP=<ip> && echo "deny $IP;" >> /etc/nginx/banlist/403.conf && service nginx reload
actionunban = IP=<ip> && sed -i "/$IP/d" /etc/nginx/banlist/403.conf && service nginx reload
END
cok "Writing nginx 403 jail"
cat >> /etc/fail2ban/jail.conf <<END
[nginx-403]
enabled = true
port = http,https
filter = nginx-403
action = nginx-403
logpath = /var/log/nginx/error.log
END
cok "Creating banlist dir"
mkdir -p /etc/nginx/banlist/
touch /etc/nginx/banlist/403.conf
cok "Please whitelist your ip addresses in /etc/fail2ban/jail.conf"
cok "ok"
else
cinfo "Fail2Ban installation skipped. Next step"
fi
echo
cecho "============================================================================="
echo
echo -n "---> Load optimized configs of apc, php, fpm, fastcgi, memcached, sysctl, varnish? [y/n][n]:"
read load_configs
if [ "$load_configs" == "y" ];then
echo
cecho "YOU HAVE TO CHECK THEM AFTER ANYWAY"
cat > /etc/sysctl.conf <<END
fs.file-max = 360000
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 8388608 8388608 8388608
net.ipv4.tcp_rmem = 4096 87380 8388608
net.ipv4.tcp_wmem = 4096 65536 8388608
net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.tcp_fin_timeout = 15
net.ipv4.tcp_keepalive_time = 15
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_max_tw_buckets = 400000
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_sack = 1
net.ipv4.route.flush = 1
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.rmem_default = 8388608
net.core.wmem_default = 8388608
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 262144
END
sysctl -q -p
echo
cecho "sysctl.conf loaded ... \033[01;32m ok"
cat > /etc/php.d/apc.ini <<END
extension = apc.so
[APC]
apc.enabled = 1
apc.shm_segments = 1
apc.shm_size = 1G
apc.num_files_hint = 5000
apc.user_entries_hint = 5000
apc.ttl = 7200
apc.user_ttl = 7200
apc.gc_ttl = 3600
apc.cache_by_default = 1
apc.filters = "apc\.php$"
apc.mmap_file_mask = "/tmp/apc.XXXXXX"
apc.slam_defense = 0
apc.file_update_protection = 2
apc.enable_cli = 1
apc.max_file_size = 5M
apc.use_request_time = 0
apc.stat = 0
apc.file_md5 = 1
apc.canonicalize = 0
apc.write_lock = 1
apc.report_autofilter = 0
apc.include_once_override = 0
apc.coredump_unmap = 0
apc.stat_ctime = 0
END
cecho "apc.ini loaded ... \033[01;32m ok"
#Tweak php.ini.
cp /etc/php.ini /etc/php.ini.BACK
sed -i 's/^\(max_execution_time = \)[0-9]*/\17200/' /etc/php.ini
sed -i 's/^\(max_input_time = \)[0-9]*/\17200/' /etc/php.ini
sed -i 's/^\(memory_limit = \)[0-9]*M/\1512M/' /etc/php.ini
sed -i 's/^\(post_max_size = \)[0-9]*M/\132M/' /etc/php.ini
sed -i 's/^\(upload_max_filesize = \)[0-9]*M/\132M/' /etc/php.ini
sed -i 's/expose_php = On/expose_php = Off/' /etc/php.ini
sed -i 's/;realpath_cache_size = 16k/realpath_cache_size = 512k/' /etc/php.ini
sed -i 's/;realpath_cache_ttl = 120/realpath_cache_ttl = 84600/' /etc/php.ini
sed -i 's/short_open_tag = Off/short_open_tag = On/' /etc/php.ini
sed -i 's/; max_input_vars = 1000/max_input_vars = 8000/' /etc/php.ini
sed -i 's/pm = dynamic/pm = ondemand/' /etc/php-fpm.d/www.conf
cecho "php.ini loaded ... \033[01;32m ok"
cat > /etc/sysconfig/memcached <<END
PORT="11211"
USER="memcached"
MAXCONN="5024"
CACHESIZE="256"
OPTIONS="-l 127.0.0.1"
END
cecho "memcached config loaded ... \033[01;32m ok"
echo -e '\nfastcgi_read_timeout 7200;\nfastcgi_send_timeout 7200;\nfastcgi_connect_timeout 65;\n' >> /etc/nginx/fastcgi_params
cecho "fastcgi_params loaded ... \033[01;32m ok"
echo
else
cinfo "Not loading optimized configs. Next step"
fi
echo
echo
echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
cok FINISHED PACKAGES INSTALLATION
echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
echo
echo
pause '------> Press [Enter] key to show menu'
printf "\033c"
;;
"magento")
echo
echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
cok NOW DOWNLOADING NEW MAGENTO
echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
echo
FPM=$(find /etc/php-fpm.d/ -name 'www.conf')
FPM_USER=$(grep "user" $FPM | grep "=" | awk '{print $3}')
echo -n "---> Download latest Magento version? [y/n][n]:"
read new_down
if [ "$new_down" == "y" ];then
read -e -p "---> Edit your installation folder full path: " -i "/var/www/html/myshop.com" MY_SHOP_PATH
echo " Magento will be downloaded to:"
cok $MY_SHOP_PATH
pause '------> Press [Enter] key to continue'
mkdir -p $MY_SHOP_PATH
echo
cd $MY_SHOP_PATH
echo -n " DOWNLOADING MAGENTO "
long_progress &
pid="$!"
wget -qO - http://www.magentocommerce.com/downloads/assets/1.8.1.0/magento-1.8.1.0.tar.gz | tar -xzp
stop_progress "$pid"
echo
cecho "Cleanup"
mv magento/* .
rm -rf magento RELEASE_NOTES.txt LICENSE.txt LICENSE.html LICENSE_AFL.txt index.php.sample php.ini.sample
echo
cecho "============================================================================="
cok " == MAGENTO DOWNLOADED AND READY FOR INSTALLATION =="
cecho "============================================================================="
echo
echo
echo "---> CREATING NGINX CONFIG FILE NOW"
echo
read -p "---> Enter your domain name: " MY_DOMAIN
MY_CPU=$(grep -c processor /proc/cpuinfo)
cok "NGINX CONFIG SET UP WITH:"
cecho " DOMAIN: $MY_DOMAIN"
cecho " ROOT: $MY_SHOP_PATH"
cecho " CPU: $MY_CPU"
if [ -f /etc/fail2ban/jail.conf ]
then
FAIL2BAN='include /etc/nginx/banlist/403.conf;'
fi
cat > /etc/nginx/nginx.conf <<END
user $FPM_USER;
worker_processes $MY_CPU; ## = CPU qty
error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
use epoll;
}
http {
index index.html index.php; ## Allow a static html file to be shown first
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '\$remote_addr - \$remote_user [\$time_local] "\$request" '
'\$status \$body_bytes_sent "\$http_referer" '
'"\$http_user_agent" "\$http_x_forwarded_for"';
#log_format error403 '\$remote_addr - \$remote_user [\$time_local] '
# '\$status "\$request" "\$http_x_forwarded_for"';
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
$FAIL2BAN
## Gzipping is an easy way to reduce page weight
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_types text/css application/x-javascript;
gzip_buffers 16 8k;
gzip_comp_level 8;
gzip_min_length 1024;
#ssl_session_cache shared:SSL:15m;
#ssl_session_timeout 15m;
#ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
#ssl_ciphers "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EECDH EDH+aRSA RC4 !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS !RC4";
#ssl_prefer_server_ciphers on;
keepalive_timeout 10;
## Use when Varnish in front
#set_real_ip_from 127.0.0.1;
#real_ip_header X-Forwarded-For;
## Multi domain configuration
#map \$http_host \$storecode {
#www.domain1.com 1store_code; ## US main
#www.domain2.net 2store_code; ## EU store
#www.domain3.de 3store_code; ## German store
#www.domain4.com 4store_code; ## different products
#}
server {
listen 80 default;
return 444;
}
#server {
#listen 443 default;
#ssl_certificate /etc/ssl/certs/www_server_com.chained.crt;
#ssl_certificate_key /etc/ssl/certs/server.key;
#return 444;
#}
#server {
# listen 80; ## change to 8080 with Varnish
# server_name example.com;
# return 301 \$scheme://www.example.com\$request_uri;
#}
server {
listen 80; ## change to 8080 with Varnish
#listen 443 ssl;
server_name $MY_DOMAIN; ## Domain is here
root $MY_SHOP_PATH;
access_log /var/log/nginx/access_mydomain.log main;
## Nginx will not add the port in the url when the request is redirected.
#port_in_redirect off;
####################################################################################
## SSL CONFIGURATION
#ssl_certificate /etc/ssl/certs/www_server_com.chained.crt;
#ssl_certificate_key /etc/ssl/certs/server.key;
####################################################################################
## Server maintenance block. insert dev ip 1.2.3.4 static address www.whatismyip.com
#if (\$remote_addr !~ "^(1.2.3.4|1.2.3.4)$") {
#return 503;
#}
#error_page 503 @maintenance;
#location @maintenance {
#rewrite ^(.*)$ /error_page/503.html break;
#internal;
#access_log off;
#log_not_found off;
#}
####################################################################################
## 403 error log/page
#error_page 403 /403.html;
#location = /403.html {
#root /var/www/html/error_page;
#internal;
#access_log /var/log/nginx/403.log error403;
#}
####################################################################################
## Main Magento location
location / {
try_files \$uri \$uri/ @handler;
}
####################################################################################
## These locations would be hidden by .htaccess normally, protected
location ~ (/(app/|includes/|/pkginfo/|var/|errors/local.xml)|/\.svn/|/\.ht.+) {
deny all;
#internal;
}
####################################################################################
## Protecting /admin/ and /downloader/ 1.2.3.4 = static ip (www.whatismyip.com)
#location /downloader/ {
#allow 1.2.3.4;
#allow 1.2.3.4;
#deny all;
#rewrite ^/downloader/(.*)$ /downloader/index.php$1;
#}
#location /admin {
#allow 1.2.3.4;
#allow 1.2.3.4;
#deny all;
#rewrite / /@handler;
#}
####################################################################################
## Images, scripts and styles set far future Expires header
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
open_file_cache max=10000 inactive=8h;
open_file_cache_valid 1h;
open_file_cache_min_uses 2;
open_file_cache_errors off;
expires max;
log_not_found off;
}
####################################################################################
## Main Magento location
location @handler {
rewrite / /index.php;
}
location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
rewrite ^(.*.php)/ \$1 last;
}
####################################################################################
## Execute PHP scripts
location ~ .php$ {
add_header X-Config-By 'MagenX -= www.magenx.com =-';
add_header X-UA-Compatible 'IE=Edge,chrome=1';
add_header X-Time-Spent \$request_time;
try_files \$uri \$uri/ =404;
#try_files \$uri \$uri/ @handler;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
## Store code with multi domain
#fastcgi_param MAGE_RUN_CODE \$storecode;
## Default Store code
fastcgi_param MAGE_RUN_CODE default;
fastcgi_param MAGE_RUN_TYPE store; ## or website;
include fastcgi_params; ## See /etc/nginx/fastcgi_params
}
}
}
END
echo
echo
mkdir -p ~/mascm/
cat >> ~/mascm/.mascm_index <<END
webshop $MY_DOMAIN $MY_SHOP_PATH
END
echo
###################################################################################
# LOADING ALL THE POSSIBLE EXTENSIONS FROM HERE #
###################################################################################
echo
cok "INSTALLING TURPENTINE VARNISH FPC INTO MAGENTO"
pause '------> Press [Enter] key to continue'
echo