Openstack常用命令

零、消息队列

1、查看消息队列

rabbitmqctl list_queues


一、nova

0、启动控制节点服务,:

for svc in keystone glance-api glance-registry nova-api nova-objectstore nova-volume nova-scheduler nova-cert nova-novncproxy; do sudo service openstack-$svc start ; sudo chkconfig openstack-$svc on ; done


启动计算节点服务命令:

for svc in compute network metadata-api; do sudo service openstack-nova-$svc start ; sudo chkconfig openstack-nova-$svc on ; done


0、修改配额

tenant_name="admin"

tenant_id="`keystone tenant-list | grep $tenant_name | awk '{print $2}'`"

neutron quota-update --port 2000

cinder  quota-update $tenant_id --volumes 500

cinder  quota-update $tenant_id --snapshots 500

cinder  quota-update $tenant_id --gigabytes 500000

nova quota-update  $tenant_id --instances 1000

nova quota-update  $tenant_id --cores 2000

nova quota-update  $tenant_id --ram 51200000


1、查看openstack集群中的宿主机

 [root@node-44 ~]# nova host-list

2、查看虚拟机

 [root@node-44 ~]# nova host  或 nova list

3、查看一个虚拟机的详情

 [root@node-44 ~]# nova show 089bf9c6-170b-4bf1-9922-494565e33dc0

4、查看镜像列表

[root@control ~]# nova image-list

+--------------------------------------+-------------------+--------+--------+

| ID                                   | Name              | Status | Server |

+--------------------------------------+-------------------+--------+--------+

| a760ccc0-782f-4102-bdb8-fd6dc2915ad8 | cirros-0.3.0-i386 | ACTIVE |        |

| 6c81f0da-54d0-4f7d-a56d-5c07efa9ed8f | precise-ceph      | ACTIVE |        |

+--------------------------------------+-------------------+--------+--------+

[root@control ~]# 

5、删除镜像

[root@control ~]# nova image-delete cirros-0.3.0-i386-1

6、查看虚拟机模板

[root@control ~]# nova flavor-list

+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+-------------+

| ID | Name      | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor | Is_Public | extra_specs |

+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+-------------+

| 1  | m1.tiny   | 512       | 0    | 0         |      | 1     | 1.0         | True      | {}          |

| 2  | m1.small  | 2048      | 20   | 0         |      | 1     | 1.0         | True      | {}          |

| 3  | m1.medium | 4096      | 40   | 0         |      | 2     | 1.0         | True      | {}          |

| 4  | m1.large  | 8192      | 80   | 0         |      | 4     | 1.0         | True      | {}          |

| 5  | m1.xlarge | 16384     | 160  | 0         |      | 8     | 1.0         | True      | {}          |

+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+-------------+

[root@control ~]# 

7、新建一个虚拟机模板

[root@control ~]# nova flavor-create flavor-test 6 512 10 2 --is-public=true 

+----+-------------+-----------+------+-----------+------+-------+-------------+-----------+-------------+

| ID | Name        | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor | Is_Public | extra_specs |

+----+-------------+-----------+------+-----------+------+-------+-------------+-----------+-------------+

| 6  | flavor-test | 512       | 10   | 0         |      | 2     | 1           | True      | {}          |

+----+-------------+-----------+------+-----------+------+-------+-------------+-----------+-------------+

[root@control ~]# 


9、关机虚拟机

[root@os-node1 ~]# nova stop 9b57d145-d810-4ab2-92e1-11ec44c2cd85

10、开机虚拟机

[root@os-node1 ~]# nova start 9b57d145-d810-4ab2-92e1-11ec44c2cd85

10、查看宿主机的服务状态

[root@os-node1 ~]# nova-manage service list

Binary           Host                                 Zone             Status     State Updated_At

nova-cert        os-node1                             internal         enabled    :-)   2014-08-05 00:48:24

nova-consoleauth os-node1                             internal         enabled    :-)   2014-08-05 00:48:33

nova-conductor   os-node1                             internal         enabled    :-)   2014-08-05 00:48:29

nova-scheduler   os-node1                             internal         enabled    :-)   2014-08-05 00:48:31

nova-compute     os-node4                             nova             enabled    XXX   2014-08-04 03:28:00

nova-cells       os-node1                             internal         enabled    :-)   2014-08-05 00:48:32

nova-console     os-node1                             internal         enabled    :-)   2014-08-05 00:48:34

nova-compute     os-node5                             nova             enabled    :-)   2014-08-05 00:48:32

