【自动化快速部署OpenStack Train版控制节点】识字粗堪供赋役,不须辛苦慕公卿。这篇文章主要讲述自动化快速部署OpenStack Train版控制节点相关的知识,希望能为你提供帮助。
[root@openstack-controller1 ~]#cat openstack-deploy-controller-node.sh
#!/bin/bash
#Author:QsyjSmy
#Date:2022-01-24
#QQ:582673967
#定义变量
HOST_IP=`ifconfig | grep 172 | awk print $2`
FIREWALLD_STATUS=`systemctl is-enabled firewalld.service`
GETENFORCE_STATUS=`getenforce`
#更改hosts文件
function setup-hosts
echo "172.31.7.101openstack-controller1.qsyjsmy.com openstack-controller1" > > /etc/hosts
echo "172.31.7.107openstack-compute1.qsyjsmy.com openstack-compute1" > > /etc/hosts
echo "172.31.7.108openstack-compute2.qsyjsmy.com openstack-compute2" > > /etc/hosts
#关闭防火墙与selinux
function disable-firewalld-seliunx
if [ $FIREWALLD_STATUS != disabled ]
then
systemctl disable --now firewalld.service & & echo "防火墙禁用成功" & & sleep 3
fi
if [ $GETENFORCE_STATUS != disabled ]
then
sed -i.bak s/^\\(SELINUX=\\).*/\\1disabled/g /etc/selinux/config & & echo "selinux禁用成功" & & sleep 3
fi
#配置阿里云yum源
function setup-aliyun-yum
yum repolist | grep aliyun & > /dev/null
if [ $? -ne 0 ]
then
mkdir -p /etc/yum.repos.d/back/ & & mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/back/
ping -c 3 www.baidu.com & > /dev/null & & curl -so /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[ -f /etc/yum.repos.d/CentOS-Base.repo ] || ( echo "阿里云yum源下载失败,请检查网络配置,,脚本正在退出..." & & sleep 3 & & exit 1 )
yum clean all & > /dev/null & & yum makecache & > /dev/null & & yum repolist | grep aliyun & > /dev/null & & echo "阿里云yum源配置成功" & & sleep 3
fi
#安装常用基础命令
function install-software
yum install -y vim wget tree lrzsz gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel openssl openssl-devel iproute net-tools iotop lsof \\
ntpdate telnet bridge-utils bash-completion sshpass libibverbs & & echo "常用基础命令安装完成" & & sleep 3
#配置时钟同步
function setup-timedate
crontab -l | grep "ntp.aliyun.com" || echo "*/10 * * * * /usr/sbin/ntpdate ntp.aliyun.com & & /usr/sbin/hwclock -w" | crontab & & \\
echo "时钟同步配置成功"
echo "当前服务器时间是: `date +%Y年%m月%d日 %H时%M分%S秒`" & & sleep 3
#安装Train版yum源
function install-train-yum
yum list centos-release-openstack* | grep "centos-release-openstack-train" & > /dev/null & & yum install -y centos-release-openstack-train.noarch
if [ $? -eq 0 ]
then
yum install -y https://rdoproject.org/repos/rdo-release.rpm & & yum repolist | grep train & > /dev/null & & echo "Train版yum源安装完成" & & \\
sleep 3
else
echo "Train版yum源安装失败,请检查网络配置,脚本正在退出..." & & sleep 3 & & exit 1
fi
#安装OpenStack客户端
function install-openstack-client
yum install -y python2-openstackclient.noarch & & echo "OpenStack客户端安装完成" & & sleep 3
#安装OpenStack selinux管理包
function install-openstack-selinux
yum install -y openstack-selinux.noarch & & echo "OpenStack客户端安装完成" & & sleep 3
#安装并配置mysql数据库服务
function install-mysql
yum install mariadb mariadb-server python2-PyMySQL -y & & sleep 3
if [ $? -eq 0 ]
then
wget -O /opt/openstack.conf http://www.qsyjsmy.com/testdir/openstack.conf & & cat /opt/openstack.conf > /etc/my.cnf.d/openstack.conf
systemctl enable --now mariadb.service; sleep 3 & & systemctl status mariadb.service || \\
echo "MySQL数据库服务启动失败,正在退出..."; sleep 3; exit 1; & & echo "MySQL数据库服务安装配置完成" & & sleep 3
else
echo "MySQL数据库服务安装失败,请检查网络配置,脚本正在退出..."; sleep 3; exit 1;
fi
#安装并配置RabbitMQ服务
function install-rabbitmq
yum install rabbitmq-server -y & & sleep 3
if [ $? -eq 0 ]
then
systemctl enable --now rabbitmq-server.service; sleep 3 & & netstat -tnlp | grep 5672 || \\
echo "RabbitMQ服务启动失败,正在退出..."; sleep 3; exit 1; & & echo "RabbitMQ服务启动成功" & & sleep 3
rabbitmqctl add_user openstack RABBIT_PASS; sleep 5 & & rabbitmqctl set_permissions openstack ".*" ".*" ".*"; sleep 5 & & \\
rabbitmq-plugins enable rabbitmq_management; sleep 5 & & echo "RabbitMQ服务配置成功" & & sleep 3
else
echo "RabbitMQ服务安装失败,请检查网络配置,脚本正在退出..."; sleep 3; exit 1;
fi
#安装并配置memcached服务
function install-memcached
yum install memcached python-memcached -y & & sleep 3
if [ $? -eq 0 ]
then
sed -i s/^\\(CACHESIZE=\\).*/\\1"1024"/g /etc/sysconfig/memcached
sed -i s/^\\(OPTIONS=\\).*/\\1"-l 0.0.0.0,::1"/g /etc/sysconfig/memcached
systemctl enable --now memcached.service; sleep 3 & & netstat -tnlp | grep memcached || \\
echo "memcached服务启动失败,正在退出..."; sleep 3; exit 1; & & echo "memcached服务配置成功" & & sleep 3
else
echo "memcached服务安装失败,请检查网络配置,脚本正在退出..."; sleep 3; exit 1;
fi
#安装并配置keystone服务
function install-keystone
#创建数据库并授权
mysql -e "CREATE DATABASE keystone; " & & \\
mysql -e "GRANT ALL PRIVILEGES ON keystone.* TO keystone@localhost IDENTIFIED BY KEYSTONE_DBPASS; " & & \\
mysql -e "GRANT ALL PRIVILEGES ON keystone.* TO keystone@% IDENTIFIED BY KEYSTONE_DBPASS; " & & \\
mysql -e "show databases; " | grep keystone ||echo "keystone服务创库授权失败,正在退出..."; sleep 3; exit 1; & & echo "创库授权完成" & & sleep 3
if [ $? -eq 0 ]
then
#安装keystone服务
yum install openstack-keystone httpd mod_wsgi -y & & echo "keystone服务安装成功" & & sleep 3
#配置keystone服务
cp /etc/keystone/keystone.conf,.bak & & wget -O /opt/keystone.conf http://www.qsyjsmy.com/testdir/keystone.conf & & \\
cat /opt/keystone.conf > /etc/keystone/keystone.conf
#初始化数据库
su -s /bin/sh -c "keystone-manage db_sync" keystone; sleep 3 & & mysql -e "use keystone; show tables; " | grep "access_rule" || \\
echo "初始化数据库失败,正在退出..."; sleep 3; exit 1; & & echo "初始化数据库成功" & & sleep 3
#初始化证书
keystone-manage fernet_setup --keystone-user keystone --keystone-group keystone & & \\
keystone-manage credential_setup --keystone-user keystone --keystone-group keystone & & \\
[ -d /etc/keystone/credential-keys/ -a -d /etc/keystone/fernet-keys/ ] ||echo "初始化证书失败,正在退出..."; sleep 3; exit 1; & & \\
echo "证书初始化成功" & & sleep 3
#初始化OpenStack
keystone-manage bootstrap --bootstrap-password ADMIN_PASS
推荐阅读
- #私藏项目实操分享#现代企业信息化综合运维管理实例
- 2021前端校招直通车,实现Offer零距离
- 全网稀缺的DDD(领域驱动设计)思想解读及落地指南
- 笨叔(用4维空间来理解进程负载)
- HCIE-Security Day2(防火墙安全区域理解实验)
- #yyds干货盘点#Linux系统文件权限与归属
- 用于WordPress插件开发的7个精彩的工具
- 如何使用Python生成罗马风格的马赛克(代码实现)
- 如何修改Windows 10环境变量(详细图解)