Repository navigation
Expand file tree
/
Copy pathinit.sh
More file actions
329 lines (256 loc) · 13.2 KB
/
Copy pathinit.sh
File metadata and controls
329 lines (256 loc) · 13.2 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
#!/bin/bash
# TRUSTeK Server Init Script v3.0
# https://trustek.it
clear
echo ''
echo '********************************************************************************************************'
echo ' $$$$$$\ $$$$$$\ $$\ $$\ $$$$$$\ $$$$$$$$\ '
echo ' $$ __$$\ \_$$ _|$$$\ $$ |\_$$ _|\__$$ __|'
echo ' $$ / \__| $$$$$$\ $$$$$$\ $$\ $$\ $$$$$$\ $$$$$$\ $$ | $$$$\ $$ | $$ | $$ | '
echo ' \$$$$$$\ $$ __$$\ $$ __$$\\$$\ $$ |$$ __$$\ $$ __$$\ $$ | $$ $$\$$ | $$ | $$ | '
echo ' \____$$\ $$$$$$$$ |$$ | \__|\$$\$$ / $$$$$$$$ |$$ | \__| $$ | $$ \$$$$ | $$ | $$ | '
echo ' $$\ $$ |$$ ____|$$ | \$$$ / $$ ____|$$ | $$ | $$ |\$$$ | $$ | $$ | '
echo ' \$$$$$$ |\$$$$$$$\ $$ | \$ / \$$$$$$$\ $$ | $$$$$$\ $$ | \$$ |$$$$$$\ $$ | '
echo ' \______/ \_______|\__| \_/ \_______|\__| \______|\__| \__|\______| \__| '
echo ''
echo ' by TRUSTeK'
echo '********************************************************************************************************'
echo ''
echo ''
if [ "x$(id -u)" != 'x0' ]; then
echo 'Error: this script can only be executed by root'
exit 1
fi
function StartTheProcess() {
read -r -p "Do you want to upgrade PHP 5 to PHP 7? [y/N] " vPhp7
read -r -p "Do you want to upgrade MariaDB 5 to MariaDB 10? [y/N] " vMariaDB10
read -r -p "Do you want to harden sysctl.conf? [y/N] " vSysctl
read -r -p "What is your hostname? " vHostname
localectl set-keymap it
timedatectl set-timezone Europe/Rome
curl https://raw.githubusercontent.com/fulviocri/server-init/master/wordpress.sh > /root/wordpress.sh
chmod +x /root/wordpress.sh
yum clean all
yum -y install bind-utils wget tmux nano htop iotop unzip
IPAddress=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
#IPAddress=$(hostname -i)
DigResult=$(dig @8.8.8.8 +short $vHostname)
if [ "$IPAddress" != "$DigResult" ]; then
echo 'Error: Hostname does not match IP address yet, please wait otherwise LetsEncrypt will not work.'
exit 1
fi
echo " "
echo " "
read -r -p "Enter new password for root user: " ROOT_PWD
echo "$ROOT_PWD" | passwd --stdin root
echo " "
read -r -p "Enter the new admin username: " NADMIN
useradd -m $NADMIN
usermod -aG wheel $NADMIN
echo " "
read -r -p "Enter new admin password: " NADMIN_PWD
echo "$NADMIN_PWD" | passwd --stdin $NADMIN
echo " "
read -r -p "What is the IP Address for shared services? " vSharedIPAddress
read -r -p "What is the IP Address for BIND9 DNS Server " vDNSIPAddress
read -r -p "What e-mail address would you like to receive Monit and VestaCP alerts to? " vEmail
read -r -p "Please type a password to use with VestaCP and Monit: " vPassword
read -r -p "Monit needs an SMTP server to use to send email alerts properly. What's your SMTP Hostname? " vSMTPHostname
read -r -p "What port does the SMTP Hostname listen on (usually 25 or 587)? " vSMTPPort
read -r -p "What's your SMTP Username (usually a full email address)? " vSMTPEmail
read -r -p "What's your SMTP Password? " vSMTPPassword
# ---------------------------------
# Set the hostname and stop it from being edited
hostname $vHostname
echo $vHostname > /etc/hostname
chattr +i /etc/hostname
# ---------------------------------
# Make the server use local DNS and stop it from being edited
echo 'nameserver 127.0.0.1' | cat - /etc/resolv.conf > temp && mv temp /etc/resolv.conf
chattr +i /etc/resolv.conf
curl https://raw.githubusercontent.com/SS88UK/VestaCP-Server-Installer/master/CentOS7/named.conf > /etc/named.conf
/sbin/service named restart
# ---------------------------------
# Disable IPV6
echo ''
sed -i 's/GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet"/GRUB_CMDLINE_LINUX="ipv6.disable=1 crashkernel=auto rhgb quiet"/g' /etc/default/grub
grub2-mkconfig -o /boot/grub2/grub.cfg
echo 'net.ipv6.conf.all.disable_ipv6 = 1' >> /etc/sysctl.conf
echo 'net.ipv6.conf.default.disable_ipv6 = 1' >> /etc/sysctl.conf
sysctl -p
# ---------------------------------
# Setting TMUX preferences
[ -e /root/.tmux.conf ] && rm -rf /root/.tmux.conf > /dev/null 2>&1
curl https://raw.githubusercontent.com/fulviocri/server-init/master/tmux.conf > /root/.tmux.conf
if ! grep -q "tmux attach" /root/.bashrc; then
echo '' >> /root/.bashrc
echo 'if command -v tmux &> /dev/null && [ -z "$TMUX" ]; then' >> /root/.bashrc
echo ' tmux attach -t default || tmux new -s default' >> /root/.bashrc
echo 'fi' >> /root/.bashrc
echo '' >> /root/.bashrc
echo 'cd' >> /root/.bashrc
echo 'w' >> /root/.bashrc
fi
# ---------------------------------
# Setting BASHRC alias
if ! grep -q "extip" /etc/bashrc; then
echo "alias cls='clear'" >> /etc/bashrc
echo "alias ll='ls -lah --color=auto'" >> /etc/bashrc
echo "alias ld='ls -lahd'" >> /etc/bashrc
echo "alias df='df -h'" >> /etc/bashrc
echo "alias nw='tmux new-window'" >> /etc/bashrc
echo "alias shutdown='shutdown -h now'" >> /etc/bashrc
echo "alias extip='curl ipinfo.io/ip'" >> /etc/bashrc
source /etc/bashrc
fi
# ---------------------------------
# Setting SWAP partition
if ! grep -q "/swapfile" /etc/fstab; then
fallocate -l 4G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo "/swapfile none swap sw 0 0" >> /etc/fstab
fi
# ---------------------------------
# Securing SSH
sed -i "s/#ListenAddress 0.0.0.0/ListenAddress $IPAddress/g" /etc/ssh/sshd_config
sed -i "s/#AddressFamily any/AddressFamily inet/g" /etc/ssh/sshd_config
sed -i "s/#PermitRootLogin yes/PermitRootLogin no/g" /etc/ssh/sshd_config
sed -i "s/PermitRootLogin yes/PermitRootLogin no/g" /etc/ssh/sshd_config
# ---------------------------------
# Harden sysctl.conf
if [ $vSysctl == "y" ] || [ $vSysctl == "Y" ]; then
a="`netstat -i | cut -d' ' -f1 | grep eth0`";
b="`netstat -i | cut -d' ' -f1 | grep venet0:0`";
if [ "$a" == "eth0" ]; then
curl https://raw.githubusercontent.com/SS88UK/VestaCP-Server-Installer/master/CentOS7/sysctl.conf-eth0 > /etc/sysctl.conf
elif [ "$b" == "venet0:0" ]; then
curl https://raw.githubusercontent.com/SS88UK/VestaCP-Server-Installer/master/CentOS7/sysctl.conf-venet0 > /etc/sysctl.conf
fi
sysctl -p
fi
# ---------------------------------
# Installing VestaCP
curl -O http://vestacp.com/pub/vst-install.sh
bash vst-install.sh --nginx yes --phpfpm yes --apache no --vsftpd no --proftpd no --exim yes --dovecot yes --spamassassin yes --clamav yes --named yes --iptables yes --fail2ban yes --mysql yes --postgresql no --remi yes --softaculous no --quota yes --hostname $vHostname --email $vEmail --password $vPassword
export VESTA=/usr/local/vesta/
source /etc/profile
/usr/local/vesta/bin/v-change-web-domain-ip admin $vHostname $IPAddress y
/usr/local/vesta/bin/v-change-dns-domain-ip admin $vHostname $IPAddress
/usr/local/vesta/bin/v-add-sys-ip $vSharedIPAddress 255.255.255.255
/usr/local/vesta/bin/v-add-sys-ip $vDNSIPAddress 255.255.255.255
sed -i 's/8083;/8443;/' /usr/local/vesta/nginx/conf/nginx.conf
/usr/local/vesta/bin/v-add-firewall-rule ACCEPT 0.0.0.0/0 8443 TCP
/usr/local/vesta/bin/v-delete-firewall-rule 2
systemctl restart vesta
echo "local_interfaces = <; 127.0.0.1 ; $vSharedIPAddress" >> /etc/exim/exim.conf
systemctl restart exim
# ---------------------------------
# Set SpamAssassin Rules + Extras
curl https://raw.githubusercontent.com/SS88UK/VestaCP-Server-Installer/master/CentOS7/dnsbl.conf > /etc/exim/dnsbl.conf
curl https://raw.githubusercontent.com/SS88UK/VestaCP-Server-Installer/master/CentOS7/custom_SA-rules.cf > /etc/mail/spamassassin/custom_SA-rules.cf
sed -i 's/rfc1413_query_timeout = 5s/rfc1413_query_timeout = 0s/' /etc/exim/exim.conf
curl https://raw.githubusercontent.com/SS88UK/VestaCP-Server-Installer/master/CentOS7/90-quota.conf > /etc/dovecot/conf.d/90-quota.conf
sed -i 's/mail_plugins = .*/mail_plugins = $mail_plugins autocreate quota imap_quota/' /etc/dovecot/conf.d/20-imap.conf
echo "mail_max_userip_connections = 50" >> /etc/dovecot/conf.d/10-mail.conf
echo "mail_fsync = never" >> /etc/dovecot/conf.d/10-mail.conf
# ---------------------------------
# Let's fix LetsEncrypt and secure our own server!
yum -y install vim-common
#sed -i 's/agreement=.*/agreement="https:\/\/letsencrypt.org\/documents\/LE-SA-v1.1.1-August-1-2016.pdf"/' /usr/local/vesta/bin/v-add-letsencrypt-user
/usr/local/vesta/bin/v-add-letsencrypt-domain admin $vHostname
if [ -f /home/admin/conf/web/ssl.$vHostname.pem ]; then
rm -f /usr/local/vesta/ssl/certificate.crt
ln -s /home/admin/conf/web/ssl.$vHostname.pem /usr/local/vesta/ssl/certificate.crt
chown -h root:mail /usr/local/vesta/ssl/certificate.crt
fi
if [ -f /home/admin/conf/web/ssl.$vHostname.key ]; then
rm -f /usr/local/vesta/ssl/certificate.key
ln -s /home/admin/conf/web/ssl.$vHostname.key /usr/local/vesta/ssl/certificate.key
chown -h root:mail /usr/local/vesta/ssl/certificate.key
fi
# ---------------------------------
# Let's fix NGINX up! This will take a very long time.
if [ ! -f /etc/nginx/dhparams.pem ]; then
openssl dhparam -dsaparam -out /etc/nginx/dhparams.pem 4096
fi
curl https://raw.githubusercontent.com/SS88UK/VestaCP-Server-Installer/master/CentOS7/nginx.conf > /etc/nginx/nginx.conf
# ---------------------------------
# Let's fix PHP-FPM
curl https://raw.githubusercontent.com/SS88UK/VestaCP-Server-Installer/master/CentOS7/default.tpl > /usr/local/vesta/data/templates/web/php-fpm/default.tpl
curl https://raw.githubusercontent.com/SS88UK/VestaCP-Server-Installer/master/CentOS7/socket.tpl > /usr/local/vesta/data/templates/web/php-fpm/socket.tpl
/usr/local/vesta/bin/v-rebuild-web-domains admin
# ---------------------------------
# Make it HTTP2 and SPDY
sed -i 's/\%web_ssl_port\%/\%web_ssl_port\% ssl http2/' /usr/local/vesta/data/templates/web/nginx/php-fpm/*.stpl
#sed -i 's/\%web_port\%/\%web_port\% spdy/' /usr/local/vesta/data/templates/web/nginx/php-fpm/*.tpl
# ---------------------------------
# Let's install Monit & Configure it
yum -y install monit
curl https://raw.githubusercontent.com/SS88UK/VestaCP-Server-Installer/master/CentOS7/monitrc > /etc/monitrc
sed -i "s/vPassword/$vPassword/" /etc/monitrc
sed -i "s/vEmail/$vEmail/" /etc/monitrc
sed -i "s/IPAddress/$IPAddress/" /etc/monitrc
sed -i "s/vSMTPEmail/$vSMTPEmail/" /etc/monitrc
sed -i "s/vSMTPPassword/$vSMTPPassword/" /etc/monitrc
sed -i "s/vSMTPHostname/$vSMTPHostname/" /etc/monitrc
sed -i "s/vSMTPPort/$vSMTPPort/" /etc/monitrc
chkconfig monit on
# ---------------------------------
# Install PHP 7
if [ $vPhp7 == "y" ] || [ $vPhp7 == "Y" ]; then
service php-fpm stop
yum -y --enablerepo=remi install php73-php php73-php-pear php73-php-bcmath php73-php-pecl-jsond-devel php73-php-mysqlnd php73-php-gd php73-php-common php73-php-fpm php73-php-intl php73-php-cli php73-php php73-php-xml php73-php-opcache php73-php-pecl-apcu php73-php-pecl-jsond php73-php-pdo php73-php-gmp php73-php-process php73-php-pecl-imagick php73-php-devel php73-php-mbstring
rm -f /usr/bin/php
ln -s /usr/bin/php73 /usr/bin/php
sed -i 's/include=.*/include=\/etc\/php-fpm.d\/\*\.conf/' /etc/opt/remi/php73/php-fpm.conf
sed -i 's/;pid/pid/' /etc/opt/remi/php73/php-fpm.conf
service php73-php-fpm restart
rm -f /usr/lib/systemd/system/php-fpm.service
ln -s /usr/lib/systemd/system/php73-php-fpm.service /usr/lib/systemd/system/php-fpm.service
systemctl daemon-reload
yum -y install yum-utils
yum-config-manager --disable remi-php56 remi-php55 remi-test
sed -i "s/\/var\/run\/php-fpm\/php-fpm.pid/\/var\/opt\/remi\/php73\/run\/php-fpm\/php-fpm.pid/" /etc/monitrc
fi
# ---------------------------------
# Install MariaDB 10
if [ $vMariaDB10 == "y" ] || [ $vMariaDB10 == "Y" ]; then
systemctl stop mariadb
yum -y remove mariadb mariadb-server
yum -y install epel-release
curl https://raw.githubusercontent.com/fulviocri/server-init/master/mariadb.repo > /etc/yum.repos.d/mariadb.repo
yum -y install MariaDB-server MariaDB-client
systemctl enable mariadb
systemctl start mariadb
mysql_upgrade
fi
echo "bind-address=127.0.0.1" >> /etc/my.cnf
systemctl restart mariadb
# ---------------------------------
echo "Done!";
echo " ";
echo "You can access VestaCP here: https://$vHostname:8083/";
echo "Username: admin";
echo "Username: $vPassword";
echo " ";
echo " ";
echo "You can access Monit here (always best to use IP address: http://$IPAddress:2812/";
echo "Username: admin";
echo "Username: $vPassword";
echo " ";
echo "Have fun! Visit https://blog.ss88.uk/ for more great tutorials!";
echo " ";
echo "PLEASE REBOOT THE SERVER ONCE YOU HAVE COPIED THE DETAILS ABOVE. REBOOT COMMAND: shutdown -r now";
}
echo "IMPORTANT! Make sure you have VestaCP install and are running CentOS 7.x";
read -r -p "Do you want to continue? [y/N] " response
case $response in
[yY][eE][sS]|[yY])
StartTheProcess
;;
*)
echo "OK. Bye bye.";
;;
esac