Openstack平臺部署+節點擴容python
1)搭建腳本apache
1 #!/bin/bash 2 #openstack私有云平臺部署 3 #腳本使用前提:三臺虛擬機openstack(ip地址:192.168.1.10,至少7G內存,50G硬盤),nova01(ip地址:192.168.1.11至少4G內存,100G硬盤),擴容用nova02(ip地址:192.168.1.12至少4G內存,100G硬盤);yum源正常;本次部署爲精簡版安裝 4 source /root/moudle.sh 5 while : 6 do 7 echo "#############################_menu_##################################" 8 echo "1.openstack服務器環境部署與檢查" 9 echo "2.nova環境部署與檢查" 10 echo "3.openstack服務安裝與登陸" 11 echo "4.openstack節點擴容" 12 echo "5.exit" 13 echo "#####################################################################" 14 read -p "請輸入您要部署的服務(1|2|3|4|5):" select 15 if [ "$select" == "1" ];then 16 env_openstack 17 elif [ "$select" == "2" ];then 18 env_nova 19 elif [ "$select" == "3" ];then 20 install_openstack 21 elif [ "$select" == "4" ];then 22 ext_nova 23 elif [ "$select" == "5" ];then 24 exit 25 else 26 echo "I AM SORRY" 27 sleep 2 28 fi 29 done
2)腳本模塊centos
1 #!/bin/bash 2 #函數定義 3 env_openstack() 4 { 5 hostnamectl set-hostname openstack 6 hostname openstack 7 sleep 1 8 echo "1.主機名已同步" 9 10 echo "192.168.1.10 openstack 11 192.168.1.11 nova01 12 192.168.1.12 nova02 13 " >> /etc/hosts 14 sleep 1 15 echo "2.域名已同步" 16 17 sed -i '/search/d' /etc/resolv.conf 18 sleep 1 19 echo "3.域名解析服務器已指定" 20 21 sed -i '7 s/gateway/192.168.1.254/' /etc/chrony.conf #1.254是真機ip 22 systemctl restart chronyd 23 sleep 5 24 if [ `chronyc sources -v | tail -1 | awk '{print $1}'` == ^* ];then 25 echo "4.時間同步成功" 26 else 27 echo '##########!!!時間未同步,請檢查' 28 fi 29 30 echo "[local_repo] 31 name=CentOS-$releasever - Base 32 baseurl="ftp://192.168.1.254/centos-1804" 33 enabled=1 34 gpgcheck=0 35 [extras] 36 name=extras 37 baseurl="ftp://192.168.1.254/extras/" 38 enabled=1 39 gpgcheck=0 40 [openstack1] 41 name=openstack1 42 baseurl="ftp://192.168.1.254/openstack/rhel-7-server-openstack-10-rpms" 43 enabled=1 44 gpgcheck=0 45 [openstack2] 46 name=openstack2 47 baseurl="ftp://192.168.1.254/openstack/rhel-7-server-openstack-10-devtools-rpms" 48 enabled=1 49 gpgcheck=0 50 " > /etc/yum.repos.d/local.repo 51 sleep 1 52 if [ `yum repolist | tail -1 | awk '{print $2}'` == "10,670" ];then 53 echo "5.yum源配置成功" 54 else 55 echo "##########!!!yum源有問題" 56 fi 57 58 yum remove firewalld-* &>/dev/null;yum remove NetworkManager &>/dev/null 59 sleep 1 60 echo "6.已卸載firewalld和NetworkManager" 61 sleep 1 62 if [ `cat /etc/sysconfig/network-scripts/ifcfg-eth0 | awk -F'"' '/ONBOOT/{print $2}'` == "yes" ];then 63 echo "7.network衝突解決" 64 else 65 echo "###########!!!network衝突" 66 fi 67 sleep 1 68 ping -c 3 192.168.1.11 &>/dev/null && ping -c 3 192.168.1.12 &>/dev/null && echo "8.網絡暢通" || echo "##########!!!請檢查網絡" 69 sleep 1 70 echo "環境依賴包安裝,請稍等..." 71 sleep 1 72 yum -y install python-setuptools &> /dev/null && echo "9.依賴包安裝成功,環境配置完畢,請進行下一步,安裝openstack服務" 73 sleep 1.5 74 } 75 76 env_nova() 77 { 78 read -p "請輸入主機名尾號(01|02):" a 79 hostnamectl set-hostname nova$a 80 hostname nova$a 81 sleep 1 82 echo "1.主機名已同步" 83 84 echo "192.168.1.10 openstack 85 192.168.1.11 nova01 86 192.168.1.12 nova02 87 " >> /etc/hosts 88 sleep 1 89 echo "2.域名已同步" 90 91 sed -i '/search/d' /etc/resolv.conf 92 sleep 1 93 echo "3.域名解析服務器已指定" 94 95 sed -i '7 s/gateway/192.168.1.254/' /etc/chrony.conf #1.254是真機ip 96 systemctl restart chronyd 97 sleep 5 98 if [ `chronyc sources -v | tail -1 | awk '{print $1}'` == "^*" ];then 99 echo "4.時間同步成功" 100 else 101 echo '##########!!!時間未同步,請檢查' 102 fi 103 104 echo "[local_repo] 105 name=CentOS-$releasever - Base 106 baseurl="ftp://192.168.1.254/centos-1804" 107 enabled=1 108 gpgcheck=0 109 [extras] 110 name=extras 111 baseurl="ftp://192.168.1.254/extras/" 112 enabled=1 113 gpgcheck=0 114 [openstack1] 115 name=openstack1 116 baseurl="ftp://192.168.1.254/openstack/rhel-7-server-openstack-10-rpms" 117 enabled=1 118 gpgcheck=0 119 [openstack2] 120 name=openstack2 121 baseurl="ftp://192.168.1.254/openstack/rhel-7-server-openstack-10-devtools-rpms" 122 enabled=1 123 gpgcheck=0 124 " > /etc/yum.repos.d/local.repo 125 sleep 1 126 if [ `yum repolist | tail -1 | awk '{print $2}'` == "10,670" ];then 127 echo "5.yum源配置成功" 128 else 129 echo "##########!!!yum源有問題" 130 fi 131 yum remove firewalld-* &>/dev/null;yum remove NetworkManager &>/dev/null 132 sleep 1 133 echo "6.已卸載firewalld和NetworkManager" 134 sleep 1 135 if [ `cat /etc/sysconfig/network-scripts/ifcfg-eth0 | awk -F'"' '/ONBOOT/{print $2}'` == "yes" ];then 136 echo "7.network衝突解決" 137 else 138 echo "###########!!!network衝突" 139 fi 140 sleep 1 141 ping -c 3 192.168.1.10 &>/dev/null && ping -c 3 192.168.1.12 &>/dev/null && echo "8.網絡暢通" || echo "##########!!!請檢查網絡" 142 143 echo "環境依賴包安裝,請稍等..." 144 yum -y install python-setuptools qemu-kvm libvirt-daemon libvirt-daemon-driver-qemu libvirt-client &> /dev/null && echo "9.依賴包安裝成功,環境配置完畢,請進行下一步" 145 sleep 1.5 146 } 147 148 install_openstack() 149 { 150 yum -y install openstack-packstack 151 cd /root/ 152 packstack --gen-answer-file=answer.ini 153 sed -i '42 s/=y/=n/' answer.ini 154 sed -i '45 s/=y/=n/' answer.ini 155 sed -i '49 s/=y/=n/' answer.ini 156 sed -i '53 s/=y/=n/' answer.ini 157 sed -i '75 s/=/=192.168.1.254/' answer.ini 158 sed -i '98 s/1.10/1.11/' answer.ini 159 sed -i '102 s/1.10/1.10,192.168.1.11/' answer.ini 160 sed -i '333 s/=.*$/=a/' answer.ini 161 sed -i '840 s/=vx/=flat,vx/' answer.ini 162 sed -i '910 s/=/=physnet1:br-ex/' answer.ini 163 sed -i '921 s/=/=br-ex:eth0/' answer.ini 164 sed -i '1179 s/=y/=n/' answer.ini 165 echo "開始安裝請耐心等待大約30min..." 166 packstack --answer-file=answer.ini 167 sed -i '/WSGIProcessGroup apache/a WSGIApplicationGroup %{GLOBAL}' /etc/httpd/conf.d/15-horizon-vhost.conf 168 apachectl graceful 169 echo "安裝成功!歡迎使用,請訪問如下網址http://192.168.1.10進行訪問,帳戶密碼爲您的應答文件設置" 170 } 171 172 ext_nova() 173 { 174 cd /root/ 175 sed -i '98 s/1.11/1.11,192.168.1.12/' answer.ini 176 sed -i '102 s/1.11/1.11,192.168.1.12/' answer.ini 177 echo "開始安裝請耐心等待大約30min..." 178 packstack --answer-file=answer.ini 179 sed -i '/WSGIProcessGroup apache/a WSGIApplicationGroup %{GLOBAL}' /etc/httpd/conf.d/15-horizon-vhost.conf 180 apachectl graceful 181 echo "擴容成功!歡迎使用,請訪問如下網址http://192.168.1.10進行訪問,帳戶密碼>爲您的應答文件設置" 182 }