Jonathan Hart | 53433b5 | 2015-03-26 17:23:34 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # vm-setup.sh |
Jonathan Hart | a509f47 | 2015-04-02 16:19:47 -0700 | [diff] [blame] | 3 | # |
| 4 | # Runs as root. |
| 5 | # |
Jonathan Hart | 53433b5 | 2015-03-26 17:23:34 -0700 | [diff] [blame] | 6 | # 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 Hart | 92cd3a8 | 2015-05-03 22:40:30 -0700 | [diff] [blame] | 9 | sudo sh -c 'echo "Acquire::http { Proxy \"http://10.0.2.2:3142\"; };" > /etc/apt/apt.conf.d/02proxy' |
| 10 | |
Jonathan Hart | 53433b5 | 2015-03-26 17:23:34 -0700 | [diff] [blame] | 11 | sudo apt-get update |
| 12 | |
Jonathan Hart | 59c036f | 2015-04-01 16:33:33 -0700 | [diff] [blame] | 13 | sudo 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 Hart | d860933 | 2015-04-01 11:16:33 -0700 | [diff] [blame] | 14 | |
Jonathan Hart | 53433b5 | 2015-03-26 17:23:34 -0700 | [diff] [blame] | 15 | sudo update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java |
| 16 | sudo update-alternatives --set javac /usr/lib/jvm/java-8-openjdk-amd64/bin/javac |
| 17 | |
Jonathan Hart | c397cf2 | 2015-03-27 08:04:08 -0700 | [diff] [blame] | 18 | # -------------- Setup keys ------------------- |
| 19 | |
| 20 | mkdir -p ~/.ssh |
| 21 | ssh-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 Hart | 2f4271d | 2015-03-26 18:40:57 -0700 | [diff] [blame] | 26 | sudo lxc-create --name onos1 -t download -- --dist ubuntu --release utopic --arch amd64 |
Jonathan Hart | 53433b5 | 2015-03-26 17:23:34 -0700 | [diff] [blame] | 27 | |
Jonathan Hart | c397cf2 | 2015-03-27 08:04:08 -0700 | [diff] [blame] | 28 | sudo sh -c "echo lxc.start.auto=1 >> /var/lib/lxc/onos1/config" |
Jonathan Hart | 53433b5 | 2015-03-26 17:23:34 -0700 | [diff] [blame] | 29 | |
Jonathan Hart | 4bb029f | 2015-03-26 22:45:15 -0700 | [diff] [blame] | 30 | sudo sh -c "sed -i s/dhcp/static/ /var/lib/lxc/onos1/rootfs/etc/network/interfaces" |
| 31 | sudo 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 |
| 36 | EOF" |
| 37 | |
Jonathan Hart | 53433b5 | 2015-03-26 17:23:34 -0700 | [diff] [blame] | 38 | sudo lxc-start --name onos1 --daemon |
Jonathan Hart | c397cf2 | 2015-03-27 08:04:08 -0700 | [diff] [blame] | 39 | |
Jonathan Hart | a897f4e | 2015-03-26 22:31:41 -0700 | [diff] [blame] | 40 | sudo lxc-ls --fancy |
Jonathan Hart | c397cf2 | 2015-03-27 08:04:08 -0700 | [diff] [blame] | 41 | sleep 5 |
Jonathan Hart | a897f4e | 2015-03-26 22:31:41 -0700 | [diff] [blame] | 42 | sudo lxc-ls --fancy |
Jonathan Hart | 17a0039 | 2015-03-26 22:24:25 -0700 | [diff] [blame] | 43 | sudo lxc-attach --name onos1 -- ip a |
Jonathan Hart | c397cf2 | 2015-03-27 08:04:08 -0700 | [diff] [blame] | 44 | |
Jonathan Hart | 53433b5 | 2015-03-26 17:23:34 -0700 | [diff] [blame] | 45 | sudo lxc-attach --name onos1 -- useradd -m sdn -s /bin/bash |
| 46 | sudo lxc-attach --name onos1 -- /bin/bash -c "echo sdn:rocks | chpasswd" |
| 47 | sudo lxc-attach --name onos1 -- /bin/bash -c "echo \"sdn ALL=(ALL) NOPASSWD:ALL\" > /etc/sudoers.d/sdn" |
| 48 | sudo lxc-attach --name onos1 -- apt-get update |
Jonathan Hart | c397cf2 | 2015-03-27 08:04:08 -0700 | [diff] [blame] | 49 | sudo lxc-attach --name onos1 -- apt-get install -y openssh-server openjdk-8-jre-headless |
| 50 | |
Jonathan Hart | caba161 | 2015-03-27 08:22:16 -0700 | [diff] [blame] | 51 | sudo mkdir -p /var/lib/lxc/onos1/rootfs/home/sdn/.ssh |
Jonathan Hart | c397cf2 | 2015-03-27 08:04:08 -0700 | [diff] [blame] | 52 | sudo cp ~/.ssh/id_rsa.pub /var/lib/lxc/onos1/rootfs/home/sdn/.ssh/authorized_keys |
Jonathan Hart | dd7016a | 2015-03-31 09:31:58 -0700 | [diff] [blame] | 53 | sudo lxc-attach --name onos1 -- chown sdn:sdn /home/sdn/.ssh/authorized_keys |
| 54 | sudo lxc-attach --name onos1 -- chmod 600 /home/sdn/.ssh/authorized_keys |
Jonathan Hart | c397cf2 | 2015-03-27 08:04:08 -0700 | [diff] [blame] | 55 | |
Jonathan Hart | a509f47 | 2015-04-02 16:19:47 -0700 | [diff] [blame] | 56 | sudo lxc-attach --name onos1 -- apt-get clean |
Jonathan Hart | a2cabf9 | 2015-03-31 10:31:59 -0700 | [diff] [blame] | 57 | |
| 58 | sudo lxc-stop --name onos1 |
| 59 | |
Jonathan Hart | a509f47 | 2015-04-02 16:19:47 -0700 | [diff] [blame] | 60 | # Clone the first node to create two more nodes |
Jonathan Hart | c397cf2 | 2015-03-27 08:04:08 -0700 | [diff] [blame] | 61 | sudo lxc-clone onos1 onos2 |
Jonathan Hart | caba161 | 2015-03-27 08:22:16 -0700 | [diff] [blame] | 62 | sudo sh -c "sed -i s/10.0.3.11/10.0.3.12/ /var/lib/lxc/onos2/rootfs/etc/network/interfaces" |
Jonathan Hart | c397cf2 | 2015-03-27 08:04:08 -0700 | [diff] [blame] | 63 | |
| 64 | sudo lxc-clone onos1 onos3 |
Jonathan Hart | caba161 | 2015-03-27 08:22:16 -0700 | [diff] [blame] | 65 | sudo sh -c "sed -i s/10.0.3.11/10.0.3.13/ /var/lib/lxc/onos3/rootfs/etc/network/interfaces" |
Jonathan Hart | c397cf2 | 2015-03-27 08:04:08 -0700 | [diff] [blame] | 66 | |
| 67 | sudo lxc-start --name onos1 |
| 68 | sudo lxc-start --name onos2 |
| 69 | sudo lxc-start --name onos3 |
| 70 | |
Jonathan Hart | 1cc5a1a | 2015-03-31 16:54:11 -0700 | [diff] [blame] | 71 | sleep 10 |
Jonathan Hart | c397cf2 | 2015-03-27 08:04:08 -0700 | [diff] [blame] | 72 | |
| 73 | sudo lxc-ls --fancy |
Jonathan Hart | 97b8121 | 2015-03-27 11:19:22 -0700 | [diff] [blame] | 74 | |
Jonathan Hart | 8b3b183 | 2015-03-31 10:02:22 -0700 | [diff] [blame] | 75 | echo "adding host keys to known_hosts" |
Jonathan Hart | dd7016a | 2015-03-31 09:31:58 -0700 | [diff] [blame] | 76 | # SSH to each once to add the host key to known_hosts |
| 77 | for onos in 10.0.3.11 10.0.3.12 10.0.3.13 |
| 78 | do |
Jonathan Hart | 8b3b183 | 2015-03-31 10:02:22 -0700 | [diff] [blame] | 79 | echo "sshing to $onos" |
Jonathan Hart | dd7016a | 2015-03-31 09:31:58 -0700 | [diff] [blame] | 80 | ssh -o "StrictHostKeyChecking no" sdn@${onos} ls |
| 81 | done |