OpenStack for icehouse的自动化安装脚本——控制节点

注意:建议大家直接打开编辑复制,由于编辑器的编码问题,会出现自动将:


“sudo sed -i "/ \ [ DEFAULT \ ] / a \ rpc_backend = rabbit" /etc/nova/nova.conf”


转换为sudo sed -i "/ DEFAULT /a\rpc_backend = rabbit" /etc/nova/nova.conf


#!/bin/bash
# Program
# 2015/6/29 by lishaohua
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/loacl/sbin:~/bin
export PATH

#===============================================================
#
#Controller Node Configuate OS Env
#
#===============================================================

echo "==============Reading network info======================="
export controller_eth=eth0
export SourceIP=192.168.3.199
export controller="$(/sbin/ifconfig $controller_eth | awk '/inet addr/ {print $2}' | cut -f2 -d ":")"

export rabbit_pass=mq4smtest
export root_pass=#db4smtest#
export admin_token=SuperMap_Token

export keystone_db_user=keystonedbadmin
export keystone_db_pass=keystone4smtest
export admin_pass=admin4smtest

export glance_db_user=glancedbadmin
export glance_db_pass=glance4smtest
export glance_pass=glance4smtest

export nova_db_user=novadbadmin
export nova_db_pass=nova4smtest
export nova_pass=nova4smtest

export neutron_db_user=neutrondbadmin
export neutron_db_pass=neutron4smtest
export neutron_pass=neutron4smtest

export cinder_db_user=cinderdbadmin
export cinder_db_pass=cinder4smtest
export cinder_pass=cinder4smtest

export is_configuate_openstack_source=0
export is_update_os=0
export is_Install_SoftWare=0 
export is_NTP=0 
export is_MySQL=0 
export is_RabbitMQ=0 
export is_Keystone=0
export is_Glance=0 
export is_Nova=0 
export is_Neutron=0 
export is_Horizon=0 
export is_Cinder=0 


#===============================================================
#
#Controller Node Configuate OpenStack Source
#
#===============================================================

configuate_openstack_source_func(){	
	file=/etc/apt/sources.list
	> $file
	echo "deb http://$SourceIP/openstack trusty icehouse" >> $file
	echo "deb http://$SourceIP/openstack trusty icehouse-ext" >> $file
	echo "deb http://$SourceIP/openstack trusty os" >> $file
	echo "deb http://$SourceIP/openstack trusty tools" >> $file	
}

Update_os_func(){
	sudo apt-get update
}

Install_SoftWare_func(){
	echo "*"
	echo "*"
	echo "*"
	echo "=====================openssh-server"
	echo "*"
	echo "*"
	echo "*"
	sudo apt-get install openssh-server -y --force-yes
	echo "*"
	echo "*"
	echo "*"
	echo "=====================ntp"
	echo "*"
	echo "*"
	echo "*"
	sudo apt-get install ntp -y --force-yes
	echo "*"
	echo "*"
	echo "*"
	echo "=====================mysql"
	echo "*"
	echo "*"
	echo "*"
	sudo apt-get install python-mysqldb  -y --force-yes
	sudo DEBIAN_FRONTEND=noninteractive \
	apt-get --option "Dpkg::Options::=--force-confold" --assume-yes \
	install -y --force-yes mysql-server
	echo "*"
	echo "*"
	echo "*"
	echo "=====================Python-software-properties"
	echo "*"
	echo "*"
	echo "*"
	sudo apt-get install python-software-properties -y --force-yes
	echo "*"
	echo "*"
	echo "*"
	echo "=====================rabbitmq"
	echo "*"
	echo "*"
	echo "*"
	sudo apt-get install rabbitmq-server -y --force-yes
	echo "*"
	echo "*"
	echo "*"
	echo "=====================keystone"
	echo "*"
	echo "*"
	echo "*"
	sudo apt-get install keystone -y --force-yes
	echo "*"
	echo "*"
	echo "*"
	echo "=====================glance"
	echo "*"
	echo "*"
	echo "*"
	sudo apt-get install glance python-glanceclient -y --force-yes
	echo "*"
	echo "*"
	echo "*"
	echo "=====================nova"
	echo "*"
	echo "*"
	echo "*"
	sudo apt-get install nova-api nova-cert nova-conductor nova-consoleauth nova-novncproxy nova-scheduler python-novaclient -y --force-yes
	echo "*"
	echo "*"
	echo "*"
	echo "=====================neutron"
	echo "*"
	echo "*"
	echo "*"
	sudo apt-get install neutron-server neutron-plugin-ml2 -y --force-yes
	echo "*"
	echo "*"
	echo "*"
	echo "=====================horizon"
	echo "*"
	echo "*"
	echo "*"
	sudo apt-get install apache2 memcached libapache2-mod-wsgi openstack-dashboard -y --force-yes
	sudo apt-get remove --purge openstack-dashboard-ubuntu-theme -y --force-yes
	echo "*"
	echo "*"
	echo "*"
	echo "=====================cinder"
	echo "*"
	echo "*"
	echo "*"
	sudo apt-get install cinder-api cinder-scheduler -y --force-yes
}

