| #!/bin/bash |
| # vm-setup.sh |
| # |
| # This script sets up the VM ready to run ONOS and tutorials, including installing an LXC cluster |
| # for ONOS to run in. |
| |
| sudo apt-get update |
| |
| # TODO erlang, quagga, wireshark |
| #sudo apt-get install -y git openjdk-8-jdk maven unzip curl make gcc wget autoconf openssl libssl0.9.8 libssl-dev libncurses5 libncurses5-dev lxc |
| sudo apt-get install -y git openjdk-8-jdk maven unzip curl wget lxc virtualbox-guest-utils |
| #sudo apt-get install -y git wget curl lxc |
| sudo update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java |
| sudo update-alternatives --set javac /usr/lib/jvm/java-8-openjdk-amd64/bin/javac |
| |
| # -------------- Setup keys ------------------- |
| |
| mkdir -p ~/.ssh |
| ssh-keygen -t rsa -P "" -f .ssh/id_rsa |
| #cp .ssh/id_rsa.pub .ssh/authorized_keys |
| |
| # -------------- Setup 3-node LXC cluster ---------------- |
| |
| sudo lxc-create --name onos1 -t download -- --dist ubuntu --release utopic --arch amd64 |
| |
| sudo sh -c "echo lxc.start.auto=1 >> /var/lib/lxc/onos1/config" |
| |
| sudo sh -c "sed -i s/dhcp/static/ /var/lib/lxc/onos1/rootfs/etc/network/interfaces" |
| sudo sh -c "cat << EOF >> /var/lib/lxc/onos1/rootfs/etc/network/interfaces |
| address 10.0.3.11 |
| netmask 255.255.255.0 |
| gateway 10.0.3.1 |
| dns-nameservers 10.0.3.1 |
| EOF" |
| |
| sudo lxc-start --name onos1 --daemon |
| |
| sudo lxc-ls --fancy |
| sleep 5 |
| sudo lxc-ls --fancy |
| sudo lxc-attach --name onos1 -- ip a |
| |
| sudo lxc-attach --name onos1 -- useradd -m sdn -s /bin/bash |
| sudo lxc-attach --name onos1 -- /bin/bash -c "echo sdn:rocks | chpasswd" |
| sudo lxc-attach --name onos1 -- /bin/bash -c "echo \"sdn ALL=(ALL) NOPASSWD:ALL\" > /etc/sudoers.d/sdn" |
| sudo lxc-attach --name onos1 -- apt-get update |
| sudo lxc-attach --name onos1 -- apt-get install -y openssh-server openjdk-8-jre-headless |
| |
| sudo lxc-stop --name onos1 |
| |
| sudo mkdir -p /var/lib/lxc/onos1/rootfs/home/sdn/.ssh |
| sudo cp ~/.ssh/id_rsa.pub /var/lib/lxc/onos1/rootfs/home/sdn/.ssh/authorized_keys |
| sudo lxc-attach --name onos1 -- chown sdn:sdn /home/sdn/.ssh/authorized_keys |
| sudo lxc-attach --name onos1 -- chmod 600 /home/sdn/.ssh/authorized_keys |
| |
| sudo lxc-clone onos1 onos2 |
| sudo sh -c "sed -i s/10.0.3.11/10.0.3.12/ /var/lib/lxc/onos2/rootfs/etc/network/interfaces" |
| |
| sudo lxc-clone onos1 onos3 |
| sudo sh -c "sed -i s/10.0.3.11/10.0.3.13/ /var/lib/lxc/onos3/rootfs/etc/network/interfaces" |
| |
| sudo lxc-start --name onos1 |
| sudo lxc-start --name onos2 |
| sudo lxc-start --name onos3 |
| |
| sleep 5 |
| |
| sudo lxc-ls --fancy |
| |
| echo "adding host keys to known_hosts" |
| # SSH to each once to add the host key to known_hosts |
| for onos in 10.0.3.11 10.0.3.12 10.0.3.13 |
| do |
| echo "sshing to $onos" |
| ssh -o "StrictHostKeyChecking no" sdn@${onos} ls |
| done |