特别声明:请先学会如何手动搭建后再使用,自行更改相关参数!
附:手动官方脚本搭建详细教程:
2020 ~ 2021 云计算先电 2.4 私有云 IaaS 最小化部署 & 创建 PaaS 实验云主机环境
Controller 控制节点
#!/bin/bash
## Author:孤_存
ControllerPasswd=000000
ComputePasswd=000000
InstallDir=/opt
CentOSDir=${InstallDir}/centos
IaaSDir=${InstallDir}/iaas
RedHatReposDir=/etc/yum.repos.d
LocalRepo=${RedHatReposDir}/local.repo
CentOSISO=/root/CentOS-7-x86_64-DVD-1804.iso
XiandianISO=/root/XianDian-IaaS-v2.4.iso
XiandianConf=/etc/xiandian/openrc.sh
SSHConf=/etc/ssh/ssh_config
## 组合函数
function CombinationFunction() {
UserJudgment
BasicConfig
MountImage
YUMConfig
FTPConfig
SSHConfig
IaaSConfig
IaaSInstallation
ResultJudgment
}
## 当前用户名判定:
function UserJudgment() {
if [ $(hostname) != "controller" ]; then
echo -e "\033[31m ------------ 请更改主机名为 controller 并重启! --------------- \033[0m"
return
fi
}
## 基础配置:
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 ${CentOSDir} ${IaaSDir}
mount -o loop ${CentOSISO} ${CentOSDir}
mount -o loop ${XiandianISO} ${IaaSDir}
mv ${CentOSISO} ${XiandianISO} ${InstallDir}
}
## 配置YUM源:
function YUMConfig() {
mkdir -p ${RedHatReposDir}.bak
mv -f ${RedHatReposDir}/* ${RedHatReposDir}.bak
echo -e "[centos]\nname=centos\nbaseurl=file://${CentOSDir}\nenabled=1\ngpgcheck=0" >>${LocalRepo}
echo -e "[iaas]\nname=iaas\nbaseurl=file://${IaaSDir}/iaas-repo\nenabled=1\ngpgcheck=0" >>${LocalRepo}
yum makecache
}
## 配置FTP服务器
function FTPConfig() {
yum -y install vsftpd
echo "anon_root=${InstallDir}" >>/etc/vsftpd/vsftpd.conf
systemctl enable --now vsftpd
}
## 配置ssh免密登录
function SSHConfig() {
yum install -y expect
systemctl daemon-reload
echo "StrictHostKeyChecking no" >>${SSHConf}
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 \"${ControllerPasswd}\r\"
expect eof
"
expect -c "
spawn ssh-copy-id 192.168.100.20
expect \"password: \"
send \"${ComputePasswd}\r\"
expect eof
"
}
## 配置iaas-xiandian软件包
function IaaSConfig() {
yum install -y iaas-xiandian
sed -i "3c HOST_IP=192.168.100.10" ${XiandianConf}
sed -i "6c HOST_PASS=000000" ${XiandianConf}
sed -i "9c HOST_NAME=controller" ${XiandianConf}
sed -i "12c HOST_IP_NODE=192.168.100.20" ${XiandianConf}
sed -i "15c HOST_PASS_NODE=000000" ${XiandianConf}
sed -i "18c HOST_NAME_NODE=compute" ${XiandianConf}
sed -i "22c network_segment_IP=192.168.100.0/24" ${XiandianConf}
sed -i "26c RABBIT_USER=openstack" ${XiandianConf}
sed -i "29c RABBIT_PASS=000000" ${XiandianConf}
sed -i "33c DB_PASS=000000" ${XiandianConf}
sed -i "37c DOMAIN_NAME=demo" ${XiandianConf}
sed -i "38c ADMIN_PASS=000000" ${XiandianConf}
sed -i "39c DEMO_PASS=000000" ${XiandianConf}
sed -i "42c KEYSTONE_DBPASS=000000" ${XiandianConf}
sed -i "46c GLANCE_DBPASS=000000" ${XiandianConf}
sed -i "49c GLANCE_PASS=000000" ${XiandianConf}
sed -i "53c NOVA_DBPASS=000000" ${XiandianConf}
sed -i "56c NOVA_PASS=000000" ${XiandianConf}
sed -i "60c NEUTRON_DBPASS=000000" ${XiandianConf}
sed -i "63c NEUTRON_PASS=000000" ${XiandianConf}
sed -i "66c METADATA_SECRET=000000" ${XiandianConf}
sed -i "69c INTERFACE_IP=192.168.100.10" ${XiandianConf}
sed -i "72c INTERFACE_NAME=ens33" ${XiandianConf}
sed -i "75c Physical_NAME=provider" ${XiandianConf}
sed -i "78c minvlan=101" ${XiandianConf}
sed -i "81c maxvlan=200" ${XiandianConf}
sed -i "85c CINDER_DBPASS=000000" ${XiandianConf}
sed -i "88c CINDER_PASS=000000" ${XiandianConf}
sed -i "91c BLOCK_DISK=sdb1" ${XiandianConf}
sed -i "95c SWIFT_PASS=000000" ${XiandianConf}
sed -i "98c OBJECT_DISK=sdb2" ${XiandianConf}
sed -i "101c STORAGE_LOCAL_NET_IP=192.168.100.20" ${XiandianConf}
sed -i "105c HEAT_DBPASS=000000" ${XiandianConf}
sed -i "108c HEAT_PASS=000000" ${XiandianConf}
sed -i "112c ZUN_DBPASS=000000" ${XiandianConf}
sed -i "115c ZUN_PASS=000000" ${XiandianConf}
sed -i "118c KURYR_DBPASS=000000" ${XiandianConf}
sed -i "121c KURYR_PASS=000000" ${XiandianConf}
sed -i "125c CEILOMETER_DBPASS=000000" ${XiandianConf}
sed -i "128c CEILOMETER_PASS=000000" ${XiandianConf}
sed -i "132c AODH_DBPASS=000000" ${XiandianConf}
sed -i "135c AODH_PASS=000000" ${XiandianConf}
sed -i "139c BARBICAN_DBPASS=000000" ${XiandianConf}
sed -i "142c BARBICAN_PASS=000000" ${XiandianConf}
. ${XiandianConf}
}
## 执行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
}
CombinationFunction
Compute 计算节点
#!/bin/bash
## Author:孤_存
ControllerPasswd=000000
ComputePasswd=000000
InstallDir=/opt
CentOSDir=${InstallDir}/centos
IaaSDir=${InstallDir}/iaas
RedHatReposDir=/etc/yum.repos.d
FtpRepo=${RedHatReposDir}/ftp.repo
XiandianConf=/etc/xiandian/openrc.sh
SSHConf=/etc/ssh/ssh_config
## 组合函数
function CombinationFunction() {
UserJudgment
BasicConfig
YUMConfig
SSHConfig
IaaSConfig
IaaSInstallation
FixError ## 解决虚拟机环境下QEMU模拟器无法正常使用,服务器请注释
ResultJudgment
}
## 当前用户名判定:
function UserJudgment() {
if [ $(hostname) != "compute" ]; then
echo -e "\033[31m ------------ 请更改主机名为 compute 并重启! --------------- \033[0m"
return
fi
}
## 基础配置:
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() {
mkdir -p ${RedHatReposDir}.bak
mv -f ${RedHatReposDir}/* ${RedHatReposDir}.bak
echo -e "[centos]\nname=centos\nbaseurl=ftp://controller/centos\nenabled=1\ngpgcheck=0" >>${FtpRepo}
echo -e "[iaas]\nname=iaas\nbaseurl=ftp://controller/iaas/iaas-repo\nenabled=1\ngpgcheck=0" >>${FtpRepo}
yum makecache
}
## 配置ssh免密登录
function SSHConfig() {
yum install -y expect
systemctl daemon-reload
echo "StrictHostKeyChecking no" >>${SSHConf}
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 \"${ControllerPasswd}\r\"
expect eof
"
expect -c "
spawn ssh-copy-id 192.168.100.20
expect \"password: \"
send \"${ComputePasswd}\r\"
expect eof
"
}
## 配置iaas-xiandian软件包
function IaaSConfig() {
yum install -y iaas-xiandian
scp root@controller:${XiandianConf} /etc/xiandian
sed -i "69c INTERFACE_IP=192.168.100.20" ${XiandianConf}
. ${XiandianConf}
}
## 执行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
}
CombinationFunction
创建云主机环境
#!/bin/bash
## Author:孤_存
## 请在控制节点执行此脚本
## 网卡1 192.168.100.0/24 网卡2 192.168.200.0/24
## 使环境变量生效
source /etc/keystone/admin-openrc.sh
## 创建镜像
glance image-create --name CentOS7.5 --disk-format qcow2 --container-format bare --progress < /opt/iaas/images/CentOS_7.5_x86_64_XD.qcow2
# ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 二选一 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
## 创建外部网络(虚拟机)
openstack network create ext-net --provider-physical-network provider --provider-network-type flat --external
## 创建外部网络(服务器)
openstack network create ext-net --provider-network-type vlan --provider-physical-network provider --provider-segment 1 --external
## 创建内部网络
openstack network create int-net1 --provider-network-type vxlan --provider-segment 1
openstack network create int-net2 --provider-network-type vxlan --provider-segment 2
## 创建子网
openstack subnet create ext-subnet --network ext-net --gateway 192.168.200.1 --subnet-range 192.168.200.0/24 --allocation-pool start=192.168.200.100,end=192.168.200.200 --dhcp
openstack subnet create int-subnet1 --network int-net1 --gateway 10.0.0.1 --subnet-range 10.0.0.0/24 --dhcp
openstack subnet create int-subnet2 --network int-net2 --gateway 10.0.1.1 --subnet-range 10.0.1.0/24 --dhcp
## 创建路由
openstack router create ext-router
openstack router set ext-router --external-gateway ext-net
openstack router add subnet ext-router int-subnet1
## 创建安全组和规则
openstack security group create all
openstack security group rule list all | grep None >> rules.txt
sed -i "s/None//g" rules.txt
sed -i "s/|//g" rules.txt
sed -i s/[[:space:]]//g rules.txt
SECURITY_RULE1=$(sed -n 1p rules.txt)
SECURITY_RULE2=$(sed -n 2p rules.txt)
openstack security group rule delete $SECURITY_RULE1
openstack security group rule delete $SECURITY_RULE2
rm -rf rules.txt
openstack security group rule create --ingress --protocol tcp all
openstack security group rule create --ingress --protocol udp all
openstack security group rule create --ingress --protocol icmp all
openstack security group rule create --egress --protocol tcp all
openstack security group rule create --egress --protocol udp all
openstack security group rule create --egress --protocol icmp all
## 创建实例类型
nova flavor-create master 1 12288 100 8
nova flavor-create node 2 8192 100 4
## 创建云主机
nova boot --image CentOS7.5 --flavor 1 --nic net-name=int-net1,v4-fixed-ip=10.0.0.3 --security-groups all --poll master
nova boot --image CentOS7.5 --flavor 2 --nic net-name=int-net1,v4-fixed-ip=10.0.0.4 --security-groups all --poll node
## 创建浮动IP并绑定至云主机
openstack floating ip create ext-net --floating-ip-address 192.168.200.104
openstack floating ip create ext-net --floating-ip-address 192.168.200.105
openstack server add floating ip master 192.168.200.104
openstack server add floating ip node 192.168.200.105
注释:
- 第
12~15
行创建外部网络命令重复,根据物理环境执行对应的命令- 第
21~29
行内容含义为删除创建安全组后自带的两条默认规则- 自行更改
IP地址
等参数,还有下面创建云主机和浮动IP都固定了IP地址
- 创建云主机环境脚本的内容与上面提到的 手动官方脚本搭建 教程博客完全对应。