OpenStack Neutron服务安装脚本

Controller

#!/bin/bash

readonly NEUTRON_DBPASS=openstack
readonly NEUTRON_PASS=openstack # 在keystone服务中的密码
readonly METADATA_SECRET=openstack

readonly RABBIT_PASS=openstack
readonly NOVA_PASS=openstack
#Replace PROVIDER_INTERFACE_NAME with the name of the underlying provider physical network interface
readonly PROVIDER_INTERFACE_NAME=eth1
#Replace OVERLAY_INTERFACE_IP_ADDRESS with the IP address of the underlying physical network interface that handles overlay networks. The example architecture uses the management interface to tunnel traffic to the other nodes. Therefore, replace OVERLAY_INTERFACE_IP_ADDRESS with the management IP address of the controller node. See Host networking for more information.
readonly OVERLAY_INTERFACE_IP_ADDRESS=172.16.199.11

#获取参数范围的头部行数
#$1 匹配正则
#$2 文件名
function get_range_start_line() {
   
grep -n $1 $2 | cut -d ":" -f 1 
}

#获取参数范围的尾部行数
# $1 文件名
# $2 头部行数
function get_range_end_line() {
   
grep -n "^\[" $1 | cut -d ":" -f 1 | grep $2 -A1 | tail -n1 
}

#在OpenStack中创建域、角色、服务和端点
function create_object(){
   
. ~/admin-openrc
openstack user create --domain default --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://controller:9696
openstack endpoint create --region RegionOne network internal http://controller:9696
openstack endpoint create --region RegionOne network admin http://controller:9696
}

function config_network() {
   
#echo "-- option1"
#source ./install_neutron_controller_network_option1.sh
echo "-- option2"
source ./install_neutron_controller_network_option2.sh
}

# in /etc/neutron/metadata_agent.ini
function init_config_metadata_agent() {
   
filepath='/etc/neutron/metadata_agent.ini'
cp $filepath ${filepath}.bak
default_start=$(get_range_start_line "^\[DEFAULT\]" $filepath)
default_end=$(get_range_end_line $filepath $default_start)
sed -i "${default_start},$default_end s/^#nova_metadata_host =.*/nova_metadata_host = controller/g" $filepath
sed -i "${default_start},$default_end s/^#metadata_proxy_shared_secret =.*/metadata_proxy_shared_secret = "$METADATA_SECRET"/g" $filepath
}

# in /etc/nova/nova.conf
function init_config_nova() {
   
filepath='/etc/nova/nova.conf'
# 备份原有配置
cp $filepath ${filepath}.bak

neutron_start=$(get_range_start_line "^\[neutron\]" $filepath)
neutron_end=$(get_range_end_line $filepath $neutron_start)

sed -i "${neutron_start},$neutron_end s#^\#url =.*#url = http://controller:9696#g" $filepath
sed -i "${neutron_start},$neutron_end s#^\#auth_url =.*#auth_url = http://controller:5000#g" $filepath
sed -i "${neutron_start},$neutron_end s/^#auth_type =.*/auth_type = password/g" $filepath
sed -i "${neutron_start},$neutron_end s/^#project_domain_name =.*/project_domain_name = default/g" $filepath
sed -i "${neutron_start},$neutron_end s/^#user_domain_name =.*/user_domain_name = default/g" $filepath
sed -i "${neutron_start},$neutron_end s/^#region_name =.*/region_name = RegionOne/g" $filepath
sed -i "${neutron_start},$neutron_end s/^#project_name =.*/project_name = service/g" $filepath
sed -i "${neutron_start},$neutron_end s/^#username =.*/username = neutron/g" $filepath
sed -i "${neutron_start},$neutron_end s/^#password =.*/password = "$NEUTRON_PASS"/g" $filepath
sed -i "${neutron_start},$neutron_end s/^#service_metadata_proxy =.*/service_metadata_proxy = true/g" $filepath
sed -i "${neutron_start},$neutron_end s/^#metadata_proxy_shared_secret =.*/metadata_proxy_shared_secret = "$METADATA_SECRET"/g" $filepath
}

function check_neutron() {
   
. ~/admin-openrc
openstack extension list --network
echo "--------------网络配置opt1 和 opt2的区别在于,opt2会多一个在controller上的L3 agent"
openstack network agent list
}

install_neutron(){
   
#报错即刻退出
set -o errexit
set -x

#Prerequisites
echo "--------------创建neutron数据库"
source ./sql_scripts/neutron.sql

echo "--------------在OpenStack中创建域、角色、服务和端点"
create_object

echo "--------------设置网络选项"
config_network

echo "--------------设置元数据代理"
init_config_metadata_agent

echo "--------------设置nova.conf,使compute服务可以使用网络服务"
init_config_nova

echo "--------------生成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

# 完成安装
echo "--------------完成安装"
service nova-api restart

#重启网络服务
service neutron-server restart
service neutron-linuxbridge-agent restart
service neutron-dhcp-agent restart
service neutron-metadata-agent restart
# option2时,额外操作
service neutron-l3-agent restart

echo "-----------验证操作及常用命令--------"
check_neutron

}

install_neutron

network option1

#!/bin/bash

# in /etc/neutron/neutron.conf
function init_config_neutron() {
   
    filepath='/etc/neutron/neutron.conf'
	# 备份原有配置
	cp $filepath ${filepath}.bak

    sed -i '/^\[database\]/,/^\[/ {s#^connection =.*#connection = mysql+pymysql://neutron:'$NEUTRON_DBPASS'@controller/neutron#g} ' $filepath 

    default_start=$(get_range_start_line "^\[DEFAULT\]" $filepath)
    default_end=$(get_range_end_line $filepath $default_start)
    sed -i "${default_start},$default_end s/^core_plugin =.*/core_plugin = ml2/g" $filepath
    sed -i "${default_start},$default_end s/^#service_plugins =.*/service_plugins = /g" $filepath
    sed -i "${default_start},$default_end s#^\#transport_url =.*#transport_url = rabbit://openstack:"$RABBIT_PASS"@controller#g" $filepath
    sed -i "${default_start},$default_end s/^#auth_strategy =.*/auth_strategy = keystone/g" $filepath
    sed -i "${default_start},$default_end s/^#notify_nova_on_port_status_changes =.*/notify_nova_on_port_status_changes = true/g" $filepath
    sed -i "${default_start},$default_end s/^#notify_nova_on_port_data_changes =.*/notify_nova_on_port_data_changes = true/g" $filepath

    keystone_start=$(get_range_start_line "^\[keystone_authtoken\]" $filepath)
    keystone_end=$(get_range_end_line $filepath $keystone_start)
    sed -i "${keystone_start},$keystone_end {/^\w/d}" $filepath
    sed -i $keystone_start"a\www_authenticate_uri = http://controller:5000" $filepath 
    sed -i $((keystone_start + 1))"a\auth_url = http://controller:5000" $filepath 
    sed -i 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值