Deploy Openstack all-in-one Shell Script

Deploy Openstack all-in-one Shell Script

At present(2015/10), the RDO deploment method can only install VNC console defalut,
and there is no other way to config the configuration file to change to Spice like DevStack.

The following script shows how to deploy quickly.

#!/bin/bash

###############################################
# This shell script is used to deploy openstack
# in one node (a vm or a physical machine)
# which host OS is CentOS (CentOS 7) is
# recommended.
# 
# Date: 2015/10/25
###############################################

# get the host ip address
# HOSTIP=`ifconfig | grep "inet " | grep -v "127.0.0.1" | awk '{print $2}'`
HOSTIP=`ifconfig | grep "inet " | grep -v "127.0.0.1" | cut -d: -f2 | awk '{print $1}'`

# update system and install openstack using packstack
sudo yum update -y &&
sudo yum install -y https://rdoproject.org/repos/rdo-release.rpm &&
sudo yum install -y openstack-packstack &&
packstack --allinone
if [[ $? == 0 ]];
then
    echo -e "\033[32m ****** Install Openstack successfully ****** \033[0m "
    systemctl stop openstack-nova-novncproxy.service
else
    echo -e "\033[33m ****** Install Openstack failed ****** \033[0m "
    sleep 3
    exit
fi

sleep 5

# simplify the nova configuration file
NOVACONF=/etc/nova/nova.conf
if [ -f $NOVACONF ];
then
    cp $NOVACONF $NOVACONF.bak &&
    cat $NOVACONF.bak | grep -v '^#' | grep -v '^$' > $NOVACONF
fi

sleep 10

# disable vnc server
sed -i '/vnc/d' $NOVACONF && sed -i '2a vnc_enabled=False' $NOVACONF

sleep 5

# install spice proxy
sudo yum install spice-html5 -y &&
sudo yum install openstack-nova-spicehtml5proxy -y &&

sleep 5

# add spice configutation
sudo sed -i '/spice/d' /etc/nova/nova.conf
if [[ $? == 0 ]];
then
    echo "[spice]" >> $NOVACONF
    echo "enabled=True" >> $NOVACONF
    echo "agent_enabled=true" >> $NOVACONF
    echo "server_listen=0.0.0.0" >> $NOVACONF
    echo "html5proxy_host=0.0.0.0" >> $NOVACONF
    echo "html5proxy_port=6082" >> $NOVACONF
    echo "html5proxy_base_url=http://$HOSTIP:6082/spice_auto.html" >> $NOVACONF
    echo "keymap=en-us" >> $NOVACONF
fi

# open the spice port
iptables -I INPUT -p tcp -m multiport --dports 6082 -m comment --comment "Allow SPICE connections for console access " -j ACCEPT

sleep 5

# restart related services
service openstack-nova-compute restart &&
service httpd restart &&
systemctl enable openstack-nova-spicehtml5proxy &&
systemctl start  openstack-nova-spicehtml5proxy.service

# print the result
if [[ $? == 0 ]];

then
    echo -e "\033[32m ***************************************************** \033[0m"
    echo -e "\033[32m ****** The OpenStack is deployed successfully******** \033[0m"
    echo -e "\033[32m ***************************************************** \033[0m"
fi

 

Run the following scrip as root and get the spice client access addresss:

#!/bin/sh


virsh list | grep "instance" > virshlist.log

ps -ef | grep spice > spiceport.log

hostip=`ifconfig | grep "inet " | grep -v "127.0.0.1" | awk '{print $2}'`

echo "Instance name               Access address"
echo "------------------------------------------------------------"

for i in `cat virshlist.log | awk {'print $2'}`
do
#    echo $i
    virsh dumpxml $i > $i.xml &&
    instance_name=`grep "nova:name" $i.xml | cut -d ">" -f 2 | cut -d "<" -f 1` &&
    spiceport=`grep $i spiceport.log | awk -F "port=" '{print $2}' | cut -d"," -f1` &&
    echo "\033[32m $instance_name \t\t $hostip:$spiceport \033[0m"
done

if downloading from fedora repo is too slowly or some problem like "Cannot retrieve repository"
please change the /etc/yum.repos.d/rdo-release.repo as following:

[openstack]
name=cloud
baseurl=http://mirrors.sohu.com/centos/7/cloud/x86_64/openstack-liberty/
gpgcheck=0
enabled=1
posted @ 2015-10-25 22:09  AndyBlog  阅读(406)  评论(0编辑  收藏  举报