-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig-memsql.sh
executable file
·81 lines (76 loc) · 2.56 KB
/
config-memsql.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
#!/bin/sh
usage() {
echo "usage: $0 -n <cluster_name>"
}
if (( $# < 2 )); then
echo "You must provide the cluster name."
usage
exit
fi
while getopts ":n:" opt_char
do
case $opt_char in
n)
CFGDIR=/var/lib/rapids/cfg/clusters/$OPTARG
;;
\?)
echo "$OPTARG is not a valid option."
usage
exit
;;
esac
done
CLUSTER=`basename $CFGDIR`
MASTER=`cat ${CFGDIR}/memsql.cluster | grep master | cut -d: -f1`
#MASTER=192.168.10.86
for line in `cat $CFGDIR/memsql.cluster`
do
IFS=: read HOST DSROLE NODE_COUNT <<< $line
echo "host: $HOST, Role: $DSROLE, Node Count: $NODE_COUNT"
if [[ $DSROLE == "master" ]]; then
echo "Starting MemSQL master agent on $HOST ..."
ssh $HOST "memsql-ops stop; memsql-ops start -h $HOST"
AGENTID=`ssh $HOST "memsql-ops agent-list -r primary -q"`
echo "Checking if master Memsql has been deployed ..."
result=`ssh $HOST "memsql-ops memsql-list --agent-id $AGENTID"`
if [[ $result == "No MemSQL nodes were found." ]]; then
echo "Deploying master Memsql node on $HOST ..."
ssh $HOST ifdown eth1
ssh $HOST "memsql-ops memsql-deploy -r master -a $AGENTID --community-edition"
if (( $? != 0 )); then
echo "MemSQL Master deployment is failed, please fix and rerun this program."
exit 1
fi
ssh $HOST ifup eth1
echo "Master Memsql node deployment is finished."
fi
elif [[ $DSROLE == "leaf" ]]; then
ssh $MASTER "memsql-ops agent-list | grep $HOST > /dev/null"
if (( $? != 0 )); then
echo "deploy MemSQL agent to $HOST ..."
ssh $MASTER "cp /root/.ssh/id_rsa /tmp/id.tmp; chmod 660 /tmp/id.tmp"
ssh $MASTER "memsql-ops agent-deploy -h $HOST --ops-datadir /opt/data_store/memsql_ops --memsql-installs-dir /opt/data_store/memsql_data -u root -i /tmp/id.tmp"
if (( $? == 0 )); then
echo "MemSQL agent is deployed on $HOST."
ssh $MASTER "rm -rf /tmp/id.tmp"
fi
fi
echo "deploy MemSQL leaf node to $HOST ..."
AGENTID=`ssh $MASTER "memsql-ops agent-list | grep $HOST" | awk '{ print $1 }'`
echo "AgentID: $AGENTID"
i=1
while (( $i <= $NODE_COUNT ))
do
echo "Deploy MemSQL leaf node on $HOST ..."
PORT=`expr $i + 3305`
ssh $MASTER "memsql-ops memsql-deploy -a $AGENTID -r leaf -P $PORT"
echo "MemSQL node is deployed on $HOST:$PORT"
i=`expr $i + 1`
done
else
echo "The provided role $DSROLE is not recognized."
exit 1
fi
done
ssh $MASTER "memsql-ops memsql-list"
echo "Data store: MemSQL configuration is finished now."