雲計算--OpenStack Grizzly 安裝指南

OpenStack Grizzly 安裝指南

Version:1.0
Source:https://github.com/ist0ne/OpenStack-Grizzly-Install-Guide-CN
Keywords:單節點OpenStack安裝, Grizzly, Quantum, Nova, Keystone, Glance, Horizon, Cinder, LinuxBridge, KVM, Ubuntu Server 12.04 (64 bits).

作者

Shi Dongliang <[email protected]>

本指南fork自 Bilel Msekni 的git倉庫。向第一作者致敬!

內容列表

0. 簡介
1. 測試環境
2. 準備宿主機
3. 設置Keystone
4. 設置Glance
5. 設置Quantum
6. 設置Nova
7. 設置Cinder
8. 設置Horizon
9. 你的第一個VM

0. 簡介

OpenStack Grizzly安裝指南旨在讓你輕鬆創建自己的OpenStack雲平臺。

狀態: Stable

1. 測試環境

節點角色:NICs
單節點:eth0 (10.10.100.51), eth1 (192.168.100.51)

注意1: 多節點部署鍵OVS_MultiNode分支

注意2: 你總是可以使用dpkg -s <packagename>確認你使用的是grizzly軟件包(版本: 2013.1)

注意3: 這個是當前網絡架構

http://i.imgur.com/JyMokiY.jpg

2. 準備節點

2.1. 準備Ubuntu

  • 安裝好Ubuntu 12.04 Server 64bits後, 進入sudo模式直到完成本指南:

    sudo su -
    
  • 添加Grizzly倉庫:

    apt-get install ubuntu-cloud-keyring python-software-properties software-properties-common python-keyring
    echo deb http://ubuntu-cloud.archive.canonical.com/ubuntu precise-updates/grizzly main >> /etc/apt/sources.list.d/grizzly.list
    
  • 升級系統:

    apt-get update
    apt-get upgrade
    apt-get dist-upgrade
    

2.2.設置網絡

  • 如下編輯網卡配置文件/etc/network/interfaces:

    #Not internet connected(used for OpenStack management)
    auto eth0
    iface eth0 inet static
    address 10.10.100.51
    netmask 255.255.255.0
    
    #For Exposing OpenStack API over the internet
    auto eth1
    iface eth1 inet static
    address 192.168.100.51
    netmask 255.255.255.0
    gateway 192.168.100.1
    dns-nameservers 8.8.8.8
    
  • 重啓網絡服務:

    service networking restart
    

2.3. 安裝MySQL和RabbitMQ

  • 安裝MySQL併爲root用戶設置密碼:

    apt-get install -y mysql-server python-mysqldb
    
  • 配置mysql監聽所有網絡接口請求:

    sed -i 's/127.0.0.1/0.0.0.0/g' /etc/mysql/my.cnf
    service mysql restart
    
  • 安裝RabbitMQ:

    apt-get install -y rabbitmq-server
    
  • 安裝NTP服務:

    apt-get install -y ntp
    

3. 配置Keystone

  • 安裝keystone軟件包:

    apt-get install -y keystone
    
  • 確認keystone在運行:

    service keystone status
    
  • 爲keystone創建MySQL數據庫:

    mysql -u root -p
    CREATE DATABASE keystone;
    GRANT ALL ON keystone.* TO 'keystoneUser'@'%' IDENTIFIED BY 'keystonePass';
    quit;
    
  • 在/etc/keystone/keystone.conf中設置連接到新創建的數據庫:

    connection = mysql://keystoneUser:[email protected]/keystone
    
  • 重啓身份認證服務並同步數據庫:

    service keystone restart
    keystone-manage db_sync
    
  • 使用git倉庫中腳本填充keystone數據庫: 腳本文件夾

    #注意在執行腳本前請按你的網卡配置修改HOST_IP和HOST_IP_EXT
    
    wget https://raw.github.com/ist0ne/OpenStack-Grizzly-Install-Guide-CN/master/KeystoneScripts/keystone_basic.sh
    wget https://raw.github.com/ist0ne/OpenStack-Grizzly-Install-Guide-CN/master/KeystoneScripts/keystone_endpoints_basic.sh
    
    chmod +x keystone_basic.sh
    chmod +x keystone_endpoints_basic.sh
    
    ./keystone_basic.sh
    ./keystone_endpoints_basic.sh
    
  • 創建一個簡單的憑據文件,這樣稍後就不會因爲輸入過多的環境變量而感到厭煩:

    vi creds-admin
    
    #Paste the following:
    export OS_TENANT_NAME=admin
    export OS_USERNAME=admin
    export OS_PASSWORD=admin_pass
    export OS_AUTH_URL="http://192.168.100.51:5000/v2.0/"
    
    # Load it:
    source creds-admin
    
  • 通過命令行列出Keystone中添加的用戶:

    keystone user-list
    

