[Openstack] 杂七杂八的记录

1.常用命令
(1)镜像
列出镜像
glance image-list
nova image-list
openstack image list

上传/创建镜像
glance image-create --name <image_name> --disk-format qcow2 --container-format bare
--file <image_file_name> --progress

说明:
  --disk-format <DISK_FORMAT>
                        Format of the disk Valid values: None, ami, ari, aki,
                        vhd, vmdk, raw, qcow2, vdi, iso
  --container-format <CONTAINER_FORMAT>
                        Format of the container Valid values: None, ami, ari,
                        aki, bare, ovf, ova, docker
  --progress            Show upload progress bar.
 

删除镜像
openstack image delete <Image_Name>
glance image-delete <IMAGE_ID>


(2)Flavor
列出Flavor
nova flavor-list
openstack flavor list

创建Flavor
nova flavor-create <flavor_name> <id> <ram_size:MB> <disk_size:GB> <vcpu_numbers>

Set huge pages allocations ==>

nova flavor-key <flavor_name> set hw:mem_page_size=<memory_size, suggest 1048576>
nova flavor-key <flavor_name> set hw:cpu_policy=dedicated

OR
openstack flavor create <Flavor_Name> --ram <RAM_in_MB> --disk <Disk_in_GB> --vcpus <Number_of_VCPU>
 
Set huge pages allocations ==>
openstack flavor set <Flavor_Name> --property hw:mem_page_si
ze=1048576

(3)neutron
列出网络
neutron net-list

列出子网
neutron subnet-list
neutron subnet-list --network_id=xxx

查看子网
neutron subnet-show <subnet_id>

列出PORT
neutron port-list

创建PORT
neutron port-create [--name NAME] [--fixed-ip subnet_id=SUBNET,ip_address=IP_ADDR] <net_id>

列出虚拟机的接口
nova interface-list <VM name>

一个 subnet 只能属于某个 network;一个 network 可以有多个 subnet,这些 subnet 可以是不同的 IP 段,但不能重叠。

注意:

1.这里不是判断 IP 是否有重叠,而是 subnet 的 CIDR 重叠

2.如果 subnet 在不同的 network 中,CIDR 和 IP 都是可以重叠的
 

port 与 subnet 是 1对多 关系。一个 port 必须属于某个 subnet;一个 subnet 可以有多个 port。

port 可以看做虚拟交换机上的一个端口。port 上定义了 MAC 地址和 IP 地址,当 instance 的虚拟网卡 VIF(Virtual Interface) 绑定到 port 时,port 会将 MAC 和 IP 分配给 VIF

推荐阅读:
openstack的网络、子网、端口的关系 https://www.cnblogs.com/boshen-hzb/p/9870345.html

(4)可用区
openstack availability zone list


(5)Stack
openstack stack list
openstack stack show <stack name>
openstack stack delete <stack name>

2.杂七杂八问题和记录
(1)VM部署/换flavor总是因为资源不足失败
查看有哪些计算节点可以列出host: nova host-list
查看特定计算节点资源: nova host-describe <Compute Host Name>
查看计算节点上的虚拟机: nova list --host <Compute Host Name> --all-tenants
查看计算节点详细资源: nova hypervisor-show <Compute Host Name>
查看VM创建失败原因: nova show <VM name>

(2)换flavor

参考 https://blog.csdn.net/wy_hhxx/article/details/111541096 附: 给Openstack上的VM加内存

(3)给两个PORT添加浮动IP
neutron port-show  <PORT1>  => get value of id -> id1
neutron port-update --allowed-address-pair ip_address=<float ip> <id1>
neutron port-show  <PORT2>  => get value of id -> id2
neutron port-update --allowed-address-pair ip_address=<float ip> <id2>

再执行

$ openstack port show <PORT1/PORT2>
+-----------------------+----------------------------------------------------------------------------------------------------------------
| Field                 | Value
+-----------------------+----------------------------------------------------------------------------------------------------------------
| admin_state_up        | UP
| allowed_address_pairs |ip_address='<float ip>', mac_address='<xxx>'

(4)Boot instance from image不能登录的问题

默认创建的VM中sshd_config的配置是
PermitRootLogin no
PubkeyAuthentication yes

这时需要打开远程控制台登录修改

~$ nova get-vnc-console TEST-4 novnc
+-------+----------------------------------------------------------------------------------------+
| Type  | Url                                                                                    |
+-------+----------------------------------------------------------------------------------------+
| novnc | https://[2112:0:0:16::4]:6080/vnc_auto.html?token=aaa6d141-07a8-4b5e-8144-3f8a792ac4ae |
+-------+----------------------------------------------------------------------------------------+

为了避免这种情况, 创建命令中可以带上 --user-data参数

nova boot --user-data <script_file> --flavor <flavor_name> --image <image_id> --nic port-id=<port_id> --availability zone=<availability_zone_name>:<compute_node_name> <instance_name>

script_file的内容如下

#!/bin/bash
echo "Note: Modify sshd_config to enable root login"
sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g'
/etc/ssh/sshd_config
sed -i 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config
sed -i 's/PubkeyAuthentication yes/PubkeyAuthentication no/g' /etc/ssh/sshd_config
systemctl restart sshd

或者用heat模板创建VM,使用cloud-init初始化云环境可以避开上述问题

猜你喜欢

转载自blog.csdn.net/wy_hhxx/article/details/119253848