This repository has been archived by the owner on Oct 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsetup-ucp-dtr-node.sh
243 lines (201 loc) · 7.9 KB
/
setup-ucp-dtr-node.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
232
233
234
235
236
237
238
239
240
241
242
#!/bin/bash
#should work for all skus
#set -x
#set -xeuo pipefail
#if [[ $(id -u) -ne 0 ]] ; then
# echo "Must be run as root"
# exit 1
#fi
# We need five params: (1) PASSWORD (2) MASTERFQDN (3) DTR_PUBLIC_IP (4) REPLICA_ID (5) MASTERPRIVATEIP (6) UCP_NODE_REP (7) COUNT (8) SLEEP
echo $(date) " - Starting Script"
USER=admin
PASSWORD=$1
UCP_NODE=$(hostname)
FQDNDET=$2
MASTERFQDN=$( echo "$2" |cut -d\: -f1 )
DTR_PUBLIC_IP=$( echo "$2" |cut -d\: -f2 )
UCP_URL=https://$MASTERFQDN
REPLICA_ID=$3
MASTERPRIVATEIP=$4
UCP_NODE_REP=$5
UCP_NODE_SUF=-ucpdtrnode
COUNT=$6
SLEEP=$7
DTR_PUBLIC_URL=https://$DTR_PUBLIC_IP
omsworkspaceid=$( echo "$8" |cut -d\: -f1 )
omsworkspacekey=$( echo "$8" |cut -d\: -f2 )
omslnxagentver=$( echo "$8" |cut -d\: -f3 )
DOCKERDET=$9
DOCKERVER=$( echo "$9" |cut -d\: -f1 )
DOCKERCOMPVER=$( echo "$9" |cut -d\: -f2 )
DOCKERMCVER=$( echo "$9" |cut -d\: -f3 )
TRUSTYREPO=$( echo "$9" |cut -d\: -f4 )
DOCKERDCVER=$( echo "$9" |cut -d\: -f5 )
UCPIMAGETAG=$( echo "$DOCKERDCVER" |cut -d\_ -f1|sed 's/ucp\-/ucp\:/g')
DTRIMAGETAG=$( echo "$DOCKERDCVER" |cut -d\_ -f2|sed 's/dtr\-/dtr\:/g')
if [ ! -z "$omsworkspaceid" ]; then
echo "omsworkspaceid is" $omsworkspaceid
else
echo "All are respectively " $1 $2 $3 $4
fi
disable_ufw_iptables()
{
ufw disable
iptables-save > $HOME/firewall.txt
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
ip6tables-save > $HOME/firewall-6.txt
ip6tables -X
ip6tables -t mangle -F
ip6tables -t mangle -X
ip6tables -P INPUT ACCEPT
ip6tables -P FORWARD ACCEPT
ip6tables -P OUTPUT ACCEPT
}
disable_ufw_iptables;
installomsagent()
{
#wget https://github.com/Microsoft/OMS-Agent-for-Linux/releases/download/OMSAgent_Ignite2016_v$omslnxagentver/omsagent-${omslnxagentver}.universal.x64.sh
wget https://github.com/Microsoft/OMS-Agent-for-Linux/releases/download/OMSAgent-201610-v$omslnxagentver/omsagent-${omslnxagentver}.universal.x64.sh
chmod +x ./omsagent-${omslnxagentver}.universal.x64.sh
md5sum ./omsagent-${omslnxagentver}.universal.x64.sh
sudo sh ./omsagent-${omslnxagentver}.universal.x64.sh --upgrade -w $omsworkspaceid -s $omsworkspacekey
}
instrumentfluentd_docker()
{
cd /etc/systemd/system/multi-user.target.wants/ && sed -i.bak -e '12d' docker.service
cd /etc/systemd/system/multi-user.target.wants/ && sed -i '12iEnvironment="DOCKER_OPTS=--log-driver=fluentd --log-opt fluentd-address=localhost:25225"' docker.service
cd /etc/systemd/system/multi-user.target.wants/ && sed -i '13iExecStart=/usr/bin/dockerd -H fd:// $DOCKER_OPTS' docker.service
service docker restart
}
install_docker_tools()
{
# System Update and docker version update
DEBIAN_FRONTEND=noninteractive apt-mark hold walinuxagent
DEBIAN_FRONTEND=noninteractive apt-get -y update
apt-get install -y apt-transport-https ca-certificates
#apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
#echo 'deb https://apt.dockerproject.org/repo ubuntu-trusty main' >> /etc/apt/sources.list.d/docker.list
curl -s 'https://sks-keyservers.net/pks/lookup?op=get&search=0xee6d536cf7dc86e2d7d56f59a178ac6c6238f52e' | apt-key add --import
#echo 'deb https://packages.docker.com/1.12/apt/repo ubuntu-trusty testing' >> /etc/apt/sources.list.d/docker.list
echo "deb https://packages.docker.com/${DOCKERVER}/apt/repo ubuntu-trusty ${TRUSTYREPO}" >> /etc/apt/sources.list.d/docker.list
apt-cache policy docker-engine
DEBIAN_FRONTEND=noninteractive apt-get -y update
DEBIAN_FRONTEND=noninteractive apt-get -y upgrade
#curl -L https://github.com/docker/compose/releases/download/1.9.0-rc4/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
#curl -L https://github.com/docker/machine/releases/download/v0.8.2/docker-machine-`uname -s`-`uname -m` >/usr/local/bin/docker-machine
curl -L https://github.com/docker/compose/releases/download/$DOCKERCOMPVER/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
curl -L https://github.com/docker/machine/releases/download/v$DOCKERMCVER/docker-machine-`uname -s`-`uname -m` >/usr/local/bin/docker-machine
chmod +x /usr/local/bin/docker-machine
chmod +x /usr/local/bin/docker-compose
export PATH=$PATH:/usr/local/bin/
groupadd docker
usermod -aG docker ucpadmin
service docker restart
}
install_docker_tools;
if [ ! -z "$omsworkspaceid" ]; then
sleep 45;
instrumentfluentd_docker;
sleep 30;
installomsagent;
fi
installbundle ()
{
echo $(date) "Sleeping for $SLEEP"
sleep $SLEEP
echo $(date) " - Staring Swarm Join as worker UCP Controller"
apt-get -y update && apt-get install -y curl jq
# Create an environment variable with the user security token
AUTHTOKEN=$(curl -sk -d '{"username":"admin","password":"'"$PASSWORD"'"}' https://$MASTERPRIVATEIP/auth/login | jq -r .auth_token)
echo "$AUTHTOKEN"
# Download the client certificate bundle
curl -k -H "Authorization: Bearer ${AUTHTOKEN}" https://$MASTERPRIVATEIP/api/clientbundle -o bundle.zip
unzip -o bundle.zip && chmod +x env.sh && source env.sh
}
joinucp() {
installbundle;
#docker swarm join-token worker|sed '1d'|sed '1d'|sed '$ d'>swarmjoin.sh
docker swarm join-token worker|sed '1d'|sed '1d'|sed '$ d'> /usr/local/bin/docker-workerswarmjoin
unset DOCKER_TLS_VERIFY
unset DOCKER_CERT_PATH
unset DOCKER_HOST
#chmod 755 swarmjoin.sh
chmod +x /usr/local/bin/docker-workerswarmjoin
export PATH=$PATH:/usr/local/bin/
docker-workerswarmjoin
#source swarmjoin.sh
}
## Insecure TLS as self signed will fail -- Failed to get bootstrap client: Failed to get UCP CA: Get https://blahblah/ca: x509: certificate signed by unknown authority
installdtr() {
installbundle;
echo $(date) " - Loading docker install Tar"
#cd /opt/ucp && wget https://s3.amazonaws.com/packages.docker.com/caas/ucp-2.0.0-beta3_dtr-2.1.0-beta3.tar.gz
#cd /opt/ucp && wget https://packages.docker.com/caas/ucp-2.0.0-beta4_dtr-2.1.0-beta4.tar.gz
cd /opt/ucp && wget https://packages.docker.com/caas/$DOCKERDCVER.tar.gz
#docker load < ucp-2.0.0-beta4_dtr-2.1.0-beta4.tar.gz
docker load < $DOCKERDCVER.tar.gz
# Implement delay timer to stagger load of the bits - docker.com CDN Dependent
sleep 45;
echo $(date) " - Loading complete. Starting UCP Install"
# Start installation of UCP with master Controller
docker run --rm \
docker/${DTRIMAGETAG} install \
--ucp-node $UCP_NODE \
--ucp-insecure-tls \
--dtr-external-url $DTR_PUBLIC_URL \
--ucp-url https://$MASTERFQDN \
--ucp-username admin --ucp-password $PASSWORD
}
joinucp;
# Implement delay timer to stagger joining of Agent Nodes to cluster
echo $(date) "Sleeping for 45"
sleep 60;
# Install DTR
installdtr;
if [ $? -eq 0 ]
then
echo $(date) " - Completed DTR installation on master DTR node"
else
echo $(date) " - DTR installation on master DTR node failed"
fi
# Install DTR for replica placeholder
#docker run -it --rm \
# dockerhubenterprise/dtr:2.1.0-beta1 install \
# --ucp-node $UCP_NODE \
# --ucp-insecure-tls \
# --dtr-external-url https://dlbpipddcdev01.westeurope.cloudapp.azure.com:443 \
# --ucp-url https://ucpclus0-ucpctrl \
# --ucp-username admin --ucp-password $PASSWORD \
# --replica-id $REPLICA_ID"0"
###########################
# WIP - TBC for BETA and/or GA (UCP 2.0.0 and DTR 2.10
###########################
for ((loop=1; loop<=$COUNT; loop++))
do
echo $(date) " - Start DTR installation on replica DTR node"
#joinucp()
# Install DTR Replica
docker run -it --rm \
docker/${DTRIMAGETAG} join \
--ucp-url $UCP_URL \
--ucp-node $UCP_NODE_REP$loop$UCP_NODE_SUF \
--ucp-insecure-tls \
--replica-id $REPLICA_ID$loop \
--existing-replica-id $REPLICA_ID"0" \
--ucp-username $USER --ucp-password $PASSWORD
if [ $? -eq 0 ]
then
echo $(date) " - Completed DTR installation on replica DTR node - $UCP_NODE_REP$loop$UCP_NODE_SUF"
else
echo $(date) " -- DTR installation on replica DTR node - $UCP_NODE_REP$loop$UCP_NODE_SUF failed"
fi
sleep 20
done
echo $(date) " - Completed DTR installation on Master and all replica DTR nodes"