Skip to content

Instantly share code, notes, and snippets.

@vanduc95
Last active October 30, 2019 03:39
Show Gist options
  • Save vanduc95/628c98b40325b0c6f9c2398f11994c4c to your computer and use it in GitHub Desktop.
Save vanduc95/628c98b40325b0c6f9c2398f11994c4c to your computer and use it in GitHub Desktop.

Hướng dẫn cài đặt Openstack OCATA trên Centos7 64bit

Mục lục

1. Mô hình

  • Mô hình cài đặt Openstack Ocata. Trong hướng dẫn này thực hiện cài đặt 2 node là controller, compute1.

    enter image description here

2. IP Planning

  • Controller
    • ens160: 10.10.0.163 / Netmask - 255.255.255.0
    • ens192: IP - 192.168.10.163 / Netmask - 255.255.255.0/ Gateway - 192.168.10.254/ DNS - 8.8.8.8
  • Compute1
    • ens160: 10.10.0.164 / Netmask - 255.255.255.0
    • ens192: IP - 192.168.10.164 / Netmask - 255.255.255.0/ Gateway - 192.168.10.254/ DNS - 8.8.8.8

3. Cài đặt môi trường

3.1 Cài đặt node controller

  • Lưu ý:

    - Đăng nhập với quyền root cho tất cả các bước cài đặt
    - Password thống nhất cho tất cả các dịch vụ là hostvn2017
    
  • Tiến hành cài đặt trên hệ điều hành Centos 7 64bit.

3.1.1 Cài đặt môi trường

  • Cập nhật các gói phần mềm
    yum -y update
    

3.1.2 Cấu hình card mạng cho máy

  • Cấu hình card mạng, tắt firewalld và disable SELinux. Sau đó khởi động lại máy.

    # Setup IP ens160
    nmcli c modify ens160 ipv4.addresses 10.10.0.163/24
    nmcli c modify ens160 ipv4.method manual
    nmcli con mod ens160 connection.autoconnect yes
    
    # Setup IP ens192 
    nmcli c modify ens192 ipv4.addresses 192.168.10.163/24
    nmcli c modify ens192 ipv4.gateway 192.168.10.254
    nmcli c modify ens192 ipv4.dns 8.8.8.8
    nmcli c modify ens192 ipv4.method manual
    nmcli con mod ens192 connection.autoconnect yes
    
    systemctl disable firewalld
    systemctl stop firewalld
    systemctl disable NetworkManager
    systemctl stop NetworkManager
    systemctl enable network
    systemctl start network
    
    sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
    sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
    init 6
    

3.1.3 Cấu hình hostname.

  • Đặt hostname

    hostnamectl set-hostname controller
    
  • Cập nhật file /etc/hosts để phân giải từ IP sang hostname và ngược lại, nội dung như sau

    127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
    
    10.10.0.163 controller
    10.10.0.164 compute1
    
  • Khởi động lại máy, sau đó đăng nhập vào với quyền root.

    init 6
    

3.1.4 Cài đặt NTP.

    1. Cài gói chrony.
    yum -y install chrony
    
    1. Sửa file /etc/chrony.conf như sau:
    • commnet dòng sau:
    #server 0.centos.pool.ntp.org iburst
    #server 1.centos.pool.ntp.org iburst
    #server 2.centos.pool.ntp.org iburst
    #server 3.centos.pool.ntp.org iburst
    
    • Thêm các dòng sau:
    server 1.vn.poo.ntp.org iburst
    server 0.asia.pool.ntp.org iburst
    server 3.asia.pool.ntp.org iburst
    
    allow 10.10.0.0/24
    
    1. Enable và start dịch vụ NTP
    systemctl enable chronyd.service
    systemctl start chronyd.service
    
    1. Kiểm tra lại hoạt động của NTP bằng lệnh dưới
    [root@controller ~]# chronyc sources
    210 Number of sources = 2
    MS Name/IP address         Stratum Poll Reach LastRx Last sample
    ===============================================================================
    ^- mta.khangthong.net            2   6   357   225    -72ms[  -75ms] +/-  462ms
    ^* forteca.e-lista.pl            2   7   377    74    -27ms[  -30ms] +/-  207ms
    

3.1.5 Cài đặt repos để cài OpenStack OCATA

    1. Cài đặt gói để cài OpenStack OCATA
    yum -y install centos-release-openstack-ocata
    
    1. Cập nhật các gói phần mềm
    yum -y upgrade
    
    1. Cài đặt các gói client của OpenStack.
    yum -y install python-openstackclient
    
    1. Khởi động lại máy chủ
    init 6
    

3.1.6 Cài đặt SQL database

    1. Cài đặt MariaDB
    yum -y install mariadb mariadb-server python2-PyMySQL
    
    1. Cấu hình cho Mariadb, tạo file /etc/my.cnf.d/openstack.cnf với nội dung sau:
    [mysqld]
    bind-address = 0.0.0.0
    
    default-storage-engine = innodb
    innodb_file_per_table = on
    max_connections = 4096
    collation-server = utf8_general_ci
    character-set-server = utf8
    
    1. Enable và start dịch vụ MariaDB
    systemctl enable mariadb.service
    systemctl start mariadb.service
    
    1. Thiết lập mật khẩu cho tài khoản root (tài khoản root của mariadb)
    mysql_secure_installation
    
    • Ngay đoạn đầu tiên nó sẽ hỏi bạn nhập mật khẩu root hiện tại, nhưng chúng ta chưa có mật khẩu thì hãy Enter để bỏ qua, kế tiếp chọn gõ Y để bắt đầu thiết lập mật khẩu cho root và các tùy chọn sau bạn vẫn Y hết.
    • Nhập mật khẩu root là: hostvn2017
    1. Kiểm tra lại cài đặt. Đăng nhập bằng tài khoản root của MariaDB . Sau đó gõ lệnh exit để thoát.
    [root@controller ~]# mysql -u root -phostvn2017
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 10
    Server version: 10.1.20-MariaDB MariaDB Server
    
    Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    MariaDB [(none)]> Bye
    

3.1.7 Cài đặt RabbitMQ

    1. Cài đặt gói
    yum -y install rabbitmq-server
    
    1. Enable và start dịch vụ RabbitMQ
    systemctl enable rabbitmq-server.service
    systemctl start rabbitmq-server.service
    
    1. Cấu hình RabbitMQ, tạo user openstack với mật khẩu là hostvn2017
    rabbitmqctl add_user openstack hostvn2017
    
    1. Gán quyền read, write cho tài khoản openstack trong RabbitMQ
    rabbitmqctl set_permissions openstack ".*" ".*" ".*"
    

3.1.8 Cài đặt Memcached

    1. Cài đặt các gói cần thiết cho memcached
    yum -y install memcached python-memcached
    
    1. Sửa file /etc/sysconfig/memcached, thay dòng OPTIONS="-l 127.0.0.1,::1" bằng dòng dưới.
    OPTIONS="-l 127.0.0.1,::1,controller"
    
    1. Enable và start dịch vụ Memcached
    systemctl enable memcached.service
    systemctl start memcached.service
    

3.2 Cài đặt node Compute1

3.2.1 Cài đặt môi trường

  • Cập nhật các gói phần mềm
    yum -y update
    

3.2.2 Cấu hình card mạng cho máy

  • Cấu hình card mạng, tắt firewalld và disable SELinux. Sau đó khởi động lại máy.

    # Setup IP ens160
    nmcli c modify ens160 ipv4.addresses 10.10.0.164/24
    nmcli c modify ens160 ipv4.method manual
    nmcli con mod ens160 connection.autoconnect yes
    
    # Setup IP ens192 
    nmcli c modify ens192 ipv4.addresses 192.168.10.164/24
    nmcli c modify ens192 ipv4.gateway 192.168.10.254
    nmcli c modify ens192 ipv4.dns 8.8.8.8
    nmcli c modify ens192 ipv4.method manual
    nmcli con mod ens192 connection.autoconnect yes
    
    systemctl disable firewalld
    systemctl stop firewalld
    systemctl disable NetworkManager
    systemctl stop NetworkManager
    systemctl enable network
    systemctl start network
    
    sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
    sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
    init 6
    

