OpenStack一键安装部署

本文档提供了两个自动化脚本,分别用于部署OpenStack控制器节点和计算节点。脚本涵盖了主机名设置、基础配置、YUM源配置、FTP服务器配置、SSH免密登录、iaas-xiandian软件包配置、安装过程以及部署结果验证。通过这些步骤,实现了OpenStack环境的快速搭建和验证。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

返回目录

OpenStack脚本controlller端部署

## 当前用户名判定:
function UserJudgment() {
  read -p "当前的主机名为${HOSTNAME},是否修改(y/n):"
  echo -n "正在改名....."
  dop1=controller
  hostnamectl set-hostname ${dop1}
  bash
}

## 基础配置:
function BasicConfig() {
  systemctl disable --now firewalld
  setenforce 0
  echo "192.168.100.10 controller" >>/etc/hosts
  echo "192.168.100.20 compute" >>/etc/hosts
}

## 挂载镜像:
function MountImage() {
  mkdir -p /opt/centos /opt/iaas
  echo "/dev/cdrom              /opt/centos             iso9660 defaults        0 0" >>/etc/fstab
  echo "/opt/chinaskills_cloud_iaas.iso /opt/iaas       iso9660 defaults        0 0" >>/etc/fstab
  mount -a
}

## 配置YUM源:
function YUMConfig() {
  rm -rf /etc/yum.repos.d/*
  touch /etc/yum.repos.d/local.repo
  echo -e "[centos]\nname=centos\nbaseurl=file:///opt/centos\nenabled=1\ngpgcheck=0" >>/etc/yum.repos.d/local.repo
  echo -e "[iaas]\nname=iaas\nbaseurl=file:///opt/iaas/iaas-repo\nenabled=1\ngpgcheck=0" >>/etc/yum.repos.d/local.repo
  yum makecache
}

## 配置FTP服务器
function FTPConfig() {
  yum -y install vsftpd
  echo "anon_root=/opt" >>/etc/vsftpd/vsftpd.conf
  systemctl start vsftpd && systemctl enable vsftpd
}

## 配置ssh免密登录,000000
function SSHConfig() {
  yum install -y expect
  systemctl daemon-reload
  echo "StrictHostKeyChecking no" >>/etc/ssh/ssh_config
  expect -c "
spawn ssh-keygen
expect \"(/root/.ssh/id_rsa):\"
send \"\r\"
expect \"(empty for no passphrase):\"
send \"\r\"
expect \"passphrase again\"
send \"\r\"
expect eof
"
  expect -c "
spawn ssh-copy-id 192.168.100.10
expect \"password: \"
send \"000000\r\"
expect eof
"
  expect -c "
spawn ssh-copy-id 192.168.100.20
expect \"password: \"
send \"000000\r\"
expect eof
"
}

## 配置iaas-xiandian软件包
function IaaSConfig() {
  yum install -y iaas-xiandian
  sed -i "3c HOST_IP=192.168.100.10" /etc/xiandian/openrc.sh
  sed -i "6c HOST_PASS=000000" /etc/xiandian/openrc.sh
  sed -i "9c HOST_NAME=controller" /etc/xiandian/openrc.sh
  sed -i "12c HOST_IP_NODE=192.168.100.20" /etc/xiandian/openrc.sh
  sed -i "15c HOST_PASS_NODE=000000" /etc/xiandian/openrc.sh
  sed -i "18c HOST_NAME_NODE=compute" /etc/xiandian/openrc.sh
  sed -i "22c network_segment_IP=192.168.100.0/24" /etc/xiandian/openrc.sh
  sed -i "26c RABBIT_USER=openstack" /etc/xiandian/openrc.sh
  sed -i "29c RABBIT_PASS=000000" /etc/xiandian/openrc.sh
  sed -i "33c DB_PASS=000000" /etc/xiandian/openrc.sh
  sed -i "37c DOMAIN_NAME=demo" /etc/xiandian/openrc.sh
  sed -i "38c ADMIN_PASS=000000" /etc/xiandian/openrc.sh
  sed -i "39c DEMO_PASS=000000" /etc/xiandian/openrc.sh
  sed -i "42c KEYSTONE_DBPASS=000000" /etc/xiandian/openrc.sh
  sed -i "46c GLANCE_DBPASS=000000" /etc/xiandian/openrc.sh
  sed -i "49c GLANCE_PASS=000000" /etc/xiandian/openrc.sh
  sed -i "53c NOVA_DBPASS=000000" /etc/xiandian/openrc.sh
  sed -i "56c NOVA_PASS=000000" /etc/xiandian/openrc.sh
  sed -i "60c NEUTRON_DBPASS=000000" /etc/xiandian/openrc.sh
  sed -i "63c NEUTRON_PASS=000000" /etc/xiandian/openrc.sh
  sed -i "66c METADATA_SECRET=000000" /etc/xiandian/openrc.sh
  sed -i "69c INTERFACE_IP=192.168.100.10" /etc/xiandian/openrc.sh
  sed -i "72c INTERFACE_NAME=ens33" /etc/xiandian/openrc.sh
  sed -i "75c Physical_NAME=provider" /etc/xiandian/openrc.sh
  sed -i "78c minvlan=101" /etc/xiandian/openrc.sh
  sed -i "81c maxvlan=200" /etc/xiandian/openrc.sh
  sed -i "85c CINDER_DBPASS=000000" /etc/xiandian/openrc.sh
  sed -i "88c CINDER_PASS=000000" /etc/xiandian/openrc.sh
  sed -i "91c BLOCK_DISK=sdb1" /etc/xiandian/openrc.sh
  sed -i "95c SWIFT_PASS=000000" /etc/xiandian/openrc.sh
  sed -i "98c OBJECT_DISK=sdb2" /etc/xiandian/openrc.sh
  sed -i "101c STORAGE_LOCAL_NET_IP=192.168.100.20" /etc/xiandian/openrc.sh
  sed -i "105c HEAT_DBPASS=000000" /etc/xiandian/openrc.sh
  sed -i "108c HEAT_PASS=000000" /etc/xiandian/openrc.sh
  sed -i "112c ZUN_DBPASS=000000" /etc/xiandian/openrc.sh
  sed -i "115c ZUN_PASS=000000" /etc/xiandian/openrc.sh
  sed -i "118c KURYR_DBPASS=000000" /etc/xiandian/openrc.sh
  sed -i "121c KURYR_PASS=000000" /etc/xiandian/openrc.sh
  sed -i "125c CEILOMETER_DBPASS=000000" /etc/xiandian/openrc.sh
  sed -i "128c CEILOMETER_PASS=000000" /etc/xiandian/openrc.sh
  sed -i "132c AODH_DBPASS=000000" /etc/xiandian/openrc.sh
  sed -i "135c AODH_PASS=000000" /etc/xiandian/openrc.sh
  sed -i "139c BARBICAN_DBPASS=000000" /etc/xiandian/openrc.sh
  sed -i "142c BARBICAN_PASS=000000" /etc/xiandian/openrc.sh
  source /etc/xiandian/openrc.sh
}

## 执行iaas-xiandian安装脚本
function IaaSInstallation() {
  iaas-pre-host.sh
  iaas-install-mysql.sh
  iaas-install-keystone.sh
  iaas-install-glance.sh
  iaas-install-nova-controller.sh
  iaas-install-neutron-controller.sh
  iaas-install-dashboard.sh
}

## 验证最小化部署结果
function ResultJudgment() {
  source /etc/keystone/admin-openrc.sh
  TEST=$(openstack service list | egrep 'placement|keystone|glance|nova|neutron' -wc)
  if [ $TEST -eq "5" ]; then
    echo -e "\033[32m -------------- controller 控制节点部署完成,服务启动正常 -------------- \033[0m"
  else
    echo -e '\033[31m ------------ !!!最小化部署失败 !!! --------------- \033[0m'
  fi
}

UserJudgment
BasicConfig
MountImage
YUMConfig
FTPConfig
SSHConfig
IaaSConfig
IaaSInstallation
ResultJudgment

OpenStack脚本compute端部署

## 当前用户名判定:
function UserJudgment() {
  read -p "当前的主机名为${HOSTNAME},是否修改(y/n):"
  echo -n "正在改名....."
  dop1=compute
  hostnamectl set-hostname ${dop1}
  bash
}

## 基础配置:
function BasicConfig() {
  systemctl disable --now firewalld
  setenforce 0
  echo "192.168.100.10 controller" >>/etc/hosts
  echo "192.168.100.20 compute" >>/etc/hosts
}

## 配置YUM源:
function YUMConfig() {
  rm -rf /etc/yum.repos.d/*
  touch /etc/yum.repos.d/ftp.repo
  echo -e "[centos]\nname=centos\nbaseurl=ftp://controller/centos\nenabled=1\ngpgcheck=0" >>/etc/yum.repos.d/ftp.repo
  echo -e "[iaas]\nname=iaas\nbaseurl=ftp://controller/iaas/iaas-repo\nenabled=1\ngpgcheck=0" >>/etc/yum.repos.d/ftp.repo
  yum makecache
}

## 配置ssh免密登录,000000
function SSHConfig() {
  yum install -y expect
  systemctl daemon-reload
  echo "StrictHostKeyChecking no" >>/etc/ssh/ssh_config
  expect -c "
spawn ssh-keygen
expect \"(/root/.ssh/id_rsa):\"
send \"\r\"
expect \"(empty for no passphrase):\"
send \"\r\"
expect \"passphrase again\"
send \"\r\"
expect eof
"
  expect -c "
spawn ssh-copy-id 192.168.100.10
expect \"password: \"
send \"000000\r\"
expect eof
"
  expect -c "
spawn ssh-copy-id 192.168.100.20
expect \"password: \"
send \"000000\r\"
expect eof
"
}

## 配置iaas-xiandian软件包
function IaaSConfig() {
  yum install -y iaas-xiandian
  scp root@controller:/etc/xiandian/openrc.sh /etc/xiandian
  sed -i "69c INTERFACE_IP=192.168.100.20" /etc/xiandian/openrc.sh
  source /etc/xiandian/openrc.sh
}

## 执行iaas-xiandian安装脚本
function IaaSInstallation() {
  iaas-pre-host.sh
  iaas-install-nova-compute.sh
  iaas-install-neutron-compute.sh
}

## 解决虚拟机环境下QEMU模拟器无法正常使用,服务器请忽略
function FixError() {
  crudini --set /etc/nova/nova.conf libvirt virt_type qemu
  systemctl restart libvirtd.service openstack-nova-compute.service
}

## 验证最小化部署结果
function ResultJudgment() {
  scp root@controller:/etc/keystone/admin-openrc.sh /root/
  source /root/admin-openrc.sh
  TEST=$(openstack compute service list | egrep 'nova-consoleauth|nova-conductor|nova-scheduler|nova-compute' -wc)
  if [ $TEST -eq "4" ]; then
    echo -e "\033[32m -------------- openstack 最小化部署成功 -------------- \033[0m"
  else
    echo -e '\033[31m ------------ !!!最小化部署失败 !!! --------------- \033[0m'
  fi
  rm -rf /root/admin-openrc.sh
}

UserJudgment
BasicConfig
YUMConfig
SSHConfig
IaaSConfig
IaaSInstallation
FixError
ResultJudgment

OpenStack脚本controllor端添加为计算节点

sed -i "12c HOST_IP_NODE=192.168.100.10" /etc/xiandian/openrc.sh
sed -i "18c HOST_NAME_NODE=controller" /etc/xiandian/openrc.sh
iaas-install-nova-compute.sh
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值