重置 OpenStack Nova 数据库

如果使用 OpenStack 的时候遇到莫名其妙的问题,或者直接操作 OpenStack 数据表的时候把里面的关系或记录搞砸了,或者使用一些从网上抄来连自己都不理解的命令把数据库记录弄乱了,或者自己想推倒重来等等,碰到这些问题的时候大家想到的第一个办法就是“重装系统,重装 OpenStack”,其实大部分时候都不必要重装,只需要重置一下数据库就可以了,避免重复劳动把操作命令整理到下面的简单脚本里:

# Delete the database and create a new one
mysql -u root -ppassword -e "drop database nova;"
mysql -u root -ppassword -e "create database nova;"
mysql -u root -ppassword -e "set password for 'root'@'%'=password('password');"
mysql -u root -ppassword -e "grant all privileges on *.* to 'root'@'%';"

# Sync up the database scheme
nova-manage db sync

# Create a network
nova-manage network create private 10.0.1.0/24 1 256
nova-manage floating create 192.168.2.240/28

# Create a admin user and a project and assign the admin user to it
nova-manage user admin linuxidc
nova-manage project create linuxidccloud linuxidc

# Restart all the services
restart libvirt-bin
restart nova-api
restart nova-scheduler
restart nova-network
restart nova-volume
restart nova-compute

# Create novarc
nova-manage project zipfile linuxidccloud linuxidc
unzip nova.zip
. novarc

# Allowing icmp and ssh access to instances
euca-authorize -P icmp -t -1:-1 default
euca-authorize -P tcp -p 22 default

# Create a keypair
euca-add-keypair linuxidc > linuxidc.priv
chmod 600 linuxidc.priv

相关推荐