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

#===============================================================
#
#Compute Node Configuate OS Env
#
#===============================================================

export controller_eth=eth0
export data_eth=eth1

export SourceIP=192.168.3.199
export controller=192.168.3.180
export my_ip="$(/sbin/ifconfig $controller_eth | awk '/inet addr/ {print $2}' | cut -f2 -d ":")"
export my_tunnel_ip="$(/sbin/ifconfig $data_eth | awk '/inet addr/ {print $2}' | cut -f2 -d ":")"
export nova_pass=nova4smtest
export rabbit_pass=mq4smtest
export neutron_pass=neutron4smtest
export nova_db_user=novadbadmin
export nova_db_pass=nova4smtest
sleep 3s

export is_configuate_openstack_source=0
export is_update_os=0
export is_Install_SoftWare=0 
export is_NTP=0 
export is_ip_forward=0 
export is_Neutron_conf=0 
export is_Nova_conf=0
export is_cpuinfo=0 
export is_Configuate_statoverride=0 



#===============================================================
#
#Network 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 apt-get install python-software-properties -y --force-yes
	echo "*"
	echo "*"
	echo "*"
	echo "=====================nova"
	echo "*"
	echo "*"
	echo "*"
	sudo apt-get install nova-compute-kvm python-guestfs -y --force-yes
	echo "*"
	echo "*"
	echo "*"
	echo "=====================neutron"
	echo "*"
	echo "*"
	echo "*"
	sudo apt-get install neutron-common neutron-plugin-ml2 neutron-plugin-openvswitch-agent openvswitch-datapath-dkms -y --force-yes
}




#===============================================================
#
#Network Node Configuate NTP
#
#===============================================================


NTP_func(){
	echo "===============Start configuate ntp"
	sudo sed -i -e " s/server 0.ubuntu.pool.ntp.org/#server 0.ubuntu.pool.ntp.org/g;\
	 s/server 1.ubuntu.pool.ntp.org/#server 1.ubuntu.pool.ntp.org/g;\
	 s/server 2.ubuntu.pool.ntp.org/#server 2.ubuntu.pool.ntp.org/g;\
	 s/server 3.ubuntu.pool.ntp.org/#server 3.ubuntu.pool.ntp.org/g;\
	 s/server ntp.ubuntu.com/server $controller/g" /etc/ntp.conf
	 
	sudo service ntp stop
	sudo ntpdate $controller
	sudo service ntp start
	echo "Successfull===================Start configuate ntp"
	sleep 3s
}

Configuate_statoverride_func(){
	sudo dpkg-statoverride  --update --add root root 0644 /boot/vmlinuz-$(uname -r)
			
	sudo touch /etc/kernel/postinst.d/statoverride
	
	echo "#!/bin/sh" >> /etc/kernel/postinst.d/statoverride
	sudo sed -i '1a version="$1"' /etc/kernel/postinst.d/statoverride
	sudo sed -i '2a # passing the kernel version is required' /etc/kernel/postinst.d/statoverride
	sudo sed -i '3a [ -z "${version}" ] && exit 0' /etc/kernel/postinst.d/statoverride
	sudo sed -i '4a dpkg-statoverride --update --add root root 0644 /boot/vmlinuz-${version}' /etc/kernel/postinst.d/statoverride

	sudo chmod +x /etc/kernel/postinst.d/statoverride
}