nova-compute     os-node6                             nova             enabled    XXX   2014-08-04 04:05:41

[root@os-node1 ~]# nova service-list

+------------------+----------+----------+---------+-------+----------------------------+-----------------+

| Binary           | Host     | Zone     | Status  | State | Updated_at                 | Disabled Reason |

+------------------+----------+----------+---------+-------+----------------------------+-----------------+

| nova-cert        | os-node1 | internal | enabled | up    | 2014-08-05T01:08:44.000000 | -               |

| nova-consoleauth | os-node1 | internal | enabled | up    | 2014-08-05T01:08:44.000000 | -               |

| nova-conductor   | os-node1 | internal | enabled | up    | 2014-08-05T01:08:49.000000 | -               |

| nova-scheduler   | os-node1 | internal | enabled | up    | 2014-08-05T01:08:51.000000 | -               |

| nova-compute     | os-node4 | nova     | enabled | down  | 2014-08-04T03:28:00.000000 | -               |

| nova-cells       | os-node1 | internal | enabled | up    | 2014-08-05T01:08:52.000000 | -               |

| nova-console     | os-node1 | internal | enabled | up    | 2014-08-05T01:08:44.000000 | -               |

| nova-compute     | os-node5 | nova     | enabled | up    | 2014-08-05T01:08:52.000000 | -               |

| nova-compute     | os-node6 | nova     | enabled | down  | 2014-08-04T04:05:41.000000 | -               |

+------------------+----------+----------+---------+-------+----------------------------+-----------------+

11、创建网段

nova-manage network create --fixed_range_v4=10.0.1.0/24 --vlan=102  --project_id="tenantID"

12、删除虚拟机

nova delete ID

14、迁移一个宿主机上的所有的虚拟机到可用的宿主机上(首先这个被迁移的宿主机的状态是正常的)

[root@LX-OS-node1 ~]# nova   host-servers-migrate  LX-OS-node11 

+--------------------------------------+--------------------+---------------+

| Server UUID                          | Migration Accepted | Error Message |

+--------------------------------------+--------------------+---------------+

| dcb0a622-839f-4310-b8c7-74bb69dd7d7a | True               |               |

| 5e748a54-43d6-4bb8-9696-8f13cf45220c | True               |               |

| 28e1b0f1-1741-4677-bbb6-07f884889cc9 | True               |               |

+--------------------------------------+--------------------+---------------+

确认迁移

[root@LX-OS-node1 ~]# nova   resize-confirm  4bbc5ff6-e9e5-4765-b3c0-60608009153e

[root@LX-OS-node1 ~]# nova   resize-confirm  5e748a54-43d6-4bb8-9696-8f13cf45220c

[root@LX-OS-node1 ~]# nova   resize-confirm  8b4f2aab-70ca-494d-ad7a-5d67f43ea8f0

15、从一个故障的宿主机迁移上面所有的虚拟机到另外一台宿主机(前者是可用的宿主机,后者是故障的虚拟机,注:只有在用镜像启动建立虚拟机这种情况下可以迁移成功)

[root@LX-OS-node1 ~]# nova   host-evacuate  --target_host BGW-OS-node11 --on-shared-storage BGW-OS-node12

+--------------------------------------+-------------------+---------------+

| Server UUID                          | Evacuate Accepted | Error Message |

+--------------------------------------+-------------------+---------------+

| 4bbc5ff6-e9e5-4765-b3c0-60608009153e | True              |               |

| 5e748a54-43d6-4bb8-9696-8f13cf45220c | True              |               |

| 8b4f2aab-70ca-494d-ad7a-5d67f43ea8f0 | True              |               |

+--------------------------------------+-------------------+---------------+

16、把名为aaa的虚拟机迁移到宿主机LX-OS-node12上(次迁移只是迁移虚拟机的内存 cpu 网卡资源,迁移时间很短,网络不会中断,此迁移虚拟机不会重启)

nova  live-migration  aaa  LX-OS-node12 

17、普通迁移一台虚拟机(此迁移的目标主机控制器会自动分配,迁移动作执行后需要对此次迁移进行确认,此迁移虚拟机会重启)

nova   migrate  aaa 

nova    resize-revert  aaa

18、建立一个虚拟机(指定固定IP,此启动方式是:从云硬盘快照启动并创建一个云硬盘,注用这种方式建的当虚拟机被删除是云硬盘不会被删除)