4. 設置Glance

  • 安裝Glance:

    apt-get install -y glance
    
  • 確保glance服務在運行:

    service glance-api status
    service glance-registry status
    
  • 爲Glance創建MySQL數據庫:

    mysql -u root -p
    CREATE DATABASE glance;
    GRANT ALL ON glance.* TO 'glanceUser'@'%' IDENTIFIED BY 'glancePass';
    quit;
    
  • 按下面更新/etc/glance/glance-api-paste.ini:

    [filter:authtoken]
    paste.filter_factory = keystoneclient.middleware.auth_token:filter_factory
    delay_auth_decision = true
    auth_host = 10.10.100.51
    auth_port = 35357
    auth_protocol = http
    admin_tenant_name = service
    admin_user = glance
    admin_password = service_pass
    
  • 按下面更新/etc/glance/glance-registry-paste.ini:

    [filter:authtoken]
    paste.filter_factory = keystoneclient.middleware.auth_token:filter_factory
    auth_host = 10.10.100.51
    auth_port = 35357
    auth_protocol = http
    admin_tenant_name = service
    admin_user = glance
    admin_password = service_pass
    
  • 按下面更新/etc/glance/glance-api.conf:

    sql_connection = mysql://glanceUser:[email protected]/glance
    
  • 和:

    [paste_deploy]
    flavor = keystone
    
  • 按下面更新/etc/glance/glance-registry.conf:

    sql_connection = mysql://glanceUser:[email protected]/glance
    
  • 和:

    [paste_deploy]
    flavor = keystone
    
  • 重啓glance-api和glance-registry服務:

    service glance-api restart; service glance-registry restart
    
  • 同步glance數據庫:

    glance-manage db_sync
    
  • 重啓服務使配置生效:

    service glance-registry restart; service glance-api restart
    
  • 測試Glance, 從網絡上傳cirros雲鏡像:

    glance image-create --name cirros --is-public true --container-format bare --disk-format qcow2 --location https://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-disk.img
    
    注意:通過此鏡像創建的虛擬機可通過用戶名/密碼登陸, 用戶名:cirros 密碼:cubswin:)
    
  • 本地創建Ubuntu雲鏡像:

    wget http://cloud-images.ubuntu.com/precise/current/precise-server-cloudimg-amd64-disk1.img
    glance add name="Ubuntu 12.04 cloudimg amd64" is_public=true container_format=ovf disk_format=qcow2 < ./precise-server-cloudimg-amd64-disk1.img
    
  • 列出鏡像檢查是否上傳成功:

    glance image-list
    

5. 設置Quantum

5.2. Quantum-*

  • 安裝Quantum組件:

    apt-get install -y quantum-server quantum-plugin-linuxbridge quantum-plugin-linuxbridge-agent dnsmasq quantum-dhcp-agent quantum-l3-agent
    
  • 創建數據庫:

    mysql -u root -p
    CREATE DATABASE quantum;
    GRANT ALL ON quantum.* TO 'quantumUser'@'%' IDENTIFIED BY 'quantumPass';
    quit;
    
  • 確認Quantum組件在運行:

    cd /etc/init.d/; for i in $( ls quantum-* ); do sudo service $i status; done
    
  • 編輯/etc/quantum/api-paste.ini

    [filter:authtoken]
    paste.filter_factory = keystoneclient.middleware.auth_token:filter_factory
    auth_host = 10.10.100.51
    auth_port = 35357
    auth_protocol = http
    admin_tenant_name = service
    admin_user = quantum
    admin_password = service_pass
    
  • 編輯OVS配置文件/etc/quantum/plugins/linuxbridge/linuxbridge_conf.ini:

    # under [DATABASE] section
    sql_connection = mysql://quantumUser:[email protected]/quantum
    # under [LINUX_BRIDGE] section
    physical_interface_mappings = physnet1:eth1
    # under [VLANS] section
    tenant_network_type = vlan
    network_vlan_ranges = physnet1:1000:2999
    
  • 更新/etc/quantum/metadata_agent.ini:

    # The Quantum user information for accessing the Quantum API.
    auth_url = http://10.10.100.51:35357/v2.0
    auth_region = RegionOne
    admin_tenant_name = service
    admin_user = quantum
    admin_password = service_pass
    
    # IP address used by Nova metadata server
    nova_metadata_ip = 10.10.100.51
    
    # TCP Port used by Nova metadata server
    nova_metadata_port = 8775
    
    metadata_proxy_shared_secret = helloOpenStack
    
  • 編輯/etc/quantum/quantum.conf:

    core_plugin = quantum.plugins.linuxbridge.lb_quantum_plugin.LinuxBridgePluginV2
    
    [keystone_authtoken]
    auth_host = 10.10.100.51
    auth_port = 35357
    auth_protocol = http
    admin_tenant_name = service
    admin_user = quantum
    admin_password = service_pass
    signing_dir = /var/lib/quantum/keystone-signing
    
  • 編輯/etc/quantum/l3_agent.ini:

    [DEFAULT]
    interface_driver = quantum.agent.linux.interface.BridgeInterfaceDriver
    use_namespaces = True
    external_network_bridge = br-ex
    signing_dir = /var/cache/quantum
    admin_tenant_name = service
    admin_user = quantum
    admin_password = service_pass
    auth_url = http://10.10.100.51:35357/v2.0
    l3_agent_manager = quantum.agent.l3_agent.L3NATAgentWithStateReport
    root_helper = sudo quantum-rootwrap /etc/quantum/rootwrap.conf
    
  • 編輯/etc/quantum/dhcp_agent.ini:

    [DEFAULT]
    interface_driver = quantum.agent.linux.interface.BridgeInterfaceDriver
    dhcp_driver = quantum.agent.linux.dhcp.Dnsmasq
    use_namespaces = True
    signing_dir = /var/cache/quantum
    admin_tenant_name = service
    admin_user = quantum
    admin_password = service_pass
    auth_url = http://10.10.100.51:35357/v2.0
    dhcp_agent_manager = quantum.agent.dhcp_agent.DhcpAgentWithStateReport
    root_helper = sudo quantum-rootwrap /etc/quantum/rootwrap.conf
    state_path = /var/lib/quantum
    
  • 重啓quantum所有服務:

    cd /etc/init.d/; for i in $( ls quantum-* ); do sudo service $i restart; done
    service dnsmasq restart
    