NTP_func(){
	sed -i 's/server ntp.ubuntu.com/ \
	server ntp.ubuntu.com \
	server 127.127.1.0 \
	fudge 127.127.1.0 stratum 10/g' /etc/ntp.conf
	echo "*"
	sudo service ntp restart	
}

MySQL_func(){
	echo "===============Start configuate mysql-server"
	sudo sed -i -e " s/127.0.0.1/$controller/g" /etc/mysql/my.cnf

	sudo sed -i "/\[mysqld\]/a\character-set-server = utf8" /etc/mysql/my.cnf
	sudo sed -i "/\[mysqld\]/a\init-connect = 'SET NAMES utf8'" /etc/mysql/my.cnf
	sudo sed -i "/\[mysqld\]/a\collation-server = utf8_general_ci" /etc/mysql/my.cnf
	sudo sed -i "/\[mysqld\]/a\innodb_file_per_table" /etc/mysql/my.cnf
	sudo sed -i "/\[mysqld\]/a\default-storage-engine = innodb" /etc/mysql/my.cnf

	sudo service mysql restart
	echo "Successfull===================Start configuate MySQL Server"
	sleep 3s

	echo "===============Start mysql_install_db"
	sudo mysql_install_db
	echo "Successfull===================mysql_install_db"
	sleep 3s

	echo "===============Start mysql_secure_installation"
	sudo mysql_secure_installation
	echo "Successfull===================mysql_secure_installation"
}

RabbitMQ_func(){
	echo "===============Start configuate RabbitMQ"
	#Edit rabbitmq guest password
	sudo rabbitmqctl change_password guest $rabbit_pass
	#Enable Web Manage
	sudo rabbitmq-plugins enable rabbitmq_management  
	sudo service rabbitmq-server restart 
	echo "Successfull===================configuate RabbitMQ"
}

