基础-O版-02-命令实战¶
环境准备¶
检查集群状态¶
nova service-list ; cinder service-list ; neutron agent-list
初始化加载管理员账户¶
1.初始化管理员账户
cat >./admin_openrc<<EOF
export OS_PROJECT_DOMAIN_NAME=default
export OS_USER_DOMAIN_NAME=default
export OS_PROJECT_NAME=admin
export OS_USERNAME=admin
export OS_PASSWORD=ADMIN_PASS
export OS_AUTH_URL=http://keystone-admin.cty.os:10006/v3
export OS_IDENTITY_API_VERSION=3
export OS_IMAGE_API_VERSION=2
EOF
source admin_openrc
2.验证方式如下
nova service-list ; cinder service-list ; neutron agent-list
普通账户¶
1.创建一个demo_test01项目
openstack project create demo_test01
2.创建一个demo_test01用户并加入到demo_test01项目,设置密码为demo_test01_pass
openstack user create --project demo_test01 --password demo_test01_pass demo_test01
3.设置demo_test01用户有user角色的权限
openstack role add --project demo_test01 --user demo_test01 user
4.初始化普通用户
cat >./client_openrc<<EOF
export OS_PROJECT_DOMAIN_NAME=default
export OS_USER_DOMAIN_NAME=default
export OS_PROJECT_NAME=demo_test01
export OS_USERNAME=demo_test01
export OS_PASSWORD=demo_test01_pass
export OS_AUTH_URL=http://keystone-admin.cty.os:10006/v3
export OS_IDENTITY_API_VERSION=3
export OS_IMAGE_API_VERSION=2
EOF
source client_openrc
5.验证方式如下:
nova list
镜像信息¶
[root@hb02-control-10e114e194e29 .work]# glance image-list
+--------------------------------------+-----------------------------------------------+
| ID | Name |
+--------------------------------------+-----------------------------------------------+
| 86f277e2-e602-45ed-b214-2588684352fc | amphora-x64-haproxy |
| 86233538-1a4b-43bc-8b33-dbeaf651c9f1 | Baremetal-CentOS6.9 |
| 7ee02643-c5f4-4e9e-816d-ee7c3f2907d9 | Baremetal-CentOS7.2 |
| e45305c6-3e1b-4550-b0b5-e2a3f8065fcf | Baremetal-CentOS7.3 |
| b1f56319-337b-4fce-a656-9638f954d1e8 | Baremetal-Ubuntu16.04 |
| 45c48f9e-d4c9-42e8-98be-5e45589ab17b | bm-centos69-zhao |
| a1b36956-668f-4f1a-aa3a-7c6c5ca481b0 | CentOS6.5 |
| d03f83d7-f7cd-4700-a3b8-31eb90956272 | CentOS6.7 |
| 32f5682a-373e-4250-a021-753d5683147b | CentOS6.8 |
| 7ecba60b-ad8b-4da7-9483-90b13b9be8ab | CentOS6.8_190926 |
| 85722648-7b80-4a92-963f-29633a15745d | CentOS7.2 |
| ade1698e-c100-449a-9576-4b17a5c29f31 | CentOS7.2_20191204_qga |
| a68f25d9-d0b4-44e1-a10b-b7f1e7921c62 | CentOS7.3 |
| 3576249a-f7e4-44e3-beae-cbaaf42af818 | CentOS7.3_190926 |
| d70faef5-2972-42a6-9b59-72e6ef416c35 | CentOS7.3_20191204_qga |
| ad05b15f-47f2-400e-bb26-ba218c5e4fa5 | CentOS7.4 |
| 040af07b-0e01-4d93-b55e-d80f595498f8 | CentOS7.4_190926 |
| 07d3652e-bc62-4cc1-b33e-062a8876499e | CentOS7.4_20191204_qga |
| 7e8d8df8-de5c-42fc-b952-52ed058c584c | CentOS7.5 |
| 4cc6598f-3da5-4d93-8336-9cd8ba104da0 | CentOS7.5-Baremetal |
| 91457e9b-3104-46b4-9a24-d1f7f97e0f43 | CentOS7.5-ipv6 |
| 3587137b-0bf7-4d01-8914-349b0f3a2e38 | CentOS7.5-ipv6-dhcp |
| 333ffc0a-f961-494a-b315-fce870edffc6 | CentOS7.5-test |
| 2dc4e445-5056-4abc-acb2-b989443aa72f | CentOS7.5-vGPU |
| 872cdbda-408e-47a8-a3e3-f9e7a0b77b5f | CentOS7.5_190926 |
| 30f19b87-cb49-485a-99ca-e86aae2aed9f | CentOS7.5_20191204_qga |
| bc455ca3-6dce-4889-86e6-96abdab8fc72 | CentOS7.5_old(Do not use this one) |
| 355f4aeb-7fc3-41ab-bcf1-88657ff46020 | centos7.6 |
| 3559b64e-4c7e-4665-a124-9e1aa765915a | CentOS7.6-vGPU |
| 459dcd9d-f466-4f86-a03d-04aed31df150 | CentOS7.6_20191204_qga |
| b853c50f-f516-47ec-a3de-1a4679297383 | deploy_initramfs |
| cad8eb37-da20-4f38-92a5-1ec567977b0e | deploy_kernel |
| 439ebd8d-317a-48b3-87d0-a5091172477c | deploy_raid_ramdisk |
| 850cc927-cf76-41e6-9f1f-a934dbc34a76 | ECFW6000-5.5R6P1.2-V62 |
| fb596317-7730-441a-be4a-d2dcc17987e8 | ipa_kernel |
| a940b5f4-943b-4696-a59d-34d2fe808f9f | ipa_ramdisk |
| 015dfb3c-30e5-4907-898e-0de6b65b187a | kernel_zhao_deploy_raid_0530 |
| 8b1c8f2a-4053-4f82-946b-a336e0c18de3 | kloudbuster-7.1.1 |
| cde30772-7d93-4081-82e7-5de8704f1121 | lxc_test_300G |
| 8fe8ed17-40e2-4cbb-a4c4-13ed47eb910d | new1030CentOS6.8 |
| ae5d9fdf-34e0-4421-a673-951269ae919d | new1030CentOS7.2 |
| a42f1cb8-1409-44ac-a1e6-3eb119d9b050 | new1030CentOS7.3 |
| f1cb5f4e-d6ca-4c80-8990-0be8afe08baa | new1030CentOS7.4 |
| 128ae912-21f4-4c51-86a7-9ed1a66ed357 | new1030CentOS7.5 |
| 01532cb6-65a0-47d9-9889-d585d344b0e5 | new1030CentOS7.5ipv6 |
| 21b8eea0-b974-4b64-adde-12bc567fd33f | new1030CentOS7.6 |
| 478b9568-c0f1-4478-9caa-4a9642085443 | new1030Ubuntu16.04 |
| 8b993414-3112-4a04-a21d-200e05891b96 | NGFW-5.5R6P2.3-v6 |
| 6605cd0d-1128-49c3-a643-e35360c45022 | OracleLinux69 |
| b5b9de24-9473-45ec-9694-ffd40b7317b8 | OracleLinux69_waste |
| e556dcc9-fbca-4436-8cb9-bcd3a6b69ea1 | osm-cloud-tyy |
| ef20c935-3e61-4497-889f-c32c1f24e5ce | qemu-centos75-public-1108 |
| ef069579-f0ee-48c0-9653-1ecceced43c4 | ramdisk_with_kunshan |
| f00d5778-373d-4baa-a7eb-fbfa11d3fd90 | ramdisk_zhao_deploy_raid_0530 |
| f6db0bcb-0658-41ce-bea2-4c983350070f | sensos |
| 96d48ffd-5996-4594-a699-c2e6e6858f4c | sensos-1.2.11 |
| 3676d415-b6f8-4987-8d13-fab1e161253e | sensos-console |
| 8feff850-d77f-4413-9a72-db6952cea18f | sensos-vgw |
| 1e90a603-d16e-4e64-a625-c37375b55c95 | smoke-image |
| 12e15199-7f63-4a6e-9ceb-14e9e057d714 | TEST-CentOS7.5-IPv6 |
| b0424de0-3789-4873-bf90-20aafbaeeba9 | test_OracleLinux69 |
| 82ea2edf-c6f5-4f01-bafc-b607d52f3935 | Ubuntu16.04 |
| aa31348b-ed06-43df-a745-153aa02214fa | Ubuntu16.04_190926 |
| 8e6193b0-1342-45cf-9787-e5e0601aab00 | Windows2008-Standard |
| 4733ab78-08e9-43c1-bf44-d8ad60cb87e5 | Windows2008-Standard-ipv6 |
| 7a9afc86-7529-46e3-b2da-2e48b6843290 | Windows2008-Standard_190926 |
| 3f957ec8-7a38-42a7-a7fc-6e95deb95772 | Windows2012-Standard |
| ccaadf8b-5db4-40f9-99dd-35ce6d9df439 | Windows2012-Standard-ipv6 |
| 00af1d7c-11cf-428c-9c50-0e350aeadcc0 | Windows2012-Standard-vGPU |
| d380fa17-b5db-4fba-b28c-9f97639f9deb | Windows2012-Standard_190926 |
| 55494d55-e574-49c4-accd-bf892bcf623b | Windows2012-Standard_old(Do not use this one) |
| 6b7d20f9-9cc1-47cf-9cb2-4a7936a0ea4a | Windows2016-DataCenter |
| 6770586c-02e1-41dd-b3ce-0af409234a23 | Windows2016-Standard-vGPU |
| 2d947ce3-8125-411b-a253-b29140cabef6 | Windows2019-DataCenter |
| 873574a8-0a52-480b-8547-ffafebd15ee1 | YBL-Server |
+--------------------------------------+-----------------------------------------------+
创建Flavor¶
1.加载admin环境变量
source admin_openrc
2.创建常用flavor
openstack flavor create --id e20afd2f-dab2-4516-b82f-2273bd1e9001 --vcpus 1 --ram 1024 --disk 100 ctyun.os-lc1g
openstack flavor create --id e20afd2f-dab2-4516-b82f-2273bd1e9002 --vcpus 1 --ram 2048 --disk 100 ctyun.os-lc2g
openstack flavor create --id e20afd2f-dab2-4516-b82f-2273bd1e9003 --vcpus 2 --ram 4096 --disk 100 ctyun.os-2c4g
openstack flavor create --id e20afd2f-dab2-4516-b82f-2273bd1e9004 --vcpus 4 --ram 8192 --disk 100 ctyun.os-4c8g
3.验证flavor是否创建完毕
openstack flavor list|grep ctyun.os
创建网络¶
1.加载user环境变量
source client_openrc
2.创建user网络
openstack network create demo_test01_network01
openstack network create demo_test01_network02
openstack network create demo_test01_network03
3.验证user网络是否创建成功
openstack network list|grep demo_test01
创建子网¶
1.加载user环境变量
source client_openrc
2.创建user子网
openstack subnet create --subnet-range 172.16.1.0/24 --network demo_test01_network01 --dns-nameserver 114.114.114.114 demo_test01_subnet01
openstack subnet create --subnet-range 172.16.2.0/24 --network demo_test01_network02 --dns-nameserver 114.114.114.114 demo_test01_subnet02
openstack subnet create --subnet-range 172.16.3.0/24 --network demo_test01_network03 --dns-nameserver 114.114.114.114 demo_test01_subnet03
3.验证user子网是否创建成功
openstack subnet list|grep demo_test01
创建路由¶
1.加载admin环境变量
source admin_openrc
- 查看公网网络名称
openstack network list|grep ext-net
3.查看公网子网名称
openstack subnet list|grep ext-sub
4.加载user环境变量
source client_openrc
5.创建路由
openstack router create demo_test01_router01
6.创建子网并绑定到路由上
openstack router add subnet demo_test01_router01 demo_test01_subnet01
7.设置路由绑定网关
openstack router set --external-gateway ext-net demo_test01_router01
8.查看验证路由信息
openstack router show demo_test01_router01
浮动IP申请¶
openstack floating ip create ext-net
浮动IP查询¶
openstack floating ip list
浮动IP释放¶
openstack floating ip delete $UUID
创建安全组¶
1.加载user环境变量
source client_openrc
2.创建安全组
openstack security group create --description "demo_test01_security_group" demo_test01_security_group
3.设置安全组规则(22/3389/icmp允许通过)
openstack security group rule create --proto icmp demo_test01_security_group
openstack security group rule create --proto tcp --dst-port 22 demo_test01_security_group
openstack security group rule create --proto tcp --dst-port 3389 demo_test01_security_group
4.验证检查安全组
openstack security group show demo_test01_security_group
创建key免密¶
1.加载user环境变量
source client_openrc
2.现在我们使用ssh-keygen命令来生成一对秘钥对
ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
3.创建os租户密钥对
openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey
4.查看os租户密钥对
openstack keypair list
5.创建虚拟机如何引用密钥对
--key-name mykey
准备创建VM¶
查看flavor¶
[root@hb02-control-10e114e194e29 .work]# openstack flavor list|grep "ctyun.os"
| e20afd2f-dab2-4516-b82f-2273bd1e9001 | ctyun.os-lc1g | 1024 | 100 | 0 | 1 | True |
| e20afd2f-dab2-4516-b82f-2273bd1e9002 | ctyun.os-lc2g | 2048 | 100 | 0 | 1 | True |
| e20afd2f-dab2-4516-b82f-2273bd1e9003 | ctyun.os-2c4g | 4096 | 100 | 0 | 2 | True |
| e20afd2f-dab2-4516-b82f-2273bd1e9004 | ctyun.os-4c8g | 8192 | 100 | 0 | 4 | True |
查看网络¶
[root@hb02-control-10e114e194e29 .work]# openstack network list |grep "demo_test01"
| 8a110e83-27b1-4480-94b3-a7f99d77910f | demo_test01_network03 | 77f7f0bd-4f6b-4e72-87d3-32844b4ec748 |
| 8da89321-9ca6-411a-aab9-6f1f8327626a | demo_test01_network01 | e4dde8c3-a1d5-4ab6-90ce-85d58d4c6add |
| bacf4abb-ebfc-4168-9122-ff56281adfd7 | demo_test01_network02 | 150184f5-fd64-45fd-bf05-0ac207e3b63c |
查看子网¶
[root@hb02-control-10e114e194e29 .work]# openstack subnet list|grep demo_test01
| 150184f5-fd64-45fd-bf05-0ac207e3b63c | demo_test01_subnet02 | bacf4abb-ebfc-4168-9122-ff56281adfd7 | 172.16.2.0/24 |
| 77f7f0bd-4f6b-4e72-87d3-32844b4ec748 | demo_test01_subnet03 | 8a110e83-27b1-4480-94b3-a7f99d77910f | 172.16.3.0/24 |
| e4dde8c3-a1d5-4ab6-90ce-85d58d4c6add | demo_test01_subnet01 | 8da89321-9ca6-411a-aab9-6f1f8327626a | 172.16.1.0/24 |
查看路由¶
openstack router show demo_test01_router01
查看安全组¶
openstack security group show demo_test01_security_group
开始创建VM¶
权限切换¶
授权demo_test01用户admin权限
source admin_openrc
openstack role add --project demo_test01 --user demo_test01 admin
source client_openrc
授权demo_test01用户user权限
source admin_openrc
openstack role add --project demo_test01 --user demo_test01 user
source client_openrc
准备信息¶
根据以上命令我们可以获取到如下信息:
--flavor ctyun.os-2c4g
--image 355f4aeb-7fc3-41ab-bcf1-88657ff46020
--nic net-name=demo_test01_network01,v4-fixed-ip=172.16.1.2
--security-group demo_test01_security_group
--meta admin_pass=www.123
创建带本地磁盘的虚拟机¶
1.创建虚拟机(指定IP)
nova boot \
--flavor ctyun.os-2c4g \
--image 355f4aeb-7fc3-41ab-bcf1-88657ff46020 \
--nic net-name=demo_test01_network01,v4-fixed-ip=172.16.1.11 \
--security-group demo_test01_security_group \
--meta admin_pass=www.123 \
demo_test01_vm01
2.创建虚拟机(随机IP)
nova boot \
--flavor ctyun.os-2c4g \
--image 355f4aeb-7fc3-41ab-bcf1-88657ff46020 \
--nic net-name=demo_test01_network01 \
--security-group demo_test01_security_group \
--meta admin_pass=www.123 \
demo_test01_vm01
3.验证创建的虚拟机
nova list
openstack server list
创建带云硬盘虚拟机¶
1.创建虚拟机(指定IP)
nova boot \
--flavor ctyun.os-2c4g-2.large \
--nic net-name=demo_test01_network01 \
--security-group demo_test01_security_group \
--block-device id=355f4aeb-7fc3-41ab-bcf1-88657ff46020,source=image,dest=volume,bootindex=0,size=100,shutdown=remove \
--meta vif_model=virtio \
--meta admin_pass=www.123 \
demo_test01_vm02
1.创建虚拟机(随机IP)
nova boot \
--flavor ctyun.os-2c4g \
--nic net-name=demo_test01_network01 \
--security-group demo_test01_security_group \
--block-device id=355f4aeb-7fc3-41ab-bcf1-88657ff46020,source=image,dest=volume,bootindex=0,size=100,shutdown=remove \
--meta vif_model=virtio \
--meta admin_pass=www.123 \
demo_test01_vm02
2.验证创建的虚拟机
nova list
openstack volume list
创建带云硬盘虚拟机(多网卡)¶
1.创建虚拟机(指定IP)
nova boot \
--flavor ctyun.os-2c4g \
--security-group demo_test01_security_group \
--block-device id=355f4aeb-7fc3-41ab-bcf1-88657ff46020,source=image,dest=volume,bootindex=0,size=100,shutdown=remove \
--nic net-name=demo_test01_network01,v4-fixed-ip=172.16.1.13 \
--meta vif_model=virtio \
--nic net-name=demo_test01_network02 \
--nic net-name=demo_test01_network03 \
--meta admin_pass=www.123 \
demo_test01_vm03
2.创建虚拟机(随机IP)
nova boot \
--flavor ctyun.os-2c4g \
--security-group demo_test01_security_group \
--block-device id=355f4aeb-7fc3-41ab-bcf1-88657ff46020,source=image,dest=volume,bootindex=0,size=100,shutdown=remove \
--nic net-name=demo_test01_network01 \
--meta vif_model=virtio \
--nic net-name=demo_test01_network02 \
--nic net-name=demo_test01_network03 \
--meta admin_pass=www.123 \
demo_test01_vm03
2.验证创建的虚拟机
nova list
openstack volume list
创建带云硬盘虚拟机(多磁盘)¶
1.创建虚拟机(指定IP)
nova boot \
--flavor ctyun.os-2c4g \
--nic net-name=demo_test01_network01,v4-fixed-ip=172.16.1.14 \
--security-group demo_test01_security_group \
--block-device id=355f4aeb-7fc3-41ab-bcf1-88657ff46020,source=image,dest=volume,bootindex=0,size=100,shutdown=remove \
--block-device dest=volume,size=500 \
--block-device dest=volume,size=500 \
--block-device dest=volume,size=500 \
--meta vif_model=virtio \
--meta admin_pass=www.123 \
demo_test01_vm04
2.创建虚拟机(随机IP)
nova boot \
--flavor ctyun.os-2c4g \
--nic net-name=demo_test01_network01 \
--security-group demo_test01_security_group \
--block-device id=355f4aeb-7fc3-41ab-bcf1-88657ff46020,source=image,dest=volume,bootindex=0,size=100,shutdown=remove \
--block-device dest=volume,size=500 \
--block-device dest=volume,size=500 \
--block-device dest=volume,size=500 \
--meta vif_model=virtio \
--meta admin_pass=www.123 \
demo_test01_vm04
2.验证创建的虚拟机
nova list
openstack volume list
创建带云硬盘虚拟机(浮动IP)¶
1.创建虚拟机(随机IP)
nova boot \
--flavor ctyun.os-2c4g \
--nic net-name=demo_test01_network01 \
--security-group demo_test01_security_group \
--block-device id=355f4aeb-7fc3-41ab-bcf1-88657ff46020,source=image,dest=volume,bootindex=0,size=100,shutdown=remove \
--meta vif_model=virtio \
--meta admin_pass=www.123 \
demo_test01_vm05
2.申请浮动IP
neutron floatingip-create ext-net
3.查看申请的浮动IP
openstack floating ip list
4.绑定申请的浮动IP
绑定浮动IP
vm_prot_uuid=$(nova interface-list $vm_name|grep "172.16.10"|awk -F "|" '{print $3}'|xargs)
neutron floatingip-associate $floating_ip_uuid $vm_prot_uuid
[root@172e28e12e165 ~]# neutron floatingip-associate 4423cb1c-a4c0-457b-a868-3855129e50fc 7e2a30c8-a16b-4301-b5c5-5e284a631925
管理VM¶
查询虚拟机列表¶
[root@172e28e12e165 ~]# nova list
查询虚拟机详细信息¶
[root@172e28e12e165 ~]# nova show demo_test01_vm01
查询虚拟机动作日志¶
[root@172e28e12e165 ~]# nova instance-action-list demo_test01_vm01
重置虚拟机状态¶
nova reset-state eec6d2f8-f295-417c-8d12-c31ea005c689 --active
查看虚拟机日志¶
第一种方法:
nova console-log demo_test01_vm01
第二种方法:
在虚拟机所在的compute节点上找到log文件:
通过virsh dumpxml指令,找到如下关键段:
<console type='file'>
<source path='/var/lib/nova/instances/842d5f63-6c0f-4582-8237-076ccc29e759/console.log'/>
<target type='serial' port='0'/>
<alias name='serial0'/>
</console>
再到相应的目录下即可:
root@compute-1:~# cd /var/lib/nova/instances/842d5f63-6c0f-4582-8237-076ccc29e759
root@compute-1:/var/lib/nova/instances/842d5f63-6c0f-4582-8237-076ccc29e759# ls
console.log disk disk.config disk.info libvirt.xml
关闭虚拟机¶
[root@172e28e12e165 ~]# nova stop demo_test01_vm01
Request to stop server demo_test01_vm01 has been accepted.
启动虚拟机¶
[root@172e28e12e165 ~]# nova start demo_test01_vm01
Request to start server demo_test01_vm01 has been accepted.
重启虚拟机¶
[root@172e28e12e165 ~]# nova reboot demo_test01_vm01
Request to reboot server <Server: demo_test01_vm01> has been accepted.
挂起虚拟机¶
[root@172e28e12e165 ~]# nova suspend demo_test01_vm01
恢复虚拟机¶
[root@172e28e12e165 ~]# nova resume demo_test01_vm01
重装虚拟机¶
[root@172e28e12e165 ~]# nova rebuild --meta admin_pass=www.123 demo_test01_vm01 6be2a276-85dc-4e5b-ab0a-a1ae8fdaa09e
重置密码¶
[root@172e28e12e165 ~]# nova set-password demo_test01_vm01
调整虚拟机规格¶
| e20afd2f-dab2-4516-b82f-2273bd1e9001 | ctyun.os-lc1g-1.small | 1024 | 100 | 0 | 1 | True |
| e20afd2f-dab2-4516-b82f-2273bd1e9002 | ctyun.os-lc2g-2.small | 2048 | 100 | 0 | 1 | True |
| e20afd2f-dab2-4516-b82f-2273bd1e9003 | ctyun.os-2c2g-1.large | 2048 | 100 | 0 | 2 | True |
| e20afd2f-dab2-4516-b82f-2273bd1e9004 | ctyun.os-2c4g-2.large | 4096 | 100 | 0 | 2 | True |
| e20afd2f-dab2-4516-b82f-2273bd1e9005 | ctyun.os-2c8g-3.large | 8192 | 100 | 0 | 2 | True |
| e20afd2f-dab2-4516-b82f-2273bd1e9006 | ctyun.os-4c4g-1.xlarge | 4096 | 100 | 0 | 4 | True |
| e20afd2f-dab2-4516-b82f-2273bd1e9007 | ctyun.os-4c8g-2.xlarge | 8192 | 100 | 0 | 4 | True |
| e20afd2f-dab2-4516-b82f-2273bd1e9008 | ctyun.os-4c16g-3.xlarge | 16384 | 100 | 0 | 4 | True |
| e20afd2f-dab2-4516-b82f-2273bd1e9009 | ctyun.os-8c8g-1.huge | 8192 | 100 | 0 | 8 | True |
| e20afd2f-dab2-4516-b82f-2273bd1e9010 | ctyun.os-8c16g-2.huge | 16384 | 100 | 0 | 8 | True |
| e20afd2f-dab2-4516-b82f-2273bd1e9011 | ctyun.os-8c32g-3.huge | 32768 | 100 | 0 | 8 | True |
| e20afd2f-dab2-4516-b82f-2273bd1e9012 | ctyun.os-16c16g-1.plus | 16384 | 100 | 0 | 16 | True |
| e20afd2f-dab2-4516-b82f-2273bd1e9013 | ctyun.os-16c32g-2.plus | 32768 | 100 | 0 | 16 | True |
| e20afd2f-dab2-4516-b82f-2273bd1e9014 | ctyun.os-16c64g-3.plus | 65536 | 100 | 0 | 16 | True |
| e20afd2f-dab2-4516-b82f-2273bd1e9015 | ctyun.os-22c4g-1.pressure | 4096 | 100 | 0 | 22 | True |
| e20afd2f-dab2-4516-b82f-2273bd1e9016 | ctyun.os-22c4g-2.pressure | 4096 | 100 | 0 | 24 | True |
| e20afd2f-dab2-4516-b82f-2273bd1e9051 | ctyun.os-2c4g_false | 4096 | 100 | 0 | 2 | True |
| e20afd2f-dab2-4516-b82f-2273bd1e9052 | ctyun.os-4c8g_false | 8192 | 100 | 0 | 4 | True |
| e20afd2f-dab2-4516-b82f-2273bd1e9053 | ctyun.os-8c16g_false | 16384 | 100 | 0 | 8 | True |
| e20afd2f-dab2-4516-b82f-2273bd1e9054 | ctyun.os-16c32g_false | 32768 | 100 | 0 | 16 | True |
| e20afd2f-dab2-4516-b82f-2273bd1e9055 | ctyun.os-32c64g_false | 65536 | 100 | 0 | 32 | True |
[root@172e28e12e165 ~]# openstack server resize --flavor ctyun.os-8c8g-1.huge demo_test01_vm01
[root@172e28e12e165 ~]# nova resize-confirm demo_test01_vm01
查询虚拟机vnc地址¶
nova get-vnc-console demo_test01_vm01 novnc|awk -F "|" '{print $3}'|xargs
openstack console url show huxining-20201011-49
查询虚拟机console log日志¶
openstack console log show huxining-20201011-49
申请浮动IP¶
neutron net-list
neutron floatingip-create ext-net
绑定浮动IP¶
查看申请的浮动IP
neutron floatingip-list
绑定浮动IP
vm_prot_uuid=$(nova interface-list $vm_name|grep "172.16.10"|awk -F "|" '{print $3}'|xargs)
neutron floatingip-associate $floating_ip_uuid $vm_prot_uuid
[root@172e28e12e165 ~]# neutron floatingip-associate 4423cb1c-a4c0-457b-a868-3855129e50fc 7e2a30c8-a16b-4301-b5c5-5e284a631925
解绑浮动IP¶
[root@172e28e12e165 ~]# openstack server remove floating ip demo_test01_vm01 172.28.15.162
释放浮动IP¶
查看申请的浮动IP
[root@172e28e12e165 ~]# neutron floatingip-list
[root@172e28e12e165 ~]# openstack floating ip delete 172.28.15.138
添加网卡¶
openstack server add fixed ip --fixed-ip-address 172.16.${num}.${ip_num} $vm_name $network_name$num
添加两块网卡
[root@172e28e12e165 ~]# neutron net-list
[root@172e28e12e165 ~]# openstack server add fixed ip --fixed-ip-address 172.16.2.11 demo_test01_vm01 demo_test01_network02
[root@172e28e12e165 ~]# openstack server add fixed ip --fixed-ip-address 172.16.3.11 demo_test01_vm01 demo_test01_network03
删除网卡¶
[root@172e28e12e165 ~]# nova interface-list demo_test01_vm01
nova interface-detach <server> <port_id>
[root@172e28e12e165 ~]# nova interface-detach demo_test01_vm01 c4dd0302-3ce6-4ec2-b9ce-3b7789fcf289
[root@172e28e12e165 ~]# nova interface-detach demo_test01_vm01 6965d262-9d38-4382-917a-7f9de2a16c22
创建云硬盘¶
查看volume类型
[root@172e28e12e165 ~]# openstack volume type list
openstack volume create --size $vm_disk_size --type $volume_type --count 1 ${vm_name}_${volume_name} &>/dev/null
创建一个500GB的云硬盘
[root@172e28e12e165 ~]# openstack volume create --size 500 --type default --count 1 demo_test01_vm01_volume_disk01
查看云硬盘¶
[root@172e28e12e165 ~]# openstack volume list
挂载云硬盘¶
查看创建的云硬盘
[root@172e28e12e165 ~]# openstack volume list
openstack server add volume --device $device_name $vm_name ${vm_name}_${volume_name} &>/dev/null
挂载云硬盘
[root@172e28e12e165 ~]# openstack server add volume --device /dev/vdb demo_test01_vm01 demo_test01_vm01_volume_disk01
调整云硬盘¶
openstack volume set --size <size> <volume>
[root@172e28e12e165 ~]# openstack volume set --size 10000 demo_test01_vm01_volume_disk01
[root@172e28e12e165 ~]# openstack volume set --size 10 demo_test01_vm01_volume_disk01
卸载云硬盘¶
openstack server remove volume <server> <volume>
[root@172e28e12e165 ~]# openstack server remove volume demo_test01_vm01 demo_test01_vm01_volume_disk01
删除云硬盘¶
openstack volume delete <volume>
[root@172e28e12e165 ~]# openstack volume delete demo_test01_vm01_volume_disk01
删除虚拟机卷¶
cinder delete feee18fa-4cb5-4d81-be2c-43cd6c220b8f
cinder list-delete-confirm-resources
cinder delete-confirm d1c22510-fb02-4645-8945-96e2468797e7
设置router gateway无限速¶
此功能可以开启租户网段打通出外网(默认租户网段无法出外网,需要绑定浮动ip才能出)
(选择 ext-net)
openstack network list
openstack router list
openstack router set --no-qos-policy --enable-snat --external-gateway net-id router-id
openstack router set --no-qos-policy --enable-snat --external-gateway 3e490fbe-6da7-46e0-a3d6-529d3ac34e26 ccce747a-5416-4bb8-9e2e-240b8f3d5c48
此功能可以关闭租户网段打通出外网(默认租户网段无法出外网,需要绑定浮动ip才能出)
(选择 ext-net)
openstack network list
openstack router list
openstack router set --no-qos-policy --disable-snat --external-gateway net-id router-id
openstack router set --no-qos-policy --disable-snat --external-gateway 3e490fbe-6da7-46e0-a3d6-529d3ac34e26 ccce747a-5416-4bb8-9e2e-240b8f3d5c48
删除fip限速规则¶
openstack port list
openstack floating ip list
openstack floating ip set --port c3659a5e-43bb-42ad-b6e5-510dc12071c8 --no-qos-policy 49.7.12.45
允许内核转发功能¶
方式一:放开allow_address_pair 权限
查询port id
nova interface-list b365a78b-3c0a-4f0c-8fc2-7667204f52e5
放开当前机器allow_address_pair 权限
neutron port-update --allowed-address-pair ip_address=0.0.0.0/0 PORT_ID
集群管理¶
查看集群nova服务¶
nova service-list
查看集群neutron服务¶
neutron agent-list
查看集群cinder服务器¶
cinder service-list
查看计算节点¶
nova hypervisor-list
查看计算节点上的虚拟机¶
nova hypervisor-servers hb02-compute-10e114e194e16
设置计算节点超配比¶
nova hypervisor-list
nova hypervisor-get-ratio 8bd04dcb-5676-4c29-b504-6121403714c6
nova hypervisor-set-ratio --cpu 10.0 --ram 10.0 --disk 0 e409d1f2-b3ad-43e5-8779-66fd69b98bbb
nova hypervisor-show e409d1f2-b3ad-43e5-8779-66fd69b98bbb
[root@compute2 ~]# vi /etc/nova/nova.conf
disk_allocation_ratio = 10.0
cpu_allocation_ratio = 10.0
ram_allocation_ratio = 5.0
将计算节点下线¶
nova service-list
nova service-disable 154ad59a-d986-446e-91ac-fab6dbf47f0b
nova service-enable 154ad59a-d986-446e-91ac-fab6dbf47f0b
nova service-delete 154ad59a-d986-446e-91ac-fab6dbf47f0b
cinder service-disable js03-test-10e0e0e3 cinder-backup
cinder service-enable js03-test-10e0e0e3 cinder-backup
cinder service-delete js03-test-10e0e0e3 cinder-backup
neutron agent-delete 154ad59a-d986-446e-91ac-fab6dbf47f0b
nova service-delete fa56e1f0-696a-4493-9728-2ce2cd27bf91
进入网络命名空间¶
ip netns
ip netns exec snat-6fd1d400-c1d7-48e1-a665-16bbebb7cad6 ip a
ip netns exec snat-6fd1d400-c1d7-48e1-a665-16bbebb7cad6 bash
查看计算节点资源¶
nova hypervisor-list
nova hypervisor-show d551c4af-b4e6-4094-95df-8fd87a6e1810
nova hypervisor-stats