*注意: 如果有服務運行在53端口,'dnsmasq'重啓失敗。 你可以kill掉那個服務器後再重啓'dnsmasq'

6. 設置Nova

6.1 KVM

  • 確保你的硬件啓用virtualization:

    apt-get install cpu-checker
    kvm-ok
    
  • 現在安裝kvm並配置它:

    apt-get install -y kvm libvirt-bin pm-utils
    
  • 在/etc/libvirt/qemu.conf配置文件中啓用cgroup_device_acl數組:

    cgroup_device_acl = [
    "/dev/null", "/dev/full", "/dev/zero",
    "/dev/random", "/dev/urandom",
    "/dev/ptmx", "/dev/kvm", "/dev/kqemu",
    "/dev/rtc", "/dev/hpet","/dev/net/tun"
    ]
    
  • 刪除默認的虛擬網橋

    virsh net-destroy default
    virsh net-undefine default
    
  • 更新/etc/libvirt/libvirtd.conf配置文件:

    listen_tls = 0
    listen_tcp = 1
    auth_tcp = "none"
    
  • E編輯libvirtd_opts變量在/etc/init/libvirt-bin.conf配置文件中:

    env libvirtd_opts="-d -l"
    
  • 編輯/etc/default/libvirt-bin文件

    libvirtd_opts="-d -l"
    
  • 重啓libvirt服務使配置生效:

    service libvirt-bin restart
    

6.2 Nova-*

  • 安裝nova組件:

    apt-get install -y nova-api nova-cert novnc nova-consoleauth nova-scheduler nova-novncproxy nova-doc nova-conductor nova-compute-kvm
    
    注意:如果你的宿主機不支持kvm虛擬化,可把nova-compute-kvm換成nova-compute-qemu
    同時/etc/nova/nova-compute.conf配置文件中的libvirt_type=qemu
    
  • 檢查nova服務是否正常啓動:

    cd /etc/init.d/; for i in $( ls nova-* ); do service $i status; cd; done
    
  • 爲Nova創建Mysql數據庫:

    mysql -u root -p
    CREATE DATABASE nova;
    GRANT ALL ON nova.* TO 'novaUser'@'%' IDENTIFIED BY 'novaPass';
    quit;
    
  • 在/etc/nova/api-paste.ini配置文件中修改認證信息:

    [filter:authtoken]
    paste.filter_factory = keystoneclient.middleware.auth_token:filter_factory
    auth_host = 10.10.100.51
    auth_port = 35357
    auth_protocol = http
    admin_tenant_name = service
    admin_user = nova
    admin_password = service_pass
    signing_dirname = /tmp/keystone-signing-nova
    # Workaround for https://bugs.launchpad.net/nova/+bug/1154809
    auth_version = v2.0
    
  • 如下修改/etc/nova/nova.conf:

    [DEFAULT]
    logdir=/var/log/nova
    state_path=/var/lib/nova
    lock_path=/run/lock/nova
    verbose=True
    api_paste_config=/etc/nova/api-paste.ini
    compute_scheduler_driver=nova.scheduler.simple.SimpleScheduler
    rabbit_host=10.10.100.51
    nova_url=http://10.10.100.51:8774/v1.1/
    sql_connection=mysql://novaUser:[email protected]/nova
    root_helper=sudo nova-rootwrap /etc/nova/rootwrap.conf
    
    # Auth
    use_deprecated_auth=false
    auth_strategy=keystone
    
    # Imaging service
    glance_api_servers=10.10.100.51:9292
    image_service=nova.image.glance.GlanceImageService
    
    # Vnc configuration
    novnc_enabled=true
    novncproxy_base_url=http://192.168.100.51:6080/vnc_auto.html
    novncproxy_port=6080
    vncserver_proxyclient_address=10.10.100.51
    vncserver_listen=0.0.0.0
    
    # Metadata
    service_quantum_metadata_proxy = True
    quantum_metadata_proxy_shared_secret = helloOpenStack
    
    # Network settings
    network_api_class=nova.network.quantumv2.api.API
    quantum_url=http://10.10.100.51:9696
    quantum_auth_strategy=keystone
    quantum_admin_tenant_name=service
    quantum_admin_username=quantum
    quantum_admin_password=service_pass
    quantum_admin_auth_url=http://10.10.100.51:35357/v2.0
    libvirt_vif_driver=nova.virt.libvirt.vif.QuantumLinuxBridgeVIFDriver
    linuxnet_interface_driver=nova.network.linux_net.LinuxBridgeInterfaceDriver
    firewall_driver=nova.virt.libvirt.firewall.IptablesFirewallDriver
    
    # Compute #
    compute_driver=libvirt.LibvirtDriver
    
    # Cinder #
    volume_api_class=nova.volume.cinder.API
    osapi_volume_listen_port=5900
    
  • 修改/etc/nova/nova-compute.conf:

    [DEFAULT]
    libvirt_type=kvm
    compute_driver=libvirt.LibvirtDriver
    libvirt_vif_type=ethernet
    libvirt_vif_driver=nova.virt.libvirt.vif.QuantumLinuxBridgeVIFDriver
    
  • 同步數據庫:

    nova-manage db sync
    
  • 重啓所有nova服務:

    cd /etc/init.d/; for i in $( ls nova-* ); do sudo service $i restart; done
    
  • 檢查所有nova服務是否啓動正常:

    nova-manage service list
    