3.2.3 Cấu hình hostname.

  • Đặt hostname

    hostnamectl set-hostname compute1
    
  • Cập nhật file /etc/hosts để phân giải từ IP sang hostname và ngược lại, nội dung như sau

    127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
    
    10.10.0.163 controller
    10.10.0.164 compute1
    
  • Khởi động lại máy, sau đó đăng nhập vào với quyền root.

    init 6
    

3.2.4 Cài đặt NTP.

    1. Cài gói chrony.
    yum -y install chrony
    
    1. Sửa file /etc/chrony.conf như sau:
    • commnet dòng sau:
    #server 0.centos.pool.ntp.org iburst
    #server 1.centos.pool.ntp.org iburst
    #server 2.centos.pool.ntp.org iburst
    #server 3.centos.pool.ntp.org iburst
    
    • Thêm dòng sau:
    server controller iburst
    
    1. Enable và start dịch vụ NTP
    systemctl enable chronyd.service
    systemctl start chronyd.service
    
    1. Kiểm tra lại hoạt động của NTP bằng lệnh dưới
    [root@compute1 ~]# chronyc sources
    210 Number of sources = 1
    MS Name/IP address         Stratum Poll Reach LastRx Last sample
    ===============================================================================
    ^* controller                    3   6   377    47  +1921us[+1803us] +/-  245ms
    

3.2.5 Cài đặt repos để cài OpenStack OCATA

    1. Cài đặt gói để cài OpenStack OCATA
    yum -y install centos-release-openstack-ocata
    
    1. Cập nhật các gói phần mềm
    yum -y upgrade
    
    1. Cài đặt các gói client của OpenStack.
    yum -y install python-openstackclient
    
    1. Khởi động lại máy chủ
    init 6
    

  • Đã chuẩn bị xong môi trường để cài đặt Openstack OCATA.
  • Tiến hành cài đặt các dịch vụ trên các node.

4. Cài dịch vụ Identity (keystone)

  • Dịch vụ này cài đặt trên node controller.

4.1 Tạo database cho keystone

    1. Đăng nhập vào MariaDB
    mysql -u root -phostvn2017
    
    1. Tạo database cho keystone
    CREATE DATABASE keystone;
    
    1. Cấp quyền truy cập vào cơ sở dữ liệu keystone.
    GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'localhost'  IDENTIFIED BY 'hostvn2017';
    GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'%' IDENTIFIED BY 'hostvn2017';
    FLUSH PRIVILEGES;
    exit;
    

4.2 Cài đặt và cấu hình keystone

    1. Cài đặt keystone
    yum -y install openstack-keystone httpd mod_wsgi
    
  • Sao lưu file cấu hình của dịch vụ keystone trước khi chỉnh sửa.
    cp /etc/keystone/keystone.conf /etc/keystone/keystone.conf.orig
    
    1. Sửa file /etc/keystone/keystone.conf.
    • Trong section [database] thêm dòng dưới
      connection = mysql+pymysql://keystone:hostvn2017@controller/keystone
      
    • Trong section [token], cấu hình Fernet token provider:
      provider = fernet
      
    1. Đồng bộ database cho keystone
    su -s /bin/sh -c "keystone-manage db_sync" keystone
    
    • Lệnh trên sẽ tạo ra các bảng trong database có tên là keysonte
    1. Thiết lập Fernet key
    keystone-manage fernet_setup --keystone-user keystone --keystone-group keystone
    keystone-manage credential_setup --keystone-user keystone --keystone-group keystone
    
    1. Bootstrap the Identity service:
    keystone-manage bootstrap --bootstrap-password hostvn2017 \
    --bootstrap-admin-url http://controller:35357/v3/ \
    --bootstrap-internal-url http://controller:5000/v3/ \
    --bootstrap-public-url http://controller:5000/v3/ \
    --bootstrap-region-id RegionOne
    

4.3 Cấu hình apache cho keysonte

  • Sửa file /etc/httpd/conf/httpd.conf. Thêm dòng dưới đây

    ServerName controller
    
  • Tạo link tới file /usr/share/keystone/wsgi-keystone.conf:

    ln -s /usr/share/keystone/wsgi-keystone.conf /etc/httpd/conf.d/
    

4.4 Kết thúc cài đặt

    1. Enable và start httpd
    systemctl enable httpd.service
    systemctl start httpd.service
    
    1. Cấu hình cho tài khoản quản trị:
    export OS_USERNAME=admin
    export OS_PASSWORD=hostvn2017
    export OS_PROJECT_NAME=admin
    export OS_USER_DOMAIN_NAME=Default
    export OS_PROJECT_DOMAIN_NAME=Default
    export OS_AUTH_URL=http://controller:35357/v3
    export OS_IDENTITY_API_VERSION=3
    

4.5 Tạo domain, projects, users, và roles

    1. Tạo project service
    ~# openstack project create --domain default \
      --description "Service Project" service
    
    +-------------+----------------------------------+
    | Field       | Value                            |
    +-------------+----------------------------------+
    | description | Service Project                  |
    | domain_id   | default                          |
    | enabled     | True                             |
    | id          | 42284bba92c1428a9811f99b99451eb3 |
    | is_domain   | False                            |
    | name        | service                          |
    | parent_id   | default                          |
    +-------------+----------------------------------+
    
    1. Tạo project demo:
    ~# openstack project create --domain default \
      --description "Demo Project" demo
      
    +-------------+----------------------------------+
    | Field       | Value                            |
    +-------------+----------------------------------+
    | description | Demo Project                     |
    | domain_id   | default                          |
    | enabled     | True                             |
    | id          | 46c2ef11a6904008be75a90d28b1928c |
    | is_domain   | False                            |
    | name        | demo                             |
    | parent_id   | default                          |
    +-------------+----------------------------------+
    
    1. Tạo user demo
    ~# openstack user create --domain default \
      --password hostvn2017 demo
      
    +---------------------+----------------------------------+
    | Field               | Value                            |
    +---------------------+----------------------------------+
    | domain_id           | default                          |
    | enabled             | True                             |
    | id                  | c83518ba02064bc795e7e282024647ad |
    | name                | demo                             |
    | options             | {}                               |
    | password_expires_at | None                             |
    +---------------------+----------------------------------+
    
    1. Tạo role user:
    ~# openstack role create user
    
    +-----------+----------------------------------+
    | Field     | Value                            |
    +-----------+----------------------------------+
    | domain_id | None                             |
    | id        | 013e86513757495c8ef8fc9b82b40523 |
    | name      | user                             |
    +-----------+----------------------------------+
    
    1. Thêm role user cho user demo trên project demo:
    openstack role add --project demo --user demo user
    

4.6 Kiểm chứng lại các bước cài đặt keysonte

    1. Vô hiệu hóa cơ chế xác thực bằng token tạm thời trong keysonte bằng cách xóa admin_token_auth trong các section [pipeline:public_api], [pipeline:admin_api][pipeline:api_v3] của file /etc/keystone/keystone-paste.ini
    1. Bỏ thiết lập trong biến môi trường của OS_AUTH_URL và OS_PASSWORD bằng lệnh:
    unset OS_AUTH_URL OS_PASSWORD
    
    1. Gõ lần lượt 2 lệnh dưới sau đó nhập mật khẩu là Welcome123
    ~# openstack --os-auth-url http://controller:35357/v3 \
      --os-project-domain-name default --os-user-domain-name default \
      --os-project-name admin --os-username admin token issue
    Password:
    
    +------------+------------------------------------------------------------------------------------------------------------------------------------+
    | Field      | Value                                                                                                                              |
    +------------+------------------------------------------------------------------------------------------------------------------------------------+
    | expires    | 2017-06-08T14:37:45+0000                                                                                                           |
    | id         | gAAAAABZOVMpzGj_G62qWkgpIL58u2l1FKFBkWTpqW5zocPPdraLwYWEdHUsKsOkCZwMNGFelZlI0vilWo4gMsZ5nWXb2ELD4aMHU4W3rnMSxKqv4QtSxiRCv8hTJ_IGIj |
    |            | vYFF_e2qtySAsuhoRCZVOhy3KfS2FelCpzQE4UDRP5VHWKX5OMeI4                                                                              |
    | project_id | b54646bf669746db8c62ec0410bd0528                                                                                                   |
    | user_id    | 102f8ea368cd4451ad6fefeb15801177                                                                                                   |
    +------------+------------------------------------------------------------------------------------------------------------------------------------+
    
    ~# openstack --os-auth-url http://controller:5000/v3 \
      --os-project-domain-name default --os-user-domain-name default \
      --os-project-name demo --os-username demo token issue
    Password:
    
    +------------+------------------------------------------------------------------------------------------------------------------------------------+
    | Field      | Value                                                                                                                              |
    +------------+------------------------------------------------------------------------------------------------------------------------------------+
    | expires    | 2017-06-08T14:39:37+0000                                                                                                           |
    | id         | gAAAAABZOVOZu1qQ0_9OkDgoDiQjRhiNH8UxWEwbXZCtiFZ7r4dX37cs5edGxwKpDVriIc3SpRWmPK-YY2Qt0VVaxJ1m8210RsQRitplup1_kBZMp86lZKLibnjoEX-    |
    |            | gqXssudHceQObctojg_m8hwihsy5wGsRk-H3HYBQqiIroJ_OHuY7T7gA                                                                           |
    | project_id | 46c2ef11a6904008be75a90d28b1928c                                                                                                   |
    | user_id    | c83518ba02064bc795e7e282024647ad                                                                                                   |
    +------------+------------------------------------------------------------------------------------------------------------------------------------+
    

