Masayoshi Kobayashi | f358ff5 | 2013-03-22 00:31:59 +0000 | [diff] [blame] | 1 | #! /bin/bash |
| 2 | USERNAME=ubuntu |
Masayoshi Kobayashi | 4de8d12 | 2013-04-08 19:19:47 +0000 | [diff] [blame] | 3 | if [ x$ONOS_CLUSTER_BASENAME == "x" -o x$ONOS_CLUSTER_NR_NODES == "x" ]; then |
| 4 | echo "set environment variable ONOS_CLUSTER_BASENAME and ONOS_CLUSTER_NR_NODES" |
| 5 | exit |
| 6 | elif [ $# != 1 ]; then |
| 7 | echo "$0 hostfile" |
Masayoshi Kobayashi | f358ff5 | 2013-03-22 00:31:59 +0000 | [diff] [blame] | 8 | exit |
| 9 | fi |
| 10 | |
Masayoshi Kobayashi | 4de8d12 | 2013-04-08 19:19:47 +0000 | [diff] [blame] | 11 | basename=$ONOS_CLUSTER_BASENAME |
| 12 | NR_NODES=$ONOS_CLUSTER_NR_NODES |
| 13 | hosts_file=$1 |
| 14 | |
Masayoshi Kobayashi | f358ff5 | 2013-03-22 00:31:59 +0000 | [diff] [blame] | 15 | for n in `seq 1 $NR_NODES`; do |
| 16 | rm -rf ${basename}${n} |
| 17 | mkdir ${basename}${n} |
| 18 | echo "${basename}${n}" > ${basename}${n}/hostname |
| 19 | echo $n > ${basename}${n}/myid |
| 20 | done |
| 21 | |
| 22 | ## ZK config ## |
| 23 | cp template/zoo.cfg common/ |
| 24 | for n in `seq 1 $NR_NODES`; do |
| 25 | echo "server.${n}=${basename}${n}:2888:3888" |
| 26 | done >> common/zoo.cfg |
| 27 | |
| 28 | ## Cassandra config ## |
| 29 | cat template/cassandra.yaml |\ |
| 30 | sed "s/__SEED__/${basename}1/g" > common/cassandra.yaml |
| 31 | |
| 32 | ## /etc/hosts ## |
| 33 | cat template/hosts $hosts_file > common/hosts |
| 34 | |
Masayoshi Kobayashi | 85b3f9b | 2013-04-01 21:03:50 +0000 | [diff] [blame] | 35 | |
Masayoshi Kobayashi | f358ff5 | 2013-03-22 00:31:59 +0000 | [diff] [blame] | 36 | ## .ssh/known_hosts ## |
| 37 | ssh-keyscan -H -t rsa github.com > common/known_hosts |
| 38 | ssh-keyscan -H -t rsa onosnat >> common/known_hosts |
| 39 | for n in `seq 1 $NR_NODES`; do |
| 40 | ssh-keyscan -H -t rsa ${basename}${n} |
| 41 | done >> common/known_hosts |
| 42 | |
Masayoshi Kobayashi | 85b3f9b | 2013-04-01 21:03:50 +0000 | [diff] [blame] | 43 | echo "GROUP: $basename" > bin/cluster.txt |
| 44 | cat $hosts_file | awk '{print $2}' >> bin/cluster.txt |
Masayoshi Kobayashi | f358ff5 | 2013-03-22 00:31:59 +0000 | [diff] [blame] | 45 | |
| 46 | |
| 47 | ## Creating shell script to login each node ## |
| 48 | for n in `seq 1 $NR_NODES`; do |
| 49 | cat << EOF > bin/${basename}${n} |
| 50 | #!/bin/sh |
| 51 | ssh $USERNAME@${basename}${n} |
| 52 | EOF |
| 53 | chmod 755 bin/${basename}${n} |
| 54 | done |
| 55 | |
| 56 | echo "======================================" |
| 57 | echo "Do not forget to do the following" |
| 58 | echo "paste $hosts_file to /etc/hosts" |
| 59 | echo "paste cluster.txt to your CLUSTER file" |
| 60 | echo "======================================" |