7. 設置Cinder

  • 安裝軟件包:

    apt-get install -y cinder-api cinder-scheduler cinder-volume iscsitarget open-iscsi iscsitarget-dkms
    
  • 配置iscsi服務:

    sed -i 's/false/true/g' /etc/default/iscsitarget
    
  • 重啓服務:

    service iscsitarget start
    service open-iscsi start
    
  • 爲Cinder創建Mysql數據庫:

    mysql -u root -p
    CREATE DATABASE cinder;
    GRANT ALL ON cinder.* TO 'cinderUser'@'%' IDENTIFIED BY 'cinderPass';
    quit;
    
  • 如下配置/etc/cinder/api-paste.ini:

    [filter:authtoken]
    paste.filter_factory = keystoneclient.middleware.auth_token:filter_factory
    service_protocol = http
    service_host = 192.168.100.51
    service_port = 5000
    auth_host = 10.10.100.51
    auth_port = 35357
    auth_protocol = http
    admin_tenant_name = service
    admin_user = cinder
    admin_password = service_pass
    
  • 編輯/etc/cinder/cinder.conf:

    [DEFAULT]
    rootwrap_config=/etc/cinder/rootwrap.conf
    sql_connection = mysql://cinderUser:[email protected]/cinder
    api_paste_config = /etc/cinder/api-paste.ini
    iscsi_helper=ietadm
    volume_name_template = volume-%s
    volume_group = cinder-volumes
    verbose = True
    auth_strategy = keystone
    #osapi_volume_listen_port=5900
    
  • 接下來同步數據庫:

    cinder-manage db sync
    
  • 最後別忘了創建一個卷組命名爲cinder-volumes:

    dd if=/dev/zero of=cinder-volumes bs=1 count=0 seek=2G
    losetup /dev/loop2 cinder-volumes
    fdisk /dev/loop2
    #Type in the followings:
    n
    p
    1
    ENTER
    ENTER
    t
    8e
    w
    
  • 創建物理卷和卷組:

    pvcreate /dev/loop2
    vgcreate cinder-volumes /dev/loop2
    

注意: 重啓後卷組不會自動掛載 (點擊`這個 <https://github.com/mseknibilel/OpenStack-Folsom-Install-guide/blob/master/Tricks%26Ideas/load_volume_group_after_system_reboot.rst>`_ 設置在重啓後自動掛載) 重啓cinder服務:

cd /etc/init.d/; for i in $( ls cinder-* ); do sudo service $i restart; done
  • 確認cinder服務在運行:

    cd /etc/init.d/; for i in $( ls cinder-* ); do sudo service $i status; done
    

8. 設置Horizon

  • 如下安裝horizon

    apt-get install openstack-dashboard memcached
    
  • 如果你不喜歡OpenStack ubuntu主題, 你可以停用它:

    dpkg --purge openstack-dashboard-ubuntu-theme
    
  • 重啓Apache和memcached服務:

    service apache2 restart; service memcached restart
    

