cloudstack的manager端自动部署shell脚本

cloudstack manager 端安装和配置主要包括以下工作;

        1.configure hostname
        2.install dependedpackage
        3.install CloudStack
        4.install MySql
        5.configure MySql
        6.configure SELINUX
        7.configure database
        8.configure sudo
        9.start CloudStack

将其写成shell脚本自动部署,代码如下,在虚机上多次测试可用:

#!/bin/bash
#Install cloudstack for manager
#write by CHC
#2014.8.8
menu()
{
clear
scriptname="autocloudstack_manager.sh"
version=1.0.0
date=`date +%F.%T`
name="chc and tonny"

cat << MENULIST
====================================================================================

ScriptName:$scriptname   Version:$version   Date&Time:$date   Name:$name

====================================================================================
This shell script can automatically complete the following configuration:

        1.configure hostname
        2.install dependedpackage
        3.install CloudStack
        4.install MySql
        5.configure MySql
        6.configure SELINUX
        7.configure database
        8.configure sudo
        9.start CloudStack

====================================================================================
MENULIST
}
#menu

#del_num=`ifconfig -a | grep -v virbr0-nic | sed -e '/virbr0/=' | grep '^[0-9][0-9]' | awk  '{print $1+1}'`
ipaddra=`ifconfig -a  | grep inet | grep -v inet6 | grep -v 127.0.0.1 | awk '{print $2}' | awk -F : '{print $2}'`

####################################################################################
configure_hostname()
{
    echo -n "Do you want to configure hostname in  /etc/hosts file?[y|n]"
    read myselect
    if [[ "$myselect" = "y" || "$myselect" = "Y" ]]
    then
        unset myselect
        clear
        cp /etc/hosts /root/hosts.`date +%F-%T`
        egrep -v '^([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([2-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])' /etc/hosts > /root/hosts.txt
        mv /root/hosts.txt /etc/hosts
        echo -n "Please input your hostname[eg:xxxx.cloudstack.com]:"
        read line_hostname1
        line_hostname=`echo "$line_hostname1.cloudstack.com"`
        hname=`echo $line_hostname | awk -F . '{print $1}'`
        sed "/$ipaddra/d" /etc/hosts | sed "$ a\\$ipaddra        $line_hostname       $hname" >/root/hosts
        cp /root/hosts /etc/hosts
        sed -i "/HOSTNAME/c\HOSTNAME=$line_hostname" /etc/sysconfig/network
        grep "NOZEROCONF=yes" /etc/sysconfig/network >> /dev/null || echo "NOZEROCONF=yes">>/etc/sysconfig/network
        echo -e "\nThe new /etc/hosts file's content:\n"
        cat /etc/hosts
        echo -e "\nThe new /etc/sysconfig/network file's content:\n"
        cat /etc/sysconfig/network
        echo
fi
echo
}

#configure_hostname