4.7 Tạo script biến môi trường cho client

    1. Tạo file admin-openrc với nội dung sau:
    export OS_PROJECT_DOMAIN_NAME=Default
    export OS_USER_DOMAIN_NAME=Default
    export OS_PROJECT_NAME=admin
    export OS_USERNAME=admin
    export OS_PASSWORD=hostvn2017
    export OS_AUTH_URL=http://controller:35357/v3
    export OS_IDENTITY_API_VERSION=3
    export OS_IMAGE_API_VERSION=2
    
    1. Tạo file demo-openrc với nội dung sau:
    export OS_PROJECT_DOMAIN_NAME=Default
    export OS_USER_DOMAIN_NAME=Default
    export OS_PROJECT_NAME=demo
    export OS_USERNAME=demo
    export OS_PASSWORD=hostvn2017
    export OS_AUTH_URL=http://controller:5000/v3
    export OS_IDENTITY_API_VERSION=3
    export OS_IMAGE_API_VERSION=2
    
    1. Chạy script admin-openrc
    source  admin-openrc
    
    1. Kết quả sẽ như bên dưới (Lưu ý: giá trị sẽ khác nhau)
    ~# openstack token issue
    
    +------------+------------------------------------------------------------------------------------------------------------------------------------+
    | Field      | Value                                                                                                                              |
    +------------+------------------------------------------------------------------------------------------------------------------------------------+
    | expires    | 2017-06-08T14:45:58+0000                                                                                                           |
    | id         | gAAAAABZOVUWFfzGA7YgH4B8E22pSmM1z0woDouvaBCUF8NhnY1ne65hCFHU1TnfFadXXtX8RH0NXLa1KNKClrf-                                           |
    |            | Xxdl6qOyNGHBJ2jLHSws8TCaLtZYu6UoCIHxLzVus35krZGYS1DXpfBjB77YiLmuXhvf8qryZbWvBQX5K9otIbPv7e_dHqU                                    |
    | project_id | b54646bf669746db8c62ec0410bd0528                                                                                                   |
    | user_id    | 102f8ea368cd4451ad6fefeb15801177                                                                                                   |
    +------------+------------------------------------------------------------------------------------------------------------------------------------+
    

5. Cài dịch vụ Image (Glance)

  • Dịch vụ này được cài đặt trên node controller.

5.1 Tạo database cho glance

    1. Đăng nhập vào mysql
    mysql -u root -phostvn2017
    
    1. Tạo database glance
    CREATE DATABASE glance;
    
    1. Cấp quyền truy cập vào cơ sở dữ liệu
    GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'hostvn2017';
    GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'hostvn2017';
    FLUSH PRIVILEGES;
    exit;
    

5.2 Tạo user glance, gán quyền và tạo endpoint API cho dịch vụ glance

    1. Chạy script biến môi trường: source admin-openrc
    1. Tạo user glance:
    ~# openstack user create --domain default --password hostvn2017 glance
    
    +---------------------+----------------------------------+
    | Field               | Value                            |
    +---------------------+----------------------------------+
    | domain_id           | default                          |
    | enabled             | True                             |
    | id                  | 119d2cad45584585b5bf9ef799cbfbfa |
    | name                | glance                           |
    | options             | {}                               |
    | password_expires_at | None                             |
    +---------------------+----------------------------------+
    
    1. Thêm role admin cho user glance trên project service
    openstack role add --project service --user glance admin
    
    • Kiểm tra lại xem user glance có role là gì
    ~# openstack role list --user glance --project service
    Listing assignments using role list is deprecated. Use role assignment list --user <user-name> --project <project-name> --names instead.
    +----------------------------------+-------+---------+--------+
    | ID                               | Name  | Project | User   |
    +----------------------------------+-------+---------+--------+
    | ec9157c203314df69c4f3805e3fec0e7 | admin | service | glance |
    +----------------------------------+-------+---------+--------+
    
    1. Tạo dịch vụ có tên glance
    ~# openstack service create --name glance \
      --description "OpenStack Image" image
       
    +-------------+----------------------------------+
    | Field       | Value                            |
    +-------------+----------------------------------+
    | description | OpenStack Image                  |
    | enabled     | True                             |
    | id          | 5ef6ca4ca183461eb2bb64b3c406a839 |
    | name        | glance                           |
    | type        | image                            |
    +-------------+----------------------------------+
    
    1. Tạo các endpoint cho dịch vụ glance
    openstack endpoint create --region RegionOne image public http://controller:9292
     
    openstack endpoint create --region RegionOne image internal http://controller:9292
    
    openstack endpoint create --region RegionOne image admin http://controller:9292
    

5.3 Cài đặt và cấu hình cho dịch vụ glance

    1. Cài đặt gói glance
    yum -y install openstack-glance
    
    • Sao lưu các file /etc/glance/glance-api.conf và file /etc/glance/glance-registry.conf trước khi cấu hình
    cp /etc/glance/glance-api.conf /etc/glance/glance-api.conf.orig
    cp /etc/glance/glance-registry.conf /etc/glance/glance-registry.conf.orig
    
    1. Cấu hình glance
    • Sửa file /etc/glance/glance-api.conf như sau:
    • Trong section [database] thêm dòng dưới
    connection = mysql+pymysql://glance:hostvn2017@controller/glance
    
    • Trong section [keystone_authtoken][paste_deploy], cấu hình truy cập dịch vụ Identity:
    [keystone_authtoken]
    # ...
    auth_uri = http://controller:5000
    auth_url = http://controller:35357
    memcached_servers = controller:11211
    auth_type = password
    project_domain_name = default
    user_domain_name = default
    project_name = service
    username = glance
    password = hostvn2017
    
    [paste_deploy]
    # ...
    flavor = keystone
    
    • Trong section [glance_store], cấu hình lưu trữ file trên hệ thống (local file system store) và vị trí của file image (mục này không phải làm trong file /etc/glance/glance-registry.conf):
    [glance_store]
    # ...
    stores = file,http
    default_store = file
    filesystem_store_datadir = /var/lib/glance/images/
    
    • Sửa file /etc/glance/glance-registry.conf như sau:
    • Trong section [database] thêm dòng dưới
    connection = mysql+pymysql://glance:hostvn2017@controller/glance
    
    • Trong section [keystone_authtoken][paste_deploy], cấu hình truy cập dịch vụ Identity:
    [keystone_authtoken]
    # ...
    auth_uri = http://controller:5000
    auth_url = http://controller:35357
    memcached_servers = controller:11211
    auth_type = password
    project_domain_name = default
    user_domain_name = default
    project_name = service
    username = glance
    password = hostvn2017
    
    [paste_deploy]
    # ...
    flavor = keystone
    
    1. Đồng bộ database cho glance
    su -s /bin/sh -c "glance-manage db_sync" glance
    
    1. Enable và start dịch vụ Glance.
    systemctl enable openstack-glance-api.service openstack-glance-registry.service
    
    systemctl start openstack-glance-api.service openstack-glance-registry.service
    