nova boot jiayuan-1 --flavor 9f7a7929-e0f7-4f9b-be48-757aeb2462a7 --snapshot a9c7816b-0046-4aa9-9c82-cb881a969bdd  --security-groups default --nic net-id=b7fed806-5a78-4b29-92d1-475567d02643,v4-fixed-ip=10.30.215.201

19、比较完整的建立一个虚拟机(--snapshot 和 --block-device-mapping的不同之处是用后者建的虚拟机删除时可以把云硬盘同时删除,此方式包括了制定固定IP(包括多网卡)、指定宿主机、可以看到进度提示)

nova boot jiayuan-1 --flavor 9f7a7929-e0f7-4f9b-be48-757aeb2462a7 --block-device-mapping vda=a9c7816b-0046-4aa9-9c82-cb881a969bdd:snapshot:300:delete-on-terminate    --security-groups default --nic net-id=b7fed806-5a78-4b29-92d1-475567d02643,v4-fixed-ip=10.30.215.230 --nic net-id=3409eea8-9b46-4752-ac63-be0234d18275,v4-fixed-ip=10.30.216.230  --availability-zone nova:LX-OS-node13 --poll 

20、批量建立多个虚拟机

nova boot jiayuan-1 --flavor 9f7a7929-e0f7-4f9b-be48-757aeb2462a7 --block-device-mapping vda=a9c7816b-0046-4aa9-9c82-cb881a969bdd:snapshot:300:delete-on-terminate  --num-instances 1000   --security-groups default  --nic net-id=3409eea8-9b46-4752-ac63-be0234d18275 


二、glance

1、压缩一个qcow2格式的镜像

 [root@node-44 glance]#qemu-img convert -c ubuntuwcf-10.40.254.64.img -O qcow2 /var/lib/glance/SunDaMing.img

2、查看一个镜像的信息(包括:镜像格式及大小)

 [root@node-44 glance]# qemu-img info SunDaMing.img

3、镜像上传

 [root@node-44 glance]#glance image-create --is-public true --disk-format qcow2 --container-format bare --name "SunDaMing" < /var/lib/glance/SunDaMing.img 

4、使用“glance index”查看映像文件的索引信息。

glance index 

ID                                   Name                           Disk Format          Container Format     Size          

------------------------------------ ------------------------------ -------------------- -------------------- --------------

16bfa875-8e0a-4cc3-8041-e8c64cca9f5e cirros-0.3.0-i386              qcow2                bare                        9159168

9f92df26-8fd3-42b9-a00c-b9fb2c73ed21 cirros-0.3.0-x86_64            qcow2                bare                        9761280


三、cinder

1、查看所有的云硬盘卷

 [root@node-44 ~]# cinder list

2、把volume添加到虚拟机上

( ID是虚拟机的id,后面的1,是volume的ID)添加完后可以通过 nova volume-list查看结果

nova volume-attach 7eb1d4b3-13fa-4e39-be17-3a27eb0db218 1 /dev/vdc

3、删除volume

nova volume-detach VM_ID Volume_ID

4、创建snapshot ( 完成后可以通过 nova image-list 查看)

nova image-create 7eb1d4b3-13fa-4e39-be17-3a27eb0db218 "snapshot 1"


四、neutron

1、查看neutron的配额

[root@os-node1 ~]# neutron quota-show

+------------+-------+

| Field      | Value |

+------------+-------+

| floatingip | 50    |

| network    | 10    |

| port       | 50    |

| router     | 10    |

| subnet     | 10    |

+------------+-------+

2、修改neutron网络端口的数量

[root@os-node1 ~]# neutron quota-update --port 500   #端口太少的话创建不了太多虚拟机。

+------------+-------+

| Field      | Value |

+------------+-------+

| floatingip | 50    |

| network    | 10    |

| port       | 500   |

| router     | 10    |

| subnet     | 10    |

+------------+-------+

3、清空openvswitch交换机上的端口

/etc/init.d/neutron-ovs-cleanup start

4、常见一个共享的网络(如果网络是私有属于某个租户:把--shared 去掉,加上--tenant-id TENANT_ID参数)

[root@LX-OS-node1 ~]# neutron  net-create  vlan215  --shared 

+---------------------------+--------------------------------------+

| Field                     | Value                                |

+---------------------------+--------------------------------------+

| admin_state_up            | True                                 |

| id                        | c991b42d-982e-4dfc-b7cf-aacf9d00f252 |

| name                      | vlan215                              |

| provider:network_type     | vlan                                 |

| provider:physical_network | physnet1                             |

