OpenStack问题集锦(持续更新中...)

(文章来自作者维护的社区微信公众号【虚拟化云计算】)
目前有两个微信群《kvm虚拟化》和《openstack》,扫描二维码点击“云-交流”,进群交流提问
如何再添加一个管理员用户
# keystone-manage bootstrap --bootstrap-username myadmin --bootstrap-password mypasswd
 

 

如何登陆虚拟机的控制台界面:
1.查看某个实例的url(例如访问前面创建的名为instance-a 的实例)
$ openstack console url show 5b08017b-00d4-4476-9380-4f5b6165c6d7
+-------+---------------------------------------------------------------------------------+
| Field | Value                                                                           |
+-------+---------------------------------------------------------------------------------+
| type  | novnc                                                                           |
| url   | http://controller:6080/vnc_auto.html?token=6643713d-f4c8-411c-ac9e-2c5b5a419935 |
+-------+---------------------------------------------------------------------------------+
(5b08017b-00d4-4476-9380-4f5b6165c6d7 通过openstack server list 查看,是要启动实例的ID)
2.访问一个实例
(在浏览器中输入http://controller:6080/vnc_auto.html?token=6643713d-f4c8-411c-ac9e-2c5b5a419935 就可以访问虚拟机了,前提是controller主机名能被识别,或直接换成ip)

 

 
如何设置虚拟机磁盘类型,如ide、virtio
创建虚拟机时直接传入"disk_bus": "ide" :
 
Action: 'create', calling method: <bound method ServersController.create of <nova.api.openstack.compute.servers.ServersController object at 0x7f1e5c008510>>, body: {"server": {"name": "test-1", "imageRef": "", "availability_zone": "nova", "block_device_mapping_v2": [{"disk_bus": "ide", "source_type": "image", "boot_index": "0", "uuid": "907bcb20-7623-446f-b19c-ab135a0ac2d6", "destination_type": "volume", "volume_size": 400, "delete_on_termination": true, "disk_name": "test-1-disk1", "device_name": "vda"}], "flavorRef": "8a6558a8-2d36-48d9-bd0d-2fbe1ac25a2e", "max_count": 1, "interface_disconnect_names": [], "min_count": 1, "networks": "none"}}
 
如何设置虚拟机的cpu拓扑
$ openstack flavor set FLAVOR-NAME \
    --property hw:cpu_sockets=FLAVOR-SOCKETS \
    --property hw:cpu_cores=FLAVOR-CORES \
    --property hw:cpu_threads=FLAVOR-THREADS \
    --property hw:cpu_max_sockets=FLAVOR-SOCKETS \
    --property hw:cpu_max_cores=FLAVOR-CORES \
    --property hw:cpu_max_threads=FLAVOR-THREADS
 
或者
$ nova flavor-key m2.nano set hw:cpu_sockets=3  hw:cpu_cores=4  hw:cpu_threads=5
 
如何设置虚拟机的操作系统类型
# openstack image set --property os_type=windows 950420e3-98ae-454b-b073-9f75b275fcc8
或者
# nova image-meta 950420e3-98ae-454b-b073-9f75b275fcc8 set os_type=linux
 
这样在镜像的属性里面就能看到os_type
 
如何设置虚拟机磁盘的cache类型
修改配置文件中的disk_cachemodes:
/etc/nova/nova-compute.conf
[libvirt]
disk_cachemodes = "network=writeback"
 
其中network和writeback分别对应虚拟机xml中的type和cache:
  <devices>
    <disk type='network' device='disk'>
      <driver name='qemu' type='raw' cache='writeback'/>
这个配置是不会写入数据库的,每次虚拟机启动时根据这个配置文件动态生成。
 
如何设置虚拟机cpu类型
修改配置文件中的cpu_mode:
/etc/nova/nova-compute.conf
[libvirt]
cpu_mode=none
这个配置是不会写入数据库的,每次虚拟机启动时根据这个配置文件动态生成。
如果cpu_mode=none:
  <cpu>
      <topology sockets='1' cores='1' threads='1'/>                           
   </cpu>
如果cpu_mode=host-model:
  <cpu mode='host-model'>
      <model fallback='allow'/>
      <topology sockets='1' cores='1' threads='1'/>                           
   </cpu>
 
如何设置虚拟机cpu的亲和性
修改/etc/nova/nova.conf
[DEFAULT]
vcpu_pin_set = 0-1
使用上面的配置后虚拟机的xml文件如下:
  <vcpu placement='static' cpuset='0-1'>2</vcpu>
其作用主要是让openstack的虚拟机使用指定的几个物理cpu核,给物理机操作系统适当留下若干物理核,保证物理机的性能。
说明:另外openstack还可以通过flavor隐式的做虚拟机cpu的绑定,通过做host的aggregate:
The flavor extra specs will be enhanced to support twonew parameters
hw:cpu_policy=shared|dedicated
hw:cpu_threads_policy=avoid|separate|isolate|prefer
 
如何设置虚拟机的关联组与反关联组
nova可以通过命令创建一个server group,在server group中的vm可以指定一些policy。
这些policy包括affinity和anti-affinity。affinity表示尽量把vm都安排到一个host上面,anti-ffinity表示尽量把vm安排到不同的host上面。
创建server-group的命令:
nova server-group-create group_name anti-afffinity
 
创建vm的时候通过hint指定group名字:
nova boot --image cirros --flavor m1.small --hint group=group_name
这样就能把创建的vm放到某个指定的group里面了
 
如何更新网络的ip地址池的范围
neutron subnet-update --allocation-pool start=192.168.105.35,end=192.168.105.39 --allocation-pool start=192.168.105.40,end=192.168.105.49 subnet_01
 
如何使用floating ip
neutron floatingip-create providernet01
neutron floatingip-associate  fbc76a22-4a2e-43bb-982b-6e42575eebe9 12b50cb3-18c8-4c08-8caf-1203e3183406
(floating_id   port_id)
 
如何在subnet中创建port
neutron port-create --fixed-ip subnet_id=$SUBNET_ID $NET_ID
 
如何控制磁盘qos(cinder)
一。首先创建一个带限速功能的类型
# cinder type-create my-type 
# cinder qos-create my-qos consumer="front-end" read_iops_sec=2000 write_iops_sec=1000
# cinder qos-associate $QOS_ID $VOLUME_TYPE_ID
# cinder qos-get-association $QOS_ID
 
二。把创建的类型赋给磁盘
如果是已经存在的磁盘:
1.从虚拟机分离磁盘
2.# cinder retype $VOLUME_ID $VOLUME_TYPE_ID
3.给虚拟机挂载磁盘
 
如果是要新创建磁盘:
1.# cinder create --name $VOLUME_NAME --volume-type $VOLUME_TYPE_ID 
2.给虚拟机挂载磁盘
说明:
  1. consumer的合法值为front-end、back-end、both。front-end表示使用前端控制(hypervisor控制,会在libvirt xml文件中定义), 而back-end表示使用后端控制(cinder drivers,需要driver支持),both表示前后端同时进行QoS控制。
  1. libvirt中disk中配置:
      <iotune>
        <read_iops_sec>2000</read_iops_sec>
        <write_iops_sec>1000</write_iops_sec>
      </iotune>
 
如何控制磁盘qos(nova)
# openstack flavor create  --vcpus 1 --ram 4096 --disk 5 qqq
# openstack flavor set qqq --property quota:disk_read_bytes_sec=20480 --property quota:disk_write_bytes_sec=10240
    <disk type='network' device='disk'>
      <driver name='qemu' type='raw' cache='writeback' discard='unmap'/>
      <source protocol='rbd' name='images/1a956ba7-25fe-49f1-9513-7adb8928036c'>
        <host name='192.168.107.50' port='6789'/>
        <host name='192.168.107.51' port='6789'/>
        <host name='192.168.107.52' port='6789'/>
        <host name='192.168.107.53' port='6789'/>
      </source>
      <target dev='vda' bus='virtio'/>
      <iotune>
        <read_bytes_sec>20480</read_bytes_sec>
        <write_bytes_sec>10240</write_bytes_sec>
      </iotune>
      <boot order='1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x0'/>
    </disk>
# openstack flavor create  --vcpus 1 --ram 4096 --disk 5 qqqq
# openstack flavor set qqqq --property quota:disk_read_iops_sec=20480 --property quota:disk_write_iops_sec=10240
    <disk type='network' device='disk'>
      <driver name='qemu' type='raw' cache='writeback' discard='unmap'/>
      <source protocol='rbd' name='images/1a956ba7-25fe-49f1-9513-7adb8928036c'>
        <host name='192.168.107.50' port='6789'/>
        <host name='192.168.107.51' port='6789'/>
        <host name='192.168.107.52' port='6789'/>
        <host name='192.168.107.53' port='6789'/>
      </source>
      <target dev='vda' bus='virtio'/>
      <iotune>
        <read_iops_sec>20480</read_iops_sec>
        <write_iops_sec>10240</write_iops_sec>
      </iotune>
      <boot order='1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x0'/>
    </disk>
 
如何控制网络qos(neutorn)
 
 
如何控制网络qos(nova)
# openstack flavor create  --vcpus 1 --ram 512 --disk 1 q
# openstack flavor set q --property quota:vif_inbound_average=2048  --property quota:vif_outbound_average=1024
    <interface type='bridge'>
      <mac address='fa:16:3e:8f:6a:c9'/>
      <source bridge='brq5233ef6c-62'/>
      <bandwidth>
        <inbound average='2048'/>
        <outbound average='1024'/>
      </bandwidth>
      <target dev='tap9573c869-24'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
 
如何在数据库中删除虚拟机
MariaDB [nova]> delete from instance_actions_events where action_id="129";
MariaDB [nova]> delete from instance_actions_events where action_id="138";
 
MariaDB [nova]> delete from instance_actions where instance_uuid="67b6044b-bbdc-4120-b2c7-c6faf540da29"; (id和action_id关联)
 
MariaDB [nova]> delete from block_device_mapping where instance_uuid="67b6044b-bbdc-4120-b2c7-c6faf540da29";
 
MariaDB [nova]> delete from instance_extra where instance_uuid="67b6044b-bbdc-4120-b2c7-c6faf540da29";
 
MariaDB [nova]> delete from instance_info_caches where instance_uuid="67b6044b-bbdc-4120-b2c7-c6faf540da29";     
 
MariaDB [nova]> delete from instance_system_metadata where instance_uuid="67b6044b-bbdc-4120-b2c7-c6faf540da29";
 
MariaDB [nova]> delete from instances where display_name="test-1";  
 
快速创建网络脚本
#!/bin/bash
function create_providernet()
{
    openstack router create router01
    neutron net-create --shared --router:external=true --provider:physical_network provider01 --provider:network_type flat providernet01
    openstack subnet create --network providernet01 --dns-nameserver 219.146.1.66 --gateway 192.168.5.254 --subnet-range 192.168.5.0/24 --no-dhcp providernet01_subnet01
    #neutron router-gateway-set router01 providernet01
    neutron router-gateway-set --fixed-ip ip_address=192.168.5.89 router01 providernet01
}
 
function create_net()
{
    neutron net-create --shared  --provider:segmentation_id 188 --provider:physical_network provider02 --provider:network_type vlan net01
    openstack subnet create --network net01 --dns-nameserver 219.146.1.66 --gateway 172.16.1.1 --subnet-range 172.16.1.0/24  net01_subnet01
    neutron router-interface-add router01 net01_subnet01
}
 
function clear_all()
{   
    neutron router-gateway-clear router01
    neutron router-interface-delete router01 net01_subnet01
    neutron router-delete router01
 
    neutron net-delete providernet01
    neutron net-delete net01
}
 
. admin-openrc
create_providernet
create_net
#clear_all

 

 

持续更新中...
===============================================================
关注微信公众号【虚拟化云计算】,阅读更多虚拟化云计算知识

<think>好的,我现在需要处理用户关于OpenStack从硬盘启动的配置或故障排除的问题。首先,我需要回忆一下OpenStack的基本架构,特别是与实例启动相关的组件,比如Nova、Glance和Cinder。用户可能希望将实例直接从一个硬盘镜像启动,而不是传统的从镜像启动再挂载卷的方式。 首先,我应该考虑OpenStack中配置从硬盘启动的常见方法。通常,这涉及到修改实例的启动源,可能需要使用Cinder卷作为根磁盘。我记得在OpenStack中,可以通过指定block_device_mapping参数来引导实例从卷启动。需要确认用户使用的OpenStack版本,因为不同版本的配置可能有所不同。 接下来,用户可能需要具体的配置步骤。例如,使用命令行工具创建卷并从镜像中启动实例。步骤可能包括:创建卷、从Glance镜像复制到卷,然后使用该卷作为启动源。此外,需要确保Nova和Cinder的配置正确,比如允许从卷启动,以及相关的策略设置。 关于故障排除,常见的问题可能包括卷无法正确附加、启动时找不到引导设备、权限问题或配置错误。例如,检查nova.conf中的配置,确认scheduler_default_filters是否包含BlockDeviceFilter,以及是否启用了正确的驱动程序。另外,查看日志文件,如Nova和Cinder的日志,可以帮助定位问题。 还需要考虑用户是否遇到了特定的错误信息。例如,如果实例启动时进入救援模式,可能是因为根文件系统未被正确挂载或内核参数不正确。这时候可能需要检查实例的元数据或检查卷的引导记录是否完好。 此外,用户可能没有提到但需要注意的点包括:安全组设置是否正确、网络配置是否允许实例访问必要的服务(如Metadata服务),以及存储后端是否支持从卷启动。例如,某些存储驱动可能有不同的要求。 最后,根据用户提供的引用内容,虽然大部分是关于其他服务(如Kubernetes observability、容器注册表等),但需要确保在回答时不混淆这些信息,专注于OpenStack相关的配置和问题解决。可能需要参考官方文档或社区最佳实践来确保答案的准确性。</think>### OpenStack从硬盘启动配置与故障排查 #### 一、配置从硬盘启动 1. **使用Cinder卷作为启动源** OpenStack支持通过Cinder卷直接启动实例,需通过`block_device_mapping`参数指定卷配置: ```bash openstack server create --flavor <flavor-id> \ --block-device source=image,id=<glance-image-id>,dest=volume,size=<volume-size>,bootindex=0 \ --network <network-id> <instance-name> ``` 此命令会从Glance镜像创建卷,并将其作为实例的根磁盘[^1]。 2. **手动创建并挂载卷** - 创建空卷: ```bash openstack volume create --size <size> <volume-name> ``` - 将Glance镜像写入卷: ```bash openstack image save --file <image-file> <glance-image-id> openstack volume upload --image <glance-image-id> <volume-id> ``` - 启动实例时直接挂载该卷为根磁盘。 3. **验证Nova配置** 检查`/etc/nova/nova.conf`是否允许卷启动: ```ini [scheduler] enabled_filters = RetryFilter, AvailabilityZoneFilter, ComputeFilter, ComputeCapabilitiesFilter, ImagePropertiesFilter, ServerGroupAntiAffinityFilter, ServerGroupAffinityFilter, BlockDeviceFilter ``` #### 二、常见故障排查 1. **实例启动失败:卷无法附加** - 检查Cinder服务状态: ```bash systemctl status cinder-volume ``` - 查看卷状态是否为`available`或`in-use`: ```bash openstack volume show <volume-id> ``` - 日志分析:检查`/var/log/cinder/volume.log`中是否有权限或驱动错误[^1]。 2. **实例卡在启动界面(GRUB Rescue)** - **原因**:引导分区损坏或内核参数未正确传递。 - **修复步骤**: 1. 挂载卷到临时实例: ```bash openstack volume set --state available <volume-id> openstack server add volume <temp-instance> <volume-id> ``` 2 修复引导: ```bash mount /dev/vdb1 /mnt chroot /mnt grub-install /dev/vdb update-grub ``` 3. **卷启动后网络配置丢失** - 检查镜像是否包含Cloud-Init,并验证`/etc/cloud/cloud.cfg`中是否启用网络配置: ```yaml network: config: enabled ``` - 手动注入元数据: ```bash openstack server meta set <instance> --property admin_pass=<password> ``` #### 三、高级配置:直接使用物理硬盘 在**裸机部署(Ironic)**场景中,可通过以下方式直接写入硬盘: 1. 使用`dd`命令将镜像写入物理设备: ```bash dd if=<image-file> of=/dev/sdX bs=4M status=progress ``` 2. 在Ironic节点配置中指定启动设备: ```json { "capabilities": "boot_device:hd" } ``` #### 四、性能优化建议 - 启用Cinder卷缓存:在`cinder.conf`中配置: ```ini [backend] volume_dd_blocksize = 1M ``` - 使用SSD后端存储提升IOPS。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值