現在你可以訪問OpenStack 192.168.100.51/horizon ,使用 admin:admin_pass 認證.

9. 創建虛擬機

網絡拓撲如下:

http://i.imgur.com/WdRDVZJ.png

9.1. 爲admin租戶創建內網、外網、路由器和虛擬機

  • 設置環境變量:

    # cat creds-admin
    
    export OS_TENANT_NAME=admin
    export OS_USERNAME=admin
    export OS_PASSWORD=admin_pass
    export OS_AUTH_URL="http://192.168.100.51:5000/v2.0/"
    
  • 使環境變量生效:

    # source creds-admin
    
  • 列出已創建的用戶:

    # keystone user-list
    
    +----------------------------------+---------+---------+------------------+
    |                id                |   name  | enabled |      email       |
    +----------------------------------+---------+---------+------------------+
    | c815f963fef54f37b0ac84a6a7eca8b4 |  admin  |   True  |  [email protected]  |
    | f30d6d67936e41869117b42e5403255c |  cinder |   True  | [email protected]  |
    | 5ec7e55586004aabb6a9ecc8247ba751 |  glance |   True  | [email protected]  |
    | 197c373a254749f2b5cec7c91ef14c88 |   nova  |   True  |  [email protected]   |
    | 8fec2c89a87d43f19c9e7d487001efa3 | quantum |   True  | [email protected] |
    +----------------------------------+---------+---------+------------------+
    
  • 列出已創建的租戶:

    # keystone tenant-list
    
    +----------------------------------+---------+---------+
    |                id                |   name  | enabled |
    +----------------------------------+---------+---------+
    | 8c0104041b034df3a79c17a9517dd3f9 |  admin  |   True  |
    | 2b376839187441c5888d35411e8ff8b0 | service |   True  |
    +----------------------------------+---------+---------+
    
  • 爲admin租戶創建網絡:

    # quantum net-create --tenant-id 8c0104041b034df3a79c17a9517dd3f9 net_admin
    
    Created a new network:
    +---------------------------+--------------------------------------+
    | Field                     | Value                                |
    +---------------------------+--------------------------------------+
    | admin_state_up            | True                                 |
    | id                        | fed2d721-41d1-428f-b0a3-41ac8f7a51a1 |
    | name                      | net_admin                            |
    | provider:network_type     | gre                                  |
    | provider:physical_network |                                      |
    | provider:segmentation_id  | 1                                    |
    | router:external           | False                                |
    | shared                    | False                                |
    | status                    | ACTIVE                               |
    | subnets                   |                                      |
    | tenant_id                 | 8c0104041b034df3a79c17a9517dd3f9     |
    +---------------------------+--------------------------------------+
    

# 爲admin租戶創建子網:

# quantum subnet-create --tenant-id 8c0104041b034df3a79c17a9517dd3f9 net_admin 172.16.100.0/24