| provider:segmentation_id  | 215                                  |

| shared                    | True                                 |

| status                    | ACTIVE                               |

| subnets                   |                                      |

| tenant_id                 | e3f13050687a4e3e9967de3b6c22227b     |

+---------------------------+--------------------------------------+


[root@LX-OS-node1 ~]# neutron  subnet-create  vlan215 10.30.215.0/24 --name  vlan215 --gateway 10.30.215.254 --allocation-pool  start=10.30.215.1,end=10.30.215.200

Created a new subnet:

+------------------+--------------------------------------------------+

| Field            | Value                                            |

+------------------+--------------------------------------------------+

| allocation_pools | {"start": "10.30.215.1", "end": "10.30.215.200"} |

| cidr             | 10.30.215.0/24                                   |

| dns_nameservers  |                                                  |

| enable_dhcp      | True                                             |

| gateway_ip       | 10.30.215.254                                    |

| host_routes      |                                                  |

| id               | f8d95fb2-0b6e-4ce4-963d-81a8b4a89f55             |

| ip_version       | 4                                                |

| name             | vlan215                                          |

| network_id       | c991b42d-982e-4dfc-b7cf-aacf9d00f252             |

| tenant_id        | e3f13050687a4e3e9967de3b6c22227b                 |

+------------------+--------------------------------------------------+


5、查看neutron-openvswitch-agent运行状态

[root@os-node3 abrt]# service neutron-openvswitch-agent status

neutron-openvswitch-agent (pid  7523) is running...

6、查看openvswitch运行状态

[root@os-node3 abrt]#  service openvswitch status

ovsdb-server is running with pid 7477

ovs-vswitchd is running with pid 7486


五、mysql

1、进入数据库

    mysql -uroot -p  回车

    默认没有密码

2、显示所有的数据库

   show databases;

3、进入表

    use nova;  进入nova表

4、查看表结构

   desC  agent_builds;  查看“agent_builds”的表结构

5、查看数据库表信息

   mysql> show tables;

6、在数据库migrations表里查找所有东西

   mysql> select * from migrations ;

7、在数据库中删除一条信息

   mysql> delete * from ipallocationpools where id="041d7993-394b-4ec3-aae3-365aeb5dc10f";

8、变更云硬盘在数据库volumes表中的信息

   mysql> update volumes set host="node-44.domain.tld" where id="8266d5cc-9be5-4c3b-a46e-06aa055c66e1";

9、查看云硬盘几个参数的状态

   mysql> select status,attached_host,migration_status,deleted from volumes where id="0d883e29-1bc7-4e54-9eba-1883c4c32313";

10、变更云硬盘在数据库中的存储状态

   变更前:

  mysql> select status,attached_host,migration_status,deleted from volumes where id="8266d5cc-9be5-4c3b-a46e-06aa055c66e1";

  +-----------+---------------+---------------------------------------------+---------+

  | status    | attached_host | migration_status                            | deleted |

  +-----------+---------------+---------------------------------------------+---------+

  | available | NULL          | target:10de2dad-21c9-482f-b1c4-5afedef36dde |       0 |

  +-----------+---------------+---------------------------------------------+---------+

  1 row in set (0.00 sec)

  变更后:

   mysql> update volumes set migration_status="NULL" where id="8266d5cc-9be5-4c3b-a46e-06aa055c66e1";

   mysql> select status,attached_host,migration_status,deleted from volumes where id="8266d5cc-9be5-4c3b-a46e-06aa055c66e1";

  +-----------+---------------+------------------+---------+

  | status    | attached_host | migration_status | deleted |

  +-----------+---------------+------------------+---------+

  | available | NULL          | NULL             |       0 |

  +-----------+---------------+------------------+---------+

  1 row in set (0.00 sec)

11、彻底删除一个有问题的云硬盘

   先修改该云硬盘的状态status="deleted"

   mysql> update volumes set status="deleted" where id="8266d5cc-9be5-4c3b-a46e-06aa055c66e1";     

   Query OK, 1 row affected (0.02 sec)

   Rows matched: 1  Changed: 1  Warnings: 0

   然后修改该云硬盘删除状态

   mysql> update volumes set deleted="1" where id="8266d5cc-9be5-4c3b-a46e-06aa055c66e1";             

   Query OK, 1 row affected (0.02 sec)

   Rows matched: 1  Changed: 1  Warnings: 0

   mysql> update volumes set deleted="1" where Status="deleting";

11、批量删除云硬盘

    mysql> update volumes set deleted="1" where Status="deleting";