5.4 Kiểm chứng lại việc cài đặt glance

    1. Chạy script biến môi trường: source admin-openrc
    1. Tải file image cho glance.
    yum -y install wget
    wget http://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img
    
    1. Upload file image vừa tải về
    openstack image create "cirros" \
      --file cirros-0.3.5-x86_64-disk.img \
      --disk-format qcow2 --container-format bare \
      --public
    
    1. Kiểm tra lại image đã có hay chưa
    ~# openstack image list
    +--------------------------------------+--------+--------+
    | ID                                   | Name   | Status |
    +--------------------------------------+--------+--------+
    | 9b989c67-57a3-4f7d-88d0-d4137aa0a7fa | cirros | active |
    +--------------------------------------+--------+--------+
    
    • Nếu kết quả như trên là đã cài đặt thành công

6 Cài dịch vụ Compute (Nova)

6.1 Cài đặt các thành phần trên node controller.

6.1.1 Tạo database cho nova

  • Đăng nhập vào database với quyền root
    mysql -u root -phostvn2017
    
  • Tạo database nova_api, nova, và nova_cell0:
    CREATE DATABASE nova_api;
    CREATE DATABASE nova;
    CREATE DATABASE nova_cell0;
    
  • Cấp quyền truy cập database:
    GRANT ALL PRIVILEGES ON nova_api.* TO 'nova'@'localhost' IDENTIFIED BY 'hostvn2017';
    GRANT ALL PRIVILEGES ON nova_api.* TO 'nova'@'%' IDENTIFIED BY 'hostvn2017';
     
    GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'localhost' IDENTIFIED BY 'hostvn2017';
    GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'%' IDENTIFIED BY 'hostvn2017';
     
    GRANT ALL PRIVILEGES ON nova_cell0.* TO 'nova'@'localhost' IDENTIFIED BY 'hostvn2017';
    GRANT ALL PRIVILEGES ON nova_cell0.* TO 'nova'@'%' IDENTIFIED BY 'hostvn2017';
    
    FLUSH PRIVILEGES;
    EXIT;
    

6.1.2 Tạo user, service và các endpoint API cho nova

  • Chạy script biến môi trường: source admin-openrc
    1. Tạo user nova
    ~# openstack user create --domain default --password hostvn2017 nova
    
    +---------------------+----------------------------------+
    | Field               | Value                            |
    +---------------------+----------------------------------+
    | domain_id           | default                          |
    | enabled             | True                             |
    | id                  | d4645d60bdb14e9b9148a2e3193e744f |
    | name                | nova                             |
    | options             | {}                               |
    | password_expires_at | None                             |
    +---------------------+----------------------------------+
    
    1. Thêm role admin cho user nova trên project service
    openstack role add --project service --user nova admin
    
    1. Tạo dịch vụ nova
    ~# openstack service create --name nova \
      --description "OpenStack Compute" compute
    +-------------+----------------------------------+
    | Field       | Value                            |
    +-------------+----------------------------------+
    | description | OpenStack Compute                |
    | enabled     | True                             |
    | id          | 29b8545253fd4bb389480040882eff31 |
    | name        | nova                             |
    | type        | compute                          |
    +-------------+----------------------------------+
    
    1. Tạo các endpoint cho dịch vụ compute:
    openstack endpoint create --region RegionOne \
    compute public http://controller:8774/v2.1
    
    openstack endpoint create --region RegionOne \
    compute internal http://controller:8774/v2.1
    
    openstack endpoint create --region RegionOne \
    compute admin http://controller:8774/v2.1
    
    1. Tạo user placement
    ~# openstack user create --domain default --password hostvn2017 placement
    
    +---------------------+----------------------------------+
    | Field               | Value                            |
    +---------------------+----------------------------------+
    | domain_id           | default                          |
    | enabled             | True                             |
    | id                  | 6328b10db2734a4bbc8f022d8bee2630 |
    | name                | placement                        |
    | options             | {}                               |
    | password_expires_at | None                             |
    +---------------------+----------------------------------+
    
    1. Thêm role admin cho user placement trên project service:
    openstack role add --project service --user placement admin
    
    1. Tạo dịch vụ placement:
    ~# openstack service create --name placement --description "Placement API" placement
    
    +-------------+----------------------------------+
    | Field       | Value                            |
    +-------------+----------------------------------+
    | description | Placement API                    |
    | enabled     | True                             |
    | id          | 19372a41560d4df5ba04842174ef4ced |
    | name        | placement                        |
    | type        | placement                        |
    +-------------+----------------------------------+
    
    1. Tạo endpoint cho placement
    openstack endpoint create --region RegionOne placement public http://controller:8778
    
    openstack endpoint create --region RegionOne placement internal http://controller:8778
    
    openstack endpoint create --region RegionOne placement admin http://controller:8778
    

6.1.3 Cài đặt và cấu hình Nova

    1. Cài đặt các gói:
    yum -y install openstack-nova-api openstack-nova-conductor \
      openstack-nova-console openstack-nova-novncproxy \
      openstack-nova-scheduler openstack-nova-placement-api
    
  • Sao lưu file /etc/nova/nova.conf trước khi cấu hình

    cp /etc/nova/nova.conf /etc/nova/nova.conf.orig
    
    1. Cấu hình nova. Sửa file /etc/nova/nova.conf
    • Trong [api_database] và [database] sections, cấu hình truy cập database:
    [api_database]
    # ...
    connection = mysql+pymysql://nova:hostvn2017@controller/nova_api
    
    [database]
    # ...
    connection = mysql+pymysql://nova:hostvn2017@controller/nova
    
    • Trong [DEFAULT] section:
    [DEFAULT]
    # ...
    enabled_apis = osapi_compute,metadata
    use_neutron = True
    firewall_driver = nova.virt.firewall.NoopFirewallDriver
    my_ip = 10.10.0.163
    transport_url = rabbit://openstack:hostvn2017@controller
    
    • Trong [api] và [keystone_authtoken], cấu hình dịch vụ identity:
    [api]
    # ...
    auth_strategy = keystone
     
    [keystone_authtoken]
    # ...
    auth_uri = http://controller:5000
    auth_url = http://controller:35357
    memcached_servers = controller:11211
    auth_type = password
    project_domain_name = default
    user_domain_name = default
    project_name = service
    username = nova
    password = hostvn2017
    
    • Trong [vnc]:
    [vnc]
    enabled = true
    # ...
    vncserver_listen = $my_ip
    vncserver_proxyclient_address = $my_ip
    
    • Trong [glance]:
    [glance]
    # ...
    api_servers = http://controller:9292
    
    • Trong [oslo_concurrency]:
    [oslo_concurrency]
    # ...
    lock_path = /var/lib/nova/tmp
    
    • Trong [placement], cấu hình Placement API:
    [placement]
    # ...
    os_region_name = RegionOne
    project_domain_name = Default
    project_name = service
    auth_type = password
    user_domain_name = Default
    auth_url = http://controller:35357/v3
    username = placement
    password = hostvn2017
    
  • Thêm đoạn cấu hình sau vào file /etc/httpd/conf.d/00-nova-placement-api.conf

    #...
    <Directory /usr/bin>
       <IfVersion >= 2.4>
          Require all granted
       </IfVersion>
       <IfVersion < 2.4>
          Order allow,deny
          Allow from all
       </IfVersion>
    </Directory>
    
  • Restart dịch vụ httpd

    systemctl restart httpd
    

6.1.4 Import database cho nova

    1. Tạo database cho nova_api
    su -s /bin/sh -c "nova-manage api_db sync" nova
    
    1. Đăng ký cell0 database:
    su -s /bin/sh -c "nova-manage cell_v2 map_cell0" nova
    
    1. Create the cell1 cell:
    su -s /bin/sh -c "nova-manage cell_v2 create_cell --name=cell1 --verbose" nova  
    
    1. Tạo database cho nova
    su -s /bin/sh -c "nova-manage db sync" nova
    
    1. Kiểm tra lại nova cell0 và cell1 đã được đăng ký đúng hay chưa:
    ~# nova-manage cell_v2 list_cells
    +-------+--------------------------------------+
    |  Name |                 UUID                 |
    +-------+--------------------------------------+
    | cell0 | 00000000-0000-0000-0000-000000000000 |
    | cell1 | 3ca28930-9d49-4a26-867e-88f7285d3b0e |
    +-------+--------------------------------------+
    

