顯示具有 Nova 標籤的文章。 顯示所有文章
顯示具有 Nova 標籤的文章。 顯示所有文章

2014年9月29日 星期一

安裝 OpenStack @ Ubuntu 14.04 (4) - 安裝 Compute Service (Nova)

安裝 OpenStack @ Ubuntu 14.04 (4) - 安裝 Compute Service (Nova)

目錄

1、安裝環境說明

  • OS:Ubuntu 14.04 LTS

  • Controller

    • IP:10.0.0.11 / 24
    • Gateway:10.0.0.1
  • Network

    • Management IP:10.0.0.21 / 24 (eth0)
    • Gateway:10.0.0.1
    • Instance Tunnel IP:10.0.1.21 / 24 (eth1)
    • External Interface (eth2)
      • IP:不指定 IP
      • 設定方式如下:(修改 /etc/network/interfaces)

    auto eth2
    iface eth2 inet manual
    up ip link set dev $IFACE up
    down ip link set dev $IFACE down

  • Compute 1

    • Management IP:10.0.0.31 / 24
    • Gateway:10.0.0.1
    • Instance Tunnel IP:10.0.1.31
  • 修改每個 node 的 /etc/hosts 檔案,並加入以下內容:

    10.0.0.11 controller
    10.0.0.21 network
    10.0.0.31 compute1

    • 使用者身分:root

    2、Compute Service (NOVA) 概觀

    Compute Service 在整個 IaaS 的架構中是屬於最主要的部份,同時會向 Identity Service 進行認證授權、向 Image Service 要求 image、將資料提供給 Dashboard …. 等等。

    而整個 Compute Service (NOVA) 包含了以下幾個重要部分:

    2.1 API

    2.1.1 nova-api service

    用來處理 & 回應終端使用者的 Compute API call,除了支援 OpenStack API 之外,還支援了 Amazon EC2 以及管理用 API。

    2.1.2 nova-api-metadata service

    通常會用在多個 compute node 並安裝 nova-network 時使用,用來回應來自 instance 對 metadata 的要求。

    2.2. Compute core

    這元件包含了幾個重要的 daemon,來共同組成 Compute Core 以提供服務:

    2.2.1 nova-compute

    主要目的是與 hypervisor API 溝通,已建立 / 中止 VM instance。

    簡單來說,這個 daemon 僅接受來自 Message Queue 的訊息並執行相關命令而已,例如啟動一個 KVM instance、更新 instance 在資料庫中的狀態。

    2.2.2 nova-scheduler

    取得 VM instance 的需求後,根據制定的規則 & 目前情況,決定要讓 VM 在哪一台實體主機啟動。

    2.2.3 nova-conductor

    作為 nova-ompute 與 DB 之間的橋樑,目的是為了減少 nova-compute 直接存取 DB 的行為。

    2.3 Networking for VMs

    這個部分的功能已經被移進獨立的 Network Service (Neutron) 了,但還是可以簡單說明一下:

    2.3.1 nova-network

    同樣也是一支 daemon,接收來自 Message Queue 的網路相關需求並處理,例如:設定 bridge 介面 or iptables 規則 …. 等等。

    2.3.2 nova-dhcpbridge script

    用來追蹤在資料庫中 IP 租用 & 釋放的資訊。

    2.4 Console interface

    2.4.1 nova-novncproxy (daemon)

    作為透過 VNC 連線時存取 instance VM 的 proxy 之用,支援 browser-based novnc client。

    2.4.2 nova-xvpnvncproxy (daemon)

    作為透過 VNC 連線時存取 instance VM 的 proxy 之用,支援 Java client 的連線。

    2.4.2 nova-consoleauth (daemon)

    用來驗證由 console proxy (上面的 nova-novncproxy & nova-xvpnvncproxy) 所提供的使用者 token。

    2.5 Command-line clients and other interfaces

    2.5.1 nova client

    允許使用者以 tenant admin or 一般使用者的身分執行命令。

    2.5.2 nova-manage client

    允許 OpenStack 管理者執行命令。

    2.6 Other components

    2.6.1 Message Queue

    任何實作 AMQP 的 message queue 服務,用來作為所有 daemon 通訊的中介,這邊我們所使用的 RabbitMQ。

    2.6.2 SQL Database

    儲存在 OpenStack 上運行的所有 VM instance 的狀態、網路設定、相關專案,任何 SQLAlchemy 支援的 DB 都可以使用,我們這邊所使用的是 MySQL。

    3、安裝 Compute Service

    Compute Service 其實是由好幾個 service 一同合作,讓使用者可以啟用 VM instance。

    安裝的時候可以將這些 service 安裝在不同的機器上,也可以都裝在相同的機器上;在這邊我們將大部分的 service 安裝在 controller node 上,而主要啟動 VM instance 的服務則安裝在 compute node 上。

    首先在 controller node 上安裝 Compute 相關必要套件:

    controller# apt-get -y install nova-api nova-cert nova-conductor nova-consoleauth nova-novncproxy nova-scheduler python-novaclient

    3.1 設定 Message Queue & VNC

    修改 nova 設定檔(/etc/nova/nova.conf),指定 Message Queue 服務 & VNC 相關設定,在 [DEFAULT] 區段中加入以下設定:

    [DEFAULT]
    
    rpc_backend = rabbit
    rabbit_host = controller
    rabbit_password = YOUR_RABBIT_PASS
    
    my_ip = 10.0.0.11
    vncserver_listen = 10.0.0.11
    vncserver_proxyclient_address = 10.0.0.11

    3.2 設定資料庫

    接著準備好 nova 相關 daemon 會用到的 DB & 權限設定:

    controller# mysql -u root -p
    Enter password:
    
    mysql> create database nova;
    mysql> grant all privileges on nova.* to 'nova'@'localhost' identified by 'YOUR_NOVA_DB_PASSWORD';
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> grant all privileges on nova.* to 'nova'@'%' identified by 'YOUR_NOVA_DB_PASSWORD';
    Query OK, 0 rows affected (0.00 sec)

    新增 Tables @ Nova DB:

    controller# sh -c "nova-manage db sync" nova

    修改 nova 設定檔(/etc/nova/nova.conf),加入 DB 相關設定:

    [database]
    connection = mysql://nova:YOUR_NOVA_DBPASS@controller/nova

    移除原本存在的 SQLite 檔案:

    controller# rm /var/lib/nova/nova.sqlite

    3.3 設定 Identity Service 認證

    # 建立 nova 用的 user
    controlle# keystone user-create --name=nova --pass=YOUR_NOVA_PASSWORD --email=admin@example.com
    +----------+----------------------------------+
    | Property |              Value               |
    +----------+----------------------------------+
    |  email   |        admin@example.com         |
    | enabled  |               True               |
    |    id    | 5cdbbe2f486641e5966199af5d743441 |
    |   name   |               nova               |
    | username |               nova               |
    +----------+----------------------------------+
    
    # 將 user / service Tenant / admin Role 連結
    controller# keystone user-role-add --user=nova --tenant=service --role=admin

    3.4 向 Identity Service 註冊 Nova 為 Compute Service

    # 建立 service 資訊
    controller# keystone service-create --name=nova --type=compute --description="OpenStack Compute"
    +-------------+----------------------------------+
    |   Property  |              Value               |
    +-------------+----------------------------------+
    | description |        OpenStack Compute         |
    |   enabled   |               True               |
    |      id     | 87c4529e337e45df94a9c101d7097db4 |
    |     name    |               nova               |
    |     type    |             compute              |
    +-------------+----------------------------------+
    
    # 建立 API 服務端點資訊並與 service 連結
    controller# # keystone endpoint-create --service-id=$(keystone service-list | awk '/ compute / {print $2}') --publicurl=http://controller:8774/v2/%\(tenant_id\)s --internalurl=http://controller:8774/v2/%\(tenant_id\)s --adminurl=http://controller:8774/v2/%\(tenant_id\)s
    +-------------+-----------------------------------------------------+
    |   Property  |                        Value                        |
    +-------------+-----------------------------------------------------+
    |   adminurl  |       http://controller:8774/v2/%(tenant_id)s       |
    |      id     |           be0f81e5b41a453a920dd2360c713af6          |
    | internalurl |       http://controller:8774/v2/%(tenant_id)s       |
    |  publicurl  | --publicurl=http://controller:8774/v2/%(tenant_id)s |
    |    region   |                      regionOne                      |
    |  service_id |           87c4529e337e45df94a9c101d7097db4          |
    +-------------+-----------------------------------------------------+

    修改 nova 設定檔(/etc/nova/nova.conf),加入以下設定:

    [DEFAULT]
    auth_strategy = keystone
    
    [keystone_authtoken]
    auth_uri = http://controller:5000
    auth_host = controller
    auth_port = 35357
    auth_protocol = http
    admin_tenant_name = service
    admin_user = nova
    admin_password = YOUR_NOVA_PASS

    3.5 啟動 Compute 相關服務

    controller# service nova-api restart
    controller# service nova-cert restart
    controller# service nova-consoleauth restart
    controller# service nova-scheduler restart
    controller# service nova-conductor restart
    controller# service nova-novncproxy restart

    3.6 驗證安裝是否成功

    # 透過 shell script 匯入 OS_USERNAME / OS_PASSWORD / OS_TENANT_NAME / OS_AUTH_URL 等環境變數
    controller# source ~/OpenStack/admin-openrc.sh
    
    # 查詢目前 compute host 可用的 image list (向 Glance 查詢)
    controller# nova image-list
    +--------------------------------------+---------------------+--------+--------+
    | ID                                   | Name                | Status | Server |
    +--------------------------------------+---------------------+--------+--------+
    | 0985b2f3-058e-4ab9-84e3-65c51f849408 | cirros-0.3.3-x86_64 | ACTIVE |        |
    | 77c0d5f8-1bcc-4937-932c-72f4b0eccbc3 | cirros-0.3.3-x86_64 | ACTIVE |        |
    +--------------------------------------+---------------------+--------+--------+

    4、設定 Compute Node

    設定好 controller 上的 compute service 之後,接著要來設定實際執行 VM instance 的 compute node。

    Compute node 主要的工作是接收來自 controller 的命令,並運行 VM instance。

    4.1 安裝操作 Hypervisor 用套件

    OpenStack 可以兼容多種 hypervisor (KVM / Xen / VMware ESXi / MS Hyper-V … etc),這邊以 KVM 為例,安裝相關操作套件:

    compute1# apt-get -y install nova-compute-kvm

    4.2 修改設定檔 (/etc/nova/nova.conf)

    # 設定 Message Queue 相關資訊
    rpc_backend = rabbit
    rabbit_host = controller
    rabbit_password = YOUR_RABBIT_PASS
    
    # 設定 compute node IP & 相關的 vnc server 位置
    my_ip = 10.0.0.31
    vnc_enabled = True
    vncserver_listen = 0.0.0.0
    vncserver_proxyclient_address = 10.0.0.31
    novncproxy_base_url = http://controller:6080/vnc_auto.html
    
    # 指定以 keystone 進行認證工作
    auth_strategy = keystone
    
    # 指定 Glace 服務所在位置(這邊設定在 controller 上)
    glance_host = controller
    
    # 資料庫相關設定
    [database]
    connection = mysql://nova:YOUR_NOVA_DB_PASSWORD@controller/nova
    
    # keystone 相關設定
    [keystone_authtoken]
    auth_uri = http://controller:5000
    auth_host = controller
    auth_port = 35357
    auth_protocol = http
    admin_tenant_name = service
    admin_user = nova
    admin_password = YOUR_KEYSTONE_PASSWORD

    4.3 檢查 compute node 是否具備硬體加速功能 for 虛擬化

    透過以下指令:

    compute1# egrep -c '(vmx|svm)' /proc/cpuinfo
    1

    若以上指令出現的數字為 0,表示目前 compute node 的 cpu 不支援虛擬化硬體加速,這時候就要編輯 /etc/nova/nova-compute.conf 檔案,將 virt_type 改成 qemu

    [libvirt]
    virt_type = qemu

    4.4 啟動 compute 服務

    # 移除不需要的 SQLite 檔案
    compute1# rm /var/lib/nova/nova.sqlite
    
    # 啟動 nova-compute 服務
    compute1# service nova-compute restart

    5、參考資料