OpenStack-Train版-Allinone自动化部署脚本

一、环境准备

  • 操作系统:CentOS 7 或以上版本

  • 建议配置:

    • CPU:8 核或以上

    • 内存:16 GB 或以上

    • 磁盘:500 GB 或以上

  • 网络配置:

    • 确保虚拟机已配置静态 IP 地址

    • 确保虚拟机可以正常访问外部网络

二、自动化部署脚本

bash 复制代码
#!/bin/bash

# 设置主机名
hostnamectl set-hostname openstack.alione.local
echo "Hostname set to openstack.alione.local"

# 修改/etc/hosts文件
echo "172.16.12.48 openstack openstack.alione.local" >> /etc/hosts
echo "/etc/hosts updated with the new hostname and IP address"

# 生成SSH密钥对
ssh-keygen -t rsa -b 2048 -f /root/.ssh/id_rsa -q -N ""
echo "SSH key pair generated"

# 将公钥复制到本机
ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.16.13.44
echo "Public SSH key copied to root@172.16.13.44"

# 禁用SELinux
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
setenforce 0
echo "SELinux disabled"

# 停用并禁用firewalld
systemctl stop firewalld
systemctl disable firewalld
echo "Firewalld stopped and disabled"

# 停用并禁用NetworkManager
systemctl stop NetworkManager
systemctl disable NetworkManager
echo "NetworkManager stopped and disabled"

echo "nameserver 8.8.8.8" >> /etc/resolv.conf

# 更换为阿里云的CentOS镜像源
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
echo "YUM repository switched to Aliyun"

# 清理并重建缓存
yum clean all
yum makecache
echo "YUM cache cleaned and rebuilt"

# 安装基本软件包
yum install -y bash-completion vim telnet bridge-utils yum-utils
echo "Basic packages installed"

# 更新系统
yum -y update
echo "System updated"

# 添加OpenStack Train仓库
yum install -y centos-release-openstack-train
echo "OpenStack Train repository added"

# 修改OpenStack仓库配置
sed -i 's|^#baseurl=http://mirror.centos.org/\$contentdir/\$releasever/cloud/\$basearch/openstack-train/|baseurl=https://mirrors.aliyun.com/centos-vault/7.9.2009/cloud/x86_64/openstack-train/|' /etc/yum.repos.d/CentOS-OpenStack-train.repo
sed -i 's|^mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=cloud-openstack-train|#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=cloud-openstack-train|' /etc/yum.repos.d/CentOS-OpenStack-train.repo
echo "CentOS-OpenStack-train.repo configured for Aliyun mirrors"

# 修改Ceph Nautilus仓库配置
sed -i 's|^#baseurl=http://mirror.centos.org/\$contentdir/\$releasever/storage/\$basearch/ceph-nautilus/|baseurl=https://mirrors.aliyun.com/centos-vault/7.9.2009/storage/x86_64/ceph-nautilus/|' /etc/yum.repos.d/CentOS-Ceph-Nautilus.repo
sed -i 's|^mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=storage-ceph-nautilus|#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=storage-ceph-nautilus|' /etc/yum.repos.d/CentOS-Ceph-Nautilus.repo
echo "CentOS-Ceph-Nautilus.repo configured for Aliyun mirrors"

# 修改NFS Ganesha 28仓库配置
sed -i 's|^#baseurl=https://mirror.centos.org/\$contentdir/\$releasever/storage/\$basearch/nfs-ganesha-28/|baseurl=https://mirrors.aliyun.com/centos-vault/7.9.2009/storage/x86_64/nfs-ganesha-28/|' /etc/yum.repos.d/CentOS-NFS-Ganesha-28.repo
sed -i 's|^mirrorlist=http://mirrorlist.centos.org?arch=\$basearch&release=\$releasever&repo=storage-nfs-ganesha-28|#mirrorlist=http://mirrorlist.centos.org?arch=\$basearch&release=\$releasever&repo=storage-nfs-ganesha-28|' /etc/yum.repos.d/CentOS-NFS-Ganesha-28.repo
echo "CentOS-NFS-Ganesha-28.repo configured for Aliyun mirrors"

# 修改QEMU EV仓库配置
sed -i 's|^#baseurl=http://mirror.centos.org/\$contentdir/\$releasever/virt/\$basearch/kvm-common/|baseurl=https://mirrors.aliyun.com/centos-vault/7.9.2009/virt/x86_64/kvm-common/|' /etc/yum.repos.d/CentOS-QEMU-EV.repo
sed -i 's|^mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=virt-kvm-common|#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=virt-kvm-common|' /etc/yum.repos.d/CentOS-QEMU-EV.repo
echo "CentOS-QEMU-EV.repo configured for Aliyun mirrors"


# 再次清理并重建缓存
yum clean all
yum makecache
echo "YUM cache cleaned and rebuilt after repository configuration"

# 安装Packstack
yum install -y openstack-packstack
echo "Packstack installed"

# 执行Packstack全栈安装
packstack --allinone
echo "Packstack all-in-one installation initiated"
相关推荐
玉树临风江流儿15 小时前
Linux驱动开发总结速记
linux·运维·驱动开发
七宝大爷16 小时前
GPU服务器深度解析:H100/H200的“机头”与“模组”架构详解
运维·服务器·架构·h100·h200
A-花开堪折17 小时前
Qemu 嵌入式Linux驱动开发
linux·运维·驱动开发
磊灬泽17 小时前
【Linux驱动开发】PWM子系统-servo
linux·运维·算法
郝学胜-神的一滴18 小时前
Linux系统函数stat和lstat详解
linux·运维·服务器·开发语言·c++·程序人生·软件工程
Mr.亮先生18 小时前
常用、高效、实用的 Linux 服务器监控与运维工具清单
linux·运维·服务器
极客先躯19 小时前
高可用巡检脚本实战:一键掌握服务、网络、VIP、资源状态
运维·网络·金融
鹿鸣天涯19 小时前
Wine 10.15 发布!Linux 跑 Windows 应用更丝滑了
linux·运维·windows
西欧伯爵19 小时前
Playwright自动化实战一
自动化测试·自动化·playwright
Lynnxiaowen20 小时前
今天我们继续学习python3编程之python基础
linux·运维·python·学习