11、批量删除云硬盘快照

    mysql> update snapshots set deleted="1" where Status="error_deleting";

11、彻底删除已删除状态的云硬盘

mysql> delete from volumes  where Status="deleted";

ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`cinder`.`volume_glance_metadata`, CONSTRAINT `volume_glance_metadata_ibfk_1` FOREIGN KEY (`volume_id`) REFERENCES `volumes` (`id`))

解决上面报错用下面的命令:

mysql> SET FOREIGN_KEY_CHECKS = 0;

Query OK, 0 rows affected (0.00 sec)

再次执行删除就可以删除了

mysql> delete from volumes  where Status="deleted";

Query OK, 223 rows affected (0.06 sec)


Query OK, 2 rows affected (0.03 sec)

Rows matched: 2  Changed: 2  Warnings: 0

12、在数据库中查看ip pool

   进入neutron表

   mysql> select * from ipallocationpools;

13、在数据库中查看已使用的vlan信息

   进入neutron表

   mysql> select * from ovs_vlan_allocations;

14、变更一个KVM虚拟机的任务状态

   变更前的任务状态

   mysql> select task_state from instances where hostname="sundaming-10.40.254.62";

   +-----------------+

   | task_state      |

   +-----------------+

   | image_uploading |

   +-----------------+

   1 row in set (0.00 sec)

   变更状态命令

   update instances set task_state="none" where hostname="sundaming-10.40.254.62";

    

   变更后的状态

   mysql> select task_state from instances where hostname="sundaming-10.40.254.62";

   +------------+

   | task_state |

   +------------+

   | none       |

   +------------+

   1 row in set (0.00 sec)

15、数据库主机用户权限问题

查看mysql中的用户

mysql> use mysql;

mysql> select host, user from user;

+-----------+------+

| host      | user |

+-----------+------+

| %         | root |

| 127.0.0.1 | root |

| localhost |      |

| os-node1  |      |

| os-node1  | root |

+-----------+------+

5 rows in set (0.00 sec)


授权一个test用户从任何机器都可以远程登录mysql数据库

mysql> GRANT ALL PRIVILEGES ON *.* TO 'test'@'%' IDENTIFIED BY 'test' WITH GRANT OPTION;

Query OK, 0 rows affected (0.00 sec)


mysql> FLUSH   PRIVILEGES; 

Query OK, 0 rows affected (0.00 sec)


mysql> select host, user from user; 

+-----------+------+

| host      | user |

+-----------+------+

| %         | root |

| %         | test |

| 127.0.0.1 | root |

| localhost |      |

| os-node1  |      |

| os-node1  | root |

+-----------+------+

6 rows in set (0.00 sec)


在其他的一台机器上测试

[root@os-node11 ~]# mysql -h 10.240.216.1 -utest -p'test'

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 277

Server version: 5.1.71-log Source distribution


Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> 


16、删除库

mysql> drop database jiayuan123;

17、备份mysql数据库中的keystone库

[root@node-44 ~]# mysqldump -u root -p keystone > /mysql-bak/keystone.sql

18、查看cinder库中使用中的volumes

mysql> use cinder;

mysql> select * from volumes where status ="in-use";

19、查看一个虚拟机的状态

mysql> select vm_state from instances  where uuid="5dc5c94b-0752-40a7-9fbf-49d3cf5e4097";

+----------+

| vm_state |

+----------+

| active   |

+----------+

20、查看一个虚拟机的运行状态

mysql> select task_state from instances  where uuid="9b57d145-d810-4ab2-92e1-11ec44c2cd85";

+------------+

| task_state |

+------------+

| NULL       |

+------------+

1 row in set (0.00 sec)

20、修改虚拟机的IP

1)、查找虚拟机的网络端口

mysql> use neutron;

mysql> select * from ports where device_id="3ab73261-82ce-4b9a-9a1c-519624e19dc2";

+----------------------------------+--------------------------------------+------+--------------------------------------+-------------------+----------------+--------+--------------------------------------+--------------+

| tenant_id                        | id                                   | name | network_id                           | mac_address       | admin_state_up | status | device_id                            | device_owner |

+----------------------------------+--------------------------------------+------+--------------------------------------+-------------------+----------------+--------+--------------------------------------+--------------+

| 5855410282d54e0cac49f05b40282500 | eccd3444-bb81-4d3b-ae13-58040847da4a |      | ed547aa7-af32-495a-8173-5a04be9c37c1 | fa:16:3e:a8:bd:e4 |              1 | DOWN   | 3ab73261-82ce-4b9a-9a1c-519624e19dc2 | compute:nova |