6.1.5 Kết thúc bước cài đặt và cấu hình nova

    1. Khởi động lại các dịch vụ của nova sau khi cài đặt & cấu hình nova
    systemctl enable openstack-nova-api.service \
      openstack-nova-consoleauth.service openstack-nova-scheduler.service \
      openstack-nova-conductor.service openstack-nova-novncproxy.service
      
    systemctl start openstack-nova-api.service \
      openstack-nova-consoleauth.service openstack-nova-scheduler.service \
      openstack-nova-conductor.service openstack-nova-novncproxy.service
    

Sau khi cài đặt xong các thành phần của nova trên node controller, chúng ta bắt đầu cài đặt nova-compute trên node compute1.

6.2 Cài đặt nova-compute1

6.2.1 Cài đặt và cấu hình

    1. Cài đặt
    yum -y install openstack-nova-compute
    
    • Sao lưu file cấu hình của dịch vụ nova-compute trước khi chỉnh sửa.
    cp /etc/nova/nova.conf /etc/nova/nova.conf.orig
    
    1. Cấu hình
    • Trong [DEFAULT] section:
    [DEFAULT]
    #...
    enabled_apis = osapi_compute,metadata
    transport_url = rabbit://openstack:hostvn2017@controller
    my_ip = 10.10.0.164
    use_neutron = True
    firewall_driver = nova.virt.firewall.NoopFirewallDriver
    
  • Trong [api] và [keystone_authtoken], cấu hình dịch vụ identity:

    [api]
    # ...
    auth_strategy = keystone
    
    [keystone_authtoken]
    # ...
    auth_uri = http://controller:5000
    auth_url = http://controller:35357
    memcached_servers = controller:11211
    auth_type = password
    project_domain_name = default
    user_domain_name = default
    project_name = service
    username = nova
    password = hostvn2017
    
  • Trong [vnc] section:

    [vnc]
    # ...
    enabled = True
    vncserver_listen = 0.0.0.0
    vncserver_proxyclient_address = $my_ip
    novncproxy_base_url = http://192.168.10.163:6080/vnc_auto.html
    
  • Trong [glance]:

    [glance]
    # ...
    api_servers = http://controller:9292
    
  • Trong [oslo_concurrency]:

    [oslo_concurrency]
    # ...
    lock_path = /var/lib/nova/tmp
    
  • Trong [placement], cấu hình Placement API:

    [placement]
    # ...
    os_region_name = RegionOne
    project_domain_name = Default
    project_name = service
    auth_type = password
    user_domain_name = Default
    auth_url = http://controller:35357/v3
    username = placement
    password = hostvn2017
    

6.2.2 Kết thúc bước cài đặt và cấu hình nova

    1. Xác định xem compute1 node có hỗ trợ ảo hóa hay không
    egrep -c '(vmx|svm)' /proc/cpuinfo
    
    • Nếu lệnh này trả về một giá trị là 1 hoặc lớn hơn, thì compute node này sẽ hỗ trợ ảo hóa.

    • Nếu trả về giá trị 0, thì compute node không hỗ trợ ảo hóa, ta cần sửa section [libvirt] trong file /etc/nova/nova.conf:

      [libvirt]
      # ...
      virt_type = qemu
      
    1. Enable và start dịch vụ Compute
    systemctl enable libvirtd.service openstack-nova-compute.service
    systemctl start libvirtd.service openstack-nova-compute.service
    

6.3 Sau khi cài đặt xong nova-compute trên node compute. Chúng ta quay lại node controller tiến hành các bước tiếp theo.

    1. Kiểm tra node compute đã có trên database
    ~# . admin-openrc
    
    ~# openstack hypervisor list
    +----+---------------------+-----------------+--------------+-------+
    | ID | Hypervisor Hostname | Hypervisor Type | Host IP      | State |
    +----+---------------------+-----------------+--------------+-------+
    |  1 | compute1            | QEMU            | 10.10.0.164  | up    |
    +----+---------------------+-----------------+--------------+-------+
    
    1. Discover compute hosts:
    ~# su -s /bin/sh -c "nova-manage cell_v2 discover_hosts --verbose" nova
    
    Found 2 cell mappings.
    Skipping cell0 since it does not contain hosts.
    Getting compute nodes from cell 'cell1': 3ca28930-9d49-4a26-867e-88f7285d3b0e
    Found 1 computes in cell: 3ca28930-9d49-4a26-867e-88f7285d3b0e
    Checking host mapping for compute host 'compute1': dc48e539-3223-48d1-8a3c-47c016be15e6
    Creating host mapping for compute host 'compute1': dc48e539-3223-48d1-8a3c-47c016be15e6
    

6.3.1 Kiểm tra kết quả cài đặt nova.

    1. Khai báo các biến môi trường: source admin-openrc
    1. Liệt kê ra các dịch vụ thành phần
    ~# openstack compute service list
    +----+------------------+------------+----------+---------+-------+----------------------------+
    | ID | Binary           | Host       | Zone     | Status  | State | Updated At                 |
    +----+------------------+------------+----------+---------+-------+----------------------------+
    |  3 | nova-consoleauth | controller | internal | enabled | up    | 2017-06-08T17:22:06.000000 |
    |  4 | nova-scheduler   | controller | internal | enabled | up    | 2017-06-08T17:22:02.000000 |
    |  5 | nova-conductor   | controller | internal | enabled | up    | 2017-06-08T17:22:03.000000 |
    |  6 | nova-compute     | compute1   | nova     | enabled | up    | 2017-06-08T17:22:08.000000 |
    +----+------------------+------------+----------+---------+-------+----------------------------+
    
    1. Liệt kê ra các API endpoint.
    ~# openstack catalog list
    +-----------+-----------+-----------------------------------------+
    | Name      | Type      | Endpoints                               |
    +-----------+-----------+-----------------------------------------+
    | placement | placement | RegionOne                               |
    |           |           |   public: http://controller:8778        |
    |           |           | RegionOne                               |
    |           |           |   internal: http://controller:8778      |
    |           |           | RegionOne                               |
    |           |           |   admin: http://controller:8778         |
    |           |           |                                         |
    | nova      | compute   | RegionOne                               |
    |           |           |   internal: http://controller:8774/v2.1 |
    |           |           | RegionOne                               |
    |           |           |   admin: http://controller:8774/v2.1    |
    |           |           | RegionOne                               |
    |           |           |   public: http://controller:8774/v2.1   |
    |           |           |                                         |
    | glance    | image     | RegionOne                               |
    |           |           |   public: http://controller:9292        |
    |           |           | RegionOne                               |
    |           |           |   admin: http://controller:9292         |
    |           |           | RegionOne                               |
    |           |           |   internal: http://controller:9292      |
    |           |           |                                         |
    | keystone  | identity  | RegionOne                               |
    |           |           |   internal: http://controller:5000/v3/  |
    |           |           | RegionOne                               |
    |           |           |   admin: http://controller:35357/v3/    |
    |           |           | RegionOne                               |
    |           |           |   public: http://controller:5000/v3/    |
    |           |           |                                         |
    +-----------+-----------+-----------------------------------------+
    
    1. Liệt các image
    ~# openstack image list
    +--------------------------------------+--------+--------+
    | ID                                   | Name   | Status |
    +--------------------------------------+--------+--------+
    | 9b989c67-57a3-4f7d-88d0-d4137aa0a7fa | cirros | active |
    +--------------------------------------+--------+--------+
    
    1. Kiểm tra cells và placement API
    ~# nova-status upgrade check
    +---------------------------+
    | Upgrade Check Results     |
    +---------------------------+
    | Check: Cells v2           |
    | Result: Success           |
    | Details: None             |
    +---------------------------+
    | Check: Placement API      |
    | Result: Success           |
    | Details: None             |
    +---------------------------+
    | Check: Resource Providers |
    | Result: Success           |
    | Details: None             |
    +---------------------------+
    

7 Cài đặt Networking service (NEUTRON).

Có 2 option cung cấp network cho máy ảo

  • Provider network (không sử dụng L3 agent trong Neutron)
  • Self-service network

Trong hướng dẫn này cài đặt theo option provider network

7.1 Cài đặt trên node Controller.

7.1.1 Tạo database cho neutron

    1. Đăng nhập vào neutron
    mysql -u root -phostvn2017
    
    1. Tạo database neutron:
    CREATE DATABASE neutron;
    
    1. Cấp quyền truy cập vào neutron database
    GRANT ALL PRIVILEGES ON neutron.* TO 'neutron'@'localhost' IDENTIFIED BY 'hostvn2017';
    GRANT ALL PRIVILEGES ON neutron.* TO 'neutron'@'%' IDENTIFIED BY 'hostvn2017';
    
    FLUSH PRIVILEGES;
    exit;
    

