-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·274 lines (240 loc) · 6.92 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·274 lines (240 loc) · 6.92 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
domain=$1
email=$2
dbpass=$3
apt update
apt install apt-transport-https ca-certificates curl software-properties-common -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update
apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
apt update && apt install consul -y
apt update && apt install nomad -y
mkdir /data
mkdir /pg_data
mkdir /letsencrypt
mkdir /nocodb
mkdir /n8n
chmod 777 /data
chmod 777 /pg_data
chmod 600 /letsencrypt
chmod 777 /nocodb
chmod 777 /n8n
extip=$(dig @resolver4.opendns.com myip.opendns.com +short)
consulkey=$(consul keygen)
mv /etc/consul.d/consul.hcl /etc/consul.d/consul.hcl.bak
cat <<EOF > /etc/consul.d/consul.hcl
datacenter = "dc1"
data_dir = "/opt/consul"
client_addr = "0.0.0.0"
ui_config{
enabled = true
}
server = true
addresses = {
"http" = "0.0.0.0"
"https" = "0.0.0.0"
"dns" = "0.0.0.0"
"grpc" = "0.0.0.0"
}
ports = {
dns = 8600
http = 8500
https = 8501
grpc = 8502
}
dns_config = {
"node_ttl" = "5s"
"service_ttl" = {
"*" = "5s"
}
"max_stale" = "5s"
}
connect {
enabled = true
}
bootstrap_expect=1
encrypt = "$consulkey"
retry_join = ["$extip"]
EOF
systemctl enable consul
systemctl start consul
sleep 30
nomadkey=$(nomad operator gossip keyring generate)
ifacename=$(ifconfig | grep $extip -B1 | grep mtu | sed -r 's/:.+//')
mv /etc/nomad.d/nomad.hcl /etc/nomad.d/nomad.hcl.bak
cat <<EOF > /etc/nomad.d/nomad.hcl
bind_addr = "0.0.0.0"
datacenter = "dc1"
data_dir = "/var/lib/nomad"
name = "dev_node"
disable_update_check = true
leave_on_interrupt = true
leave_on_terminate = true
log_file = "/var/log/nomad.log"
log_rotate_bytes = 10485760
log_rotate_max_files = 5
addresses {
http = "$extip"
}
advertise {
http = "{{ GetInterfaceIP \"$ifacename\" }}"
rpc = "{{ GetInterfaceIP \"$ifacename\" }}"
serf = "{{ GetInterfaceIP \"$ifacename\" }}"
}
server {
enabled = true
bootstrap_expect = 1
encrypt = "$nomadkey"
server_join {
retry_join = ["$extip"]
retry_max = 0
}
}
consul {
address = "$extip:8500"
server_service_name = "nomad"
client_service_name = "nomad-client"
auto_advertise = true
server_auto_join = true
client_auto_join = true
}
client {
enabled = true
no_host_uuid = true
min_dynamic_port = 30000
max_dynamic_port = 35000
alloc_dir = "/opt/nomad/alloc"
max_kill_timeout = "60s"
node_class = "regular"
reserved = {
cpu = 200
memory = 200
disk = 1
}
options = {
"env.denylist" = "MY_CUSTOM_ENVVAR"
"driver.denylist" = "qemu,java,exec,raw_exec"
"driver.allowlist" = "docker"
}
host_volume "persistent-storage" {
path = "/data"
read_only = false
}
host_volume "pg_data" {
path = "/pg_data"
read_only = false
}
host_volume "letsencrypt" {
path = "/letsencrypt"
read_only = false
}
host_volume "nocodb" {
path = "/nocodb"
read_only = false
}
host_volume "n8n" {
path = "/n8n"
read_only = false
}
meta {
pg_host = "first_host"
host = "1"
}
}
plugin "docker" {
config {
allow_caps = [
"CHOWN", "DAC_OVERRIDE", "FSETID", "FOWNER", "MKNOD",
"SETGID", "SETUID", "SETFCAP", "SETPCAP", "NET_BIND_SERVICE",
"SYS_CHROOT", "KILL", "AUDIT_WRITE",
]
volumes {
enabled = true
}
gc {
image = true
}
}
}
acl {
enabled = true
}
EOF
systemctl enable nomad
systemctl start nomad
sleep 30
iptables --table nat --append OUTPUT --destination localhost --protocol udp --match udp --dport 53 --jump REDIRECT --to-ports 8600
iptables --table nat --append OUTPUT --destination localhost --protocol tcp --match tcp --dport 53 --jump REDIRECT --to-ports 8600
cat <<EOF > /etc/systemd/resolved.conf
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See resolved.conf(5) for details
[Resolve]
DNS=127.0.0.1
DNSSEC=false
Domains=~consul
#FallbackDNS=
#Domains=
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#DNSOverTLS=no
#Cache=no-negative
#DNSStubListener=yes
#ReadEtcHosts=yes
EOF
systemctl restart systemd-resolved
export NOMAD_ADDR=http://$extip:4646
nomad acl bootstrap > ~/bootstrap
echo "-----------------------------------------------------nomad token located now in this folder into bootstrap file--------------------------------------------------------------------"
cat ~/bootstrap
nomadtoken=$(cat ~/bootstrap | grep Secret | awk '{print $4}')
cat <<EOF > ~/nomadcred
export NOMAD_TOKEN=$nomadtoken
export NOMAD_ADDR=http://$extip:4646
EOF
cd tf
sed -i "s+0000000000000+$nomadtoken+g" ./nomad/traefik.nomad
sed -i "s+11111111111+$extip+g" ./nomad/traefik.nomad
sed -i "s+xxxxx+$email+g" ./nomad/traefik.nomad
sed -i "s+rootpassword+$dbpass+g" ./nomad/postgres.nomad
sed -i "s+thstnm+$domain+g" ./nomad/nocodb.nomad
sed -i "s+thstnm+$domain+g" ./nomad/n8n.nomad
curl -L https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh | bash
tfswitch
source ~/nomadcred
terraform init
terraform apply -auto-approve
echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
apt-get update
apt-get install postgresql-client-12 -y
PGPASSWORD=$dbpass psql -h $extip -U root -p 5432 -a -q -f ./nomad/psql
sed -i "s+\/\*++g" ./main.tf
sed -i "s+\*\/++g" ./main.tf
terraform apply -auto-approve
echo "all done"
echo "your bootstrap nomad token is $nomadtoken and located into ~/bootstrap"
echo "for run terraform - cd tf folder, run source ~/nomadcred and after it, run terraform apply"
echo "nomad ui http://$extip:4646"
echo "consul ui http://$extip:8500"
echo "traefik ui http://$extip:8080"
echo "n8n ui https://n8n.$domain/"
echo "$(cat ./nomad/n8n.nomad | grep BASIC_AUTH_USER) $(cat ./nomad/n8n.nomad | grep BASIC_AUTH_PASSWORD)"
echo "nocodb ui https://nocodb.$domain/"