Created a new subnet:
+------------------+----------------------------------------------------+
| Field            | Value                                              |
+------------------+----------------------------------------------------+
| allocation_pools | {"start": "172.16.100.2", "end": "172.16.100.254"} |
| cidr             | 172.16.100.0/24                                    |
| dns_nameservers  |                                                    |
| enable_dhcp      | True                                               |
| gateway_ip       | 172.16.100.1                                       |
| host_routes      |                                                    |
| id               | fb141492-8aa1-437b-8192-315e19e7f4d2               |
| ip_version       | 4                                                  |
| name             |                                                    |
| network_id       | fed2d721-41d1-428f-b0a3-41ac8f7a51a1               |
| tenant_id        | 8c0104041b034df3a79c17a9517dd3f9                   |
+------------------+----------------------------------------------------+
  • 爲admin租戶創建路由器:

    # quantum router-create --tenant-id 8c0104041b034df3a79c17a9517dd3f9 router_admin
    
    Created a new router:
    +-----------------------+--------------------------------------+
    | Field                 | Value                                |
    +-----------------------+--------------------------------------+
    | admin_state_up        | True                                 |
    | external_gateway_info |                                      |
    | id                    | 76d8ac10-a6df-4dfa-b691-297da374c811 |
    | name                  | router_admin                         |
    | status                | ACTIVE                               |
    | tenant_id             | 8c0104041b034df3a79c17a9517dd3f9     |
    +-----------------------+--------------------------------------+
    
  • 列出路由代理類型:

    # quantum agent-list
    
    +--------------------------------------+--------------------+-----------+-------+----------------+
    | id                                   | agent_type         | host      | alive | admin_state_up |
    +--------------------------------------+--------------------+-----------+-------+----------------+
    | 2b68d118-c4bb-44a0-8387-678c5bdb1653 | L3 agent           | openstack | :-)   | True           |
    | 7b42460c-cffd-494f-94b1-c6b4f3b5e102 | DHCP agent         | openstack | :-)   | True           |
    | e443fbf2-398c-47ab-89d9-5d9907217379 | Open vSwitch agent | openstack | :-)   | True           |
    +--------------------------------------+--------------------+-----------+-------+----------------+
    
  • 將router_admin設置爲L3代理類型:

    # quantum l3-agent-router-add 2b68d118-c4bb-44a0-8387-678c5bdb1653 router_admin
    
    Added router router_admin to L3 agent
    
  • 將net_admin子網與router_admin路由關聯:

    # quantum router-interface-add 76d8ac10-a6df-4dfa-b691-297da374c811 fb141492-8aa1-437b-8192-315e19e7f4d2
    
    Added interface to router 76d8ac10-a6df-4dfa-b691-297da374c811
    
  • 創建外網net_external,注意設置--router:external=True:

    # quantum net-create net_external --router:external=True --shared
    
    Created a new network:
    +---------------------------+--------------------------------------+
    | Field                     | Value                                |
    +---------------------------+--------------------------------------+
    | admin_state_up            | True                                 |
    | id                        | 7a7acad8-cabf-49f8-804f-ce6871d9cd63 |
    | name                      | net_external                         |
    | provider:network_type     | gre                                  |
    | provider:physical_network |                                      |
    | provider:segmentation_id  | 2                                    |
    | router:external           | True                                 |
    | shared                    | True                                 |
    | status                    | ACTIVE                               |
    | subnets                   |                                      |
    | tenant_id                 | 8c0104041b034df3a79c17a9517dd3f9     |
    +---------------------------+--------------------------------------+
    
  • 爲net_external創建子網,注意設置的gateway必須在給到的網段內:

    # quantum subnet-create net_external --gateway 192.168.100.1 192.168.100.0/24 --enable_dhcp=False
    
    Created a new subnet:
    +------------------+------------------------------------------------------+
    | Field            | Value                                                |
    +------------------+------------------------------------------------------+
    | allocation_pools | {"start": "192.168.100.2", "end": "192.168.100.254"} |
    | cidr             | 192.168.100.0/24                                     |
    | dns_nameservers  |                                                      |
    | enable_dhcp      | False                                                |
    | gateway_ip       | 192.168.100.1                                        |
    | host_routes      |                                                      |
    | id               | 837ad514-3c05-4357-9a36-0b18adcfb354                 |
    | ip_version       | 4                                                    |
    | name             |                                                      |
    | network_id       | 7a7acad8-cabf-49f8-804f-ce6871d9cd63                 |
    | tenant_id        | 8c0104041b034df3a79c17a9517dd3f9                     |
    +------------------+------------------------------------------------------+
    
  • 將net_external與router_admin路由器關聯:

    # quantum router-gateway-set router_admin net_external
    
    Set gateway for router router_admin
    
  • 創建floating ip:

    # quantum floatingip-create net_external
    
    Created a new floatingip:
    +---------------------+--------------------------------------+
    | Field               | Value                                |
    +---------------------+--------------------------------------+
    | fixed_ip_address    |                                      |
    | floating_ip_address | 192.168.100.3                        |
    | floating_network_id | 7a7acad8-cabf-49f8-804f-ce6871d9cd63 |
    | id                  | 15bb69fa-972d-4e86-91fc-250dc1b20fe2 |
    | port_id             |                                      |
    | router_id           |                                      |
    | tenant_id           | 8c0104041b034df3a79c17a9517dd3f9     |
    +---------------------+--------------------------------------+
    
    # quantum floatingip-create net_external
    
    Created a new floatingip:
    +---------------------+--------------------------------------+
    | Field               | Value                                |
    +---------------------+--------------------------------------+
    | fixed_ip_address    |                                      |
    | floating_ip_address | 192.168.100.4                        |
    | floating_network_id | 7a7acad8-cabf-49f8-804f-ce6871d9cd63 |
    | id                  | 561e3530-d543-427f-986a-aaff64cb1a87 |
    | port_id             |                                      |
    | router_id           |                                      |
    | tenant_id           | 8c0104041b034df3a79c17a9517dd3f9     |
    +---------------------+--------------------------------------+
    
  • 爲admin租戶創建虛擬機並關聯floating ip(可通過web界面創建虛擬機並關聯floating ip):

    注意:如下生成祕鑰對,並上傳ssh公鑰:
    # ssh-keygen
    Generating public/private rsa key pair.
    Enter file in which to save the key (/root/.ssh/id_rsa):
    Created directory '/root/.ssh'.
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in /root/.ssh/id_rsa.
    Your public key has been saved in /root/.ssh/id_rsa.pub.
    The key fingerprint is:
    ab:dc:48:ae:a6:12:d5:8b:db:cf:7c:31:c1:4a:03:39 root@grizzly
    The key's randomart image is:
    +--[ RSA 2048]----+
    |     .           |
    |    E            |
    |   . o .         |
    |  . . o o        |
    | . . o oS.       |
    |. . . . o.       |
    | . o  . .o       |
    |. . o* +.        |
    | ..o.oO..        |
    +-----------------+
    
    # nova keypair-add --pub_key /root/.ssh/id_rsa.pub nova-key
    
    上傳公鑰後便可以通過 ssh -i /root/.ssh/id_rsa [email protected] 登陸cirros虛擬機。
    
    # nova list
    
    +--------------------------------------+-----------------+--------+---------------------------------------+
    | ID                                   | Name            | Status | Networks                              |
    +--------------------------------------+-----------------+--------+---------------------------------------+
    | fb4c93a0-fc83-4779-b85f-d7326c238c94 | ubuntu.vm.admin | ACTIVE | net_admin=172.16.100.4, 192.168.100.4 |
    | 5b918d39-1ac9-4a76-83d5-8b32a29ed3fe | vm.admin        | ACTIVE | net_admin=172.16.100.3, 192.168.100.3 |
    +--------------------------------------+-----------------+--------+---------------------------------------+
    

