openstackT版脚本
实验环境采用Vmware,所使用到的脚本以及配置文件等需要搭配软件包使用,nova默认配置了控制节点加入计算资源池
节点 | IP |
---|---|
controller | 192.168.200.10 |
compute | 192.168.200.20 |
**软件包网盘地址:**下载后上传到/root目录下即可
链接:https://pan.baidu.com/s/1_BnBkIIXq5XkMj6sm2PL0Q?pwd=0345
提取码:0345
--来自百度网盘超级会员V4的分享
环境变量
自行修改环境变量信息,特别是IP、网卡等,只需要配置maxvlan即可,本脚本只搭建到dashboard
powershell
#--------------------system Config--------------------##
#Controller Server Manager IP. example:x.x.x.x
HOST_IP=192.168.200.10
#Controller HOST Password. example:000000
HOST_PASS=000000
#Controller Server hostname. example:controller
HOST_NAME=controller
#Compute Node Manager IP. example:x.x.x.x
HOST_IP_NODE=192.168.200.20
#Compute HOST Password. example:000000
HOST_PASS_NODE=000000
#Compute Node hostname. example:compute
HOST_NAME_NODE=compute
#--------------------Chrony Config-------------------##
#Controller network segment IP. example:x.x.0.0/16(x.x.x.0/24)
network_segment_IP=192.168.200.0/24
#--------------------Rabbit Config ------------------##
#user for rabbit. example:openstack
RABBIT_USER=openstack
#Password for rabbit user .example:000000
RABBIT_PASS=000000
#--------------------MySQL Config---------------------##
#Password for MySQL root user . exmaple:000000
DB_PASS=000000
#--------------------Keystone Config------------------##
#Password for Keystore admin user. exmaple:000000
DOMAIN_NAME=default
ADMIN_PASS=000000
DEMO_PASS=000000
#Password for Mysql keystore user. exmaple:000000
KEYSTONE_DBPASS=000000
#--------------------Glance Config--------------------##
#Password for Mysql glance user. exmaple:000000
GLANCE_DBPASS=000000
#Password for Keystore glance user. exmaple:000000
GLANCE_PASS=000000
#--------------------Placement Config----------------------##
#Password for Mysql placement user. exmaple:000000
PLACEMENT_DBPASS=000000
#Password for Keystore placement user. exmaple:000000
PLACEMENT_PASS=000000
#--------------------Nova Config----------------------##
#Password for Mysql nova user. exmaple:000000
NOVA_DBPASS=000000
#Password for Keystore nova user. exmaple:000000
NOVA_PASS=000000
#--------------------Neutron Config-------------------##
#Password for Mysql neutron user. exmaple:000000
NEUTRON_DBPASS=000000
#Password for Keystore neutron user. exmaple:000000
NEUTRON_PASS=000000
#metadata secret for neutron. exmaple:000000
METADATA_SECRET=000000
#External Network Interface. example:eth1
INTERFACE_NAME=ens34
#用于创建ovs网络
OVS_NAME=br-ens34
#External Network The Physical Adapter. example:provider
Physical_NAME=provider
#First Vlan ID in VLAN RANGE for VLAN Network. exmaple:101
minvlan=1
#Last Vlan ID in VLAN RANGE for VLAN Network. example:200
maxvlan=1000
#--------------------Cinder Config--------------------##
#Password for Mysql cinder user. exmaple:000000
CINDER_DBPASS=000000
#Password for Keystore cinder user. exmaple:000000
CINDER_PASS=000000
#Cinder Block Disk. example:md126p3
BLOCK_DISK=sdb1
#--------------------Swift Config---------------------##
#Password for Keystore swift user. exmaple:000000
SWIFT_PASS=000000
#The NODE Object Disk for Swift. example:md126p4.
OBJECT_DISK=sdb2
#The NODE IP for Swift Storage Network. example:x.x.x.x.
STORAGE_LOCAL_NET_IP=192.168.200.20
#--------------------Trove Config----------------------##
#Password for Mysql trove user. exmaple:000000
TROVE_DBPASS=000000
#Password for Keystore trove user. exmaple:000000
TROVE_PASS=000000
#--------------------Heat Config----------------------##
#Password for Mysql heat user. exmaple:000000
HEAT_DBPASS=000000
#Password for Keystore heat user. exmaple:000000
HEAT_PASS=000000
#--------------------Ceilometer Config----------------##
#Password for Gnocchi ceilometer user. exmaple:000000
CEILOMETER_DBPASS=000000
#Password for Keystore ceilometer user. exmaple:000000
CEILOMETER_PASS=000000
#--------------------AODH Config----------------##
#Password for Mysql AODH user. exmaple:000000
AODH_DBPASS=000000
#Password for Keystore AODH user. exmaple:000000
AODH_PASS=000000
#--------------------ZUN Config----------------##
#Password for Mysql ZUN user. exmaple:000000
ZUN_DBPASS=000000
#Password for Keystore ZUN user. exmaple:000000
ZUN_PASS=000000
#Password for Keystore KURYR user. exmaple:000000
KURYR_PASS=000000
#--------------------OCTAVIA Config----------------##
#Password for Mysql OCTAVIA user. exmaple:000000
OCTAVIA_DBPASS=000000
#Password for Keystore OCTAVIA user. exmaple:000000
OCTAVIA_PASS=000000
#--------------------Manila Config----------------##
#Password for Mysql Manila user. exmaple:000000
MANILA_DBPASS=000000
#Password for Keystore Manila user. exmaple:000000
MANILA_PASS=000000
#The NODE Object Disk for Manila. example:md126p5.
SHARE_DISK=sdb3
#--------------------Cloudkitty Config----------------##
#Password for Mysql Cloudkitty user. exmaple:000000
CLOUDKITTY_DBPASS=000000
#Password for Keystore Cloudkitty user. exmaple:000000
CLOUDKITTY_PASS=000000
#--------------------Barbican Config----------------##
#Password for Mysql Barbican user. exmaple:000000
BARBICAN_DBPASS=000000
#Password for Keystore Barbican user. exmaple:000000
BARBICAN_PASS=000000
ip初始化
powershell
#!/bin/bash
tar -xf topenstack.tar.gz -C /opt/
mkdir /opt/centos
mount /dev/sr0 /opt/centos/
mv /etc/yum.repos.d/* /home/
cat > /etc/yum.repos.d/openstack.repo <<eof
[openstack]
name=openstack
baseurl=file:///opt/openstackt
gpgcheck=0
enabled=1
[centos]
name=centos
baseurl=file:///opt/centos
gpgcheck=0
enabled=1
eof
mkdir /etc/openstack/
cp openrc.sh /etc/openstack/
source /etc/openstack/openrc.sh
#keystone
sed -i -e "s/KEYSTONE_DBPASS/$KEYSTONE_DBPASS/"g controller/keystone/keystone.conf
sed -i -e "s/GLANCE_PASS/$GLANCE_PASS/"g controller/glance/glance-api.conf
sed -i -e "s/HOST_NAME/$HOST_NAME/"g controller/keystone/keystone.conf
#glance
sed -i -e "s/GLANCE_DBPASS/$GLANCE_DBPASS/"g controller/glance/glance-api.conf
sed -i -e "s/HOST_NAME/$HOST_NAME/"g controller/glance/glance-api.conf
#placement
sed -i -e "s/HOST_NAME/$HOST_NAME/"g controller/placement/placement.conf
sed -i -e "s/PLACEMENT_PASS/$PLACEMENT_PASS/"g controller/placement/placement.conf
sed -i -e "s/PLACEMENT_DBPASS/$PLACEMENT_DBPASS/"g controller/placement/placement.conf
#nova-con
sed -i -e "s/RABBIT_USER/$RABBIT_USER/"g controller/nova/nova.conf
sed -i -e "s/RABBIT_PASS/$RABBIT_PASS/"g controller/nova/nova.conf
sed -i -e "s/HOST_NAME/$HOST_NAME/"g controller/nova/nova.conf
sed -i -e "s/HOST_IP/$HOST_IP/"g controller/nova/nova.conf
sed -i -e "s/NOVA_DBPASS/$NOVA_DBPASS/"g controller/nova/nova.conf
sed -i -e "s/NOVA_PASS/$NOVA_PASS/"g controller/nova/nova.conf
sed -i -e "s/PLACEMENT_PASS/$PLACEMENT_PASS/"g controller/nova/nova.conf
#neutron-con
sed -i -e "s/HOST_NAME/$HOST_NAME/"g controller/neutron/metadata_agent.ini
sed -i -e "s/METADATA_SECRET/$METADATA_SECRET/"g controller/neutron/metadata_agent.ini
sed -i -e "s/Physical_NAME/$Physical_NAME/"g controller/neutron/ml2_conf.ini
sed -i -e "s/minvlan/$minvlan/"g controller/neutron/ml2_conf.ini
sed -i -e "s/maxvlan/$maxvlan/"g controller/neutron/ml2_conf.ini
sed -i -e "s/RABBIT_USER/$RABBIT_USER/"g controller/neutron/neutron.conf
sed -i -e "s/RABBIT_PASS/$RABBIT_PASS/"g controller/neutron/neutron.conf
sed -i -e "s/HOST_NAME/$HOST_NAME/"g controller/neutron/neutron.conf
sed -i -e "s/HOST_NAME/$HOST_NAME/"g controller/neutron/neutron.conf
sed -i -e "s/NEUTRON_PASS/$NEUTRON_PASS/"g controller/neutron/neutron.conf
sed -i -e "s/NEUTRON_DBPASS/$NEUTRON_DBPASS/"g controller/neutron/neutron.conf
sed -i -e "s/NOVA_PASS/$NOVA_PASS/"g controller/neutron/neutron.conf
sed -i -e "s/RABBIT_USER/$RABBIT_USER/"g controller/neutron/nova.conf
sed -i -e "s/RABBIT_PASS/$RABBIT_PASS/"g controller/neutron/nova.conf
sed -i -e "s/HOST_NAME/$HOST_NAME/"g controller/neutron/nova.conf
sed -i -e "s/HOST_IP/$HOST_IP/"g controller/neutron/nova.conf
sed -i -e "s/NOVA_DBPASS/$NOVA_DBPASS/"g controller/neutron/nova.conf
sed -i -e "s/NOVA_PASS/$NOVA_PASS/"g controller/neutron/nova.conf
sed -i -e "s/PLACEMENT_PASS/$PLACEMENT_PASS/"g controller/neutron/nova.conf
sed -i -e "s/NEUTRON_PASS/$NEUTRON_PASS/"g controller/neutron/nova.conf
sed -i -e "s/METADATA_SECRET/$METADATA_SECRET/"g controller/neutron/nova.conf
sed -i -e "s/HOST_IP/$HOST_IP/"g controller/neutron/openvswitch_agent.ini
sed -i -e "s/Physical_NAME/$Physical_NAME/"g controller/neutron/openvswitch_agent.ini
sed -i -e "s/OVS_NAME/$OVS_NAME/"g controller/neutron/openvswitch_agent.ini
sed -i -e "s/HOST_NAME/$HOST_NAME/"g controller/dashboard/local_settings
#nova-com
sed -i -e "s/RABBIT_USER/$RABBIT_USER/"g compute/nova/nova.conf
sed -i -e "s/RABBIT_PASS/$RABBIT_PASS/"g compute/nova/nova.conf
sed -i -e "s/HOST_NAME/$HOST_NAME/"g compute/nova/nova.conf
sed -i -e "s/HOST_IP_NODE/$HOST_IP_NODE/"g compute/nova/nova.conf
sed -i -e "s/NOVA_PASS/$NOVA_PASS/"g compute/nova/nova.conf
sed -i -e "s/PLACEMENT_PASS/$PLACEMENT_PASS/"g compute/nova/nova.conf
sed -i -e "s/HOST_IP/$HOST_IP/"g compute/nova/nova.conf
#neutron-com
sed -i -e "s/RABBIT_USER/$RABBIT_USER/"g compute/neutron/neutron.conf
sed -i -e "s/RABBIT_PASS/$RABBIT_PASS/"g compute/neutron/neutron.conf
sed -i -e "s/HOST_NAME/$HOST_NAME/"g compute/neutron/neutron.conf
sed -i -e "s/NEUTRON_PASS/$NEUTRON_PASS/"g compute/neutron/neutron.conf
sed -i -e "s/RABBIT_USER/$RABBIT_USER/"g compute/neutron/nova.conf
sed -i -e "s/RABBIT_PASS/$RABBIT_PASS/"g compute/neutron/nova.conf
sed -i -e "s/HOST_NAME/$HOST_NAME/"g compute/neutron/nova.conf
sed -i -e "s/HOST_IP_NODE/$HOST_IP_NODE/"g compute/neutron/nova.conf
sed -i -e "s/NEUTRON_PASS/$NEUTRON_PASS/"g compute/neutron/nova.conf
sed -i -e "s/NOVA_PASS/$NOVA_PASS/"g compute/neutron/nova.conf
sed -i -e "s/PLACEMENT_PASS/$PLACEMENT_PASS/"g compute/neutron/nova.conf
sed -i -e "s/HOST_IP/$HOST_IP/"g compute/neutron/nova.conf
sed -i -e "s/HOST_IP_NODE/$HOST_IP_NODE/"g compute/neutron/openvswitch_agent.ini
sed -i -e "s/Physical_NAME/$Physical_NAME/"g compute/neutron/openvswitch_agent.ini
sed -i -e "s/OVS_NAME/$OVS_NAME/"g compute/neutron/openvswitch_agent.ini
echo "##############################################"
echo "# init ok #"
echo "##############################################"
controller
iaas-pre.sh
powershell
#/bin/bash
source /etc/openstack/openrc.sh
#Welcome page
cat > /etc/motd <<EOF
################################
# Welcome to OpenStack #
################################
EOF
#selinux
sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
#firewalld
systemctl stop firewalld
systemctl disable firewalld >> /dev/null 2>&1
#NetworkManager
systemctl stop NetworkManager >> /dev/null 2>&1
systemctl disable NetworkManager >> /dev/null 2>&1
yum remove -y NetworkManager firewalld
systemctl restart network
#iptables
yum install iptables-services -y
if [ 0 -ne $? ]; then
echo -e "\033[31mThe installation source configuration errors\033[0m"
exit 1
fi
systemctl restart iptables
iptables -F
iptables -X
iptables -Z
/usr/sbin/iptables-save
systemctl stop iptables
systemctl disable iptables
# install package
sed -i -e 's/#UseDNS yes/UseDNS no/g' -e 's/GSSAPIAuthentication yes/GSSAPIAuthentication no/g' /etc/ssh/sshd_config
yum install python-openstackclient openstack-selinux expect vim -y
#hosts
if [[ `ip a |grep -w $HOST_IP ` != '' ]];then
hostnamectl set-hostname $HOST_NAME
elif [[ `ip a |grep -w $HOST_IP_NODE ` != '' ]];then
hostnamectl set-hostname $HOST_NAME_NODE
else
hostnamectl set-hostname $HOST_NAME
fi
sed -i -e "/$HOST_NAME/d" -e "/$HOST_NAME_NODE/d" /etc/hosts
echo "$HOST_IP $HOST_NAME" >> /etc/hosts
echo "$HOST_IP_NODE $HOST_NAME_NODE" >> /etc/hosts
#ssh
if [[ ! -s ~/.ssh/id_rsa.pub ]];then
ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa -q -b 2048
fi
name=`hostname`
if [[ $name == $HOST_NAME ]];then
expect -c "set timeout -1;
spawn ssh-copy-id -i /root/.ssh/id_rsa $HOST_NAME_NODE;
expect {
*password:* {send -- $HOST_PASS_NODE\r;
expect {
*denied* {exit 2;}
eof}
}
*(yes/no)* {send -- yes\r;exp_continue;}
eof {exit 1;}
}
"
else
expect -c "set timeout -1;
spawn ssh-copy-id -i /root/.ssh/id_rsa $HOST_NAME;
expect {
*password:* {send -- $HOST_PASS\r;
expect {
*denied* {exit 2;}
eof}
}
*(yes/no)* {send -- yes\r;exp_continue;}
eof {exit 1;}
}
"
fi
#chrony
yum install -y chrony
if [[ $name == $HOST_NAME ]];then
sed -i '3,6s/^/#/g' /etc/chrony.conf
sed -i '7s/^/server controller iburst/g' /etc/chrony.conf
echo "allow $network_segment_IP" >> /etc/chrony.conf
echo "local stratum 10" >> /etc/chrony.conf
else
sed -i '3,6s/^/#/g' /etc/chrony.conf
sed -i '7s/^/server controller iburst/g' /etc/chrony.conf
fi
systemctl restart chronyd
systemctl enable chronyd
printf "\033[35mPlease Reboot or Reconnect the terminal\n\033[0m"
iaas-install-mysql.sh
powershell
#!/bin/bash
source /etc/openstack/openrc.sh
ping $HOST_IP -c 4 >> /dev/null 2>&1
if [ 0 -ne $? ]; then
echo -e "\033[31m Warning\nPlease make sure the network configuration is correct!\033[0m"
exit 1
fi
# MariaDB
yum install mariadb mariadb-server python2-PyMySQL -y
cat >> /etc/my.cnf.d/openstack.cnf << EOF
[mysqld]
bind-address = 0.0.0.0
default-storage-engine = innodb
innodb_file_per_table = on
max_connections = 4096
collation-server = utf8_general_ci
character-set-server = utf8
EOF
systemctl daemon-reload
systemctl enable mariadb.service
systemctl restart mariadb.service
expect -c "
spawn /usr/bin/mysql_secure_installation
expect \"Enter current password for root (enter for none):\"
send \"\r\"
expect \"Set root password?\"
send \"y\r\"
expect \"New password:\"
send \"$DB_PASS\r\"
expect \"Re-enter new password:\"
send \"$DB_PASS\r\"
expect \"Remove anonymous users?\"
send \"y\r\"
expect \"Disallow root login remotely?\"
send \"n\r\"
expect \"Remove test database and access to it?\"
send \"y\r\"
expect \"Reload privilege tables now?\"
send \"y\r\"
expect eof
"
# RabbitMQ
yum install rabbitmq-server -y
systemctl start rabbitmq-server.service
systemctl enable rabbitmq-server.service
rabbitmqctl add_user $RABBIT_USER $RABBIT_PASS
rabbitmqctl set_permissions $RABBIT_USER ".*" ".*" ".*"
# Memcache
yum install memcached python-memcached -y
sed -i -e 's/OPTIONS.*/OPTIONS="-l 0.0.0.0"/g' /etc/sysconfig/memcached
systemctl start memcached.service
systemctl enable memcached.service
iaas-install-keystone.sh
powershell
#!/bin/bash
source /etc/openstack/openrc.sh
#keystone mysql
mysql -uroot -p$DB_PASS -e "create database IF NOT EXISTS keystone ;"
mysql -uroot -p$DB_PASS -e "GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'localhost' IDENTIFIED BY '$KEYSTONE_DBPASS' ;"
mysql -uroot -p$DB_PASS -e "GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'%' IDENTIFIED BY '$KEYSTONE_DBPASS' ;"
#install keystone
yum install openstack-keystone httpd mod_wsgi -y
#/etc/keystone/keystone.conf
cp /etc/keystone/keystone.conf{,.bak}
cp controller/keystone/keystone.conf /etc/keystone/keystone.conf
su -s /bin/sh -c "keystone-manage db_sync" keystone
keystone-manage fernet_setup --keystone-user keystone --keystone-group keystone
keystone-manage credential_setup --keystone-user keystone --keystone-group keystone
keystone-manage bootstrap --bootstrap-password $ADMIN_PASS \
--bootstrap-admin-url http://$HOST_NAME:5000/v3/ \
--bootstrap-internal-url http://$HOST_NAME:5000/v3/ \
--bootstrap-public-url http://$HOST_NAME:5000/v3/ \
--bootstrap-region-id RegionOne
sed -i "s/#ServerName www.example.com:80/ServerName $HOST_NAME/g" /etc/httpd/conf/httpd.conf
ln -s /usr/share/keystone/wsgi-keystone.conf /etc/httpd/conf.d/
systemctl enable httpd.service
systemctl restart httpd.service
cat > /etc/keystone/admin-openrc.sh <<-EOF
export OS_PROJECT_DOMAIN_NAME=$DOMAIN_NAME
export OS_USER_DOMAIN_NAME=$DOMAIN_NAME
export OS_PROJECT_NAME=admin
export OS_USERNAME=admin
export OS_PASSWORD=$ADMIN_PASS
export OS_AUTH_URL=http://$HOST_NAME:5000/v3
export OS_IDENTITY_API_VERSION=3
export OS_IMAGE_API_VERSION=2
EOF
source /etc/keystone/admin-openrc.sh
openstack project create --domain default --description "Service Project" service
iaas-install-glance.sh
powershell
#!/bin/bash
source /etc/openstack/openrc.sh
source /etc/keystone/admin-openrc.sh
#glance mysql
mysql -uroot -p$DB_PASS -e "create database IF NOT EXISTS glance ;"
mysql -uroot -p$DB_PASS -e "GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY '$GLANCE_DBPASS' ;"
mysql -uroot -p$DB_PASS -e "GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY '$GLANCE_DBPASS' ;"
#glance user role service endpoint
openstack user create --domain $DOMAIN_NAME --password $GLANCE_PASS glance
openstack role add --project service --user glance admin
openstack service create --name glance --description "OpenStack Image" image
openstack endpoint create --region RegionOne image public http://$HOST_NAME:9292
openstack endpoint create --region RegionOne image internal http://$HOST_NAME:9292
openstack endpoint create --region RegionOne image admin http://$HOST_NAME:9292
#glance install
yum install -y openstack-glance
#/etc/glance/glance-api.conf
cp /etc/glance/glance-api.conf{,.bak}
cp controller/glance/glance-api.conf /etc/glance/glance-api.conf
#su glance mysql
su -s /bin/sh -c "glance-manage db_sync" glance
systemctl enable openstack-glance-api.service openstack-glance-registry.service
systemctl restart openstack-glance-api.service openstack-glance-registry.service
openstack image create --disk-format qcow2 --file cirros-0.3.4-x86_64-disk.img cirros
iaas-install-placement.sh
powershell
#!/bin/bash
source /etc/openstack/openrc.sh
source /etc/keystone/admin-openrc.sh
#placement mysql
mysql -uroot -p$DB_PASS -e "CREATE DATABASE placement;"
mysql -uroot -p$DB_PASS -e "GRANT ALL PRIVILEGES ON placement.* TO 'placement'@'localhost' IDENTIFIED BY '$PLACEMENT_DBPASS';"
mysql -uroot -p$DB_PASS -e "GRANT ALL PRIVILEGES ON placement.* TO 'placement'@'%' IDENTIFIED BY '$PLACEMENT_DBPASS';"
#placement user role service endpoint
openstack user create --domain $DOMAIN_NAME --password $PLACEMENT_PASS placement
openstack role add --project service --user placement admin
openstack service create --name placement --description "Placement API" placement
openstack endpoint create --region RegionOne placement public http://$HOST_NAME:8778
openstack endpoint create --region RegionOne placement internal http://$HOST_NAME:8778
openstack endpoint create --region RegionOne placement admin http://$HOST_NAME:8778
#placement install
yum install openstack-placement-api python2-pip -y
#/etc/placement/placement.conf
cp /etc/placement/placement.conf{,.bak}
cp controller/placement/placement.conf /etc/placement/placement.conf
#su placement mysql
su -s /bin/sh -c "placement-manage db sync" placement
#/etc/httpd/conf.d/00-placement-api.conf
cat >> /etc/httpd/conf.d/00-placement-api.conf <<EOF
<Directory /usr/bin>
<IfVersion >= 2.4>
Require all granted
</IfVersion>
<IfVersion < 2.4>
Order allow,deny
Allow from all
</IfVersion>
</Directory>
EOF
systemctl restart httpd
iaas-install-nova-controller.sh
powershell
#!/bin/bash
source /etc/openstack/openrc.sh
source /etc/keystone/admin-openrc.sh
#neutron mysql
mysql -uroot -p$DB_PASS -e "create database IF NOT EXISTS nova ;"
mysql -uroot -p$DB_PASS -e "create database IF NOT EXISTS nova_api ;"
mysql -uroot -p$DB_PASS -e "create database IF NOT EXISTS nova_cell0 ;"
mysql -uroot -p$DB_PASS -e "GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'localhost' IDENTIFIED BY '$NOVA_DBPASS' ;"
mysql -uroot -p$DB_PASS -e "GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'%' IDENTIFIED BY '$NOVA_DBPASS' ;"
mysql -uroot -p$DB_PASS -e "GRANT ALL PRIVILEGES ON nova_api.* TO 'nova'@'localhost' IDENTIFIED BY '$NOVA_DBPASS' ;"
mysql -uroot -p$DB_PASS -e "GRANT ALL PRIVILEGES ON nova_api.* TO 'nova'@'%' IDENTIFIED BY '$NOVA_DBPASS' ;"
mysql -uroot -p$DB_PASS -e "GRANT ALL PRIVILEGES ON nova_cell0.* TO 'nova'@'localhost' IDENTIFIED BY '$NOVA_DBPASS' ;"
mysql -uroot -p$DB_PASS -e "GRANT ALL PRIVILEGES ON nova_cell0.* TO 'nova'@'%' IDENTIFIED BY '$NOVA_DBPASS' ;"
#nova user role service endpoint
openstack user create --domain $DOMAIN_NAME --password $NOVA_PASS nova
openstack role add --project service --user nova admin
openstack service create --name nova --description "OpenStack Compute" compute
openstack endpoint create --region RegionOne compute public http://$HOST_NAME:8774/v2.1
openstack endpoint create --region RegionOne compute internal http://$HOST_NAME:8774/v2.1
openstack endpoint create --region RegionOne compute admin http://$HOST_NAME:8774/v2.1
#nova install
yum install openstack-nova-api openstack-nova-conductor openstack-nova-novncproxy openstack-nova-scheduler -y
#nova compute
yum install openstack-nova-compute -y
#/etc/nova/nova.conf
cp /etc/nova/nova.conf{,.bak}
cp controller/nova/nova.conf /etc/nova/nova.conf
#su nova mysql
su -s /bin/sh -c "nova-manage api_db sync" nova
su -s /bin/sh -c "nova-manage cell_v2 map_cell0" nova
su -s /bin/sh -c "nova-manage cell_v2 create_cell --name=cell1 --verbose" nova
su -s /bin/sh -c "nova-manage db sync" nova
su -s /bin/sh -c "nova-manage cell_v2 list_cells" nova
systemctl restart openstack-nova-api.service openstack-nova-scheduler.service openstack-nova-conductor.service openstack-nova-novncproxy.service
systemctl enable openstack-nova-api.service openstack-nova-scheduler.service openstack-nova-conductor.service openstack-nova-novncproxy.service
systemctl restart libvirtd.service openstack-nova-compute.service
systemctl enable libvirtd.service openstack-nova-compute.service
systemctl restart httpd;systemctl restart openstack-nova-compute
openstack flavor create --id 1 --vcpus 1 --ram 512 --disk 10 cirros-test
openstack compute service list --service nova-compute
su -s /bin/sh -c "nova-manage cell_v2 discover_hosts --verbose" nova
iaas-install-neutron-controller.sh
powershell
#!/bin/bash
source /etc/openstack/openrc.sh
source /etc/keystone/admin-openrc.sh
#neutron mysql
mysql -uroot -p$DB_PASS -e "create database IF NOT EXISTS neutron ;"
mysql -uroot -p$DB_PASS -e "GRANT ALL PRIVILEGES ON neutron.* TO 'neutron'@'localhost' IDENTIFIED BY '$NEUTRON_DBPASS' ;"
mysql -uroot -p$DB_PASS -e "GRANT ALL PRIVILEGES ON neutron.* TO 'neutron'@'%' IDENTIFIED BY '$NEUTRON_DBPASS' ;"
#neutron user role service endpoint
openstack user create --domain $DOMAIN_NAME --password $NEUTRON_PASS neutron
openstack role add --project service --user neutron admin
openstack service create --name neutron --description "OpenStack Networking" network
openstack endpoint create --region RegionOne network public http://$HOST_NAME:9696
openstack endpoint create --region RegionOne network internal http://$HOST_NAME:9696
openstack endpoint create --region RegionOne network admin http://$HOST_NAME:9696
#neutron install
yum install -y openstack-neutron openstack-neutron-ml2 openstack-neutron-openvswitch
#network
if [[ `ip a |grep -w $INTERFACE_IP |grep -w $INTERFACE_NAME` = '' ]];then
cat > /etc/sysconfig/network-scripts/ifcfg-$INTERFACE_NAME <<EOF
DEVICE=$INTERFACE_NAME
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
EOF
systemctl restart network
fi
#/etc/neutron/neutron.conf
cp /etc/neutron/neutron.conf{,.bak}
cp controller/neutron/neutron.conf /etc/neutron/neutron.conf
#/etc/neutron/plugins/ml2/ml2_conf.ini
cp /etc/neutron/plugins/ml2/ml2_conf.ini{,.bak}
cp controller/neutron/ml2_conf.ini /etc/neutron/plugins/ml2/ml2_conf.ini
#/etc/neutron/plugins/ml2/openvswitch_agent.ini
cp /etc/neutron/plugins/ml2/openvswitch_agent.ini{,.bak}
cp controller/neutron/openvswitch_agent.ini /etc/neutron/plugins/ml2/openvswitch_agent.ini
#br_netfilter
modprobe br_netfilter
echo 'net.ipv4.conf.all.rp_filter=0' >> /etc/sysctl.conf
echo 'net.ipv4.conf.default.rp_filter=0' >> /etc/sysctl.conf
echo 'net.bridge.bridge-nf-call-iptables = 1' >> /etc/sysctl.conf
echo 'net.bridge.bridge-nf-call-ip6tables = 1' >> /etc/sysctl.conf
sysctl -p
#/etc/neutron/l3_agent.ini
cp /etc/neutron/l3_agent.ini{,.bak}
cp controller/neutron/l3_agent.ini /etc/neutron/l3_agent.ini
#/etc/neutron/metadata_agent.ini
cp /etc/neutron/metadata_agent.ini{,.bak}
cp controller/neutron/metadata_agent.ini /etc/neutron/metadata_agent.ini
#/etc/neutron/dhcp_agent.ini
cp /etc/neutron/dhcp_agent.ini{,.bak}
cp controller/neutron/dhcp_agent.ini /etc/neutron/dhcp_agent.ini
#/etc/nova/nova.conf
cp controller/neutron/nova.conf /etc/nova/nova.conf
#su neutron mysql
ln -s /etc/neutron/plugins/ml2/ml2_conf.ini /etc/neutron/plugin.ini
su -s /bin/sh -c "neutron-db-manage --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/plugins/ml2/ml2_conf.ini upgrade head" neutron
systemctl restart openstack-nova-api
systemctl enable --now neutron-server neutron-metadata-agent neutron-openvswitch-agent openvswitch neutron-l3-agent neutron-dhcp-agent
ovs-vsctl add-br $OVS_NAME
ovs-vsctl add-port $OVS_NAME $INTERFACE_NAME
systemctl restart neutron-server neutron-metadata-agent neutron-openvswitch-agent openvswitch neutron-l3-agent neutron-dhcp-agent
echo "#network create#"
##int-net
#openstack network create --internal --provider-network-type vxlan int-net
#openstack subnet create int-net-sub --network int-net --subnet-range 10.0.0.0/24 --gateway 10.0.0.1 --dns-nameserver 114.114.114.114
##ext-net
#openstack network create --provider-physical-network physnet1 --provider-network-type flat --external ext-net
#openstack subnet create ext-net-sub --network ext-net --subnet-range 192.168.200.40/24 --allocation-pool start=192.168.200.30,end=192.168.200.200 --gateway 192.168.200.2 --dns-nameserver 114.114.114.114 --no-dhcp
##router
#openstack router add subnet Ext-Router int-net-sub
#openstack router set Ext-Router --external-gateway ext-net
iaas-install-dashboard.sh
powershell
#!/bin/bash
source /etc/openstack/openrc.sh
source /etc/keystone/admin-openrc.sh
#dashboard install
yum install openstack-dashboard -y
#/etc/openstack-dashboard/local_settings
cp /etc/openstack-dashboard/local_settings{,.bak}
cp controller/dashboard/local_settings /etc/openstack-dashboard/local_settings
#/etc/httpd/conf.d/openstack-dashboard.conf
sed -e '4iWSGIApplicationGroup %{GLOBAL}' /etc/httpd/conf.d/openstack-dashboard.conf
systemctl restart httpd.service memcached.service
#/root/logininfo.txt
printf "\033[35mThe horizon service is ready,Now you can visit the following;\n\033[0m"
echo 浏览器访问:http://$HOST_IP/dashboard
echo 域:$DOMAIN_NAME
echo 用户名:admin
echo 密码:"${ADMIN_PASS}"
echo 信息输出到root目录下的logininfo.txt中了。
cat >> /root/logininfo.txt << EOF
浏览器访问:http://$HOST_IP/dashboard
域:$DOMAIN_NAME
用户名:admin
密码:"${ADMIN_PASS}"
EOF
compute
iaas-install-nova-compute.sh
powershell
#!/bin/bash
source /etc/openstack/openrc.sh
#nova-compute install
yum install openstack-nova-compute -y
#/etc/nova/nova.conf
cp /etc/nova/nova.conf{,.bak}
cp compute/nova/nova.conf /etc/nova/nova.conf
virt_num=`egrep -c '(vmx|svm)' /proc/cpuinfo`
if [ $virt_num = '0' ];then
crudini --set /etc/nova/nova.conf libvirt virt_type qemu
fi
systemctl enable libvirtd.service openstack-nova-compute.service
systemctl restart libvirtd.service openstack-nova-compute.service
ssh $HOST_IP "source /etc/keystone/admin-openrc.sh && systemctl restart httpd && openstack compute service list --service nova-compute"
systemctl restart openstack-nova-compute.service
ssh $HOST_IP 'source /etc/keystone/admin-openrc.sh && su -s /bin/sh -c "nova-manage cell_v2 discover_hosts --verbose" nova'
iaas-install-neutron-compute.sh
powershell
#!/bin/bash
source /etc/openstack/openrc.sh
#neutron install
yum install -y openstack-neutron-openvswitch
#network
if [[ `ip a |grep -w $INTERFACE_IP |grep -w $INTERFACE_NAME` = '' ]];then
cat > /etc/sysconfig/network-scripts/ifcfg-$INTERFACE_NAME <<EOF
DEVICE=$INTERFACE_NAME
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
EOF
systemctl restart network
fi
#/etc/neutron/neutron.conf
cp /etc/neutron/neutron.conf{,.bak}
cp compute/neutron/neutron.conf /etc/neutron/neutron.conf
#/etc/neutron/plugins/ml2/openvswitch_agent.ini
cp /etc/neutron/plugins/ml2/openvswitch_agent.ini{,.bak}
cp compute/neutron/openvswitch_agent.ini /etc/neutron/plugins/ml2/openvswitch_agent.ini
#br_netfilter
modprobe br_netfilter
echo 'net.ipv4.conf.all.rp_filter=0' >> /etc/sysctl.conf
echo 'net.ipv4.conf.default.rp_filter=0' >> /etc/sysctl.conf
echo 'net.bridge.bridge-nf-call-iptables = 1' >> /etc/sysctl.conf
echo 'net.bridge.bridge-nf-call-ip6tables = 1' >> /etc/sysctl.conf
sysctl -p
systemctl enable --now neutron-openvswitch-agent
#/etc/nova/nova.conf
cp compute/neutron/nova.conf /etc/nova/nova.conf
systemctl enable --now openvswitch
ovs-vsctl add-br $OVS_NAME
ovs-vsctl add-port $OVS_NAME $INTERFACE_NAME
systemctl restart openstack-nova-compute.service
systemctl restart neutron-openvswitch-agent