当前位置: > 其它学习 > OpenStack >

OpenStack问题集锦[持续更新中...]

时间:2019-12-24 10:16来源:linux.it.net.cn 作者:IT
如何再添加一个管理员用户
# 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.给虚拟机挂载磁盘
说明:

    consumer的合法值为front-end、back-end、both。front-end表示使用前端控制(hypervisor控制,会在libvirt xml文件中定义), 而back-end表示使用后端控制(cinder drivers,需要driver支持),both表示前后端同时进行QoS控制。

    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


(责任编辑:IT)
------分隔线----------------------------