Nova_func(){
	nova_file=/etc/nova/nova.conf
	> $nova_file

	echo "[DEFAULT]" >> $nova_file
	echo "dhcpbridge_flagfile=/etc/nova/nova.conf" >> $nova_file
	echo "dhcpbridge=/usr/bin/nova-dhcpbridge" >> $nova_file
	echo "logdir=/var/log/nova" >> $nova_file
	echo "state_path=/var/lib/nova" >> $nova_file
	echo "lock_path=/var/lock/nova" >> $nova_file
	echo "force_dhcp_release=True" >> $nova_file
	echo "iscsi_helper=tgtadm" >> $nova_file
	echo "libvirt_use_virtio_for_bridges=True" >> $nova_file
	echo "connection_type=libvirt" >> $nova_file
	echo "root_helper=sudo nova-rootwrap /etc/nova/rootwrap.conf" >> $nova_file
	echo "verbose=True" >> $nova_file
	echo "ec2_private_dns_show_ip=True" >> $nova_file
	echo "api_paste_config=/etc/nova/api-paste.ini" >> $nova_file
	echo "volumes_path=/var/lib/nova/volumes" >> $nova_file
	echo "enabled_apis=ec2,osapi_compute,metadata" >> $nova_file

	echo "rpc_backend = rabbit" >> $nova_file
	echo "rabbit_host = $controller" >> $nova_file
	echo "rabbit_userid = guest" >> $nova_file
	echo "rabbit_password = $rabbit_pass" >> $nova_file
	echo "rabbit_port = 5672" >> $nova_file

	echo "my_ip = $my_ip" >> $nova_file
	echo "vnc_enabled = True" >> $nova_file
	echo "vncserver_listen = 0.0.0.0" >> $nova_file
	echo "vncserver_proxyclient_address = $my_ip" >> $nova_file

	echo "vnc_enabled = True" >> $nova_file
	echo "novncproxy_base_url = http://$controller:6080/vnc_auto.html" >> $nova_file

	echo "vif_plugging_timeout = 10" >> $nova_file
	echo "vif_plugging_is_fatal = False" >> $nova_file

	echo "auth_strategy = keystone" >> $nova_file

	echo "glance_host = $controller" >> $nova_file

	echo "network_api_class = nova.network.neutronv2.api.API" >> $nova_file
	echo "neutron_url = http://$controller:9696" >> $nova_file
	echo "neutron_auth_strategy = keystone" >> $nova_file
	echo "neutron_admin_tenant_name = service" >> $nova_file
	echo "neutron_admin_username = neutron" >> $nova_file
	echo "neutron_admin_password = $neutron_pass" >> $nova_file
	echo "neutron_admin_auth_url = http://$controller:35357/v2.0" >> $nova_file
	echo "linuxnet_interface_driver = nova.network.linux_net.LinuxOVSInterfaceDriver" >> $nova_file
	echo "firewall_driver = nova.virt.firewall.NoopFirewallDriver" >> $nova_file
	echo "security_group_api = neutron" >> $nova_file

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

	echo "[database]" >> $nova_file
	echo "connection = mysql://$nova_db_user:$nova_db_pass@$controller/nova" >> $nova_file


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

CpuInfo_func(){
	temp=`egrep -c '(vmx|svm)' /proc/cpuinfo`
	if [ "$temp" = 0 ]; then
	   sudo sed -i -e " s/virt_type=kvm/virt_type=qemu/g" /etc/nova/nova-compute.conf
	fi
}

Configuate_ip4_func(){
	echo "net.ipv4.conf.all.rp_filter=0" >> /etc/sysctl.conf
	echo "net.ipv4.conf.default.rp_filter=0" >> /etc/sysctl.conf
	sysctl -p
}

Neutron_func(){
	echo "===============Start configuate 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

	#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

	#[ovs]
	echo "[ovs]" >> /etc/neutron/plugins/ml2/ml2_conf.ini
	echo "local_ip = $my_tunnel_ip" >> /etc/neutron/plugins/ml2/ml2_conf.ini
	echo "tunnel_type = gre" >> /etc/neutron/plugins/ml2/ml2_conf.ini
	echo "enable_tunneling = True" >> /etc/neutron/plugins/ml2/ml2_conf.ini


	echo "Successfull=================== Start configuate ml2_conf.ini"

}
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_Configuate_statoverride" = 0 ]; then
   Configuate_statoverride_func;
fi

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

if [ "$is_cpuinfo" = 0 ]; then
   CpuInfo_func;
fi

	sudo service nova-compute restart
	sleep 5s
	sudo service nova-compute restart

if [ "$is_ip_forward" = 0 ]; then
   Configuate_ip4_func;
fi

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

sudo service openvswitch-switch restart
sudo service nova-compute restart
sudo service neutron-plugin-openvswitch-agent restart
sleep 3s
echo "*"
sudo service openvswitch-switch restart
sudo service nova-compute restart
sudo service neutron-plugin-openvswitch-agent restart


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