当前位置: 代码迷 >> 综合 >> OpenStack Nova服务安装脚本
  详细解决方案

OpenStack Nova服务安装脚本

热度:45   发布时间:2023-12-09 03:47:37.0

Controller

#!/bin/shinstall_nova_controller(){
    
#报错即刻退出
set -o errexit
set -x
readonly passwd=openstack
readonly my_ip=172.16.199.11source ./sql_scripts/nova.sqlsource ./admin-openrc
openstack user create --domain default --password $passwd nova
openstack role add --project service --user nova admin
openstack service create --name nova --description "OpenStack Compute" computeopenstack endpoint create --region RegionOne \
compute public http://controller:8774/v2.1
openstack endpoint create --region RegionOne \compute internal http://controller:8774/v2.1
openstack endpoint create --region RegionOne \compute admin http://controller:8774/v2.1openstack user create --domain default --password $passwd placement
openstack role add --project service --user placement adminopenstack service create --name placement --description "Placement API" placement
openstack endpoint create --region RegionOne placement public http://controller:8778
openstack endpoint create --region RegionOne placement internal http://controller:8778
openstack endpoint create --region RegionOne placement admin http://controller:8778(echo 'y')|apt install nova-api nova-conductor nova-consoleauth \nova-novncproxy nova-scheduler nova-placement-api#/etc/nova/nova.conf
#[api_database]
sed -i "3471s#^connection = .*#connection = mysql+pymysql://nova:$passwd@controller/nova_api#g" /etc/nova/nova.conf
head -n 3471 /etc/nova/nova.conf | tail -n 1#[database]
sed -i "4556s#^connection = .*#connection = mysql+pymysql://nova:$passwd@controller/nova#g" /etc/nova/nova.conf
head -n 4556 /etc/nova/nova.conf | tail -n 1#[placement_database]
sed -i "8960s/^#connection\s.*/connection = mysql+pymysql:\/\/placement:$passwd@controller\/placement/" /etc/nova/nova.conf
head -n 8960 /etc/nova/nova.conf | tail -n 1#[api]
sed -i -e "3194s/^#auth_strategy\s.*/auth_strategy = keystone/"  /etc/nova/nova.conf
head -n 3194 /etc/nova/nova.conf | tail -n 1#[glance]
sed -i "5258s/^#api_servers\s.*/api_servers = http:\/\/controller:9292/" /etc/nova/nova.conf
head -n 5258 /etc/nova/nova.conf | tail -n 1#[oslo_concurrency]
sed -i "7996s/^#lock_path\s.*/lock_path = \/var\/lib\/nova\/tmp/" /etc/nova/nova.conf 
head -n 7996 /etc/nova/nova.conf | tail -n 1#[scheduler]
sed -i "9653s/^#discover_hosts_in_cells_interval\s.*/discover_hosts_in_cells_interval = 300/" /etc/nova/nova.conf
head -n 9653 /etc/nova/nova.conf | tail -n 1#[vnc]
sed -i "10686s/^#enabled\s.*/enabled = true/" /etc/nova/nova.conf
head -n 10686 /etc/nova/nova.conf | tail -n 1
sed -i "10719s/^#server_listen\s.*/server_listen=\$my_ip/" /etc/nova/nova.conf
head -n 10719 /etc/nova/nova.conf | tail -n 1
sed -i "10732s/^#server_proxyclient_address\s.*/server_proxyclient_address=\$my_ip/" /etc/nova/nova.conf
head -n 10732 /etc/nova/nova.conf | tail -n 1#[default]
#remove log_dir
sed -i "2s/^log_dir\s.*/#&/" /etc/nova/nova.conf 
head -n 2 /etc/nova/nova.conf | tail -n 1sed -i "5i transport_url = rabbit://openstack:$passwd@controller" /etc/nova/nova.conf
head -n 5 /etc/nova/nova.conf | tail -n 1sed -i "6i my_ip = $my_ip" /etc/nova/nova.conf
head -n 6 /etc/nova/nova.conf | tail -n 1
sed -i "7i use_neutron = True" /etc/nova/nova.conf
head -n 7 /etc/nova/nova.conf | tail -n 1
sed -i "8i firewall_driver = nova.virt.firewall.NoopFirewallDriver" /etc/nova/nova.conf
head -n 8 /etc/nova/nova.conf | tail -n 1#[keystone_authtoken]
beginnum=6062
sed -i "$[beginnum]i auth_url = http://controller:5000/v3" /etc/nova/nova.conf
head -n $[beginnum] /etc/nova/nova.conf | tail -n 1
sed -i "$[beginnum+1]i memcached_servers = controller:11211" /etc/nova/nova.conf
head -n $[beginnum+1] /etc/nova/nova.conf | tail -n 1
sed -i "$[beginnum+2]i auth_type = password" /etc/nova/nova.conf
head -n $[beginnum+2] /etc/nova/nova.conf | tail -n 1
sed -i "$[beginnum+3]i project_domain_name = Default" /etc/nova/nova.conf
head -n $[beginnum+3] /etc/nova/nova.conf | tail -n 1
sed -i "$[beginnum+4]i user_domain_name = Default" /etc/nova/nova.conf
head -n $[beginnum+4] /etc/nova/nova.conf | tail -n 1
sed -i "$[beginnum+5]i project_name = service" /etc/nova/nova.conf
head -n $[beginnum+5] /etc/nova/nova.conf | tail -n 1
sed -i "$[beginnum+6]i username = nova" /etc/nova/nova.conf
head -n $[beginnum+6] /etc/nova/nova.conf | tail -n 1
sed -i "$[beginnum+7]i password = $passwd" /etc/nova/nova.conf
head -n $[beginnum+7] /etc/nova/nova.conf | tail -n 1#[placement]
sed -i "8815s/^os_region_name\s.*/os_region_name = RegionOne/" /etc/nova/nova.conf
head -n 8815 /etc/nova/nova.conf | tail -n 1beginnum=8816
sed -i "$[beginnum]i project_domain_name = Default" /etc/nova/nova.conf
head -n $[beginnum] /etc/nova/nova.conf | tail -n 1
sed -i "$[beginnum+1]i project_name = service" /etc/nova/nova.conf
head -n $[beginnum+1] /etc/nova/nova.conf | tail -n 1
sed -i "$[beginnum+2]i auth_type = password" /etc/nova/nova.conf
head -n $[beginnum+2] /etc/nova/nova.conf | tail -n 1
sed -i "$[beginnum+3]i user_domain_name = Default" /etc/nova/nova.conf
head -n $[beginnum+3] /etc/nova/nova.conf | tail -n 1
sed -i "$[beginnum+4]i auth_url = http://controller:5000/v3" /etc/nova/nova.conf
head -n $[beginnum+4] /etc/nova/nova.conf | tail -n 1
sed -i "$[beginnum+5]i username = placement" /etc/nova/nova.conf
head -n $[beginnum+5] /etc/nova/nova.conf | tail -n 1
sed -i "$[beginnum+6]i password = $passwd" /etc/nova/nova.conf
head -n $[beginnum+6] /etc/nova/nova.conf | tail -n 1su -s /bin/sh -c "nova-manage api_db sync" nova
su -s /bin/sh -c "nova-manage cell_v2 map_cell0" nova
su -s /bin/sh -c "nova-manage cell_v2 create_cell --name=cell1 --verbose" nova
su -s /bin/sh -c "nova-manage db sync" novasu -s /bin/sh -c "nova-manage cell_v2 list_cells" nova/etc/init.d/nova-api restart
/etc/init.d/nova-consoleauth restart
/etc/init.d/nova-scheduler restart
/etc/init.d/nova-conductor restart
/etc/init.d/nova-novncproxy restart
}install_nova_controller

