-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon_packages
More file actions
852 lines (723 loc) · 25 KB
/
common_packages
File metadata and controls
852 lines (723 loc) · 25 KB
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
#!/bin/bash
# ============================================================================
# This file is meant to hold all common package installation used across the
# install scripts under this project.
# Specifically those that require a special configuration or need several
# libraries to be installed to work properly
# e.x. mysql
# ============================================================================
# Uncomment the following line to debug this script
# set -o xtrace
source common_functions
SetPackageManager
#=================================================
#=================================================
function CreateSelfSignedCertificate {
# To use an SSL certificate to secure a service but without
# requiring a CA-signed certificate - i.e sign your own certificates.
# users will be displayed a browser warning about certificate not trusted.
# See http://do.co/2gtYDet
cert_path="${1}"
subj=${2:-/C=US/ST=Oregon/L=Portland/O=Dlux/OU=Data Center/CN=Dlux}
[[ ! -d $cert_path ]] && PrintError "Path ${cert_path} does not exists."
pushd $cert_path
openssl req -newkey rsa:4096 -nodes -keyout domain.key \
-x509 -days 365 -out domain.crt -subj "${subj}"
popd
}
function CreateSelfCASignedCertificate {
cert_path="${1}"
subj=${2:-/C=US/ST=Oregon/L=Portland/O=Dlux/OU=Data Center/CN=Dlux}
[[ ! -d $cert_path ]] && PrintError "Path ${cert_path} does not exists."
pushd $cert_path
# 1. Generate 4096-bit long RSA key for root CA.
openssl genrsa -out ca.key 4096
# 2. Create self-signed 5y valid root CA certificate.
openssl req -new -x509 -days 1826 \
-key ca.key -out ca.crt -subj "${subj}"
# 3. Create subordinate CA to be used for the signing. This means:
# create key, create csr, & process csr to get a crt signed by the root CA.
# KEY
openssl genrsa -out ia.key 4096
# CSR
openssl req -new -key ia.key -out ia.csr -subj "${subj}"
# 5. CRT (Signed)
openssl x509 -req -days 730 -set_serial 01 \
-CA ca.crt -CAkey ca.key -in ia.csr -out ia.crt
popd
}
function CreateCSRCertificate {
cert_path="${1}"
[[ ! -d $cert_path ]] && PrintError "Path ${cert_path} does not exists."
pushd $cert_path
# Use this method to secure an Apache HTTP or Nginx web server (SSL-HTTPS)
# Use when using a Certificate Authority (CA) to issue the SSL certificate
# Created private key. csr must be sent to CA for CA-signed SSL cert
openssl req \
-newkey rsa:2048 -nodes -keyout domain.key \
-out domain.csr
popd
}
function CustomizeApache {
Customize"${_PACKAGE_MANAGER}"Apache
}
function InstallAnsible {
echo 'installing ansible via pip'
version=${1:-2.6.1}
# Use pip
[[ -z $(which pip) ]] && curl -Lo- https://bootstrap.pypa.io/get-pip.py | python
pip install ansible==$version
}
function InstallApache {
Install"${_PACKAGE_MANAGER}"Apache
}
function InstallApacheMod {
Install"${_PACKAGE_MANAGER}"ApacheMod "$@"
}
function InstallDhcp {
Install"${_PACKAGE_MANAGER}"Dhcp "$@"
}
function InstallDns {
Install"${_PACKAGE_MANAGER}"Dns "$@"
}
function InstallDocker {
if command -v docker; then
return
fi
curl -fsSL https://get.docker.com/ | sh
usermod -aG docker $USER
systemctl enable docker.service
}
function SetDockerProxy {
if -z "$1"; then
PrintError 'Need to provide proxy variable'
fi
if -z command -v docker; then
PrintError "Docker must be installed"
fi
SetProxy "$1"
mkdir -p /etc/systemd/system/docker.service.d
pushd /etc/systemd/system/docker.service.d
WriteLog '---> SETTING PRXY ON DOCKER'
echo '[Service]' > http-proxy.conf
echo "Environment=\"HTTP_PROXY=$http_proxy\"" >> http-proxy.conf
echo '[Service]' > https-proxy.conf
echo "Environment=\"HTTPS_PROXY=$http_proxy\"" >> https-proxy.conf
echo '[Service]' > no-proxy.conf
echo "Environment=\"NO_PROXY=$no_proxy\"" >> no-proxy.conf
popd
mkdir -p "$HOME/.docker"
config="{ \"proxies\": { \"default\": { \"httpProxy\": \"$http_proxy\","
config+="\"httpsProxy\": \"$http_proxy\",\"noProxy\": \"$no_proxy\","
echo "${config::-1} } } }" | tee "$HOME/.docker/config.json"
systemctl daemon-reload
systemctl restart docker
times=0
until sudo docker info || times > 9; do
printf "."
sleep 2
times=$((times + 1))
done
}
function InstallFirewallUFW {
Install"${_PACKAGE_MANAGER}"FirewallUFW "$@"
}
function InstallJenkins {
Install"${_PACKAGE_MANAGER}"Jenkins "$@"
}
function InstallELKSElasticsearch {
Install"${_PACKAGE_MANAGER}"ELKSElasticsearch "$@"
}
function InstallELKSKibana {
Install"${_PACKAGE_MANAGER}"ELKSKibana "$@"
}
function InstallELKSLogstash {
Install"${_PACKAGE_MANAGER}"ELKSLogstash "$@"
}
function InstallMysql {
# Can accept a password
Install"${_PACKAGE_MANAGER}"Mysql "$@"
}
function InstallNginx {
Install"${_PACKAGE_MANAGER}"Nginx
}
function InstallNodejs {
# Can accept a integer representing a major version [4 to 8].
# Defaults to version 8
Install"${_PACKAGE_MANAGER}"Nodejs "$@"
}
function InstallPackages {
for arg in $@; do
${_INSTALLER_CMD} "$arg"
done
}
function InstallPhp {
# Can accept php version to install 5.5 or 7.0
Install"${_PACKAGE_MANAGER}"Php "$@"
}
function InstallPip {
if ! command -v pip; then
curl -Lo- https://bootstrap.pypa.io/get-pip.py | python
else
pip install -U pip
fi
}
function InstallPython3 {
Install"${_PACKAGE_MANAGER}"Python3 "$@"
}
function InstallQemu {
Install"${_PACKAGE_MANAGER}"Qemu
}
function InstallLibvirt {
Install"${_PACKAGE_MANAGER}"Qemu
Install"${_PACKAGE_MANAGER}"Libvirt
}
function InstallTftp {
# Can accept string "upload" to enable upload feature
Install"${_PACKAGE_MANAGER}"Tftp "$@"
}
function InstallVagrant {
Install"${_PACKAGE_MANAGER}"Vagrant
}
function InstallVirtualBox {
# Default version 6.0
Install"${_PACKAGE_MANAGER}"VirtualBox "@"
}
function UninstallApache {
Uninstall"${_PACKAGE_MANAGER}"Apache
}
function UninstallMysql {
Uninstall"${_PACKAGE_MANAGER}"Mysql
}
function WaitForJenkinsSvr {
attemptCount=1
maxAttempts=${1:-100}
echo "Waiting jenkins status to be active..."
while [ "$attemptCount" -le "$maxAttempts" ]; do
echo "Attempt: $attemptCount of $maxAttempts"
tmp=$(systemctl status jenkins | grep -s 'Active: active')
[[ -z $tmp ]] && attemptCount=$(($attemptCount + 1)) && sleep 1s || break
done
[[ -z $(systemctl status jenkins | grep -s 'Active: active') ]] && PrintError "Timeout after $maxAttempts sec." || echo 'Jenkins Launched'
}
#=================================================
# APT PACKAGE FUNCTIONS
#=================================================
function CustomizeaptApache {
# Verify apache is installed
msg="Apache server is not installed"
[[ -z $( ps aux | grep apache2 | grep -v grep ) ]] && PrintError "${msg}"
mkdir -p /var/www/html/customErrors
pushd '/var/www/html/customErrors/'
cat <<EOF > "c403.html"
<h1 style='color:red'>Permission Denied</h1>
<p>You have no permission to access this page :-(</p>
<p>If you think you should be able to see this page contact your admin.</p>
EOF
cat <<EOF > "c404.html"
<h1 style='color:red'>Error 404: Not found :-(</h1>
<p>No idea where that file is, sorry. Is it the correct URL?</p>
EOF
cat <<EOF > "c50x.html"
<h1>Oops! Something went wrong...</h1>
<p>We seem to be having some technical difficulties. Hang tight.</p>
EOF
popd
pushd '/etc/apache2/sites-available/'
sed -i 's/<\/VirtualHost>//g' 000-default.conf
cat <<EOF >> "000-default.conf"
ErrorDocument 403 /customErrors/c403.html
ErrorDocument 404 /customErrors/c404.html
ErrorDocument 500 /customErrors/c50x.html
</VirtualHost>
EOF
popd
systemctl restart apache2
}
function InstallaptApache {
apachePort=${1}
# Verify Apache is not already installed
if [[ -z $( ps aux | grep apache2 | grep -v grep ) ]]; then
apt-get install -y apache2 apache2-utils
# Disable directory browsing
pushd '/etc/apache2/'
sed -i 's/Options Indexes/Options/g' apache2.conf
# Add performance
sed -i '/#Supplementa/a\
HostnameLookups Off
' apache2.conf
# If non-default port specified (default is 80) configure it
if [ -n "$apachePort" ]; then
sed -i "s/\:80/\:$apachePort/g" sites-available/000-default.conf
sed -i "s/80/$apachePort/g" ports.conf
fi
rm sites-enabled/000-default.conf
ln -s '/etc/apache2/sites-available/000-default.conf' sites-enabled/
popd
service apache2 restart
fi
}
function InstallaptApacheOnNginx {
# Install nginx
InstallNginx
apachePort=${1:-8085}
cat <<EOF > "/etc/nginx/conf.d/infra.conf"
upstream apache_server {
server 127.0.0.1:$apachePort fail_timeout=5;
}
server {
listen 80;
server_name localhost;
location / {
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header Host \$http_host;
proxy_redirect off;
}
location /apache {
proxy_pass http://apache_server/;
proxy_set_header Host $http_host;
}
}
EOF
InstallaptApache $apachePort
}
function InstallaptApacheMod {
# Verify Apache is installed
mod="${1}"
em='Apache must be installed and running'
[[ -z $( ps aux | grep apache2 | grep -v grep ) ]] && PrintError "$em"
[[ -z "${mod}" ]] && PrintError "Expecting a mod name to install e.g. wsgi"
if [[ $mod == 'proxy' ]]; then
echo "mod-proxy Under Development. Need to be verified."
# Enable modules
a2enmod proxy
a2enmod proxy_http headers proxy_connect rewrite version
#a2enmod proxy_html proxy_balancer
#a2enmod proxy_ajp rewrite deflate headers proxy_balancer
elif [[ $mod == 'wsgi' ]]; then
apt-get install libapache2-mod-wsgi
a2enmod wsgi
echo "mod-wsgi installed."
elif [[ $mod == 'ssl' ]]; then
a2enmod ssl
echo "mod-ssl installed."
elif [[ $mod == fqdn ]]; then
echo "ServerName localhost" > /etc/apache2/conf-available/fqdn.conf
a2enmod fqdn
else
PrintError "mod-$mod NOT found."
fi
service apache2 restart
}
function InstallaptDhcp {
apt-get install -y isc-dhcp-server subnetcalc
[[ -n "$1" ]] && ConfigDhcpapt $@
}
function ConfigDhcpapt {
echo "Calculating and setting minimal subnet config"
subnet=${1:-192.168.1.0}
netmask=${2:-24} # Max 254 hosts
calc=$(subnetcalc ${subnet}/${netmask})
exp_netmask=$(echo "$calc" | grep Netmask | awk '{print $3}')
r1=$(echo "$calc" | grep Range | awk -F '{ ' '{print $2}' | awk -F ' }' '{print $1}' | awk -F ' - ' '{print $1}')
r2=$(echo "$calc" | grep Range | awk -F '{ ' '{print $2}' | awk -F ' }' '{print $1}' | awk -F ' - ' '{print $2}')
fName=/etc/dhcp/dhcpd.conf
[[ -f $fName ]] && mv $fName $fName$(date '+%Y_%m_%d_%H:%M:%S')
cat <<EOF > $fName
# minimal sample $fName
default-lease-time 600;
max-lease-time 7200;
subnet $subnet netmask $exp_netmask {
range $r1 $r2;
option routers $r2;
option domain-name-servers $r1;
option domain-name "luzcazares.com";
}
EOF
echo 'Set net interfaces'
ifaces=$(ip -o link show | awk -F': ' '{print $2}')
for iface in $ifaces; do
[[ $iface != 'lo' ]] && sed -i "s/^INTERFACES\=\"/INTERFACES\=\"$iface /g" /etc/default/isc-dhcp-server
done
systemctl restart isc-dhcp-server
}
function InstallaptDns {
echo '<--- INSTALLING DNS --'
apt-get install -y bind9 dnsutils
}
function InstallaptFirewallUFW {
apt-get install -y ufw
}
function InstallaptJenkins {
apt-get -y -qq update
# if jenkins not installed then install it
# if instaled it will be updated
if [ ! -f /etc/init.d/jenkins ]; then
wget -qO- https://pkg.jenkins.io/debian/jenkins-ci.org.key | apt-key add -
echo 'deb http://pkg.jenkins.io/debian-stable binary/' > /etc/apt/sources.list.d/jenkins.list
apt-get -y -qq update
fi
apt-get install -y jenkins
# Use given port for Jenkins
[[ -n "$1" ]] && sed -i "s/^HTTP_PORT=..../HTTP_PORT=${1}/g" /etc/default/jenkins
WaitForJenkinsSvr 10
}
function InstallaptELKSLogstash {
repo="https://artifacts.elastic.co"
apt-get install -y openjdk-8-jdk
apt-get install -y apt-transport-https
wget -qO - ${repo}/GPG-KEY-elasticsearch | apt-key add -
source_="/etc/apt/sources.list.d/elastic-6.x.list"
echo "deb ${repo}/packages/6.x/apt stable main" | sudo tee -a $source_
apt-get update && sudo apt-get install -y logstash
systemctl start logstash.service
}
function InstallaptMysql {
# MySQL - Needs a password for DB_root user
[[ -z $1 ]] && PrintError "Mysql need a password for DB root user"
# Make sure not installed
if [[ -n $(dpkg --get-selections | grep mysql) ]]; then
echo "Mysql is already installed!!"
return
fi
echo "Installing MySQL server"
apt-get install -y python-setuptools python-mysqldb
debconf-set-selections <<< "mysql-server mysql-server/root_password password ${1}"
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password ${1}"
apt-get install -y mysql-server
}
function HardeningaptMysql {
# Hardening mysql script output keep changing:
#mysql_secure_installation
#unable to run it unatended just with expect which is tight to string output
mysql -uroot -p"${1}" <<MYSQL_SCRIPT
/* Remove anonymous users */
DELETE FROM mysql.user WHERE User='';
/* Remove remote root */
DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');
/* Remove test database */
DROP DATABASE test;
/* Removing privileges on test database */
DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'
/* Install validate_password plugin */
INSTALL PLUGIN validate_password SONAME 'validate_password.so';
FLUSH PRIVILEGES;
MYSQL_SCRIPT
}
function InstallaptNginx {
apt-get install -y nginx
}
function InstallaptNodejs {
version=${1:-8}
curl -sL https://deb.nodesource.com/setup_"${version}".x | bash -
apt-get install -y nodejs
}
#function InstallaptPackages {
# for arg in $@; do
# apt-get install $arg
# done
#}
function InstallaptPhp {
release="${1:-$(lsb_release -rs)}"
if [[ $release == 14.* || $release == 5.* ]]; then
echo "Installing PHP 5.5"
apt-geit install -y php5 libapache2-mod-php5 php5-mcrypt php5-cli \
php5-curl php5-mysql php5-ldap php5-gd php5-json
php5enmod mcrypt
#elif [[ $release == 16.* || $release == 7.* ]]; then
else
echo "Installing PHP 7.0"
apt-get -y install php7.0 libapache2-mod-php7.0 php7.0-mcrypt \
php-memcache php7.0-mysql php7.0-curl php7.0-gd php7.0-xmlrpc \
php7.0-xsl php7.0-mbstring php-gettext
fi
# Move index.php as first apache site option
cat <<EOF >> "/etc/apache2/mods-enabled/dir.conf"
<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>
EOF
cat <<EOF > "/var/www/html/info.php"
<?php
phpinfo();
?>
EOF
systemctl restart apache2
}
function InstallaptTftp {
echo "Installing TFTP-HPA server."
apt-get install -y tftpd-hpa tftp
if [[ $1 -eq 'upload' ]]; then
echo "Allowing upload into the server."
cp /etc/default/tftpd-hpa /etc/default/tftpd-hpa.ORIGINAL
sed -i '/TFTP_OPTIONS/c\' /etc/default/tftpd-hpa
echo 'TFTP_OPTIONS="--secure --create"' >> /etc/default/tftpd-hpa
chown -R tftp /var/lib/tftpboot
service tftpd-hpa restart
service tftpd-hpa status
echo "Just a test file" >> /var/lib/tftpboot/test.file
fi
}
function InstallaptVagrant {
WriteLog "Installing Vagrant"
#release="${1:-2.4.9}"
#name="vagrant_${release}_x86_64.deb"
#wget -q https://releases.hashicorp.com/vagrant/$release/$name
#dpkg -i $name
wget -O - https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(grep -oP '(?<=UBUNTU_CODENAME=).*' /etc/os-release || lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install vagrant
}
function InstallaptVirtualBox {
release="${1:-6.0}"
$addr="http://download.virtualbox.org/virtualbox/debian"
echo "deb $addr $VERSION_CODENAME contrib" >> /etc/apt/sources.list
base="https://www.virtualbox.org/download"
wget -q "$base/oracle_vbox_2016.asc" -O- | apt-key add -
wget -q "$base/oracle_vbox.asc" -O- | apt-key add -
apt-get -y update
apt-get install -y "virtualBox-$release" dkms
}
function UninstallaptMysql {
echo "Uninstalling Mysql"
apt-get -y purge mysql-server mysql-client mysql-common \
mysql-server-core-5.5 mysql-client-core-5.5
rm -rf /etc/mysql /var/lib/mysql
apt-get -y autoremove
apt-get autoclean
}
function UninstallaptApache {
service apache2 stop
apt-get -y purge apache2*
rm -rf /etc/apache2
apt-get -y autoremove
apt-get autoclean
}
function UninstallaptJenkins {
systemctl stop jenkins
apt-get remove --purge jenkins
rm -f /etc/nginx/sites-available/jenkins
rm -f /etc/nginx/sites-enabled/jenkins
}
#=================================================
# YUM PACKAGE FUNCTIONS
#=================================================
#function InstallyumPackages {
# for arg in $@;do
# yum install $arg
# done
#}
function CustomizeyumApache {
# Verify apache is installed
msg="Apache server is not installed"
[[ -z $( ps aux | grep httpd | grep -v grep ) ]] && PrintError "${msg}"
mkdir -p /var/www/html/customErrors
pushd '/var/www/html/customErrors/'
cat <<EOF > "c403.html"
<h1 style='color:red'>Permission Denied</h1>
<p>You have no permission to access this page :-(</p>
<p>If you think you should be able to see this page contact your admin.</p>
EOF
cat <<EOF > "c404.html"
<h1 style='color:red'>Error 404: Not found :-(</h1>
<p>No idea where that file is, sorry. Is it the correct URL?</p>
EOF
cat <<EOF > "c50x.html"
<h1>Oops! Something went wrong...</h1>
<p>We seem to be having some technical difficulties. Hang tight.</p>
EOF
popd
pushd '/etc/httpd/conf'
sed -i '/#ErrorDocument.402/a\
ErrorDocument 403 /customErrors/c403.html\
ErrorDocument 404 /customErrors/c404.html\
ErrorDocument 500 /customErrors/c50x.html' httpd.conf
popd
systemctl restart httpd
}
function InstallyumApache {
apachePort=${1}
# Verify Apache is not already installed
if [[ -z $( ps aux | grep httpd | grep -v grep ) ]]; then
yum install -y httpd
yum groupinstall -y web-server
# Disable directory browsing
pushd '/etc/httpd/conf/'
sed -i 's/Options Indexes/Options/g' httpd.conf
# Add performance
sed -i '/#Supplementa/a\
HostnameLookups Off
' httpd.conf
# set ServerName
sed -i 's/^#ServerName.*:/ServerName localhost:/g' httpd.conf
# If non-default port specified (default is 80) configure it
if [ -n "$apachePort" ]; then
sed -i "s/\:80/\:$apachePort/g" httpd.conf
fi
popd
systemctl enable httpd
systemctl restart httpd
fi
}
function InstallyumDns {
echo '<--- INSTALLING DNS --'
yum install bind bind-utils -y
}
function InstallyumMysql {
# MySQL - Needs a password for DB_root user
[[ -z $1 ]] && PrintError "Mysql need a password for DB root user"
# Make sure not already installed
if [[ -n $(rpm -qa | grep -i MySQL) ]]; then
echo "Mysql is already installed!!"
return
fi
echo "Installing MySQL server"
curl -OL http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum update
yum install -y mysql-server
systemctl start mysql
/usr/bin/mysqladmin -u root password "${1}"
}
function InstallyumELKSElasticsearch {
repo="https://artifacts.elastic.co/downloads"
release="${1:-6.5.4}"
yum install -y java-1.8.0-openjdk
curl -L -O $repo/elasticsearch/elasticsearch-${release}.rpm
rpm -i elasticsearch-${release}.rpm
echo -e "\n\n---> Configuring elasticsearch"
echo '#Disable AssumeMP' >> /etc/elasticsearch/jvm.options
echo '-XX:-AssumeMP' >> /etc/elasticsearch/jvm.options
# Bind all interfaces so you can access elasticsearch locally and remotely
file='/etc/elasticsearch/elasticsearch.yml'
sed -i '/#network.host/a network.host: 0.0.0.0' $file
systemctl daemon-reload
systemctl enable elasticsearch.service
systemctl start elasticsearch.service
echo 'waiting for elasticsearch to start'
sleep 10
curl http://localhost:9200
}
function InstallyumELKSKibana {
repo="https://artifacts.elastic.co/downloads"
release="${1:-6.5.4}"
yum install -y java-1.8.0-openjdk
curl -L -O $repo/kibana/kibana-${release}-x86_64.rpm
rpm -i kibana-${release}-x86_64.rpm
echo -e "\n\n---> Configuring kibana"
# Bind all interfaces so you can access kibana locally and remotely
sed -i '/#server.host/a server.host: 0.0.0.0' /etc/kibana/kibana.yml
systemctl daemon-reload
systemctl enable kibana.service
systemctl start kibana.service
echo 'waiting for kibana to start'
sleep 10
}
function InstallyumELKSLogstash {
repo="https://artifacts.elastic.co/downloads"
release="${1:-6.5.4}"
yum install -y java-1.8.0-openjdk
curl -L -O $repo/logstash/logstash-${release}.rpm
rpm -i logstash-${release}.rpm
echo -e "\n\n---> Configuring logstash"
echo '#Disable AssumeMP' >> /etc/logstash/jvm.options
echo '-XX:-AssumeMP' >> /etc/logstash/jvm.options
cat <<EOF > '/etc/logstash/conf.d/logstash-simple.conf'
input { stdin { } }
output {
elasticsearch { hosts => ["localhost:9200"] }
stdout { codec => rubydebug }
}
EOF
systemctl daemon-reload
systemctl enable logstash.service
systemctl start logstash.service
echo 'waiting for logstash to start'
sleep 10
}
function InstallyumFirewallUFW {
yum install -y epel-release
yum install -y --enablerepo="epel" ufw
}
function InstallyumPhp {
release="${1:-7.0}"
[[ $release[0] != 7 ]] && echo "Currently only version 7.x is supported"
echo "Installing PHP $release"
yum install -y \
https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum update
# Make release 7.0=70 (and so on)
release=$(echo $release |sed 's/\.//g')
yum install -y yum-utils
yum-config-manager --enable remi-php$release
# Install it
yum install -y php php-mcrypt php-cli php-gd php-curl php-mysql \
php-ldap php-zip php-fileinfo
# move index.php as apache first option
cat <<EOF >> "/etc/httpd/conf.modules.d/00-dir.conf"
<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>
EOF
cat <<EOF > "/var/www/html/info.php"
<?php
phpinfo();
?>
EOF
systemctl restart apache2
}
function InstallyumLibvirt {
yum install -y quemu quemu-kvm libvirt libvirt-client libvirt-devel
yum install -y ruby-devel
}
function InstallyumPython3 {
version="${1:-3.7.4}"
yum install -y gcc openssl-devel bzip2-devel libffi-devel readline-devel
pushd /usr/src
curl -LO https://www.python.org/ftp/python/${version}/Python-${version}.tgz
tar xvzf Python-${version}.tgz
rm -f Python-${version}.tgz
cd Python-${version}
./configure --enable-optimizations
make altinstall
popd
v_=${version::-2}
ln -s /usr/local/bin/python${v_} /usr/bin/python3
ln -s /usr/local/bin/pip${v_} /usr/bin/pip3
# Next lines broke yum since it does not support python3
# alternatives --install /usr/bin/python python /usr/bin/python2 50
# alternatives --install /usr/bin/python python /usr/local/bin/python${v_} 60
}
function InstallyumQemu {
yum install -y qemu quemu-kvm genisoimage
}
function InstallyumVagrant {
if $ID == "fedora"; then
dnf install -y dnf-plugins-core
if $VERSION = '40'*; then
dnf config-manager --add-repo https://rpm.releases.hashicorp.com/fedora/hashicorp.repo
elif $VERSION = '41'*; then
dnf config-manager addrepo --from-repofile=https://rpm.releases.hashicorp.com/fedora/hashicorp.repo
fi
dnf -y install vagrant
else
yum install -y yum-utils
yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
yum -y install vagrant
fi
}
function InstallyumVirtualBox {
release="${1:-6.0}"
addr="http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo"
wget -q $addr -P /etc/yum.repos.d
yum install -y --enablerepo=epel dkms
addr="https://www.virtualbox.org/download/oracle_vbox.asc"
wget -q $addr -O- | rpm --import -
yum install -y "VirtualBox-$release"
}
function UninstallyumMysql {
systemctl stop mysql
yum remove -y $(rpm -qa|grep mysql)
yum clean all
}