centos一键部署openstackshell脚本
时间: 2023-08-31 15:08:56 浏览: 148
以下是一个CentOS一键部署OpenStack的Shell脚本,使用该脚本可以方便快速地搭建OpenStack环境:
```bash
#!/bin/bash
#更新系统
yum update -y
#安装epel源
yum install epel-release -y
#安装openstack源
yum install centos-release-openstack-ocata -y
#安装openstack客户端和python-openstackclient
yum install python-openstackclient -y
#安装MariaDB数据库
yum install mariadb mariadb-server python2-PyMySQL -y
#配置MariaDB数据库
systemctl enable mariadb.service
systemctl start mariadb.service
mysql_secure_installation
#安装rabbitmq消息队列
yum install rabbitmq-server -y
#配置rabbitmq消息队列
systemctl enable rabbitmq-server.service
systemctl start rabbitmq-server.service
rabbitmqctl add_user openstack RABBIT_PASS
rabbitmqctl set_permissions openstack ".*" ".*" ".*"
#安装memcached缓存服务器
yum install memcached python-memcached -y
#配置memcached缓存服务器
systemctl enable memcached.service
systemctl start memcached.service
#安装httpd服务器
yum install httpd mod_wsgi -y
#配置httpd服务器
systemctl enable httpd.service
systemctl start httpd.service
#安装OpenStack Keystone服务
yum install openstack-keystone httpd mod_wsgi -y
#配置OpenStack Keystone服务
systemctl enable httpd.service
systemctl start httpd.service
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://controller:35357/v3/ \
--bootstrap-internal-url http://controller:5000/v3/ \
--bootstrap-public-url http://controller:5000/v3/ \
--bootstrap-region-id RegionOne
#重启httpd服务
systemctl restart httpd.service
#安装OpenStack Glance服务
yum install openstack-glance -y
#配置OpenStack Glance服务
su -s /bin/sh -c "glance-manage db_sync" glance
#安装OpenStack Nova服务
yum install openstack-nova-api openstack-nova-conductor \
openstack-nova-console openstack-nova-novncproxy \
openstack-nova-scheduler -y
#编辑/etc/nova/nova.conf文件
cat > /etc/nova/nova.conf << EOF
[DEFAULT]
transport_url = rabbit://openstack:RABBIT_PASS@controller
auth_strategy = keystone
my_ip = MANAGEMENT_INTERFACE_IP_ADDRESS
use_neutron = True
firewall_driver = nova.virt.firewall.NoopFirewallDriver
[api]
auth_strategy = keystone
[keystone_authtoken]
auth_uri = http://controller:5000
auth_url = http://controller:35357
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = nova
password = NOVA_PASS
[vnc]
enabled = True
vncserver_listen = MANAGEMENT_INTERFACE_IP_ADDRESS
vncserver_proxyclient_address = MANAGEMENT_INTERFACE_IP_ADDRESS
[glance]
api_servers = http://controller:9292
[oslo_concurrency]
lock_path = /var/lib/nova/tmp
EOF
#配置OpenStack Nova服务
su -s /bin/sh -c "nova-manage api_db sync" nova
su -s /bin/sh -c "nova-manage db sync" nova
#重启OpenStack Nova服务
systemctl enable openstack-nova-api.service \
openstack-nova-consoleauth.service openstack-nova-scheduler.service \
openstack-nova-conductor.service openstack-nova-novncproxy.service
systemctl start openstack-nova-api.service \
openstack-nova-consoleauth.service openstack-nova-scheduler.service \
openstack-nova-conductor.service openstack-nova-novncproxy.service
#安装OpenStack Neutron服务
yum install openstack-neutron-linuxbridge ebtables ipset -y
#编辑/etc/neutron/neutron.conf文件
cat > /etc/neutron/neutron.conf << EOF
[DEFAULT]
core_plugin = ml2
service_plugins = router
allow_overlapping_ips = True
transport_url = rabbit://openstack:RABBIT_PASS@controller
auth_strategy = keystone
notify_nova_on_port_status_changes = True
notify_nova_on_port_data_changes = True
[agent]
root_helper = sudo /usr/bin/neutron-rootwrap /etc/neutron/rootwrap.conf
[keystone_authtoken]
auth_uri = http://controller:5000
auth_url = http://controller:35357
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = neutron
password = NEUTRON_PASS
[database]
connection = mysql+pymysql://neutron:NEUTRON_DBPASS@controller/neutron
[oslo_concurrency]
lock_path = /var/lib/neutron/tmp
EOF
#编辑/etc/neutron/plugins/ml2/linuxbridge_agent.ini文件
cat > /etc/neutron/plugins/ml2/linuxbridge_agent.ini << EOF
[linux_bridge]
physical_interface_mappings = provider:PHYSICAL_INTERFACE_NAME
[vxlan]
enable_vxlan = False
[securitygroup]
enable_security_group = True
firewall_driver = neutron.agent.linux.iptables_firewall.IptablesFirewallDriver
EOF
#配置OpenStack Neutron服务
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
#重启OpenStack Neutron服务
systemctl enable neutron-server.service \
neutron-linuxbridge-agent.service neutron-dhcp-agent.service \
neutron-metadata-agent.service
systemctl start neutron-server.service \
neutron-linuxbridge-agent.service neutron-dhcp-agent.service \
neutron-metadata-agent.service
#安装OpenStack Horizon服务
yum install openstack-dashboard -y
#重启httpd服务
systemctl restart httpd.service
```
在运行该脚本之前,需要将以下变量修改为您自己的值:
- RABBIT_PASS:RabbitMQ的密码
- NOVA_PASS:Nova的密码
- NEUTRON_PASS:Neutron的密码
- NEUTRON_DBPASS:Neutron数据库的密码
- MANAGEMENT_INTERFACE_IP_ADDRESS:管理接口的IP地址
- PHYSICAL_INTERFACE_NAME:物理接口的名称
运行该脚本后,您将得到一个完整的OpenStack环境。但是,在使用OpenStack之前,您还需要进行一些其他的配置和操作,请参考OpenStack官方文档进行操作。
阅读全文