SQL

mysql << EOF
CREATE DATABASE nova_api;
CREATE DATABASE nova;
CREATE DATABASE nova_cell0;
CREATE DATABASE placement;
GRANT ALL PRIVILEGES ON nova_api.* TO 'nova'@'localhost' \ IDENTIFIED BY '$passwd'; GRANT ALL PRIVILEGES ON nova_api.* TO 'nova'@'%' \ IDENTIFIED BY '$passwd'; GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'localhost' \ IDENTIFIED BY '$passwd'; GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'%' \ IDENTIFIED BY '$passwd'; GRANT ALL PRIVILEGES ON nova_cell0.* TO 'nova'@'localhost' \ IDENTIFIED BY '$passwd'; GRANT ALL PRIVILEGES ON nova_cell0.* TO 'nova'@'%' \ IDENTIFIED BY '$passwd'; GRANT ALL PRIVILEGES ON placement.* TO 'placement'@'localhost' \ IDENTIFIED BY '$passwd'; GRANT ALL PRIVILEGES ON placement.* TO 'placement'@'%' \ IDENTIFIED BY '$passwd';
EOF

Compute

#!/bin/shinstall_nova_compute(){
    
#报错即刻退出
set -o errexit
set -x
readonly passwd=openstack
#计算节点ip
readonly my_ip=172.16.199.31(echo 'y')|apt install nova-compute#[api]
sed -i "3194s/^#auth_strategy\s.*/auth_strategy = keystone/"  /etc/nova/nova.conf
head -n 3194 /etc/nova/nova.conf | tail -n 1#[vnc]
sed -i "10686s/^#enabled\s.*/enabled = True/" /etc/nova/nova.conf
head -n 10686 /etc/nova/nova.conf | tail -n 1
sed -i "10719s/^#server_listen\s.*/server_listen=0.0.0.0/" /etc/nova/nova.conf
head -n 10719 /etc/nova/nova.conf | tail -n 1
sed -i "10732s/^#server_proxyclient_address\s.*/server_proxyclient_address=\$my_ip/" /etc/nova/nova.conf
head -n 10732 /etc/nova/nova.conf | tail -n 1sed -i "10753s/^#novncproxy_base_url\s.*/novncproxy_base_url=http:\/\/controller:6080\/vnc_auto.html/" /etc/nova/nova.conf
head -n 10753 /etc/nova/nova.conf | tail -n 1#[glance]
sed -i "5258s/^#api_servers\s.*/api_servers = http:\/\/controller:9292/" /etc/nova/nova.conf
head -n 5258 /etc/nova/nova.conf | tail -n 1#[oslo_concurrency]
sed -i "7996s/^#lock_path\s.*/lock_path = \/var\/lib\/nova\/tmp/" /etc/nova/nova.conf 
head -n 7996 /etc/nova/nova.conf | tail -n 1#[default]
#remove log_dir
sed -i "2s/^log_dir\s.*/#&/" /etc/nova/nova.conf 
head -n 2 /etc/nova/nova.conf | tail -n 1
sed -i "5i transport_url = rabbit://openstack:$passwd@controller" /etc/nova/nova.conf
head -n 5 /etc/nova/nova.conf | tail -n 1
sed -i "6i my_ip = $my_ip" /etc/nova/nova.conf
head -n 6 /etc/nova/nova.conf | tail -n 1
sed -i "7i use_neutron = true" /etc/nova/nova.conf
head -n 7 /etc/nova/nova.conf | tail -n 1
sed -i "8i firewall_driver = nova.virt.firewall.NoopFirewallDriver" /etc/nova/nova.conf
head -n 8 /etc/nova/nova.conf | tail -n 1#[keystone_authtoken]
beginnum=6062
sed -i "$((beginnum))i auth_url = http://controller:5000/v3" /etc/nova/nova.conf
head -n $((beginnum)) /etc/nova/nova.conf | tail -n 1
sed -i "$((beginnum+1))i memcached_servers = controller:11211" /etc/nova/nova.conf
head -n $((beginnum+1)) /etc/nova/nova.conf | tail -n 1
sed -i "$((beginnum+2))i auth_type = password" /etc/nova/nova.conf
head -n $((beginnum+2)) /etc/nova/nova.conf | tail -n 1
sed -i "$((beginnum+3))i project_domain_name = Default" /etc/nova/nova.conf
head -n $((beginnum+3)) /etc/nova/nova.conf | tail -n 1
sed -i "$((beginnum+4))i user_domain_name = Default" /etc/nova/nova.conf
head -n $((beginnum+4)) /etc/nova/nova.conf | tail -n 1
sed -i "$((beginnum+5))i project_name = service" /etc/nova/nova.conf
head -n $((beginnum+5)) /etc/nova/nova.conf | tail -n 1
sed -i "$((beginnum+6))i username = nova" /etc/nova/nova.conf
head -n $((beginnum+6)) /etc/nova/nova.conf | tail -n 1
sed -i "$((beginnum+7))i password = $passwd" /etc/nova/nova.conf
head -n $((beginnum+7)) /etc/nova/nova.conf | tail -n 1#[placement]
sed -i "8815s/^os_region_name\s.*/region_name = RegionOne/" /etc/nova/nova.conf
head -n 8815 /etc/nova/nova.conf | tail -n 1beginnum=8816
sed -i "$((beginnum))i project_domain_name = Default" /etc/nova/nova.conf
head -n $((beginnum)) /etc/nova/nova.conf | tail -n 1
sed -i "$((beginnum+1))i project_name = service" /etc/nova/nova.conf
head -n $((beginnum+1)) /etc/nova/nova.conf | tail -n 1
sed -i "$((beginnum+2))i auth_type = password" /etc/nova/nova.conf
head -n $((beginnum+2)) /etc/nova/nova.conf | tail -n 1
sed -i "$((beginnum+3))i user_domain_name = Default" /etc/nova/nova.conf
head -n $((beginnum+3)) /etc/nova/nova.conf | tail -n 1
sed -i "$((beginnum+4))i auth_url = http://controller:5000/v3" /etc/nova/nova.conf
head -n $((beginnum+4)) /etc/nova/nova.conf | tail -n 1
sed -i "$((beginnum+5))i username = placement" /etc/nova/nova.conf
head -n $((beginnum+5)) /etc/nova/nova.conf | tail -n 1
sed -i "$((beginnum+6))i password = $passwd" /etc/nova/nova.conf
head -n $((beginnum+6)) /etc/nova/nova.conf | tail -n 1/etc/init.d/nova-compute restart
}install_nova_compute

参考

Compute service