7.1.2 Tạo user, dịch vụ và các endpoint API cho neutron

    1. Khai báo biến môi trường
    source admin-openrc
    
    1. Tạo user neutron
    ~# openstack user create --domain default --password hostvn2017 neutron
    
    +---------------------+----------------------------------+
    | Field               | Value                            |
    +---------------------+----------------------------------+
    | domain_id           | default                          |
    | enabled             | True                             |
    | id                  | 13bc1e0d3fb547d1b02ffa69d6597a73 |
    | name                | neutron                          |
    | options             | {}                               |
    | password_expires_at | None                             |
    +---------------------+----------------------------------+
    
    1. Gán role admin cho tài khoản neutron
    openstack role add --project service --user neutron admin
    
    1. Tạo dịch vụ tên là neutron
    ~# openstack service create --name neutron \
      --description "OpenStack Networking" network
      
    +-------------+----------------------------------+
    | Field       | Value                            |
    +-------------+----------------------------------+
    | description | OpenStack Networking             |
    | enabled     | True                             |
    | id          | bd88da44044c4146843b6fbffbdadb4f |
    | name        | neutron                          |
    | type        | network                          |
    +-------------+----------------------------------+
    
    1. Tạo endpoint tên cho neutron
    openstack endpoint create --region RegionOne network public http://controller:9696
    
    openstack endpoint create --region RegionOne network internal http://controller:9696
    
    openstack endpoint create --region RegionOne network admin http://controller:9696
    

7.1.3 Cài đặt và cấu hình neutron

  • Cài đặt và cấu hình cho dịch vụ neutron. Trong hướng dẫn này lựa chọn cơ chế provider netwok

    1. Cài đặt các thành phần cho neutron
    yum -y install openstack-neutron openstack-neutron-ml2 \
      openstack-neutron-linuxbridge ebtables
    
  • Sao lưu file cấu hình gốc của neutron

    cp /etc/neutron/neutron.conf  /etc/neutron/neutron.conf.orig
    
    1. Cấu hình cho dịch vụ neutron. Dùng vi chỉnh sửa file /etc/neutron/neutron.conf
    • Trong section [database]
    [database]
    # ...
    connection = mysql+pymysql://neutron:hostvn2017@controller/neutron
    
    • Trong section [DEFAULT] khai báo lại hoặc thêm mới các dòng dưới:
    [DEFAULT]
    # ...
    core_plugin = ml2
    service_plugins =
    transport_url = rabbit://openstack:hostvn2017@controller
    auth_strategy = keystone
    notify_nova_on_port_status_changes = true
    notify_nova_on_port_data_changes = true
    
    • Trong section [keystone_authtoken] khai báo hoặc thêm mới các dòng dưới:
    [keystone_authtoken]
    # ...
    auth_uri = http://controller:5000
    auth_url = http://controller:35357
    memcached_servers = controller:11211
    auth_type = password
    project_domain_name = default
    user_domain_name = default
    project_name = service
    username = neutron
    password = hostvn2017
    
    • Trong section [nova] khai báo mới hoặc thêm các dòng dưới
    [nova]
    # ...
    auth_url = http://controller:35357
    auth_type = password
    project_domain_name = default
    user_domain_name = default
    region_name = RegionOne
    project_name = service
    username = nova
    password = hostvn2017
    
    • Trong section [oslo_concurrency] khai báo mới hoặc thêm các dòng dưới
    [oslo_concurrency]
    # ...
    lock_path = /var/lib/neutron/tmp
    
    1. Cài đặt và cấu hình plug-in Modular Layer 2 (ML2)
    • Sao lưu file /etc/neutron/plugins/ml2/ml2_conf.ini
    cp /etc/neutron/plugins/ml2/ml2_conf.ini /etc/neutron/plugins/ml2/ml2_conf.ini.orig
    
    • Trong section [ml2] khai báo thêm hoặc sửa dòng dưới
    [ml2]
    # ...
    type_drivers = flat,vlan
    tenant_network_types =
    mechanism_drivers = linuxbridge
    extension_drivers = port_security
    
    • Trong section [ml2_type_flat] khai báo thêm hoặc sửa thành dòng dưới
    [ml2_type_flat]
    # ...
    flat_networks = provider
    
    • Trong section [securitygroup] khai báo thêm hoặc sửa thành dòng dưới
    [securitygroup]
    # ...
    enable_ipset = true
    
    1. Cấu hình linuxbridge
    • Sao lưu file /etc/neutron/plugins/ml2/linuxbridge_agent.ini
    cp /etc/neutron/plugins/ml2/linuxbridge_agent.ini  /etc/neutron/plugins/ml2/linuxbridge_agent.ini.orig
    
    • Trong section [linux_bridge] khai báo mới hoặc sửa thành dòng
    [linux_bridge]
    physical_interface_mappings = provider:ens192
    
    • Trong section [vxlan] khai báo mới hoặc sửa thành dòng
    [vxlan]
    enable_vxlan = false
    
    • Trong section [securitygroup] khai báo mới hoặc sửa thành dòng
    [securitygroup]
    # ...
    enable_security_group = true
    firewall_driver = neutron.agent.linux.iptables_firewall.IptablesFirewallDriver
    
    1. Cấu hình DHCP Agent
    • Sao lưu file /etc/neutron/dhcp_agent.ini gốc
    cp /etc/neutron/dhcp_agent.ini /etc/neutron/dhcp_agent.ini.orig
    
    • Trong section [DEFAULT] khai báo mới hoặc sửa thành dòng dưới
    [DEFAULT]
    # ...
    interface_driver = linuxbridge
    dhcp_driver = neutron.agent.linux.dhcp.Dnsmasq
    enable_isolated_metadata = true
    
    1. Cấu hình metadata agent
    • Sao lưu file /etc/neutron/metadata_agent.ini
    cp /etc/neutron/metadata_agent.ini /etc/neutron/metadata_agent.ini.orig
    
    • Sửa file /etc/neutron/metadata_agent.ini

    • Trong section [DEFAULT] khai báo mới hoặc sửa thành dòng dưới

    [DEFAULT]
    # ...
    nova_metadata_ip = controller
    metadata_proxy_shared_secret = hostvn2017
    
    • Sửa trong file /etc/nova/nova.conf
    • Trong section [neutron] khai báo mới hoặc sửa thành dòng dưới:
    [neutron]
    # ...
    url = http://controller:9696
    auth_url = http://controller:35357
    auth_type = password
    project_domain_name = default
    user_domain_name = default
    region_name = RegionOne
    project_name = service
    username = neutron
    password = hostvn2017
    service_metadata_proxy = true
    metadata_proxy_shared_secret = hostvn2017
    
  • Kết thúc quá trình cài đặt neutron trên controller node

7.1.4 Đồng bộ database cho neutron

ln -s /etc/neutron/plugins/ml2/ml2_conf.ini /etc/neutron/plugin.ini

su -s /bin/sh -c "neutron-db-manage --config-file        /etc/neutron/neutron.conf \
--config-file /etc/neutron/plugins/ml2/ml2_conf.ini upgrade head" neutron
  • Restart nova-api

    systemctl restart openstack-nova-api.service
    
  • Restart các dịch vụ của neutron

    systemctl enable neutron-server.service \
      neutron-linuxbridge-agent.service neutron-dhcp-agent.service \
      neutron-metadata-agent.service
      
    systemctl start neutron-server.service \
      neutron-linuxbridge-agent.service neutron-dhcp-agent.service \
      neutron-metadata-agent.service
    
  • Tiếp theo sẽ cài đặt neutron trên node compute.

7.2 Cài đặt neutron trên node compute1

