-
Notifications
You must be signed in to change notification settings - Fork 19
/
install.sh
executable file
·308 lines (266 loc) · 8.31 KB
/
install.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
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
#!/usr/bin/env bash
ENV_CONFIG=env.yaml
main() {
parse_args
echo "Start installing PolarDB Stack..."
install_helm
update_config
set_node_label
install_multipath
install_supervisor
install_agent
agent_ini
agent_conf
supervisorctl_reload
install_pfs
config_hba
}
show_usage() {
cat <<-EOF
Usage: $0 [OPTION]
Install PolarDB Stack.
-h, --help Display help and exit
-c, --config The config for PolarDB Stack, default is env.yaml
EOF
}
parse_args() {
if [[ $# -ne 0 ]]; then
local args=$(getopt \
-o "h,c" \
--long "help,config" \
-- "$@")
if [[ $? -ne 0 ]]; then
err "Invalid options"
fi
eval set -- "${args}"
while true; do
case "$1" in
-h | --help)
show_usage
exit 0
;;
esac
done
fi
}
install_helm() {
echo "Skip install helm."
}
update_config() {
if [ ! -f "$ENV_CONFIG" ]; then
echo "Config file $ENV_CONFIG not exist, exit."
exit 1
fi
network_interface=$(grep "interface" $ENV_CONFIG | awk '{print $2}')
if [ ! -z "$network_interface" ]; then
network_interface_cmd="--set network.interface=$network_interface "
echo "set config $network_interface_cmd"
fi
k8s_host=$(grep "k8s" $ENV_CONFIG -A2 | grep "host" | awk '{print $2}')
if [ ! -z "$k8s_host" ]; then
k8s_host_cmd="--set KUBERNETES_SERVICE_HOST=$k8s_host "
echo "set config $k8s_host_cmd"
fi
k8s_port=$(grep "k8s" $ENV_CONFIG -A2 | grep "port" | awk '{print $2}')
if [ ! -z "$k8s_port" ]; then
k8s_port_cmd="--set KUBERNETES_SERVICE_PORT=$k8s_port "
echo "set config $k8s_port_cmd"
fi
metabase_host=$(grep "metabase" $ENV_CONFIG -A6 | grep "host" | awk '{print $2}')
if [ ! -z "$metabase_host" ]; then
metabase_host_cmd="--set metabase.host=$metabase_host "
echo "set config $metabase_host_cmd"
fi
metabase_port=$(grep "metabase" $ENV_CONFIG -A6 | grep "port" | awk '{print $2}')
if [ ! -z "$metabase_port" ]; then
metabase_port_cmd="--set metabase.port=$metabase_port "
echo "set config $metabase_port_cmd"
fi
metabase_user=$(grep "metabase" $ENV_CONFIG -A6 | grep "user" | awk '{print $2}')
if [ ! -z "$metabase_user" ]; then
metabase_user_cmd="--set metabase.user=$metabase_user "
echo "set config $metabase_user_cmd"
fi
metabase_password=$(grep "metabase" $ENV_CONFIG -A6 | grep "password" | awk '{print $2}')
if [ ! -z "$metabase_password" ]; then
metabase_password_cmd="--set metabase.password=$metabase_password "
echo "set config $metabase_password_cmd"
fi
metabase_type=$(grep "metabase" $ENV_CONFIG -A6 | grep "type" | awk '{print $2}')
if [ ! -z "$metabase_type" ]; then
metabase_type_cmd="--set metabase.type=$metabase_type "
echo "set config $metabase_type_cmd"
fi
metabase_version=$(grep "metabase" $ENV_CONFIG -A6 | grep "version" | awk '{print $2}')
if [ ! -z "$metabase_version" ]; then
metabase_version_cmd="--set metabase.version=$metabase_version "
echo "set config $metabase_version_cmd"
fi
cmd="helm install --debug --generate-name ./polardb-stack-chart $network_interface_cmd $k8s_host_cmd $k8s_port_cmd $metabase_host_cmd $metabase_port_cmd $metabase_user_cmd $metabase_password_cmd $metabase_type_cmd $metabase_version_cmd"
echo $cmd
$cmd
}
set_node_label() {
./script/set_labels.sh
}
install_multipath() {
network_interface=$(grep "interface" $ENV_CONFIG | awk '{print $2}')
if [ -z "$network_interface" ]; then
echo "No network interface configured, exit."
exit 1
fi
ips=( `sed -n '/dbm_hosts/,/network/p' $ENV_CONFIG | grep 'ip' | awk '{print $3}'` )
cnt=${#ips[@]}
for ((i=0;i<$cnt;i++));
do
base_cmd="ssh root@${ips[$i]}"
$base_cmd yum install -y device-mapper-multipath
$base_cmd "cat <<EOF >/etc/multipath.conf
defaults {
user_friendly_names no
find_multipaths no
}
blacklist {
devnode "^sda$"
}
EOF"
$base_cmd systemctl enable multipathd.service
$base_cmd systemctl start multipathd.service
done
}
install_supervisor() {
network_interface=$(grep "interface" $ENV_CONFIG | awk '{print $2}')
if [ -z "$network_interface" ]; then
echo "No network interface configured, exit."
exit 1
fi
ips=( `sed -n '/dbm_hosts/,/network/p' $ENV_CONFIG | grep 'ip' | awk '{print $3}'` )
cnt=${#ips[@]}
for ((i=0;i<$cnt;i++));
do
base_cmd="ssh root@${ips[$i]}"
$base_cmd yum install -y supervisor
$base_cmd systemctl enable supervisord
$base_cmd systemctl start supervisord
done
}
install_agent() {
wget https://github.com/ApsaraDB/PolarDB-Stack-Storage/releases/download/v1.0.0/sms-agent
mkdir -p /home/a/project/t-polardb-sms-agent/bin/
cp sms-agent /home/a/project/t-polardb-sms-agent/bin/polardb-sms-agent
network_interface=$(grep "interface" $ENV_CONFIG | awk '{print $2}')
if [ -z "$network_interface" ]; then
echo "No network interface configured, exit."
exit 1
fi
ips=( `sed -n '/dbm_hosts/,/network/p' $ENV_CONFIG | grep 'ip' | awk '{print $3}'` )
cnt=${#ips[@]}
for ((i=0;i<$cnt;i++));
do
base_cmd="ssh root@${ips[$i]}"
$base_cmd mkdir -p /home/a/project/t-polardb-sms-agent/bin
scp /home/a/project/t-polardb-sms-agent/bin/polardb-sms-agent root@${ips[$i]}:/home/a/project/t-polardb-sms-agent/bin/polardb-sms-agent
$base_cmd chmod u+x /home/a/project/t-polardb-sms-agent/bin/polardb-sms-agent
done
}
agent_ini() {
AGENT_INI="/etc/supervisord.d/polardb-sms-agent.ini"
network_interface=$(grep "interface" $ENV_CONFIG | awk '{print $2}')
if [ -z "$network_interface" ]; then
echo "No network interface configured, exit."
exit 1
fi
ips=( `sed -n '/dbm_hosts/,/network/p' $ENV_CONFIG | grep 'ip' | awk '{print $3}'` )
cnt=${#ips[@]}
for ((i=0;i<$cnt;i++));
do
base_cmd="ssh root@${ips[$i]}"
NODE_IP=$($base_cmd ifconfig $network_interface | grep netmask | awk '{print $2}')
echo $base_cmd
$base_cmd touch $AGENT_INI
$base_cmd "cat <<EOF >$AGENT_INI
[program:polardb-sms-agent]
command=/home/a/project/t-polardb-sms-agent/bin/polardb-sms-agent --port=18888 --node-ip=$NODE_IP --node-id=%(host_node_name)s
process_name=%(program_name)s
startretries=1000
autorestart=unexpected
autostart=true
EOF"
$base_cmd cat $AGENT_INI
done
}
agent_conf() {
AGENT_CONF="/etc/polardb-sms-agent.conf"
network_interface=$(grep "interface" $ENV_CONFIG | awk '{print $2}')
if [ -z "$network_interface" ]; then
echo "No network interface configured, exit."
exit 1
fi
ips=( `sed -n '/dbm_hosts/,/network/p' $ENV_CONFIG | grep 'ip' | awk '{print $3}'` )
cnt=${#ips[@]}
for ((i=0;i<$cnt;i++));
do
base_cmd="ssh root@${ips[$i]}"
$base_cmd "cat <<EOF >$AGENT_CONF
blacklist {
attachlist {
}
locallist {
}
}
EOF"
done
}
install_pfs() {
pfsd=t-pfsd-opensource-1.2.41-1.el7.x86_64.rpm
wget https://github.com/ApsaraDB/PolarDB-FileSystem/releases/download/pfsd4pg-release-1.2.41-20211018/$pfsd
rpm -ivh $pfsd
network_interface=$(grep "interface" $ENV_CONFIG | awk '{print $2}')
if [ -z "$network_interface" ]; then
echo "No network interface configured, exit."
exit 1
fi
ips=( `sed -n '/dbm_hosts/,/network/p' $ENV_CONFIG | grep 'ip' | awk '{print $3}'` )
cnt=${#ips[@]}
for ((i=0;i<$cnt;i++));
do
scp $pfsd root@${ips[$i]}:/tmp/$pfsd
ssh root@${ips[$i]} rpm -ivh /tmp/$pfsd
done
}
supervisorctl_reload() {
network_interface=$(grep "interface" $ENV_CONFIG | awk '{print $2}')
if [ -z "$network_interface" ]; then
echo "No network interface configured, exit."
exit 1
fi
ips=( `sed -n '/dbm_hosts/,/network/p' $ENV_CONFIG | grep 'ip' | awk '{print $3}'` )
cnt=${#ips[@]}
for ((i=0;i<$cnt;i++));
do
ssh root@${ips[$i]} supervisorctl reload
done
}
config_hba() {
network_interface=$(grep "interface" $ENV_CONFIG | awk '{print $2}')
if [ -z "$network_interface" ]; then
echo "No network interface configured, exit."
exit 1
fi
ips=( `sed -n '/dbm_hosts/,/network/p' $ENV_CONFIG | grep 'ip' | awk '{print $3}'` )
cnt=${#ips[@]}
for ((i=0;i<$cnt;i++));
do
base_cmd="ssh root@${ips[$i]}"
$base_cmd "mkdir -p /etc/postgres"
$base_cmd "cat <<EOF >/etc/postgres/pg_hba.conf
local all all trust
host all postgres all reject
host all all all md5
local replication postgres trust
host replication postgres all reject
host replication all all md5
EOF"
done
}
main "$@"