自动化快速部署OpenStack Train版控制节点
Posted qsyj
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自动化快速部署OpenStack Train版控制节点相关的知识,希望对你有一定的参考价值。
[root@openstack-controller1 ~]#cat openstack-deploy-controller-node.sh
#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.101 openstack-controller1.qsyjsmy.com openstack-controller1" >> /etc/hosts
echo "172.31.7.107 openstack-compute1.qsyjsmy.com openstack-compute1" >> /etc/hosts
echo "172.31.7.108 openstack-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以上是关于自动化快速部署OpenStack Train版控制节点的主要内容,如果未能解决你的问题,请参考以下文章
OpenStack Train版 简单部署流程- ceilometer
OpenStack 运维 - 部署Keystone组件 [Train版]
⑩ OpenStack高可用集群部署方案(train版)—OpenStack对接Ceph存储
OpenStack Train版-11.启动实例(控制节点)