From 76693cce1664f6b1502c240c22168a7b566d7f73 Mon Sep 17 00:00:00 2001 From: ajmiller Date: Tue, 14 Apr 2015 10:51:22 -0700 Subject: [PATCH] Add devstack scripts that set up a working loadbalancer Change-Id: I18b4affccfc8773766e3eb66df7f97c8f58724e0 --- devstack/samples/README.md | 31 ++++++++++++++ devstack/samples/local.conf | 81 +++++++++++++++++++++++++++++++++++ devstack/samples/local.sh | 71 ++++++++++++++++++++++++++++++ devstack/samples/webserver.sh | 6 +++ 4 files changed, 189 insertions(+) create mode 100644 devstack/samples/README.md create mode 100755 devstack/samples/local.conf create mode 100755 devstack/samples/local.sh create mode 100755 devstack/samples/webserver.sh diff --git a/devstack/samples/README.md b/devstack/samples/README.md new file mode 100644 index 000000000..335720099 --- /dev/null +++ b/devstack/samples/README.md @@ -0,0 +1,31 @@ +This directory contains sample files for configuring neutron LBaaS using +devstack. By copying these files into the main devstack directory (not the +neutron-lbaas/devstack directory directly above this one), and running +stack.sh, you will create a fully functioning OpenStack installation running +a neutron-lbaas load balancer. + +1) Copy the files into place: + + cp local.conf local.sh webserver.sh + +where + + is the main devstack directory. Note: this is not + neutron-lbaas/devstack. + +2) Build your devstack: + + cd + ./stack.sh + +3) Test your loadbalancer: + + a) Determine the loadbalancer IP: + + source openrc admin admin + neutron lbaas-loadbalancer-show lb1 | grep vip_address + curl + + where is the VIP address for lb1. The subsequent invocations of + "curl " should demonstrate that the load balancer is alternating + between two member nodes. diff --git a/devstack/samples/local.conf b/devstack/samples/local.conf new file mode 100755 index 000000000..a9ddf9c71 --- /dev/null +++ b/devstack/samples/local.conf @@ -0,0 +1,81 @@ +# Sample ``local.conf`` that builds a devstack with neutron LBaaS Version 2 + +# NOTE: Copy this file to the root DevStack directory for it to work properly. + +# ``local.conf`` is a user-maintained settings file that is sourced from ``stackrc``. +# This gives it the ability to override any variables set in ``stackrc``. +# Also, most of the settings in ``stack.sh`` are written to only be set if no +# value has already been set; this lets ``local.conf`` effectively override the +# default values. + +# The ``localrc`` section replaces the old ``localrc`` configuration file. +# Note that if ``localrc`` is present it will be used in favor of this section. + +[[local|localrc]] + +# The name of the RECLONE environment variable is a bit misleading. It doesn't actually +# reclone repositories, rather it uses git fetch to make sure the repos are current. + +RECLONE=True + +# Load the external LBaaS plugin. + +enable_plugin neutron-lbaas https://git.openstack.org/openstack/neutron-lbaas + +LIBS_FROM_GIT+=python-neutronclient +DATABASE_PASSWORD=password +ADMIN_PASSWORD=password +SERVICE_PASSWORD=password +SERVICE_TOKEN=password +RABBIT_PASSWORD=password +# Enable Logging +LOGFILE=$DEST/logs/stack.sh.log +VERBOSE=True +LOG_COLOR=True +SCREEN_LOGDIR=$DEST/logs +# Pre-requisite +ENABLED_SERVICES=rabbit,mysql,key +# Horizon +ENABLED_SERVICES+=,horizon +# Nova +ENABLED_SERVICES+=,n-api,n-crt,n-obj,n-cpu,n-cond,n-sch +IMAGE_URLS+=",https://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-disk.img" +ENABLED_SERVICES+=,g-api,g-reg +# Neutron +ENABLED_SERVICES+=,q-svc,q-agt,q-dhcp,q-l3,q-meta +# Enable LBaaS V2 +ENABLED_SERVICES+=,q-lbaasv2 +# Cinder +ENABLED_SERVICES+=,c-api,c-vol,c-sch + +# enable DVR + +Q_PLUGIN=ml2 +Q_ML2_TENANT_NETWORK_TYPE=vxlan +Q_DVR_MODE=dvr_snat + + +LOGFILE=$DEST/logs/stack.sh.log + +# Old log files are automatically removed after 7 days to keep things neat. Change +# the number of days by setting ``LOGDAYS``. +LOGDAYS=2 + +# Swift +# ----- + +# Swift is now used as the back-end for the S3-like object store. If Nova's +# objectstore (``n-obj`` in ``ENABLED_SERVICES``) is enabled, it will NOT +# run if Swift is enabled. Setting the hash value is required and you will +# be prompted for it if Swift is enabled so just set it to something already: +SWIFT_HASH=66a3d6b56c1f479c8b4e70ab5c2000f5 + +# For development purposes the default of 3 replicas is usually not required. +# Set this to 1 to save some resources: +SWIFT_REPLICAS=1 + +# The data for Swift is stored by default in (``$DEST/data/swift``), +# or (``$DATA_DIR/swift``) if ``DATA_DIR`` has been set, and can be +# moved by setting ``SWIFT_DATA_DIR``. The directory will be created +# if it does not exist. +SWIFT_DATA_DIR=$DEST/data diff --git a/devstack/samples/local.sh b/devstack/samples/local.sh new file mode 100755 index 000000000..71bc9834d --- /dev/null +++ b/devstack/samples/local.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env bash + +# Sample ``local.sh`` that configures two simple webserver instances and sets +# up a Neutron LBaaS Version 2 loadbalancer. + +# Keep track of the DevStack directory +TOP_DIR=$(cd $(dirname "$0") && pwd) +BOOT_DELAY=60 + +# Import common functions +source ${TOP_DIR}/functions + +# Use openrc + stackrc for settings +source ${TOP_DIR}/stackrc + +# Destination path for installation ``DEST`` +DEST=${DEST:-/opt/stack} + +if is_service_enabled nova; then + + # Get OpenStack demo user auth + source ${TOP_DIR}/openrc demo demo + + # Create an SSH key to use for the instances + DEVSTACK_LBAAS_SSH_KEY_NAME=$(hostname)_DEVSTACK_LBAAS_SSH_KEY_RSA + DEVSTACK_LBAAS_SSH_KEY_DIR=${TOP_DIR} + DEVSTACK_LBAAS_SSH_KEY=${DEVSTACK_LBAAS_SSH_KEY_DIR}/${DEVSTACK_LBAAS_SSH_KEY_NAME} + rm -f ${DEVSTACK_LBAAS_SSH_KEY}.pub ${DEVSTACK_LBAAS_SSH_KEY} + ssh-keygen -b 2048 -t rsa -f ${DEVSTACK_LBAAS_SSH_KEY} -N "" + nova keypair-add --pub_key=${DEVSTACK_LBAAS_SSH_KEY}.pub ${DEVSTACK_LBAAS_SSH_KEY_NAME} + + # Add tcp/22,80 and icmp to default security group + nova secgroup-add-rule default tcp 22 22 0.0.0.0/0 + nova secgroup-add-rule default tcp 80 80 0.0.0.0/0 + nova secgroup-add-rule default icmp -1 -1 0.0.0.0/0 + + # Boot some instances + NOVA_BOOT_ARGS="--key-name ${DEVSTACK_LBAAS_SSH_KEY_NAME} --image $(nova image-list | awk '/ cirros-0.3.0-x86_64-disk / {print $2}') --flavor 1 --nic net-id=$(neutron net-list | awk '/ private / {print $2}')" + + nova boot ${NOVA_BOOT_ARGS} node1 + nova boot ${NOVA_BOOT_ARGS} node2 + + echo "Waiting ${BOOT_DELAY} seconds for instances to boot" + sleep ${BOOT_DELAY} + + IP1=$(nova show node1 | grep "private network" | awk '{print $5}') + IP2=$(nova show node2 | grep "private network" | awk '{print $5}') + + ssh-keygen -R ${IP1} + ssh-keygen -R ${IP2} + + # Run a simple web server on the instances + scp -i ${DEVSTACK_LBAAS_SSH_KEY} -o StrictHostKeyChecking=no ${TOP_DIR}/webserver.sh cirros@${IP1}:webserver.sh + scp -i ${DEVSTACK_LBAAS_SSH_KEY} -o StrictHostKeyChecking=no ${TOP_DIR}/webserver.sh cirros@${IP2}:webserver.sh + + screen_process node1 "ssh -i ${DEVSTACK_LBAAS_SSH_KEY} -o StrictHostKeyChecking=no cirros@${IP1} ./webserver.sh" + screen_process node2 "ssh -i ${DEVSTACK_LBAAS_SSH_KEY} -o StrictHostKeyChecking=no cirros@${IP2} ./webserver.sh" + +fi + +if is_service_enabled q-lbaasv2; then + + neutron lbaas-loadbalancer-create --name lb1 private-subnet + sleep 10 + neutron lbaas-listener-create --loadbalancer lb1 --protocol HTTP --protocol-port 80 --name listener1 + sleep 10 + neutron lbaas-pool-create --lb-algorithm ROUND_ROBIN --listener listener1 --protocol HTTP --name pool1 + neutron lbaas-member-create --subnet private-subnet --address ${IP1} --protocol-port 80 pool1 + neutron lbaas-member-create --subnet private-subnet --address ${IP2} --protocol-port 80 pool1 + +fi diff --git a/devstack/samples/webserver.sh b/devstack/samples/webserver.sh new file mode 100755 index 000000000..ee4662cf7 --- /dev/null +++ b/devstack/samples/webserver.sh @@ -0,0 +1,6 @@ +#!/bin/ash + +MYIP=$(/sbin/ifconfig eth0|grep 'inet addr'|awk -F: '{print $2}'| awk '{print $1}'); +while true; do + echo -e "HTTP/1.0 200 OK\r\n\r\nWelcome to $MYIP" | sudo nc -l -p 80 +done