This repository has been archived by the owner on May 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.sh
executable file
·231 lines (183 loc) · 5.06 KB
/
deploy.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
#!/bin/bash
read -p "Which cluster? (prod, qa, dev) " cluster
rabbit_ip="broker"
check=$( getent hosts | grep -e broker )
if [ "$check" == "" ]; then
if [ $cluster == "dev" ]; then
echo "10.4.90.102 broker" | sudo tee -a /etc/hosts
fi
if [ $cluster == "qa" ]; then
echo "10.4.90.152 broker" | sudo tee -a /etc/hosts
fi
if [ $cluster == "prod" ]; then
echo "10.4.90.52 broker" | sudo tee -a /etc/hosts
echo "10.4.90.62 broker" | sudo tee -a /etc/hosts
fi
fi
# Update repos
sudo apt update
# Do full upgrade of system
sudo apt full-upgrade -y
# Remove leftover packages and purge configs
sudo apt autoremove -y --purge
# Install required packages
sudo apt install -y ufw mariadb-server expect php-amqp php-bcmath php-cli php-common php-curl php-json php-mbstring php-mysql php-readline php-zip unzip wget inotify-tools
# Setup firewall
sudo ufw --force enable
sudo ufw allow ssh
sudo ufw allow 3306
sudo ufw default deny incoming
sudo ufw default allow outgoing
# Install zerotier
sudo apt install -y apt-transport-https ca-certificates curl gnupg lsb-release
curl -s https://install.zerotier.com | sudo bash
# Run commands from mysql_secure_installation
sudo expect -c "set timeout 10
spawn sudo mysql_secure_installation
expect \"Enter current password for root (enter for none):\"
send \"\r\"
expect \"Switch to unix_socket authentication\"
send \"n\r\"
expect \"Change the root password?\"
send \"n\r\"
expect \"Remove anonymous users?\"
send \"y\r\"
expect \"Disallow root login remotely?\"
send \"y\r\"
expect \"Remove test database and access to it?\"
send \"y\r\"
expect \"Reload privilege tables now?\"
send \"y\r\"
expect eof"
# Import DB Schema
sudo mysql < schema.sql
sudo mysql < stocks.sql
sudo mysql < currencies.sql
# Create user
sudo mysql -e "CREATE USER 'stonx'@'localhost' IDENTIFIED BY 'stonx_passwd';"
sudo mysql -e "GRANT ALL ON stonx.* TO 'stonx'@'localhost';"
sudo mysql -e "FLUSH PRIVILEGES;"
# Setup rabbitmq listener
cd rabbit
git clone [email protected]:stonX-IT490/rabbitmq-common.git rabbitmq-webHost
cd rabbitmq-webHost
./deploy.sh
cd ..
git clone [email protected]:stonX-IT490/rabbitmq-common.git rabbitmq-dmzHost
cd rabbitmq-dmzHost
./deploy.sh
cd ..
git clone [email protected]:stonX-IT490/rabbitmq-common.git rabbitmq-pushHost
cd rabbitmq-pushHost
./deploy.sh
cd ..
rabbitWebHost="<?php
\$config = [
'host' =>'$rabbit_ip',
'port' => 5672,
'username' => 'db',
'password' => 'stonx_mariadb',
'vhost' => 'webHost'
];
?>"
rabbitDmzHost="<?php
\$config = [
'host' => '$rabbit_ip',
'port' => 5672,
'username' => 'db',
'password' => 'stonx_mariadb',
'vhost' => 'dmzHost'
];
?>"
rabbitPushHost="<?php
\$config = [
'host' => '$rabbit_ip',
'port' => 5672,
'username' => 'db',
'password' => 'stonx_mariadb',
'vhost' => 'pushHost'
];
?>"
echo "$rabbitWebHost" > rabbitmq-webHost/config.php
echo "$rabbitDmzHost" > rabbitmq-dmzHost/config.php
echo "$rabbitPushHost" > rabbitmq-pushHost/config.php
cd ..
pwd=`pwd`
serviceWebHost="[Unit]
Description=Webserver RabbitMQ Consumer Listener
[Service]
Type=simple
Restart=always
ExecStart=/usr/bin/php -f $pwd/rabbit/webserver.php
[Install]
WantedBy=multi-user.target"
serviceDmzHost="[Unit]
Description=DMZ RabbitMQ Consumer Listener
[Service]
Type=simple
Restart=always
ExecStart=/usr/bin/php -f $pwd/rabbit/dmz.php
[Install]
WantedBy=multi-user.target"
servicePushHost="[Unit]
Description=Push Notification RabbitMQ Consumer Listener
[Service]
Type=simple
Restart=always
ExecStart=/usr/bin/php -f $pwd/rabbit/push.php
[Install]
WantedBy=multi-user.target"
echo "$serviceWebHost" > rmq-websrv.service
echo "$serviceDmzHost" > rmq-dmz.service
echo "$servicePushHost" > rmq-push.service
sudo cp rmq-websrv.service /etc/systemd/system/
sudo cp rmq-dmz.service /etc/systemd/system/
sudo cp rmq-push.service /etc/systemd/system/
sudo systemctl start rmq-websrv
sudo systemctl start rmq-dmz
sudo systemctl start rmq-push
sudo systemctl enable rmq-websrv
sudo systemctl enable rmq-dmz
sudo systemctl enable rmq-push
serviceCheckProd1="[Unit]
Description=Check if database-prod1 is up
[Service]
Type=simple
Restart=always
ExecStart=$pwd/check.sh
[Install]
WantedBy=multi-user.target"
if [ $cluster == "prod" ]; then
read -p "Which host? (prod1, prod2) " vm_type
if [ $vm_type == "prod2" ]; then
echo "$serviceCheckProd1" > check-prod1.service
sudo cp check-prod1.service /etc/systemd/system/
sudo systemctl start check-prod1
sudo systemctl enable check-prod1
fi
fi
autoRestart="[Unit]
Description=RMQ autoRestart Service
[Service]
Type=simple
Restart=always
WorkingDirectory=$pwd
ExecStart=/usr/bin/bash -f $pwd/autoRestart.sh
User=root
Group=root
[Install]
WantedBy=multi-user.target"
# Create autoRestart service in systemd
if [ $cluster == "prod" ]; then
chmod +x $pwd/autoRestart.sh
echo "$autoRestart" > rmq-autoRestart.service
sudo cp rmq-autoRestart.service /etc/systemd/system/
sudo systemctl start rmq-autoRestart
sudo systemctl enable rmq-autoRestart
fi
# Setup Central Logging
git clone [email protected]:stonX-IT490/logging.git ~/logging
cd ~/logging
chmod +x deploy.sh
./deploy.sh
cd ~/