2020云计算先电2.4(最小化+云主机环境)一键部署Shell脚本模板

特别声明:请先学会如何手动部署后IaaS后再使用,自行参照更改相关参数!

  • 手动官方脚本搭建详细教程CSDN帖子链接

2020云计算先电2.4私有云IaaS最小化部署 & 创建PaaS实验云主机环境

Controller控制节点

#!/bin/bash
hostname | grep controller -qw
if [ $? -ne 0 ];then
    echo -e "\033[31m ------------ !!!主机名错误,请更改主机名为 controller 并重启!!! --------------- \033[0m"
    return
fi
#关闭防火墙并临时禁用SElinux
systemctl disable --now firewalld
setenforce 0
#配置域名解析
echo "192.168.100.10 controller" >> /etc/hosts
echo "192.168.100.20 compute" >> /etc/hosts
#挂载镜像
mkdir -p /opt/centos /opt/iaas
mount -o loop CentOS-7-x86_64-DVD-1804.iso /opt/centos
mount -o loop XianDian-IaaS-v2.4.iso /opt/iaas
mv CentOS-7-x86_64-DVD-1804.iso XianDian-IaaS-v2.4.iso /opt
#配置YUM源
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服务器
yum -y install vsftpd
echo "anon_root=/opt" >> /etc/vsftpd/vsftpd.conf
systemctl start vsftpd && systemctl enable vsftpd
#配置ssh免密登录
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软件包
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安装脚本
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
#验证最小化部署结果
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

Compute计算节点

#!/bin/bash
hostname | grep compute -qw
if [ $? -ne 0 ];then
    echo -e "\033[31m ------------ !!!主机名错误,请更改主机名为 compute 并重启!!! --------------- \033[0m"
    return
fi
#关闭防火墙并临时禁用SElinux
systemctl disable --now firewalld
setenforce 0
#配置域名解析
echo "192.168.100.10 controller" >> /etc/hosts
echo "192.168.100.20 compute" >> /etc/hosts
#配置YUM源
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免密登录
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
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-pre-host.sh
iaas-install-nova-compute.sh
iaas-install-neutron-compute.sh
#解决QEMU模拟器无法正常使用
crudini --set /etc/nova/nova.conf libvirt virt_type  qemu
systemctl restart libvirtd.service openstack-nova-compute.service
#验证最小化部署结果
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

创建云主机环境

#!/bin/bash
#使环境变量生效
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 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 6
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

注释:
1.脚本20~28行内容含义为删除创建安全组后自带的两条默认规则
2.自行更改IP地址等参数,这里创建云主机和浮动IP都固定了IP地址

你可能感兴趣的:(云计算,云计算,openstack,iaas,linux,centos)