installCloudStack()
{
   echo  -e "\n3.install CloudStack:\n"
   read -p "please input a path to install cloudstack   " path1
   cd $path1
   ls cloudstack-common-4.2.1-SNAPSHOT.el6.x86_64.rpm cloudstack-awsapi-4.2.1-SNAPSHOT.el6.x86_64.rpm cloudstack-management-4.2.1-SNAPSHOT.el6.x86_64.rpm 2> /dev/null || return 1
   yum  remove cloudstack-common-4.2.1-SNAPSHOT.el6.x86_64 cloudstack-awsapi-4.2.1-SNAPSHOT.el6.x86_64 cloudstack-management-4.2.1-SNAPSHOT.el6.x86_64
   yum localinstall ./cloudstack-common-4.2.1-SNAPSHOT.el6.x86_64.rpm ./cloudstack-awsapi-4.2.1-SNAPSHOT.el6.x86_64.rpm ./cloudstack-management-4.2.1-SNAPSHOT.el6.x86_64.rpm
echo
}
####################################################################################
install()
{   
    echo -n "Do you want to install dependedpackage?[y|n]"
    read myselect
    if [[ "$myselect" = "y" || "$myselect" = "Y" ]]
    then
        unset myselect
        clear
     # 2.install dependedpackage
       echo  -e "\n2.install dependedpackage:\n"
       echo  -e "yum install -y ntp ws-commons-util tomcat6 mysql-connector-java mkisofs ipmitooll MySQL-python\n\n"
       yum install -y ntp ws-commons-util tomcat6 mysql-connector-java mkisofs ipmitooll MySQL-python
    fi

    echo -n "Do you want to install cloudstack?[y|n]"
    read myselect
    if [[ "$myselect" = "y" || "$myselect" = "Y" ]]
    then
        unset myselect
        clear
     # 3.install CloudStack
        installCloudStack
         while([ $? == 1 ])
         do
           echo  -e "\n2Bad path!!! There is no cloudstack rmp!!! \n"
           installCloudStack
         done
    fi

     # 4.install MySql
    echo -n "Do you want to install mysql-server?[y|n]"
    read myselect
    if [[ "$myselect" = "y" || "$myselect" = "Y" ]]
    then
        unset myselect
        clear
       echo  -e "\n4.install MySql:\n"
       yum remove mysql-server
       yum install -y mysql-server
    fi
echo
}
#install
####################################################################################
configure()
{
    echo -n "Do you want to configue mysql in /etc/my.cnf ?[y|n]"
    read myselect
    if [[ "$myselect" = "y" || "$myselect" = "Y" ]]
    then
        unset myselect
        clear
     cp /etc/my.cnf /root/my.cnf.`date +%F-%T`
     num_mysqld=`sed -n '/\[mysqld\]/=' /etc/my.cnf | awk  '{print $1+1}'`
     cp /etc/my.cnf /etc/my.cb
     cat /etc/my.cb
     grep "binlog-format = 'ROW'" /etc/my.cb >>/dev/null || more /etc/my.cb | sed "$num_mysqld a\binlog-format = 'ROW'" > /etc/my.cnf
     cp /etc/my.cnf /etc/my.cb
     grep "log-bin=mysql-bin" /etc/my.cb>>/dev/null || more /etc/my.cb | sed "$num_mysqld a\log-bin=mysql-bin" > /etc/my.cnf
     cp /etc/my.cnf /etc/my.cb
     grep "max_connections=350" /etc/my.cb>>/dev/null || more /etc/my.cb | sed "$num_mysqld a\max_connections=350" > /etc/my.cnf
     cp /etc/my.cnf /etc/my.cb
     grep "innodb_lock_wait_timeout=600" /etc/my.cb>>/dev/null  || more /etc/my.cb | sed "$num_mysqld a\innodb_lock_wait_timeout=600" > /etc/my.cnf
     cp /etc/my.cnf /etc/my.cb
     grep "innodb_rollback_on_timeout=1" /etc/my.cb>>/dev/null || more /etc/my.cb | sed "$num_mysqld a\innodb_rollback_on_timeout=1" > /etc/my.cnf
     echo -e "\nThe new /etc/my.cnf:\n"
     cat  /etc/my.cnf
    fi

   echo -n "Do you want to start mysqld ?[y|n]"
   read myselect
   if [[ "$myselect" = "y" || "$myselect" = "Y" ]]
   then
        unset myselect
        clear
      service mysqld start
   fi


   echo -n "Do you want to set mysqld_root_password ?[y|n]"
   read myselect
   if [[ "$myselect" = "y" || "$myselect" = "Y" ]]
   then
        unset myselect
        clear
        mysql_secure_installation
   fi


   echo -n "Do you want to set SELINUX ?[y|n]"
   read myselect
   if [[ "$myselect" = "y" || "$myselect" = "Y" ]]
   then
        unset myselect
        clear
        echo -e "\nSet SELINUX:\n"
        a_SELINUX=`sed -n '/SELINUX=/ p' /etc/selinux/config | grep -v '^#'`
        sed -i "/$a_SELINUX/c\SELINUX=permissive" /etc/selinux/config
        setenforce permissive
        if [[ SELINUX == disabled ]]
        then
          echo -e "\nNeed to reboot to set SELINUX锛侊紒锛侊紒\n"
        fi
        echo -e "\n /etc/selinux/config list as follow: \n"
        cat /etc/selinux/config
   fi

   echo -n "Do you want to set cloud_database ?[y|n]"
   read myselect
   if [[ "$myselect" = "y" || "$myselect" = "Y" ]]
   then
        unset myselect
        clear
       echo -e "\nSet cloud_database:\n"
       read -p "please input cloudstack_password   "  passwd1
       read -p "please input mysql_root_password   "  passwd2
       cloudstack-setup-databases cloud:$passwd1@localhost --deploy-as=root:$passwd2
       echo -e "\nSet sudo:\n"
       chmod +w /etc/sudoers
       grep 'Defaults:cloud !requiretty' /etc/sudoers>>/dev/null ||echo 'Defaults:cloud !requiretty' >> /etc/sudoers
       chmod -w /etc/sudoers
       echo -e "\nThe new tail -n 15 /etc/sudoers:\n"
       tail -n 15 /etc/sudoers
   fi
echo
}
#configure

####################################################################################
startCloudStack()
{
   echo -n "Do you want to start cloudstack ?[y|n]"
   read myselect
   if [[ "$myselect" = "y" || "$myselect" = "Y" ]]
   then
        unset myselect
        clear
        cloudstack-setup-management
   fi 
  echo
}
####################################################################################

menu
configure_hostname
install
configure
startCloudStack


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值