openstack扩容脚本
Posted 你奏凯
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了openstack扩容脚本相关的知识,希望对你有一定的参考价值。
#!/bin/bash
#
#修改hostname
MASTERHOSTNAME=`ip a|grep global|awk -F/ ‘{print $1}‘|awk ‘{print $2}‘|awk -F. ‘{print "-"$3"-"$4}‘`;hostnamectl --static set-hostname compute$MASTERHOSTNAME.dev01-gonn0101.bj-cn.vps.gmfcloud.com
IPADDR=`ip a|grep -w inet|grep -w brd|awk ‘{print $2}‘|awk -F/ ‘{print $1}‘`
#gome yum 源
gomerepo init
gomerepo enable openstack_newton
gomerepo enable ovirt
#安装软件
yum install -y libvirt-daemon-driver-storage-2.0.0-10.el7_3.9.x86_64
yum install -y libvirt-client-2.0.0-10.el7_3.9.x86_64
yum install -y libvirt-daemon-driver-qemu-2.0.0-10.el7_3.9.x86_64
yum install -y libvirt-daemon-driver-nodedev-2.0.0-10.el7_3.9.x86_64
yum install -y libvirt-daemon-2.0.0-10.el7_3.9.x86_64
yum install -y libvirt-daemon-driver-secret-2.0.0-10.el7_3.9.x86_64
yum install -y libvirt-python-2.0.0-2.el7.x86_64
yum install -y libvirt-daemon-driver-network-2.0.0-10.el7_3.9.x86_64
yum install -y libvirt-daemon-driver-nwfilter-2.0.0-10.el7_3.9.x86_64
yum install -y libvirt-daemon-kvm-2.0.0-10.el7_3.9.x86_64
yum install -y qemu-kvm-ev-2.6.0-27.1.el7.x86_64
yum install -y openvswitch-2.5.0-2.el7.x86_64
yum install -y python-openvswitch-2.5.0-2.el7.noarch
yum install -y openstack-neutron-common-9.1.1-1.el7.noarch
yum install -y openstack-neutron-openvswitch-9.1.1-1.el7.noarch
yum install -y openstack-neutron-ml2-9.1.1-1.el7.noarch
yum install -y openstack-nova-compute-14.0.2-1.el7.noarch
yum install -y openstack-nova-common-14.0.2-1.el7.noarch
yum install -y openstack-utils-2017.1-1.el7.noarch
#配置文件
cat <<EOF> /etc/nova/nova.conf
[DEFAULT]
my_ip = $IPADDR
log_dir = /var/log/nova
auth_strategy = keystone
debug = false
workers = 40
multi_host = true
state_path = /data/openstack/nova
allow_resize_to_same_host = true
resume_guests_state_on_host_boot = true
virt_type = kvm
cpu_allocation_ratio = 3.0
ram_allocation_ratio = 1.2
disk_allocation_ratio = 1.0
max_instances_per_host = 25
instance_usage_audit = True
instance_usage_audit_period = hour
notify_on_state_change = vm_and_task_state
enabled_apis = osapi_compute,metadata
running_deleted_instance_action = reap
multi_instance_display_name_template = %(name)s-%(count)s
scheduler_driver = nova.scheduler.filter_scheduler.FilterScheduler
#vcpu_pin_set = 8-39
#console_allowed_origins =
scheduler_default_filters = RetryFilter,AvailabilityZoneFilter,RamFilter,ComputeFilter,ComputeCapabilitiesFilter,ImagePropertiesFilter,ServerGroupAntiAffinityFilter,ServerGroupAffinityFilter,NumInstancesFilter
firewall_driver = nova.virt.firewall.NoopFirewallDriver
use_neutron = true
osapi_compute_listen = $IPADDR
osapi_compute_listen_port = 8774
metadata_listen = $IPADDR
metadata_listen_port = 8775
default_log_levels = amqplib=WARN,sqlalchemy=WARN,boto=WARN,suds=INFO,qpid.messaging=INFO,iso8601.iso8601=INFO
memcached_servers = controller-3-28:11211,controller-3-29:11211
rpc_backend = rabbit
network_api_class = nova.network.neutronv2.api.API
linuxnet_interface_driver = nova.network.linux_net.LinuxOVSInterfaceDriver
neutron_admin_tenant_name = service
neutron_auth_strategy = keystone
security_group_api = neutron
firewall_driver = nova.virt.firewall.NoopFirewallDriver
force_config_drive = true
# config_drive_skip_versions =
flat_injected = True
use_syslog = false
use_stderr = false
osapi_max_limit = 5000
[api_database]
connection = mysql+pymysql://nova:[email protected]/nova_api
max_pool_size = 100
max_overflow = 200
[barbican]
[cache]
[cells]
[cinder]
[cloudpipe]
[conductor]
[cors]
[cors.subdomain]
[crypto]
[database]
connection = mysql+pymysql://nova:[email protected]/nova
max_pool_size = 100
max_overflow = 200
[ephemeral_storage_encryption]
[glance]
api_servers = http://bj-cn.vps.gmfcloud.com:9292
[guestfs]
[hyperv]
config_drive_cdrom = true
# config_drive_inject_password = true
[image_file_url]
[ironic]
[key_manager]
[keystone_authtoken]
auth_uri = http://bj-cn.vps.gmfcloud.com:5000/v3
auth_url = http://bj-cn.vps.gmfcloud.com:35357/v3
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = nova
password = newnovapass
[libvirt]
[matchmaker_redis]
[metrics]
[mks]
[neutron]
url = http://bj-cn.vps.gmfcloud.com:9696
auth_uri = http://bj-cn.vps.gmfcloud.com:5000/v3
auth_url = http://bj-cn.vps.gmfcloud.com:35357/v3
auth_type = password
project_domain_name = default
user_domain_name = default
region_name = RegionOne
project_name = service
username = neutron
password = newneutronpass
service_metadata_proxy = false
[osapi_v21]
[oslo_concurrency]
lock_path = /var/lib/nova/tmp
[oslo_messaging_amqp]
[oslo_messaging_notifications]
[oslo_messaging_rabbit]
rabbit_hosts = controller-3-28:5672,controller-3-29:5672
rabbit_ha_queues = true
rabbit_userid = openstack
rabbit_password = h1Zg3IvdIiCx
heartbeat_timeout_threshold = 0
rabbit_max_retries = 3
[oslo_messaging_zmq]
[oslo_middleware]
[oslo_policy]
[placement]
[placement_database]
[rdp]
[remote_debug]
[serial_console]
[spice]
[ssl]
[trusted_computing]
[upgrade_levels]
[vmware]
[vnc]
novncproxy_base_url=http://10.152.3.1:6080/vnc_auto.html
novncproxy_host = $IPADDR
vncserver_listen = $IPADDR
vncserver_proxyclient_address = $IPADDR
novncproxy_port = 6080
[workarounds]
[wsgi]
[xenserver]
[xvp]
EOF
cat <<EOF> /etc/neutron/neutron.conf
[DEFAULT]
bind_host = $IPADDR
bind_port = 9696
core_plugin = ml2
debug = false
use_syslog = false
log_dir = /var/log/neutron
service_plugins = router,metering
auth_strategy = keystone
base_mac = fa:16:3f:00:00:00
allow_overlapping_ips = true
mac_generation_retries = 16
auth_strategy = keystone
notify_nova_on_port_status_changes = true
notify_nova_on_port_data_changes = true
notification_driver = neutron.openstack.common.notifier.rpc_notifier
rpc_backend = rabbit
agent_down_time = 75
api_workers = 40
rpc_workers = 40
send_events_interval = 2
[agent]
check_child_processes_interval = 30
check_child_processes_action = respawn
[cors]
[cors.subdomain]
[database]
connection = mysql+pymysql://neutron:[email protected]/neutron
max_pool_size = 150
max_overflow = 300
[keystone_authtoken]
auth_uri = http://bj-cn.vps.gmfcloud.com:5000/v3
auth_url = http://bj-cn.vps.gmfcloud.com:35357/v3
memcached_servers = controller-3-28:11211,controller-3-29:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = neutron
password = newneutronpass
[matchmaker_redis]
[nova]
url = http://bj-cn.vps.gmfcloud.com:8774/v2.1
auth_uri = http://bj-cn.vps.gmfcloud.com:5000/v3
auth_url = http://bj-cn.vps.gmfcloud.com:35357/v3
auth_type = password
project_domain_name = default
user_domain_name = default
region_name = RegionOne
project_name = service
username = nova
password = newnovapass
[oslo_concurrency]
lock_path = /var/lib/neutron/tmp
[oslo_messaging_amqp]
[oslo_messaging_notifications]
[oslo_messaging_rabbit]
rabbit_hosts=controller-3-28:5672,controller-3-29:5672
rabbit_ha_queues=true
rabbit_userid = openstack
rabbit_password = h1Zg3IvdIiCx
heartbeat_timeout_threshold=0
rabbit_max_retries=2
[oslo_messaging_zmq]
[oslo_middleware]
[oslo_policy]
[qos]
[quotas]
[ssl]
EOF
cat <<EOF> /etc/neutron/plugins/ml2/ml2_conf.ini
[DEFAULT]
[ml2]
type_drivers = vlan
tenant_network_types = vlan
mechanism_drivers = openvswitch
[ml2_type_flat]
flat_networks = physnet1
[ml2_type_geneve]
[ml2_type_gre]
[ml2_type_vlan]
network_vlan_ranges = physnet1:1:4000
[ml2_type_vxlan]
[securitygroup]
enable_security_group = false
firewall_driver = neutron.agent.firewall.NoopFirewallDriver
EOF
cat <<EOF> /etc/neutron/plugins/ml2/openvswitch_agent.ini
[DEFAULT]
[agent]
prevent_arp_spoofing = false
[ovs]
bridge_mappings = physnet1:br-bond0
[securitygroup]
enable_security_group = false
EOF
#修改nova权限
sed -i ‘/^nova/d‘ /etc/passwd
echo "nova:x:162:162:OpenStack Nova Daemons:/var/lib/nova:/bin/sh" >> /etc/passwd
#设置开机启动
systemctl enable openstack-nova-compute.service neutron-openvswitch-agent.service openvswitch.service
#启动服务
systemctl start openstack-nova-compute.service neutron-openvswitch-agent.service openvswitch.service
#设置
ovs-vsctl show
ovs-vsctl add-br br-int
ovs-vsctl add-br br-bond0
ovs-vsctl add-port br-bond0 bond0
#创建openstack目录并拷贝nova文件
mkdir -p /data/openstack ; cp -a /var/lib/nova /data/openstack/
#更改权限
echo "neutron ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
echo "nova ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
cp -a /usr/share/nova/interfaces.template /usr/share/nova/interfaces.template_bak
cat /usr/lib/python2.7/site-packages/nova/virt/interfaces.template > /usr/share/nova/interfaces.template
systemctl restart openstack-nova-compute.service ; systemctl restart neutron-openvswitch-agent.service
#拷贝key文件
scp -r [email protected]:/var/lib/nova/.ssh /var/lib/nova/
#更改权限
chown -R nova:nova /var/lib/nova/.ssh
以上是关于openstack扩容脚本的主要内容,如果未能解决你的问题,请参考以下文章
基于SaltStack+OpenStack的自动化扩容实战第1篇