特別宣告:請先學會如何手動部署后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地址
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/248065.html
標籤:其他