KeyStone_func(){
	echo "==============================update connection in keystone.conf"
	sudo sed -i '/connection = .*/{s|sqlite:///.*|mysql://'"$keystone_db_user"':'"$keystone_db_pass"'@'"$controller"'/keystone|g}'\
		  /etc/keystone/keystone.conf


	echo "*"
	echo "==============================RM keystone.db"
	 
	export keystone_db="/var/lib/keystone/keystone.db"   
	if [ -f "$keystone_db" ]; then
		sudo rm "$keystone_db"
		echo "successfull===========rm keystone db"
	fi

	echo "*" 
	echo "==============Start to Create KeyStone MySQL  info======================="
	sudo mysql -uroot -p$root_pass -e 'CREATE DATABASE keystone;'
	sudo mysql -uroot -p$root_pass -e "CREATE USER $keystone_db_user;"
	sudo mysql -uroot -p$root_pass -e "GRANT ALL PRIVILEGES ON keystone.* TO '$keystone_db_user'@'localhost' IDENTIFIED BY '$keystone_db_pass';"
	sudo mysql -uroot -p$root_pass -e "GRANT ALL PRIVILEGES ON keystone.* TO '$keystone_db_user'@'%' IDENTIFIED BY '$keystone_db_pass';"
	sudo mysql -uroot -p$root_pass -e "SET PASSWORD FOR '$keystone_db_user'@'%' = PASSWORD('$keystone_db_pass');"
	echo "Successfull============== Create KeyStone MySQL  info======================="

	echo "*" 
	echo "==============Start to Sync KeyStone DB  ======================="
	su -s /bin/sh -c "keystone-manage db_sync" keystone

	echo "*" 
	echo "==============Start to configuate keystone.conf  ======================="

	sudo sed -i -e " s/#admin_token=ADMIN/admin_token=$admin_token/g" /etc/keystone/keystone.conf
	sudo sed -i "/log_dir/a log_dir = /var/log/keystone" /etc/keystone/keystone.conf
	echo "*"
	sudo service keystone restart
	sleep 3s
	sudo service keystone restart
	sleep 5s
	echo "*"
	echo "==============Start to crontab keystone token  ======================="
	(crontab -l -u keystone 2>&1 | grep -q token_flush) || echo '@hourly /usr/bin/keystone-manage token_flush >/var/log/keystone/keystone-tokenflush.log 2>&1' >> /var/spool/cron/crontabs/keystone
	echo "*"
	export OS_SERVICE_TOKEN=$admin_token
	echo $OS_SERVICE_TOKEN
	export OS_SERVICE_ENDPOINT=http://$controller:35357/v2.0
	echo $OS_SERVICE_ENDPOINT
	echo "*"
	#***************************************************************
	#Create Admin/DEMO tenant user role
	#***************************************************************
	echo "==============Create demo tenant user role======================="
	export demo_pass=demo
	keystone user-create --name=demo --pass=$demo_pass [email protected]
	keystone tenant-create --name=demo --description="Demo Tenant"
	keystone user-role-add --user=demo --role=_member_ --tenant=demo

	echo "==============Create Admin tenant user role======================="
	keystone user-create --name=admin --pass=$admin_pass [email protected]
	keystone role-create --name=admin
	keystone tenant-create --name=admin --description="Admin Tenant"
	keystone user-role-add --user=admin --tenant=admin --role=admin
	keystone user-role-add --user=admin --role=_member_ --tenant=admin


	echo "==============Create a service tenant======================="
	keystone tenant-create --name=service --description="Service Tenant"


	echo "==============Define services and API endpoints======================="
	keystone service-create --name=keystone --type=identity \
	--description="OpenStack Identity"

	keystone endpoint-create \
	--service-id=$(keystone service-list | awk '/ identity / {print $2}') \
	--publicurl=http://$controller:5000/v2.0 \
	--internalurl=http://$controller:5000/v2.0 \
	--adminurl=http://$controller:35357/v2.0


	echo "==============Verify the Identity Service installation======================="
	unset OS_SERVICE_TOKEN OS_SERVICE_ENDPOINT
	echo "*"
	echo "==============Create admin openrc======================="
	admin_file=/root/admin-openrc.sh
	sudo touch $admin_file
	
	echo "export OS_USERNAME=admin " >> $admin_file
	echo "export OS_PASSWORD=$admin_pass " >> $admin_file
	echo "export OS_TENANT_NAME=admin " >> $admin_file
	echo "export OS_AUTH_URL=http://$controller:35357/v2.0 " >> $admin_file
	
	echo "*"

	echo "==============Create demo openrc ======================="
	demo_file=/root/demo-openrc.sh
	sudo touch $demo_file
	
	echo "export OS_USERNAME=demo " >> $demo_file
	echo "export OS_PASSWORD=$demo_pass" >> $demo_file
	echo "export OS_TENANT_NAME=demo" >> $demo_file
	echo "export OS_AUTH_URL=http://$controller:35357/v2.0" >> $demo_file
	
	echo "*"
}