+----------------------------------+--------------------------------------+------+--------------------------------------+-------------------+----------------+--------+--------------------------------------+--------------+

1 row in set (0.01 sec)


mysql> 

2)、查找虚拟机网络端口的IP地址

mysql> select * from ipallocations  where port_id="eccd3444-bb81-4d3b-ae13-58040847da4a";

+--------------------------------------+--------------+--------------------------------------+--------------------------------------+

| port_id                              | ip_address   | subnet_id                            | network_id                           |

+--------------------------------------+--------------+--------------------------------------+--------------------------------------+

| eccd3444-bb81-4d3b-ae13-58040847da4a | 10.40.211.28 | e6e73775-ddbc-461a-92ff-b13202c23540 | ed547aa7-af32-495a-8173-5a04be9c37c1 |

+--------------------------------------+--------------+--------------------------------------+--------------------------------------+

1 row in set (0.00 sec)


3)、修改虚拟机的端口的IP地址


mysql> update ipallocations set ip_address="10.40.211.29" where port_id="eccd3444-bb81-4d3b-ae13-58040847da4a";

Query OK, 1 row affected (0.00 sec)

Rows matched: 1  Changed: 1  Warnings: 0


mysql> select * from ipallocations  where port_id="eccd3444-bb81-4d3b-ae13-58040847da4a";

+--------------------------------------+--------------+--------------------------------------+--------------------------------------+

| port_id                              | ip_address   | subnet_id                            | network_id                           |

+--------------------------------------+--------------+--------------------------------------+--------------------------------------+

| eccd3444-bb81-4d3b-ae13-58040847da4a | 10.40.211.29 | e6e73775-ddbc-461a-92ff-b13202c23540 | ed547aa7-af32-495a-8173-5a04be9c37c1 |

+--------------------------------------+--------------+--------------------------------------+--------------------------------------+

1 row in set (0.01 sec)


mysql> 

21、在数据库里彻底删除一个虚拟机

mysql> SET FOREIGN_KEY_CHECKS = 0; 修改KEY值,使此库变为可直接删除状态

Query OK, 0 rows affected (0.00 sec)

删除一个虚拟机

mysql> delete from instances  where uuid="3ab73261-82ce-4b9a-9a1c-519624e19dc2";

Query OK, 1 row affected (0.03 sec)


批量删除相同状态的虚拟机

mysql> delete from instances  where vm_state="active";

Query OK, 22 rows affected (0.01 sec)


mysql> SET FOREIGN_KEY_CHECKS = 1; 删除后,修改KEY值,使此库变为不可直接删除状态

Query OK, 0 rows affected (0.00 sec)


22、导出全部数据库

mysqldump -u root -p -h10.240.216.2 -P3306 --routines --default-character-set=utf8 --lock-all-tables --add-drop-database -A > db.10.240.216.1.sql


23、导入全部数据库

第一种方法直接导入

mysql -uroot -p -h10.240.216.1 -P3306 --default-character-set=utf8 < db.10.240.216.1.sql


第二种方法登录数据库导入:

登录MySQL,执行source命令,后面的文件名要用绝对路径.

......

mysql> source /tmp/db.all.sql;

24、搜索活动的虚拟机的host和uuid的对应关系

[root@os-node1 ~]# mysql -Dnova -e "select host,uuid from instances where vm_state='active'"

+-----------+--------------------------------------+

| host      | uuid                                 |

+-----------+--------------------------------------+

| os-node12 | 5209f21b-b81e-4e19-8193-57263dc93dd7 |

| os-node12 | 4f2f3d73-83bf-42ec-81b6-c1739930e520 |

+-----------+--------------------------------------+

25、更新虚拟机实例的任务状态为NULL 

有时候一个实例一直卡死在一个任务状态上,不能再对此实例进行任何操作,这是需要在数据库中把这个虚拟机的任务状态改为NULL,修改方法如下:

update instances set task_state=NULL where uuid="5209f21b-b81e-4e19-8193-57263dc93dd7";         注:NULL值的两边是不用“”括起来的。

26、查看mysql最大连接数(默认是151)

mysql>  show variables like 'max_connections';

+-----------------+-------+

| Variable_name   | Value |

+-----------------+-------+

| max_connections | 20000 |

+-----------------+-------+

1 row in set (0.00 sec)


你可能感兴趣的:(openstack,openstack命令)