7.2.1 Cài đặt và cấu hình neutron

  • 1 cài đặt các thành phần

    yum -y install openstack-neutron-linuxbridge ebtables ipset
    
    1. Cấu hình
    • Sao lưu file /etc/neutron/neutron.conf trước khi cài đặt
    cp /etc/neutron/neutron.conf /etc/neutron/neutron.conf.orig
    
    • Trong [DEFAULT] section:
    [DEFAULT]
    # ...
    auth_strategy = keystone
    transport_url = rabbit://openstack:hostvn2017@controller
    
    • Trong [keystone_authtoken] section:
    [keystone_authtoken]
    # ...
    auth_uri = http://controller:5000
    auth_url = http://controller:35357
    memcached_servers = controller:11211
    auth_type = password
    project_domain_name = default
    user_domain_name = default
    project_name = service
    username = neutron
    password = hostvn2017
    
    • Trong [oslo_concurrency] section:
    [oslo_concurrency]
    # ...
    lock_path = /var/lib/neutron/tmp
    
    1. Cấu hình Linux bridge agent
    • Sao lưu file /etc/neutron/plugins/ml2/linuxbridge_agent.ini
    cp /etc/neutron/plugins/ml2/linuxbridge_agent.ini /etc/neutron/plugins/ml2/linuxbridge_agent.ini.orig
    
    • Trong [linux_bridge] section:
    [linux_bridge]
    physical_interface_mappings = provider:ens192
    
    • Trong [vxlan] section:
    [vxlan]
    enable_vxlan = false
    
    • Trong [securitygroup] section:
    [securitygroup]
    # ...
    enable_security_group = true
    firewall_driver = neutron.agent.linux.iptables_firewall.IptablesFirewallDriver
    
  • Cấu hình dịch vụ compute sử dụng dịch vụ network

    • Sửa file /etc/nova/nova.conf

    • Trong [neutron] section:

    [neutron]
    # ...
    url = http://controller:9696
    auth_url = http://controller:35357
    auth_type = password
    project_domain_name = default
    user_domain_name = default
    region_name = RegionOne
    project_name = service
    username = neutron
    password = hostvn2017
    
  • Kết thúc cài đặt

  • Restart nova-compute

    systemctl restart openstack-nova-compute.service
    
  • Restart Linux bridge agent:

    systemctl enable neutron-linuxbridge-agent.service
    systemctl start neutron-linuxbridge-agent.service
    
  • Quay lại node controller để kiểm lại cài đặt neutron

7.3 Kiểm tra kết quả cài đặt

  • Khai báo biến môi trường

    source admin-openrc
    
  • Thực hiện các lệnh sau để kiểm tra

    ~# openstack extension list --network
    
    # kết quả
    
    +----------------------------------------------------------+---------------------------+----------------------------------------------------------+
    | Name                                                     | Alias                     | Description                                              |
    +----------------------------------------------------------+---------------------------+----------------------------------------------------------+
    | Default Subnetpools                                      | default-subnetpools       | Provides ability to mark and use a subnetpool as the     |
    |                                                          |                           | default                                                  |
    | Network IP Availability                                  | network-ip-availability   | Provides IP availability data for each network and       |
    |                                                          |                           | subnet.                                                  |
    | Network Availability Zone                                | network_availability_zone | Availability zone support for network.                   |
    | Auto Allocated Topology Services                         | auto-allocated-topology   | Auto Allocated Topology Services.                        |
    | Neutron L3 Configurable external gateway mode            | ext-gw-mode               | Extension of the router abstraction for specifying       |
    |                                                          |                           | whether SNAT should occur on the external gateway        |
    | Port Binding                                             | binding                   | Expose port bindings of a virtual port to external       |
    |                                                          |                           | application                                              |
    | agent                                                    | agent                     | The agent management extension.                          |
    | Subnet Allocation                                        | subnet_allocation         | Enables allocation of subnets from a subnet pool         |
    | L3 Agent Scheduler                                       | l3_agent_scheduler        | Schedule routers among l3 agents                         |
    | Tag support                                              | tag                       | Enables to set tag on resources.                         |
    | Neutron external network                                 | external-net              | Adds external network attribute to network resource.     |
    | Neutron Service Flavors                                  | flavors                   | Flavor specification for Neutron advanced services       |
    | Network MTU                                              | net-mtu                   | Provides MTU attribute for a network resource.           |
    | Availability Zone                                        | availability_zone         | The availability zone extension.                         |
    | Quota management support                                 | quotas                    | Expose functions for quotas management per tenant        |
    | HA Router extension                                      | l3-ha                     | Add HA capability to routers.                            |
    | Provider Network                                         | provider                  | Expose mapping of virtual networks to physical networks  |
    | Multi Provider Network                                   | multi-provider            | Expose mapping of virtual networks to multiple physical  |
    |                                                          |                           | networks                                                 |
    | Address scope                                            | address-scope             | Address scopes extension.                                |
    | Neutron Extra Route                                      | extraroute                | Extra routes configuration for L3 router                 |
    | Subnet service types                                     | subnet-service-types      | Provides ability to set the subnet service_types field   |
    | Resource timestamps                                      | standard-attr-timestamp   | Adds created_at and updated_at fields to all Neutron     |
    |                                                          |                           | resources that have Neutron standard attributes.         |
    | Neutron Service Type Management                          | service-type              | API for retrieving service providers for Neutron         |
    |                                                          |                           | advanced services                                        |
    | Router Flavor Extension                                  | l3-flavors                | Flavor support for routers.                              |
    | Port Security                                            | port-security             | Provides port security                                   |
    | Neutron Extra DHCP opts                                  | extra_dhcp_opt            | Extra options configuration for DHCP. For example PXE    |
    |                                                          |                           | boot options to DHCP clients can be specified (e.g.      |
    |                                                          |                           | tftp-server, server-ip-address, bootfile-name)           |
    | Resource revision numbers                                | standard-attr-revisions   | This extension will display the revision number of       |
    |                                                          |                           | neutron resources.                                       |
    | Pagination support                                       | pagination                | Extension that indicates that pagination is enabled.     |
    | Sorting support                                          | sorting                   | Extension that indicates that sorting is enabled.        |
    | security-group                                           | security-group            | The security groups extension.                           |
    | DHCP Agent Scheduler                                     | dhcp_agent_scheduler      | Schedule networks among dhcp agents                      |
    | Router Availability Zone                                 | router_availability_zone  | Availability zone support for router.                    |
    | RBAC Policies                                            | rbac-policies             | Allows creation and modification of policies that        |
    |                                                          |                           | control tenant access to resources.                      |
    | Tag support for resources: subnet, subnetpool, port,     | tag-ext                   | Extends tag support to more L2 and L3 resources.         |
    | router                                                   |                           |                                                          |
    | standard-attr-description                                | standard-attr-description | Extension to add descriptions to standard attributes     |
    | Neutron L3 Router                                        | router                    | Router abstraction for basic L3 forwarding between L2    |
    |                                                          |                           | Neutron networks and access to external networks via a   |
    |                                                          |                           | NAT gateway.                                             |
    | Allowed Address Pairs                                    | allowed-address-pairs     | Provides allowed address pairs                           |
    | project_id field enabled                                 | project-id                | Extension that indicates that project_id field is        |
    |                                                          |                           | enabled.                                                 |
    | Distributed Virtual Router                               | dvr                       | Enables configuration of Distributed Virtual Routers.    |
    +----------------------------------------------------------+---------------------------+----------------------------------------------------------+
    

    ~# openstack network agent list
    
    +--------------------------------------+--------------------+------------+-------------------+-------+-------+---------------------------+
    | ID                                   | Agent Type         | Host       | Availability Zone | Alive | State | Binary                    |
    +--------------------------------------+--------------------+------------+-------------------+-------+-------+---------------------------+
    | 0400c2f6-4d3b-44bc-89fa-99093432f3bf | Metadata agent     | controller | None              | True  | UP    | neutron-metadata-agent    |
    | 83cf853d-a2f2-450a-99d7-e9c6fc08f4c3 | DHCP agent         | controller | nova              | True  | UP    | neutron-dhcp-agent        |
    | ec302e51-6101-43cf-9f19-88a78613cbee | Linux bridge agent | compute1    | None              | True  | UP    | neutron-linuxbridge-agent |
    | fcb9bc6e-22b1-43bc-9054-272dd517d025 | Linux bridge agent | controller | None              | True  | UP    | neutron-linuxbridge-agent |
    +--------------------------------------+--------------------+------------+-------------------+-------+-------+---------------------------+