9.1. 創建leju.com租戶、內網、路由器和虛擬機並關聯外網

  • 創建leju.com租戶:

    # keystone tenant-create --name leju.com
    
    +-------------+----------------------------------+
    |   Property  |              Value               |
    +-------------+----------------------------------+
    | description |                                  |
    |   enabled   |               True               |
    |      id     | 5585ffbad86d495d88b5f95729b1dc60 |
    |     name    |             leju.com             |
    +-------------+----------------------------------+
    
  • 在leju.com租戶中創建dongliang用戶:

    # keystone user-create --name=dongliang --pass=123456 --tenant-id=5585ffbad86d495d88b5f95729b1dc60 [email protected]
    
    +----------+----------------------------------+
    | Property |              Value               |
    +----------+----------------------------------+
    |  email   |        [email protected]        |
    | enabled  |               True               |
    |    id    | 21efde97763147718fee478634cd3e70 |
    |   name   |            dongliang             |
    | tenantId | 5585ffbad86d495d88b5f95729b1dc60 |
    +----------+----------------------------------+
    
  • 列出預定義的角色:

    # keystone role-list
    
    +----------------------------------+----------------------+
    |                id                |         name         |
    +----------------------------------+----------------------+
    | b90f2f8f84c4454f800f053dd5b6a54e |    KeystoneAdmin     |
    | 0ba9be2eb2c145ffb90def5a75646ed2 | KeystoneServiceAdmin |
    | b7e97eecf8cd4d6aa6f4091206ad6282 |        Member        |
    | 9fe2ff9ee4384b1894a90878d3e92bab |       _member_       |
    | 47eda7948e5d430bad3ce937fb00dc3b |        admin         |
    +----------------------------------+----------------------+
    
  • 爲用戶dongliang添加角色:

    # keystone user-role-add --tenant-id 5585ffbad86d495d88b5f95729b1dc60 --user-id 21efde97763147718fee478634cd3e70 --role-id 47eda7948e5d430bad3ce937fb00dc3b
    
  • 爲leju.com租戶創建網絡:

    # quantum net-create --tenant-id 5585ffbad86d495d88b5f95729b1dc60 net_leju_com
    
    Created a new network:
    +---------------------------+--------------------------------------+
    | Field                     | Value                                |
    +---------------------------+--------------------------------------+
    | admin_state_up            | True                                 |
    | id                        | 599e5a95-ff7f-49e5-9930-03e99e3a2d8d |
    | name                      | net_leju_com                         |
    | provider:network_type     | gre                                  |
    | provider:physical_network |                                      |
    | provider:segmentation_id  | 3                                    |
    | router:external           | False                                |
    | shared                    | False                                |
    | status                    | ACTIVE                               |
    | subnets                   |                                      |
    | tenant_id                 | 5585ffbad86d495d88b5f95729b1dc60     |
    +---------------------------+--------------------------------------+
    
  • 爲leju.com租戶創建子網:

    # quantum subnet-create --tenant-id 5585ffbad86d495d88b5f95729b1dc60 net_leju_com 172.16.200.0/24
    
    Created a new subnet:
    +------------------+----------------------------------------------------+
    | Field            | Value                                              |
    +------------------+----------------------------------------------------+
    | allocation_pools | {"start": "172.16.200.2", "end": "172.16.200.254"} |
    | cidr             | 172.16.200.0/24                                    |
    | dns_nameservers  |                                                    |
    | enable_dhcp      | True                                               |
    | gateway_ip       | 172.16.200.1                                       |
    | host_routes      |                                                    |
    | id               | dbb59749-8f05-474d-b26d-745254a22669               |
    | ip_version       | 4                                                  |
    | name             |                                                    |
    | network_id       | 599e5a95-ff7f-49e5-9930-03e99e3a2d8d               |
    | tenant_id        | 5585ffbad86d495d88b5f95729b1dc60                   |
    +------------------+----------------------------------------------------+
    
  • 爲leju.com租戶創建路由器:

    # quantum router-create --tenant-id 5585ffbad86d495d88b5f95729b1dc60 router_leju_com
    
    Created a new router:
    +-----------------------+--------------------------------------+
    | Field                 | Value                                |
    +-----------------------+--------------------------------------+
    | admin_state_up        | True                                 |
    | external_gateway_info |                                      |
    | id                    | 451a6166-d082-4f02-8f37-07703a8118ab |
    | name                  | router_leju_com                      |
    | status                | ACTIVE                               |
    | tenant_id             | 5585ffbad86d495d88b5f95729b1dc60     |
    +-----------------------+--------------------------------------+
    
  • 列出代理列表:

    quantum agent-list
    
    +--------------------------------------+--------------------+-----------+-------+----------------+
    | id                                   | agent_type         | host      | alive | admin_state_up |
    +--------------------------------------+--------------------+-----------+-------+----------------+
    | 2b68d118-c4bb-44a0-8387-678c5bdb1653 | L3 agent           | openstack | :-)   | True           |
    | 7b42460c-cffd-494f-94b1-c6b4f3b5e102 | DHCP agent         | openstack | :-)   | True           |
    | e443fbf2-398c-47ab-89d9-5d9907217379 | Open vSwitch agent | openstack | :-)   | True           |
    +--------------------------------------+--------------------+-----------+-------+----------------+
    
  • 設置路由器使用L3代理:

    # quantum l3-agent-router-add 2b68d118-c4bb-44a0-8387-678c5bdb1653 router_leju_com
    
    Added router router_leju_com to L3 agent
    
  • 連接net_leju_com到router_leju_com:

    # quantum router-interface-add 451a6166-d082-4f02-8f37-07703a8118ab dbb59749-8f05-474d-b26d-745254a22669
    
    Added interface to router 451a6166-d082-4f02-8f37-07703a8118ab
    
  • 設置net_leju_com外網網關:

    # quantum router-gateway-set 451a6166-d082-4f02-8f37-07703a8118ab net_external
    
    Set gateway for router 451a6166-d082-4f02-8f37-07703a8118ab
    
  • 設置leju.com租戶環境變量:

    # cat creds-dongliang
    
    export OS_TENANT_NAME=leju.com
    export OS_USERNAME=dongliang
    export OS_PASSWORD=123456
    export OS_AUTH_URL="http://192.168.100.51:5000/v2.0/"
    
  • 用dongliang用戶登陸web界面,創建虛擬主機vm.leju.com

  • 使變量生效:

    source creds-dongliang
    
  • 列出虛擬主機:

    # nova list
    
    +--------------------------------------+-------------+--------+---------------------------+
    | ID                                   | Name        | Status | Networks                  |
    +--------------------------------------+-------------+--------+---------------------------+
    | eefc20a9-251c-44de-99ee-179463cb7aca | vm.leju.com | ACTIVE | net_leju_com=172.16.200.2 |
    +--------------------------------------+-------------+--------+---------------------------+
    
  • 列出vm.leju.com虛擬機的端口:

    # quantum port-list -- --device_id eefc20a9-251c-44de-99ee-179463cb7aca
    
    +--------------------------------------+------+-------------------+-------------------------------------------------------------------------------------+
    | id                                   | name | mac_address       | fixed_ips                                                                           |
    +--------------------------------------+------+-------------------+-------------------------------------------------------------------------------------+
    | d0195246-5863-4ede-ac40-3cc06516279e |      | fa:16:3e:0c:f2:01 | {"subnet_id": "dbb59749-8f05-474d-b26d-745254a22669", "ip_address": "172.16.200.2"} |
    +--------------------------------------+------+-------------------+-------------------------------------------------------------------------------------+
    
  • 爲vm.leju.com創建floating ip:

    # quantum floatingip-create net_external
    
    Created a new floatingip:
    +---------------------+--------------------------------------+
    | Field               | Value                                |
    +---------------------+--------------------------------------+
    | fixed_ip_address    |                                      |
    | floating_ip_address | 192.168.100.8                        |
    | floating_network_id | 7a7acad8-cabf-49f8-804f-ce6871d9cd63 |
    | id                  | 2efa6e49-9d99-4402-9a61-85c235d0ccb8 |
    | port_id             |                                      |
    | router_id           |                                      |
    | tenant_id           | 5585ffbad86d495d88b5f95729b1dc60     |
    +---------------------+--------------------------------------+
    
  • 將新創建的floating ip與vm.leju.com關聯:

    # quantum floatingip-associate 2efa6e49-9d99-4402-9a61-85c235d0ccb8 d0195246-5863-4ede-ac40-3cc06516279e
    
    Associated floatingip 2efa6e49-9d99-4402-9a61-85c235d0ccb8
發佈了383 篇原創文章 · 獲贊 774 · 訪問量 271萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章