-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvm2.sh
More file actions
76 lines (64 loc) · 2.55 KB
/
Copy pathvm2.sh
File metadata and controls
76 lines (64 loc) · 2.55 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
#!/bin/bash
####################### CONFIG ################################
IF_CFG='/etc/network/interfaces'
RESOLV='/etc/resolv.conf'
HOSTNAME='vm2'
#IMPORT VAR
source $(dirname $0)/vm2.config
###### CONFIG ETHER INTERFACE ##################################################################
echo '# Config interfaces
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
' > $IF_CFG
#INTERNAL
echo '# Internal interface' >> $IF_CFG
echo "auto $INTERNAL_IF
iface $INTERNAL_IF inet static
address $INT_IP
gateway $GW_IP
dns-nameservers 8.8.8.8
dns-nameservers 8.8.4.4
" >> $IF_CFG
ifconfig $INTERNAL_IF $INT_IP
route del default
route add default gw $GW_IP
echo "nameserver 8.8.8.8" > /etc/resolv.conf
echo "nameserver 8.8.4.4" >> /etc/resolv.conf
#INTERNAL VLAN
echo '# Internal interface vlan' >> $IF_CFG
echo "auto $INTERNAL_IF.$VLAN
iface $INTERNAL_IF.$VLAN inet static
address $APACHE_VLAN_IP
vlan-raw-device $INTERNAL_IF
" >> $IF_CFG
apt install vlan -y
modprobe 8021q
vconfig add $INTERNAL_IF $VLAN
ifconfig $INTERNAL_IF.$VLAN $APACHE_VLAN_IP
###### SYS CONFIG #############################################################################
CUR_IP=$(ifconfig $INTERNAL_IF | grep 'inet addr' | cut -d: -f2 | awk '{print $1}')
APH_IP=$(ifconfig $INTERNAL_IF.$VLAN | grep 'inet addr' | cut -d: -f2 | awk '{print $1}')
hostname $HOSTNAME
echo $CUR_IP $HOSTNAME > /etc/hosts
################################################################################################
##### APACHE INSTALL##############################################################################
apt update && apt install apache2 -y
#################################################################################################
##### NGINX CONFIG #########################################################################
rm -r /etc/apache2/sites-enabled/*
cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/$HOSTNAME.conf
echo '### CONFIG ###' > /etc/apache2/sites-available/$HOSTNAME.conf
echo "
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog \${APACHE_LOG_DIR}/error.log
CustomLog \${APACHE_LOG_DIR}/access.log combined
</VirtualHost>" >> /etc/apache2/sites-available/$HOSTNAME.conf
ln -s /etc/apache2/sites-available/$HOSTNAME.conf /etc/apache2/sites-enabled/$HOSTNAME.conf
echo "Listen $APH_IP:80" > /etc/apache2/ports.conf
sed -i "/# Global configuration/a \ServerName $HOSTNAME" /etc/apache2/apache2.conf
echo "###### done ######" && systemctl restart apache2
exit $?