diff options
author | Pasha <pasha@member.fsf.org> | 2022-08-16 21:48:31 +0000 |
---|---|---|
committer | Pasha <pasha@member.fsf.org> | 2022-08-16 21:48:31 +0000 |
commit | 2195fa1ed94786e1f5a760b860e1ee8976e1ffe4 (patch) | |
tree | 3bcaa704511278c0d5d938b86a629a37d2409292 /openstack_setup.sh | |
download | debian_openstack_installer-2195fa1ed94786e1f5a760b860e1ee8976e1ffe4.tar.gz debian_openstack_installer-2195fa1ed94786e1f5a760b860e1ee8976e1ffe4.tar.bz2 |
initial commit
Diffstat (limited to 'openstack_setup.sh')
-rw-r--r-- | openstack_setup.sh | 347 |
1 files changed, 347 insertions, 0 deletions
diff --git a/openstack_setup.sh b/openstack_setup.sh new file mode 100644 index 0000000..97575b5 --- /dev/null +++ b/openstack_setup.sh @@ -0,0 +1,347 @@ +#!/bin/bash + +# Copyright (C) 2022 Pasha <pasha@member.fsf.org> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + + +OPENSTACK_HOST_IP="192.168.0.155" +EXTERNAL_BRIDGE_INTERFACE="enp7s0" + + +if [ -z ${OPENSTACK_HOST_IP} ]; then + echo "Please set OpenStack host IP" + exit 1 +fi + +if [ -z ${EXTERNAL_BRIDGE_INTERFACE} ]; then + echo "Please set external bridge interface name" + exit 1 +fi + +OPENSTACK_HOST=$HOSTNAME +CONFIG_DIR="configs" + +export DEBIAN_FRONTEND=noninteractive + +function download_packages() { + echo "downloading packages..." + apt-get -dy install chrony mariadb-server python3-pymysql rabbitmq-server memcached python3-memcache etcd keystone apache2 python3-openstackclient glance placement-api libguestfs-tools virt-manager nova-api nova-conductor nova-novncproxy nova-scheduler neutron-server neutron-plugin-ml2 neutron-linuxbridge-agent neutron-dhcp-agent neutron-metadata-agent neutron-plugin-ml2 neutron-openvswitch-agent neutron-l3-agent python3-neutronclient openstack-dashboard + apt-get -dy install nova-compute-qemu + echo "done" +} + +function update_hostip() { + echo "updating host IP..." + sed -i "s/127.0.1.1[[:blank:]]${OPENSTACK_HOST}/#127.0.1.1 ${OPENSTACK_HOST}/" /etc/hosts + sed -i "/#127.0.1.1/a ${OPENSTACK_HOST_IP} ${OPENSTACK_HOST}" /etc/hosts + echo "done" +} + +function setup_chrony() { + echo "installing chrony..." + apt-get -y install chrony + systemctl enable chrony + systemctl restart chrony + echo "done" +} + +function setup_mariadb() { + echo "installing mariadb..." + apt-get -y install mariadb-server python3-pymysql + sed "s/REPLACE_WITH_OPENSTACK_HOST_IP/${OPENSTACK_HOST_IP}/" ${CONFIG_DIR}/99-openstack.cnf > /etc/mysql/mariadb.conf.d/99-openstack.cnf + systemctl restart mariadb + echo "done" +} + +function setup_rabbitmq() { + echo "installing rabbitmq" + apt-get -y install rabbitmq-server + export PATH=$PATH:/usr/sbin/:/sbin + rabbitmqctl add_user openstack RABBIT_PASS + rabbitmqctl set_permissions openstack ".*" ".*" ".*" + echo "done" +} + +function setup_memcahed() { + echo "installing memcahed" + apt-get -y install memcached python3-memcache + sed -i "s/-l 127.0.0.1/-l ${OPENSTACK_HOST_IP}/" /etc/memcached.conf + systemctl enable memcached + systemctl restart memcached + echo "done" +} + +function setup_etcd() { + echo "installing etcd" + apt-get -y install etcd + sed "s/REPLACE_WITH_OPENSTACK_HOST_IP/${OPENSTACK_HOST_IP}/" ${CONFIG_DIR}/etcd >> /etc/default/etcd + sed -i "s/REPLACE_WITH_HOST/${OPENSTACK_HOST}/" /etc/default/etcd + systemctl enable etcd + systemctl restart etcd + echo "done" +} + +function setup_database_tables() { + echo "creating database tables..." + mysql -u root < ${CONFIG_DIR}/database.sql + echo "done" +} + +function setup_apache2() { + echo "installing apache2..." + apt-get -y install apache2 + # set servername in apache2 + sed -i "1i ServerName ${OPENSTACK_HOST}" /etc/apache2/apache2.conf + systemctl restart apache2 + echo "done" +} + + +function setup_keystone() { + echo "installing keystone..." + apt-get -y install keystone + mv /etc/keystone/keystone.conf /etc/keystone/keystone.conf.org + systemctl stop keystone + sed "s/REPLACE_WITH_HOST/${OPENSTACK_HOST}/" ${CONFIG_DIR}/keystone.conf > /etc/keystone/keystone.conf + apt-get -y install python3-openstackclient + su -s /bin/sh -c "keystone-manage db_sync" keystone + systemctl restart apache2 + systemctl start keystone + echo "done" +} + +function configure_keystone() { + echo "configuring keystone..." + # keystone-manage + 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://${OPENSTACK_HOST}:5000/v3/ --bootstrap-internal-url http://${OPENSTACK_HOST}:5000/v3/ --bootstrap-public-url http://${OPENSTACK_HOST}:5000/v3/ --bootstrap-region-id RegionOne + echo "done" +} + + +function set_auth_variables() { + echo "setting auth variables..." + sed "s/REPLACE_WITH_HOST/${OPENSTACK_HOST}/" ${CONFIG_DIR}/admin-openrc > admin-openrc + sed "s/REPLACE_WITH_HOST/${OPENSTACK_HOST}/" ${CONFIG_DIR}/demo-openrc > demo-openrc + source admin-openrc + echo "done" +} + +function configure_domain_project() { + echo "configuring doamin and project..." + openstack domain create --description "An Example Domain" example + openstack project create --domain default --description "Service Project" service + openstack project create --domain default --description "Demo Project" myproject + openstack user create --domain default --password myuser myuser + openstack role create myrole + openstack role add --project myproject --user myuser myrole + echo "done" +} + + +function configure_glance_endpoints() { + echo "configuring glance endpoints..." + openstack user create --domain default --password glance 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://${OPENSTACK_HOST}:9292 + openstack endpoint create --region RegionOne image internal http://${OPENSTACK_HOST}:9292 + openstack endpoint create --region RegionOne image admin http://${OPENSTACK_HOST}:9292 + + openstack user create --domain default --password MY_SERVICE MY_SERVICE + openstack role add --user MY_SERVICE --user-domain default --system all reader + echo "done" +} + +function setup_glance() { + echo "installing glance..." + apt-get -y install glance + systemctl stop glance-* + mv /etc/glance/glance-api.conf /etc/glance/glance-api.conf.org + sed "s/REPLACE_WITH_HOST/${OPENSTACK_HOST}/" ${CONFIG_DIR}/glance-api.conf > /etc/glance/glance-api.conf + su -s /bin/sh -c "glance-manage db_sync" glance + systemctl start glance-api + systemctl restart glance-* + #wget http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img + #glance image-create --name "cirros" \ + # --file cirros-0.4.0-x86_64-disk.img \ + # --disk-format qcow2 --container-format bare \ + # --visibility=public + echo "done" +} + +function configure_placement_endpoints() { + echo "configuring placement endpoints..." + openstack user create --domain default --password placement 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://${OPENSTACK_HOST}:8778 + openstack endpoint create --region RegionOne placement internal http://${OPENSTACK_HOST}:8778 + openstack endpoint create --region RegionOne placement admin http://${OPENSTACK_HOST}:8778 + echo "done" +} + +function setup_placement() { + echo "installing placement..." + apt-get -y install placement-api + mv /etc/placement/placement.conf /etc/placement/placement.conf.org + sed "s/REPLACE_WITH_HOST/${OPENSTACK_HOST}/" ${CONFIG_DIR}/placement.conf > /etc/placement/placement.conf + su -s /bin/sh -c "placement-manage db sync" placement + systemctl restart placement-api + systemctl enable placement-api + systemctl restart apache2 + echo "done" +} + +function configure_nova_endpoints() { + echo "configuring nova endpoints..." + openstack user create --domain default --password nova 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://${OPENSTACK_HOST}:8774/v2.1 + openstack endpoint create --region RegionOne compute internal http://${OPENSTACK_HOST}:8774/v2.1 + openstack endpoint create --region RegionOne compute admin http://${OPENSTACK_HOST}:8774/v2.1 + echo "done" +} + +function setup_nova() { + echo "installing nova..." + apt-get -y install libguestfs-tools virt-manager + apt-get -y install nova-api nova-conductor nova-novncproxy nova-scheduler + systemctl stop nova-* + mv /etc/nova/nova.conf /etc/nova/nova.conf.org + cp ${CONFIG_DIR}/nova.conf /etc/nova/nova.conf + + sed -i "s/REPLACE_WITH_HOST/${OPENSTACK_HOST}/" /etc/nova/nova.conf + sed -i "s/REPLACE_WITH_OPENSTACK_HOST_IP/${OPENSTACK_HOST_IP}/" /etc/nova/nova.conf + + 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 + apt-get -y install nova-compute + apt-get -y install nova-compute-qemu + systemctl start nova-api + systemctl enable nova-api + systemctl enable nova-scheduler + systemctl enable nova-conductor + systemctl enable nova-novncproxy + systemctl enable nova-serialproxy + systemctl enable nova-spicehtml5proxy + systemctl enable nova-novncproxy + systemctl enable nova-compute + # find hypervisor + su -s /bin/bash nova -c "nova-manage cell_v2 discover_hosts" + #systemctl restart nova-* + systemctl restart nova-api + systemctl restart nova-scheduler + systemctl restart nova-conductor + systemctl restart nova-novncproxy + systemctl restart nova-serialproxy + systemctl restart nova-spicehtml5proxy + systemctl restart nova-novncproxy + systemctl restart nova-compute + echo "done" +} + + +function configure_neutron_endpoints() { + echo "configuring neutron endpoints..." + openstack user create --domain default --password neutron 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://${OPENSTACK_HOST}:9696 + openstack endpoint create --region RegionOne network internal http://${OPENSTACK_HOST}:9696 + openstack endpoint create --region RegionOne network admin http://${OPENSTACK_HOST}:9696 + echo "done" +} + + +function setup_neutron() { + echo "installing neutron..." + apt-get -y install neutron-server neutron-plugin-ml2 neutron-linuxbridge-agent neutron-dhcp-agent neutron-metadata-agent + systemctl stop neutron-* + + mv /etc/neutron/neutron.conf /etc/neutron/neutron.conf.org + cp ${CONFIG_DIR}/neutron.conf /etc/neutron/neutron.conf + sed -i "s/REPLACE_WITH_HOST/${OPENSTACK_HOST}/" /etc/neutron/neutron.conf + + mv /etc/neutron/metadata_agent.ini /etc/neutron/metadata_agent.ini.org + cp ${CONFIG_DIR}/metadata_agent.ini /etc/neutron/metadata_agent.ini + sed -i "s/REPLACE_WITH_HOST/${OPENSTACK_HOST}/" /etc/neutron/metadata_agent.ini + + # update for neutron config + cp ${CONFIG_DIR}/nova2.conf /etc/nova/nova.conf + sed -i "s/REPLACE_WITH_HOST/${OPENSTACK_HOST}/" /etc/nova/nova.conf + sed -i "s/REPLACE_WITH_OPENSTACK_HOST_IP/${OPENSTACK_HOST_IP}/" /etc/nova/nova.conf + + mv /etc/neutron/plugins/ml2/ml2_conf.ini /etc/neutron/plugins/ml2/ml2_conf.ini.org + cp ${CONFIG_DIR}/ml2_conf.ini /etc/neutron/plugins/ml2/ml2_conf.ini + mv /etc/neutron/plugins/ml2/linuxbridge_agent.ini /etc/neutron/plugins/ml2/linuxbridge_agent.ini.org + sed 's/PROVIDER_INTERFACE/'$EXTERNAL_BRIDGE_INTERFACE'/' ${CONFIG_DIR}/linuxbridge_agent.ini > /etc/neutron/plugins/ml2/linuxbridge_agent.ini + mv /etc/neutron/dhcp_agent.ini /etc/neutron/dhcp_agent.ini.org + cp ${CONFIG_DIR}/dhcp_agent.ini /etc/neutron/dhcp_agent.ini + + cp /etc/neutron/l3_agent.ini /etc/neutron/l3_agent.ini.org + sed -i "s/interface_driver = openvswitch/interface_driver = linuxbride/" /etc/neutron/l3_agent.ini + + systemctl enable neutron-api + systemctl enable neutron-rpc-server + systemctl enable neutron-metadata-agent + systemctl enable neutron-linuxbridge-agent + systemctl enable neutron-dhcp-agent + + systemctl restart nova-* + systemctl restart neutron-api + systemctl restart neutron-rpc-server + systemctl restart neutron-metadata-agent + systemctl restart neutron-linuxbridge-agent + systemctl restart neutron-dhcp-agent + + 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 + + echo "done" +} + +function enable_hypervisor() { + echo "updating hypervisor" + su -s /bin/bash nova -c "nova-manage cell_v2 discover_hosts" + echo "done" +} + +download_packages +update_hostip +setup_chrony +setup_mariadb +setup_rabbitmq +setup_memcahed +setup_etcd +setup_database_tables +setup_apache2 +setup_keystone +configure_keystone +set_auth_variables +configure_domain_project +configure_glance_endpoints +setup_glance +configure_placement_endpoints +setup_placement +configure_nova_endpoints +setup_nova +configure_neutron_endpoints +setup_neutron +enable_hypervisor |