From 8233e63e95641ffb708053065fdde16416442d35 Mon Sep 17 00:00:00 2001 From: Changbin Liu Date: Wed, 23 Jul 2014 19:55:11 -0400 Subject: [PATCH] Add procedures/scripts as starting point of multi-DC deployment Change-Id: If455358e9164aa51b99ed3a06dd49ab2cf03d69b --- bin/delete_docker_instances.sh | 10 ++ ...efserver.sh => install_chefserver_deps.sh} | 2 +- ..._install_libvirt.sh => install_libvirt.sh} | 17 --- ..._install_ovs.sh => install_openvswitch.sh} | 0 bin/install_zookeeper.sh | 58 ++++++++ bin/launch_docker_instance.py | 81 +++++++++++ bin/launch_libvirt_instance.py | 94 +++++++++++++ bin/procedures | 126 ++++++++++++++++++ ...{pre_switch_kernel.sh => switch_kernel.sh} | 3 +- setup.py | 49 ++++--- 10 files changed, 399 insertions(+), 41 deletions(-) create mode 100644 bin/delete_docker_instances.sh rename bin/{pre_install_chefserver.sh => install_chefserver_deps.sh} (97%) rename bin/{pre_install_libvirt.sh => install_libvirt.sh} (68%) rename bin/{pre_install_ovs.sh => install_openvswitch.sh} (100%) create mode 100644 bin/install_zookeeper.sh create mode 100644 bin/launch_docker_instance.py create mode 100644 bin/launch_libvirt_instance.py create mode 100644 bin/procedures rename bin/{pre_switch_kernel.sh => switch_kernel.sh} (79%) diff --git a/bin/delete_docker_instances.sh b/bin/delete_docker_instances.sh new file mode 100644 index 0000000..939e34a --- /dev/null +++ b/bin/delete_docker_instances.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +CONTROLLERS=$@ + +docker.io rm -f `docker.io ps -a | grep changbl | awk '{print $1}'` + +for i in `ovs-vsctl show | grep Port | grep pl | awk '{print $2}' | cut -d '"' -f 2` +do + ovs-vsctl del-port obr2 $i +done diff --git a/bin/pre_install_chefserver.sh b/bin/install_chefserver_deps.sh similarity index 97% rename from bin/pre_install_chefserver.sh rename to bin/install_chefserver_deps.sh index e432c13..582aefa 100755 --- a/bin/pre_install_chefserver.sh +++ b/bin/install_chefserver_deps.sh @@ -14,7 +14,7 @@ sudo apt-get install -y opscode-keyring # permanent upgradeable keyring sudo apt-get install -y debconf-utils sudo apt-get -y upgrade -sudo apt-get install -y libgnumail-java ruby-addressable libextlib-ruby jsvc \ +sudo apt-get install -y libgnumail-java ruby-addressable libextlib-ruby jsvc \ libdb5.1-java-gcj erlang-eunit libjaxp1.3-java libcommons-pool-java \ libdb-je-java ruby-mixlib-config gcj-4.6-jre-lib libjson-ruby1.8 \ libbcel-java erlang-crypto libgeronimo-jta-1.1-spec-java libecj-java \ diff --git a/bin/pre_install_libvirt.sh b/bin/install_libvirt.sh similarity index 68% rename from bin/pre_install_libvirt.sh rename to bin/install_libvirt.sh index c5cb9ea..99fbe2e 100644 --- a/bin/pre_install_libvirt.sh +++ b/bin/install_libvirt.sh @@ -47,20 +47,3 @@ cd libvirt # --with-xen=yes to the command make -j sudo make install - -# enable libvirt for VM live migration -sudo sed -i /etc/libvirt/libvirtd.conf \ - -e 's/#listen_tls = 0/listen_tls = 0/g' \ - -e 's/#listen_tcp = 1/listen_tcp = 1/g' \ - -e 's/#auth_tcp = "sasl"/auth_tcp = "none"/g' -sudo sed -i /etc/init/libvirt-bin.conf \ - -e 's/env libvirtd_opts="-d"/env libvirtd_opts="-d -l"/g' -sudo sed -i /etc/default/libvirt-bin \ - -e 's/libvirtd_opts="-d"/libvirtd_opts="-d -l"/g' - -# restart libvirt -sudo service libvirt-bin restart - -# Remove the default network created by libvirt -sudo virsh net-destroy default -sudo virsh net-undefine default diff --git a/bin/pre_install_ovs.sh b/bin/install_openvswitch.sh similarity index 100% rename from bin/pre_install_ovs.sh rename to bin/install_openvswitch.sh diff --git a/bin/install_zookeeper.sh b/bin/install_zookeeper.sh new file mode 100644 index 0000000..c17bd01 --- /dev/null +++ b/bin/install_zookeeper.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +## Install ZooKeeper and OpenJDK 7 + +VERSION=3.4.6 + +sudo apt-get -y install openjdk-7-jdk + +sudo mkdir -p /opt/zookeeper +sudo chmod 00777 /opt/zookeeper +sudo chown root:root /opt/zookeeper + +cd /opt/zookeeper +wget http://mirrors.gigenet.com/apache/zookeeper/zookeeper-${VERSION}/zookeeper-${VERSION}.tar.gz +tar xzvf zookeeper-${VERSION}.tar.gz +mv zookeeper-${VERSION} zookeeper +cd zookeeper + +sudo mkdir -p /mnt/zookeeper +sudo chmod 00777 /mnt/zookeeper +sudo chown root:root /mnt/zookeeper + +echo "1" | tee /mnt/zookeeper/myid + +echo "# The number of milliseconds of each tick +tickTime=2000 +# The number of ticks that the initial +# synchronization phase can take +initLimit=5 +# The number of ticks that can pass between +# sending a request and getting an acknowledgement +syncLimit=2 +# the directory where the snapshot is stored. +# do not use /tmp for storage, /tmp here is just +# example sakes. +dataDir=/mnt/zookeeper +# the port at which the clients will connect +clientPort=2181 +server.1=:2888:3888 +server.2=:2888:3888 +server.3=:2888:3888 +# the directory where the log is stored +# dataLogDir=/mnt/zookeeper +# +# Be sure to read the maintenance section of the +# administrator guide before turning on autopurge. +# +# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance +# +# The number of snapshots to retain in dataDir +#autopurge.snapRetainCount=3 +# Purge task interval in hours +# Set to 0 to disable auto purge feature +#autopurge.purgeInterval=1 +" | tee /opt/zookeeper/zookeeper/conf/zoo.cfg + +# Start the service +# /opt/zookeeper/zookeeper/bin/zkServer.sh start diff --git a/bin/launch_docker_instance.py b/bin/launch_docker_instance.py new file mode 100644 index 0000000..b45e89e --- /dev/null +++ b/bin/launch_docker_instance.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python + +import sys +import os + +BRIDGE = "obr2" +# BRIDGE = "br2" +GATEWAY = "10.2.2.10" +NET_PREFIX = "10.2" +MAC_ADDR_PREFIX = "52:54:00:2d:" +IMAGE = "changbl/u1404-3" + + +def int_to_hex(n): + if not 1 <= n <= 254: + raise KeyError('Wrong value: number not within [1, 254]') + s = hex(n)[2:] + if len(s) == 2: + return s + else: + return '0' + s + + +def launch(subnet, begin, end): + for i in range(begin, end): + name = "%s.%s" % (subnet, i) + mac_addr = (MAC_ADDR_PREFIX + "%s:%s" % ( + int_to_hex(subnet), int_to_hex(i))) + +# cmd = """/root/pipework %s -i eth0 $(\ +# docker.io run --privileged=true -n=false --name=%s -d %s /usr/sbin/sshd -D\ +# ) %s.%s.%s/16@%s %s""" % ( +# BRIDGE, name, IMAGE, NET_PREFIX, subnet, i, GATEWAY, mac_addr) + + cmd = """/root/pipework %s -i eth0 $(\ +docker.io run -n=false --privileged=true --name=%s -d %s /usr/sbin/sshd -D\ +) dhcp %s""" % (BRIDGE, name, IMAGE, mac_addr) + + print cmd + os.system(cmd) + +""" +docker.io run --privileged=true -d -n=false \ + -lxc-conf="lxc.network.type = veth" \ + -lxc-conf="lxc.network.link = br2" \ + -lxc-conf="lxc.network.flags = up" \ + -lxc-conf="lxc.network.name = eth0" \ + -lxc-conf="lxc.network.ipv4 = 10.2.101.3/16" \ + -lxc-conf="lxc.network.hwaddr=52:54:00:2d:65:03" \ + -lxc-conf="lxc.network.ipv4.gateway = 10.2.1.10" \ + --name=101.3 changbl/u1401-1 /usr/sbin/sshd -D + +ID=$(docker.io run -n=false --name=test4 -d changbl/u1404-2 /usr/sbin/sshd -D) + +./pipework obr2 -i eth0 $ID dhcp 52:54:00:2d:c9:04 + +./pipework obr2 -i eth0 $ID 10.2.201.8/16@10.2.2.10 52:54:00:2d:c9:08 + +docker.io inspect da1fbd5421f7 | grep ID + +lxc-attach -n \ +da1fbd5421f75ef1a640019d4659489ee53faf4135f4e6feeb8872580f74549a -- /bin/bash +""" +# cmd = """docker.io run --privileged=true -d -n=false \ +# -lxc-conf="lxc.network.type = veth" \ +# -lxc-conf="lxc.network.link = %s" \ +# -lxc-conf="lxc.network.flags = up" \ +# -lxc-conf="lxc.network.name = eth0" \ +# -lxc-conf="lxc.network.ipv4 = %s.%s.%s/16" \ +# -lxc-conf="lxc.network.hwaddr=%s" \ +# -lxc-conf="lxc.network.ipv4.gateway = %s" \ +# --name=%s \ +# %s /usr/sbin/sshd -D""" % ( +# BRIDGE, NET_PREFIX, subnet, i, mac_addr, GATEWAY, name, IMAGE) +# + +if __name__ == "__main__": + subnet = int(sys.argv[1]) + begin = int(sys.argv[2]) + end = int(sys.argv[3]) + launch(subnet, begin, end) diff --git a/bin/launch_libvirt_instance.py b/bin/launch_libvirt_instance.py new file mode 100644 index 0000000..c43a100 --- /dev/null +++ b/bin/launch_libvirt_instance.py @@ -0,0 +1,94 @@ +#!/usr/bin/env python + +import sys +import os +import uuid + +XML_TEMPLATE = """ + %s + %s + 262144 + 1 + + hvm + + + + + + + destroy + restart + destroy + + /usr/bin/kvm + + + + +
+ + +
+ + + + + + + +
+ + + + + + +