Glance_func(){
	echo "==============================update connection in glance.conf"
	sudo sed -i '/#connection = <None>/i\connection = mysql://'$glance_db_user':'"$glance_db_pass"'@'"$controller"'/glance' \
	/etc/glance/glance-registry.conf /etc/glance/glance-api.conf

	echo "*"
	echo "==============================update glance-api.conf-rabbit info"

	sudo sed -i "/rabbit_host = localhost/a rpc_backend = rabbit" /etc/glance/glance-api.conf
	sudo sed -i -e " s/rabbit_host = localhost/rabbit_host = $controller/g; \
			  s/rabbit_password = guest/rabbit_password = $rabbit_pass/g" \
			   /etc/glance/glance-api.conf


	echo "*"
	echo "==============================rm glance.sqlite"	
	export glance_sqlite="/var/lib/glance/glance.sqlite"   
	if [ -f "$glance_sqlite" ]; then
		sudo rm "$glance_sqlite"
	fi

	echo "*"
	echo "==============================Create glance db"	
	sudo mysql -uroot -p$root_pass -e 'CREATE DATABASE glance;'
	sudo mysql -uroot -p$root_pass -e 'CREATE USER $glance_db_user;'
	sudo mysql -uroot -p$root_pass -e "GRANT ALL PRIVILEGES ON glance.* TO '$glance_db_user'@'localhost' IDENTIFIED BY '$glance_db_pass';"
	sudo mysql -uroot -p$root_pass -e "GRANT ALL PRIVILEGES ON glance.* TO '$glance_db_user'@'%' IDENTIFIED BY '$glance_db_pass';"
	sudo mysql -uroot -p$root_pass -e "SET PASSWORD FOR '$glance_db_user'@'%' = PASSWORD('$glance_db_pass');"
	echo "*"
	echo "==============================Create glance db table"
	su -s /bin/sh -c "glance-manage db_sync" glance
	echo "*"



	echo "==============================update glance-api.conf-keystone_authtoken info"
	sudo sed -i -e " s/%SERVICE_TENANT_NAME%/service/g; s/%SERVICE_USER%/glance/g; \
			  s/%SERVICE_PASSWORD%/$glance_pass/g; \
			  s/#flavor=/flavor=keystone/g; \
			  s/auth_host = 127.0.0.1/auth_host = $controller/g" /etc/glance/glance-api.conf  /etc/glance/glance-registry.conf
			  
	sudo sed -i "/\[keystone_authtoken\]/a\auth_uri = http://$controller:5000" /etc/glance/glance-api.conf  /etc/glance/glance-registry.conf
	echo "*"


	echo "==============================Create glance for keystone"


	export OS_USERNAME=admin
	echo $OS_USERNAME
	export OS_PASSWORD=$admin_pass
	echo $OS_PASSWORD
	export OS_TENANT_NAME=admin
	echo $OS_TENANT_NAME
	export OS_AUTH_URL=http://$controller:35357/v2.0
	echo $OS_AUTH_URL

	keystone --os-tenant-name admin --os-username admin --os-password $admin_pass --os-auth-url=http://$controller:35357/v2.0  user-create --name=glance --pass=$glance_pass [email protected]

	keystone --os-tenant-name admin --os-username admin --os-password $admin_pass --os-auth-url=http://$controller:35357/v2.0  user-role-add --user=glance --tenant=service --role=admin

	keystone --os-tenant-name admin --os-username admin --os-password $admin_pass --os-auth-url=http://$controller:35357/v2.0 service-create --name=glance --type=image --description="OpenStack Image Service"


	keystone --os-tenant-name admin --os-username admin --os-password $admin_pass --os-auth-url=http://$controller:35357/v2.0 endpoint-create --service-id=$(keystone service-list | awk '/ image / {print $2}') --publicurl=http://$controller:9292 --internalurl=http://$controller:9292 --adminurl=http://$controller:9292

	echo "*"

	sudo service glance-registry restart
	sudo service glance-api restart
	sleep 3s
	sudo service glance-registry restart
	sudo service glance-api restart
}