8. Cài đặt và cấu hình HORIZON (dashboad)

  • Thành phần cài đặt trên controller node.

    1. Cài đặt các thành phần cho dashboad
    yum -y install openstack-dashboard
    
  • Sao lưu lại file cấu hình cho dashboad

    cp /etc/openstack-dashboard/local_settings /etc/openstack-dashboard/local_settings.orig
    
    1. Tìm các dòng sau trong file /etc/openstack-dashboard/local_settings và chỉnh sửa như bên dưới
    OPENSTACK_HOST = "controller"
    
    ALLOWED_HOSTS = ['*']
    
    SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
    
    CACHES = {
        'default': {
             'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
             'LOCATION': 'controller:11211',
        }
    }
    
    OPENSTACK_KEYSTONE_URL = "http://%s:5000/v3" % OPENSTACK_HOST
    
    OPENSTACK_KEYSTONE_MULTIDOMAIN_SUPPORT = True
    
    OPENSTACK_API_VERSIONS = {
      "identity": 3,
      "image": 2,
      "volume": 2,
    }
    
    OPENSTACK_KEYSTONE_DEFAULT_DOMAIN = "Default"
    
    OPENSTACK_KEYSTONE_DEFAULT_ROLE = "user"
    

    Vì ta cấu hình neutron theo option provider, nên cần disable layer-3 networking services

    OPENSTACK_NEUTRON_NETWORK = {
      ...
      'enable_router': False,
      'enable_quotas': False,
      'enable_distributed_router': False,
      'enable_ha_router': False,
      'enable_lb': False,
      'enable_firewall': False,
      'enable_vpn': False,
      'enable_fip_topology_check': False,
    }
    
    TIME_ZONE = "Asia/Ho_Chi_Minh"
    
  • Kết thúc cài đặt

  • Restart web server

    systemctl restart httpd.service memcached.service
  • Vào trình duyệt nhập địa chỉ http://192.168.10.163/dashboard để kiểm tra kết quả

9. Tạo và khởi động máy ảo

9.1 Sử dụng command

  • Tạo network không sửa tên các tùy chọn ở đây vì đã đúng với cấu hình trước đó khi cài neutron và nova)

    openstack network create  --share --external \
    --provider-physical-network provider \
    --provider-network-type flat provider
    
  • Tạo subnet

    openstack subnet create --network provider \
    --allocation-pool start=192.168.10.20,end=192.168.10.100 \
    --dns-nameserver 8.8.8.8 --gateway 192.168.10.254 \
    --subnet-range 192.168.10.0/24 provider
    
  • Tạo flavor

    openstack flavor create --id 0 --vcpus 1 --ram 64 --disk 1 m1.nano
    
  • Mở các security group rules

    openstack security group rule create --proto icmp default
    openstack security group rule create --proto tcp --dst-port 22 default
    
  • Tạo máy ảo

    openstack server create vm01 --flavor m1.nano --image cirros \
      --nic net-id=PROVIDER_NET_ID --security-group default 
    

    Thay PROVIDER_NET_ID bằng id của provider network. Để lấy id của provider network, sử dụng câu lệnh sau:

    # openstack network list
    +--------------------------------------+----------+--------------------------------------+
    | ID                                   | Name     | Subnets                              |
    +--------------------------------------+----------+--------------------------------------+
    | 444312b8-b36b-40df-b624-631f5b2f8fac | provider | 45c6e617-e37c-42e9-9660-3ea0708a2400 |
    +--------------------------------------+----------+--------------------------------------+
    
  • Kiểm tra trạng thái của máy ảo

    # openstack server list
    +--------------------------------------+------+--------+------------------------+-----------
    | ID                                   | Name | Status | Networks               | Image Name 
    +--------------------------------------+------+--------+------------------------+-----------
    | 58854028-9c2a-4dbb-82c7-72d50584b600 | vm01 | ACTIVE | provider=192.168.10.40 | cirros     
    +--------------------------------------+------+--------+------------------------+-----------
    
  • Ping tới máy ảo được cấp

    # ping -c 4 192.168.10.33
    PING 192.168.10.33 (192.168.10.33) 56(84) bytes of data.
    64 bytes from 192.168.10.33: icmp_seq=1 ttl=64 time=2.57 ms
    64 bytes from 192.168.10.33: icmp_seq=2 ttl=64 time=0.888 ms
    64 bytes from 192.168.10.33: icmp_seq=3 ttl=64 time=0.483 ms
    64 bytes from 192.168.10.33: icmp_seq=4 ttl=64 time=0.475 ms
    
    --- 192.168.10.33 ping statistics ---
    4 packets transmitted, 4 received, 0% packet loss, time 3000ms
    rtt min/avg/max/mdev = 0.475/1.105/2.575/0.865 ms
    

9.2 Sử dụng dashboard (Horizon)

9.2.1 Đăng nhập vào dashboard

Đăng nhập bằng tài khoản admin, password: hostvn2017

Screenshot_46

9.2.2 Add thêm rule

  • Click tab Project => Network => Security groups => manage rules

    Screenshot_1

  • Sau đó click Add rule

    Screenshot_2

  • Chọn Other Protocol để mở tất cả các rule từ bên ngoài vào VMs. Bạn có thể chọn SSH để đăng nhập vào máy ảo thông qua ssh (chọn Other Protocol thì cũng đã bao gồm cả ssh rồi).

    Screenshot_3

9.2.3 Tạo provider network

  • Click tab Admin => Networks =>Create network

    Screenshot_4

  • Điền các thông tin như hình sau rồi Submit

    Screenshot_5

  • Tạo sub-net

    Screenshot_15

  • Click vào tab Subnet => Create Subnet

    Screenshot_16

  • Khai báo dải địa chỉ mạng. Dải địa chỉ này trùng với dải địa của node controller dùng để ra ngoài internet, là dải mà trong mô hình chúng ta dùng để provider network.

    Screenshot_7

  • Khai báo pool ip và ip của DNS

    Screenshot_7

  • Kết quả

    Screenshot_7

9.2.4 Tạo flavor

  • Click Admin => Flavors => Create Flavor

    Screenshot_7

  • Tạo mới một flavor

    Screenshot_7

9.2.5 Tạo máy ảo

  • Click Project => Compute => Instances => Launch Instance

    Screenshot_7

  • Đặt tên vm01, số lượng 1.

    Screenshot_7

  • Chọn images cho VM.

    Screenshot_7

  • Chọn flavor.

    Screenshot_7

  • Chọn network => click Launch Instance

    Screenshot_7

  • Chờ một lát sẽ có kết quả như hình sau. Click vào máy ảo.

    Screenshot_7

  • Click tab Console => Click here to show only console

    Screenshot_7

  • Đăng nhập vào vm01 với user: cirros và password: cubswin:)

    Screenshot_20

10. Cách fix bug trong qúa trình cài đặt

10.1 Bug 'Too many connections'

  • Trong qúa trình sử dụng dashboard, khi chọn Instances xuất hiện lỗi Unable to retrieve instances và check log /var/log/nova/nova-api.log có lỗi ERROR nova.api.openstack.extensions OperationalError: (pymysql.err.OperationalError) (1040, u'Too many connections')

  • Cách fix:

    • Kiểm tra trong mysql command line:
     mysql -u root -phostvn2017
    
    • Check command sau: SHOW VARIABLES LIKE "max_connections"; Nếu =214 hoặc nhỏ hơn thì cấu hình chưa nhận được.
    • Thêm dòng open_files_limit = 8192 trong file /etc/my.cnf.d/openstack.cnf trên node controller
    • Restart Mariadb:
     systemctl restart mariadb
    

10.2 Bug Unserializable message: ('#ERROR', ValueError('I/O operation on closed file',))

  • Check file /var/log/neutron/linuxbridge-agent.log trên node compute1, xuất hiên lối:
ERROR neutron.plugins.ml2.drivers.agent._common_agent Unserializable message: ('#ERROR', ValueError('I/O operation on closed file',))
  • Cách fix:

    • Kiểm tra trên node compute đã cài conntrack-tools hay chưa?
     rpm -aq | grep -i conntrack
    
    • Nếu chưa có thì cài package conntrack-tools
     yum install conntrack-tools
    
    • Restart service:
     systemctl restart neutron-linuxbridge-agent.service    
    

Bạn đọc có thể tham khảo trực tiếp từ docs của openstack. Docs là một tài liệu chuẩn của Openstack. Bạn click vào đường link sau để cài đặt theo hướng dẫn của docs. https://docs.openstack.org/ocata/install-guide-rdo/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment