blob: 76dfd19b13333f2b00b131513b0027501b528f20 [file] [log] [blame]
Jonathan Hart53433b52015-03-26 17:23:34 -07001#!/bin/bash
2# vm-setup.sh
Jonathan Harta509f472015-04-02 16:19:47 -07003#
4# Runs as root.
5#
Jonathan Hart53433b52015-03-26 17:23:34 -07006# This script sets up the VM ready to run ONOS and tutorials, including installing an LXC cluster
7# for ONOS to run in.
8
Jonathan Hart92cd3a82015-05-03 22:40:30 -07009sudo sh -c 'echo "Acquire::http { Proxy \"http://10.0.2.2:3142\"; };" > /etc/apt/apt.conf.d/02proxy'
10
Jonathan Hart53433b52015-03-26 17:23:34 -070011sudo apt-get update
12
Jonathan Hart59c036f2015-04-01 16:33:33 -070013sudo apt-get install -y git openjdk-8-jdk maven unzip curl wget lxc virtualbox-guest-utils wireshark quagga erlang make gcc autoconf openssl libssl0.9.8 libssl-dev libncurses5 libncurses5-dev
Jonathan Hartd8609332015-04-01 11:16:33 -070014
Jonathan Hart53433b52015-03-26 17:23:34 -070015sudo update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
16sudo update-alternatives --set javac /usr/lib/jvm/java-8-openjdk-amd64/bin/javac
17
Jonathan Hartc397cf22015-03-27 08:04:08 -070018# -------------- Setup keys -------------------
19
20mkdir -p ~/.ssh
21ssh-keygen -t rsa -P "" -f .ssh/id_rsa
22#cp .ssh/id_rsa.pub .ssh/authorized_keys
23
24# -------------- Setup 3-node LXC cluster ----------------
25
Jonathan Hart2f4271d2015-03-26 18:40:57 -070026sudo lxc-create --name onos1 -t download -- --dist ubuntu --release utopic --arch amd64
Jonathan Hart53433b52015-03-26 17:23:34 -070027
Jonathan Hartc397cf22015-03-27 08:04:08 -070028sudo sh -c "echo lxc.start.auto=1 >> /var/lib/lxc/onos1/config"
Jonathan Hart53433b52015-03-26 17:23:34 -070029
Jonathan Hart4bb029f2015-03-26 22:45:15 -070030sudo sh -c "sed -i s/dhcp/static/ /var/lib/lxc/onos1/rootfs/etc/network/interfaces"
31sudo sh -c "cat << EOF >> /var/lib/lxc/onos1/rootfs/etc/network/interfaces
32 address 10.0.3.11
33 netmask 255.255.255.0
34 gateway 10.0.3.1
35 dns-nameservers 10.0.3.1
36EOF"
37
Jonathan Hart53433b52015-03-26 17:23:34 -070038sudo lxc-start --name onos1 --daemon
Jonathan Hartc397cf22015-03-27 08:04:08 -070039
Jonathan Harta897f4e2015-03-26 22:31:41 -070040sudo lxc-ls --fancy
Jonathan Hartc397cf22015-03-27 08:04:08 -070041sleep 5
Jonathan Harta897f4e2015-03-26 22:31:41 -070042sudo lxc-ls --fancy
Jonathan Hart17a00392015-03-26 22:24:25 -070043sudo lxc-attach --name onos1 -- ip a
Jonathan Hartc397cf22015-03-27 08:04:08 -070044
Jonathan Hart53433b52015-03-26 17:23:34 -070045sudo lxc-attach --name onos1 -- useradd -m sdn -s /bin/bash
46sudo lxc-attach --name onos1 -- /bin/bash -c "echo sdn:rocks | chpasswd"
47sudo lxc-attach --name onos1 -- /bin/bash -c "echo \"sdn ALL=(ALL) NOPASSWD:ALL\" > /etc/sudoers.d/sdn"
48sudo lxc-attach --name onos1 -- apt-get update
Jonathan Hartc397cf22015-03-27 08:04:08 -070049sudo lxc-attach --name onos1 -- apt-get install -y openssh-server openjdk-8-jre-headless
50
Jonathan Hartcaba1612015-03-27 08:22:16 -070051sudo mkdir -p /var/lib/lxc/onos1/rootfs/home/sdn/.ssh
Jonathan Hartc397cf22015-03-27 08:04:08 -070052sudo cp ~/.ssh/id_rsa.pub /var/lib/lxc/onos1/rootfs/home/sdn/.ssh/authorized_keys
Jonathan Hartdd7016a2015-03-31 09:31:58 -070053sudo lxc-attach --name onos1 -- chown sdn:sdn /home/sdn/.ssh/authorized_keys
54sudo lxc-attach --name onos1 -- chmod 600 /home/sdn/.ssh/authorized_keys
Jonathan Hartc397cf22015-03-27 08:04:08 -070055
Jonathan Harta509f472015-04-02 16:19:47 -070056sudo lxc-attach --name onos1 -- apt-get clean
Jonathan Harta2cabf92015-03-31 10:31:59 -070057
58sudo lxc-stop --name onos1
59
Jonathan Harta509f472015-04-02 16:19:47 -070060# Clone the first node to create two more nodes
Jonathan Hartc397cf22015-03-27 08:04:08 -070061sudo lxc-clone onos1 onos2
Jonathan Hartcaba1612015-03-27 08:22:16 -070062sudo sh -c "sed -i s/10.0.3.11/10.0.3.12/ /var/lib/lxc/onos2/rootfs/etc/network/interfaces"
Jonathan Hartc397cf22015-03-27 08:04:08 -070063
64sudo lxc-clone onos1 onos3
Jonathan Hartcaba1612015-03-27 08:22:16 -070065sudo sh -c "sed -i s/10.0.3.11/10.0.3.13/ /var/lib/lxc/onos3/rootfs/etc/network/interfaces"
Jonathan Hartc397cf22015-03-27 08:04:08 -070066
67sudo lxc-start --name onos1
68sudo lxc-start --name onos2
69sudo lxc-start --name onos3
70
Jonathan Hart1cc5a1a2015-03-31 16:54:11 -070071sleep 10
Jonathan Hartc397cf22015-03-27 08:04:08 -070072
73sudo lxc-ls --fancy
Jonathan Hart97b81212015-03-27 11:19:22 -070074
Jonathan Hart8b3b1832015-03-31 10:02:22 -070075echo "adding host keys to known_hosts"
Jonathan Hartdd7016a2015-03-31 09:31:58 -070076# SSH to each once to add the host key to known_hosts
77for onos in 10.0.3.11 10.0.3.12 10.0.3.13
78do
Jonathan Hart8b3b1832015-03-31 10:02:22 -070079 echo "sshing to $onos"
Jonathan Hartdd7016a2015-03-31 09:31:58 -070080 ssh -o "StrictHostKeyChecking no" sdn@${onos} ls
81done