Nova_func(){
	echo "*"
	echo "==============configuate nova.conf  info======================="



	sudo sed -i "/\[DEFAULT\]/a\rpc_backend = rabbit" /etc/nova/nova.conf
	sudo sed -i "/\[DEFAULT\]/a\rabbit_host = $controller" /etc/nova/nova.conf
	sudo sed -i "/\[DEFAULT\]/a\rabbit_password = $rabbit_pass" /etc/nova/nova.conf
	sudo sed -i "/\[DEFAULT\]/a\auth_strategy = keystone" /etc/nova/nova.conf
	sudo sed -i "/\[DEFAULT\]/a\my_ip = $controller" /etc/nova/nova.conf
	sudo sed -i "/\[DEFAULT\]/a\vncserver_listen = $controller" /etc/nova/nova.conf
	sudo sed -i "/\[DEFAULT\]/a\vncserver_proxyclient_address = $controller" /etc/nova/nova.conf

	echo "[keystone_authtoken]" >> /etc/nova/nova.conf
	echo "auth_uri = http://$controller:5000" >> /etc/nova/nova.conf
	echo "auth_host = $controller" >> /etc/nova/nova.conf
	echo "auth_port = 35357" >> /etc/nova/nova.conf
	echo "auth_protocol = http" >> /etc/nova/nova.conf
	echo "admin_tenant_name = service" >> /etc/nova/nova.conf
	echo "admin_user = nova" >> /etc/nova/nova.conf
	echo "admin_password = $nova_pass" >> /etc/nova/nova.conf

	echo "[database]" >> /etc/nova/nova.conf
	echo "connection = mysql://$nova_db_user:$nova_db_pass@$controller/nova" >> /etc/nova/nova.conf
	echo "*"

	echo "==============================rm nova.sqlite"	
	export nova_sqlite="/var/lib/nova/nova.sqlite"   
	if [ -f "$nova_sqlite" ]; then
		sudo rm "$nova_sqlite"
	fi

	echo "*"
	echo "==============================Create nova db"	
	sudo mysql -uroot -p$root_pass -e 'CREATE DATABASE nova;'
	sudo mysql -uroot -p$root_pass -e 'CREATE USER $nova_db_user;'
	sudo mysql -uroot -p$root_pass -e "GRANT ALL PRIVILEGES ON nova.* TO '$nova_db_user'@'localhost' IDENTIFIED BY '$nova_db_pass';"
	sudo mysql -uroot -p$root_pass -e "GRANT ALL PRIVILEGES ON nova.* TO '$nova_db_user'@'%' IDENTIFIED BY '$nova_db_pass';"
	sudo mysql -uroot -p$root_pass -e "SET PASSWORD FOR '$nova_db_user'@'%' = PASSWORD('$nova_db_pass');"

	echo "*"
	echo "==============================Create nova db table"
	su -s /bin/sh -c "nova-manage db sync" nova
	echo "*"

	echo "==============================Create nova for keystone"
	export OS_USERNAME=admin
	echo $OS_USERNAME
	export OS_PASSWORD=$admin_pass
	echo $OS_PASSWORD
	export OS_TENANT_NAME=admin
	echo $OS_TENANT_NAME
	export OS_AUTH_URL=http://$controller:35357/v2.0
	echo $OS_AUTH_URL


	keystone --os-tenant-name admin --os-username admin --os-password $admin_pass --os-auth-url=http://$controller:35357/v2.0 user-create --name=nova --pass=$nova_pass [email protected]
	keystone --os-tenant-name admin --os-username admin --os-password $admin_pass --os-auth-url=http://$controller:35357/v2.0 user-role-add --user=nova --tenant=service --role=admin
	keystone --os-tenant-name admin --os-username admin --os-password $admin_pass --os-auth-url=http://$controller:35357/v2.0 service-create --name=nova --type=compute \
	--description="OpenStack Compute"
	keystone --os-tenant-name admin --os-username admin --os-password $admin_pass --os-auth-url=http://$controller:35357/v2.0 endpoint-create \
	--service-id=$(keystone service-list | awk '/ compute / {print $2}') \
	--publicurl=http://$controller:8774/v2/%\(tenant_id\)s \
	--internalurl=http://$controller:8774/v2/%\(tenant_id\)s \
	--adminurl=http://$controller:8774/v2/%\(tenant_id\)s
	echo "*"

	sudo service nova-api restart
	sudo service nova-cert restart
	sudo service nova-consoleauth restart
	sudo service nova-scheduler restart
	sudo service nova-conductor restart
	sudo service nova-novncproxy restart
	sleep 3s
	sudo service nova-api restart
	sudo service nova-cert restart
	sudo service nova-consoleauth restart
	sudo service nova-scheduler restart
	sudo service nova-conductor restart
	sudo service nova-novncproxy restart
	sleep 3s
}


Neutron_func(){
	echo "==============================Create neutron db"	
	sudo mysql -uroot -p$root_pass -e 'CREATE DATABASE neutron;'
	sudo mysql -uroot -p$root_pass -e 'CREATE USER $neutron_db_user;'
	sudo mysql -uroot -p$root_pass -e "GRANT ALL PRIVILEGES ON neutron.* TO '$neutron_db_user'@'localhost' IDENTIFIED BY '$neutron_db_pass';"
	sudo mysql -uroot -p$root_pass -e "GRANT ALL PRIVILEGES ON neutron.* TO '$neutron_db_user'@'%' IDENTIFIED BY '$neutron_db_pass';"
	sudo mysql -uroot -p$root_pass -e "SET PASSWORD FOR '$neutron_db_user'@'%' = PASSWORD('$neutron_db_pass');"

	echo "*"
	echo "==============================Create neutron for keystone"
	export OS_USERNAME=admin
	echo $OS_USERNAME
	export OS_PASSWORD=$admin_pass
	echo $OS_PASSWORD
	export OS_TENANT_NAME=admin
	echo $OS_TENANT_NAME
	export OS_AUTH_URL=http://$controller:35357/v2.0
	echo $OS_AUTH_URL
	keystone --os-tenant-name admin --os-username admin --os-password $admin_pass --os-auth-url=http://$controller:35357/v2.0 user-create --name neutron --pass $neutron_pass --email [email protected]
	keystone --os-tenant-name admin --os-username admin --os-password $admin_pass --os-auth-url=http://$controller:35357/v2.0 user-role-add --user neutron --tenant service --role admin
	keystone --os-tenant-name admin --os-username admin --os-password $admin_pass --os-auth-url=http://$controller:35357/v2.0 service-create --name neutron --type network --description "OpenStack Networking"
	keystone --os-tenant-name admin --os-username admin --os-password $admin_pass --os-auth-url=http://$controller:35357/v2.0 endpoint-create --service-id $(keystone service-list | awk '/ network / {print $2}') \
	--publicurl http://$controller:9696 \
	--adminurl http://$controller:9696 \
	--internalurl http://$controller:9696


	echo "*"
	#***************************************************************
	#Neutron.conf
	#***************************************************************
	echo "===============Start configuate neutron.conf"

	#connection
	sudo sed -i '/connection = .*/{s|sqlite:///.*|mysql://'"$neutron_db_user"':'"$neutron_db_pass"'@'"$controller"'/neutron|g}'\
		  /etc/neutron/neutron.conf

	sudo sed -i -e 's/# verbose = False/verbose = True/g' /etc/neutron/neutron.conf
	#Keystone
	sudo sed -i -e 's/# auth_strategy = keystone/auth_strategy = keystone/g' /etc/neutron/neutron.conf

	sudo sed -i -e " s/%SERVICE_TENANT_NAME%/service/g; s/%SERVICE_USER%/neutron/g; \
			  s/%SERVICE_PASSWORD%/$neutron_pass/g; \
			  s/auth_host = 127.0.0.1/auth_host = $controller/g" /etc/neutron/neutron.conf
			  
	sudo sed -i "/\[keystone_authtoken\]/a\auth_uri = http://$controller:5000" /etc/neutron/neutron.conf

	#RabbitMQ
	sudo sed -i -e " s/# rpc_backend = neutron.openstack.common.rpc.impl_kombu/rpc_backend = neutron.openstack.common.rpc.impl_kombu/g; \
			  s/# rabbit_host = localhost/rabbit_host = $controller/g; \
			  s/# rabbit_password = guest/rabbit_password = $rabbit_pass/g; \
			  s/# rabbit_userid = guest/rabbit_userid = guest/g" \
			  /etc/neutron/neutron.conf
			  
	#Neutron for Nova 
	export OS_USERNAME=admin
	echo $OS_USERNAME
	export OS_PASSWORD=$admin_pass
	echo $OS_PASSWORD
	export OS_TENANT_NAME=admin
	echo $OS_TENANT_NAME
	export OS_AUTH_URL=http://$controller:35357/v2.0
	echo $OS_AUTH_URL
	nova_admin_tenant_id=`keystone tenant-get service | awk '$2~/^id/{print $4}'`
	echo $nova_admin_tenant_id		  
	sed -i -e " s/# notify_nova_on_port_status_changes = True/notify_nova_on_port_status_changes = True/g; \
	  s/# notify_nova_on_port_data_changes = True/notify_nova_on_port_data_changes = True/g; \
	  s/# nova_url = http:\/\/127.0.0.1:8774\/v2/nova_url = http:\/\/$controller:8774\/v2/g; \
	  s/# nova_admin_username =/nova_admin_username = nova/g; \
			s/# nova_admin_tenant_id =/nova_admin_tenant_id = $nova_admin_tenant_id/g; \
	  s/# nova_admin_password =/nova_admin_password = $nova_pass/g; \
			s/# nova_admin_auth_url =/nova_admin_auth_url = http:\/\/$controller:35357\/v2.0/g" \
	  /etc/neutron/neutron.conf
	  
	#ML2 plug-in
	sudo sed -i -e 's/core_plugin = neutron.plugins.ml2.plugin.Ml2Plugin/core_plugin = ml2/g' /etc/neutron/neutron.conf
	sudo sed -i -e 's/# service_plugins =/service_plugins = router/g' /etc/neutron/neutron.conf
	sudo sed -i -e 's/# allow_overlapping_ips = False/allow_overlapping_ips = True/g' /etc/neutron/neutron.conf
	echo "Successfull=================== Start configuate neutron.conf"
	sleep 3s


	#***************************************************************
	#ml2_conf.ini
	#***************************************************************

	echo "===============Start configuate ml2_conf.ini"
	#[ml2]
	sudo sed -i -e 's/# type_drivers = local,flat,vlan,gre,vxlan/type_drivers = gre/g' /etc/neutron/plugins/ml2/ml2_conf.ini
	sudo sed -i -e 's/# tenant_network_types = local/tenant_network_types = gre/g' /etc/neutron/plugins/ml2/ml2_conf.ini
	sudo sed -i -e 's/# mechanism_drivers =/mechanism_drivers = openvswitch/g' /etc/neutron/plugins/ml2/ml2_conf.ini

	#[ml2_type_gre]
	sudo sed -i -e 's/# tunnel_id_ranges =/tunnel_id_ranges = 1:1000/g' /etc/neutron/plugins/ml2/ml2_conf.ini

	#[securitygroup]
	sudo sed -i -e 's/# enable_security_group = True/enable_security_group = True/g' /etc/neutron/plugins/ml2/ml2_conf.ini
	echo "firewall_driver = neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver" >> /etc/neutron/plugins/ml2/ml2_conf.ini



	#***************************************************************
	#Nova.conf
	#***************************************************************
	echo "===============Start configuate nov.conf"

	sudo sed -i "/\[DEFAULT\]/a\network_api_class = nova.network.neutronv2.api.API" /etc/nova/nova.conf
	sudo sed -i "/\[DEFAULT\]/a\neutron_url = http:\/\/$controller:9696" /etc/nova/nova.conf
	sudo sed -i "/\[DEFAULT\]/a\neutron_auth_strategy = keystone" /etc/nova/nova.conf
	sudo sed -i "/\[DEFAULT\]/a\neutron_admin_tenant_name = service" /etc/nova/nova.conf
	sudo sed -i "/\[DEFAULT\]/a\neutron_admin_username = neutron" /etc/nova/nova.conf
	sudo sed -i "/\[DEFAULT\]/a\neutron_admin_password = $neutron_pass" /etc/nova/nova.conf
	sudo sed -i "/\[DEFAULT\]/a\neutron_admin_auth_url = http:\/\/$controller:35357/v2.0" /etc/nova/nova.conf
	sudo sed -i "/\[DEFAULT\]/a\linuxnet_interface_driver = nova.network.linux_net.LinuxOVSInterfaceDriver" /etc/nova/nova.conf
	sudo sed -i "/\[DEFAULT\]/a\firewall_driver = nova.virt.firewall.NoopFirewallDriver" /etc/nova/nova.conf
	sudo sed -i "/\[DEFAULT\]/a\security_group_api = neutron" /etc/nova/nova.conf

	#Update Nova.conf  from Network Node 
	export metadata_pass=neutron4smtest
	sudo sed -i "/\[DEFAULT\]/a\service_neutron_metadata_proxy = true" /etc/nova/nova.conf
	sudo sed -i "/\[DEFAULT\]/a\neutron_metadata_proxy_shared_secret = $metadata_pass" /etc/nova/nova.conf
	echo "*"

	sudo service nova-api restart
	sudo service nova-scheduler restart
	sudo service nova-conductor restart
	sudo service neutron-server restart
	sleep 3s
	sudo service nova-api restart
	sudo service nova-scheduler restart
	sudo service nova-conductor restart
	sudo service neutron-server restart
}


Horizon_func(){
	echo "*"
	sudo sed -i -e " s/127.0.0.1/$controller/g" /etc/openstack-dashboard/local_settings.py
	echo "*"
	echo "ServerName $controller" >>  /etc/apache2/apache2.conf
	echo "*"
	sudo service apache2 restart
	sudo service memcached restart
}

Cinder_func(){
	
	cinder_file=/etc/cinder/cinder.conf
	> $cinder_file
	echo "[DEFAULT]" >> $cinder_file	
	echo "rootwrap_config = /etc/cinder/rootwrap.conf" >> $cinder_file
	echo "api_paste_confg = /etc/cinder/api-paste.ini" >> $cinder_file
	echo "iscsi_helper = tgtadm" >> $cinder_file
	echo "volume_name_template = volume-%s" >> $cinder_file
	echo "volume_group = cinder-volumes" >> $cinder_file
	echo "verbose = True" >> $cinder_file
	echo "auth_strategy = keystone" >> $cinder_file
	echo "state_path = /var/lib/cinder" >> $cinder_file
	echo "lock_path = /var/lock/cinder" >> $cinder_file
	echo "volumes_dir = /var/lib/cinder/volumes" >> $cinder_file

	echo "rpc_backend = cinder.openstack.common.rpc.impl_kombu" >> $cinder_file
	echo "rabbit_host = $controller" >> $cinder_file
	echo "rabbit_port = 5672" >> $cinder_file
	echo "rabbit_userid = guest" >> $cinder_file
	echo "rabbit_password = $rabbit_pass" >> $cinder_file

	echo "[keystone_authtoken]" >> $cinder_file
	echo "auth_uri = http://$controller:5000" >> $cinder_file
	echo "auth_host = $controller" >> $cinder_file
	echo "auth_port = 35357" >> $cinder_file
	echo "auth_protocol = http" >> $cinder_file
	echo "admin_tenant_name = service" >> $cinder_file
	echo "admin_user = cinder" >> $cinder_file
	echo "admin_password = $cinder_pass" >> $cinder_file

	echo "[database]" >> $cinder_file
	echo "connection = mysql://$cinder_db_user:$cinder_db_pass@$controller/cinder" >> $cinder_file

	
	echo "==============================rm cinder.sqlite"	
	export cinder_sqlite="/var/lib/cinder/cinder.sqlite"   
	if [ -f "$cinder_sqlite" ]; then
		sudo rm "$cinder_sqlite"
	fi
	

	echo "*"
	echo "==============================Create cinder db"	
	sudo mysql -uroot -p$root_pass -e 'CREATE DATABASE cinder;'
	sudo mysql -uroot -p$root_pass -e 'CREATE USER $cinder_db_user;'
	sudo mysql -uroot -p$root_pass -e "GRANT ALL PRIVILEGES ON cinder.* TO '$cinder_db_user'@'localhost' IDENTIFIED BY '$cinder_db_pass';"
	sudo mysql -uroot -p$root_pass -e "GRANT ALL PRIVILEGES ON cinder.* TO '$cinder_db_user'@'%' IDENTIFIED BY '$cinder_db_pass';"
	sudo mysql -uroot -p$root_pass -e "SET PASSWORD FOR '$cinder_db_user'@'%' = PASSWORD('$cinder_db_pass');"
	echo "*"
	echo "==============================Create cinder db table"
	su -s /bin/sh -c "cinder-manage db sync" cinder
	echo "*"

	export OS_USERNAME=admin
	echo $OS_USERNAME
	export OS_PASSWORD=$admin_pass
	echo $OS_PASSWORD
	export OS_TENANT_NAME=admin
	echo $OS_TENANT_NAME
	export OS_AUTH_URL=http://$controller:35357/v2.0
	echo $OS_AUTH_URL

	keystone user-create --name=cinder --pass=$cinder_pass [email protected]
	keystone user-role-add --user=cinder --tenant=service --role=admin

	keystone service-create --name=cinder --type=volume --description="OpenStack Block Storage"
	keystone endpoint-create \
	--service-id=$(keystone service-list | awk '/ volume / {print $2}') \
	--publicurl=http://$controller:8776/v1/%\(tenant_id\)s \
	--internalurl=http://$controller:8776/v1/%\(tenant_id\)s \
	--adminurl=http://$controller:8776/v1/%\(tenant_id\)s

	keystone service-create --name=cinderv2 --type=volumev2 --description="OpenStack Block Storage v2"
	keystone endpoint-create \
	--service-id=$(keystone service-list | awk '/ volumev2 / {print $2}') \
	--publicurl=http://$controller:8776/v2/%\(tenant_id\)s \
	--internalurl=http://$controller:8776/v2/%\(tenant_id\)s \
	--adminurl=http://$controller:8776/v2/%\(tenant_id\)s

	sudo service cinder-scheduler restart
	sudo service cinder-api restart
	sleep 3s
	sudo service cinder-scheduler restart
	sudo service cinder-api restart
	
}

if [ `id -u ` -ne "0" ]; then
   echo "please use root login in "
   exit 1
fi

if [ "$is_configuate_openstack_source" = 0 ]; then
   configuate_openstack_source_func;
fi

if [ "$is_update_os" = 0 ]; then
   Update_os_func;
fi

if [ "$is_Install_SoftWare" = 0 ]; then
   Install_SoftWare_func;
fi

if [ "$is_NTP" = 0 ]; then
   NTP_func;
fi

if [ "$is_MySQL" = 0 ]; then
   MySQL_func;
fi

if [ "$is_RabbitMQ" = 0 ]; then
   RabbitMQ_func;
fi

if [ "$is_Keystone" = 0 ]; then
   KeyStone_func;
fi

if [ "$is_Glance" = 0 ]; then
   Glance_func;
fi

if [ "$is_Nova" = 0 ]; then
   Nova_func;
fi

if [ "$is_Neutron" = 0 ]; then
   Neutron_func;
fi

if [ "$is_Horizon" = 0 ]; then
   Horizon_func;
fi

if [ "$is_Cinder" = 0 ]; then
   Cinder_func;
fi






你可能感兴趣的:(OpenStack for icehouse的自动化安装脚本——控制节点)