# 2. Tạo Autoscale Profile từ Cloud-init script

{% hint style="info" %}
**Mục đích:** Việc dùng cloud-init script giúp người dùng có thể tự do thay đổi các thông số, tự động hóa quá trình setup network, storage,... một cách linh hoạt. Đoạn script này nên được thử nghiệm trên các Virtual Instances đảm bảo hoạt động tốt trước khi dùng cho việc tạo Autocale Profile.

**Điều kiện cần thiết (Có thể bỏ qua nếu VPC đã có sẵn):**

* [1.-tao-subnet](https://docs.fptcloud.com/networking-service/subnet/1.-tao-subnet "mention")
* [1.-tao-security-group](https://docs.fptcloud.com/networking-service/security-group-and-firewall/1.-tao-security-group "mention")
  {% endhint %}

**Bước 1:** Truy cập trang **Autoscale Profile** > Chọn **Create profile.**

![](https://2837260264-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F18Kpdo0VNH9pUQatMCfo%2Fuploads%2FAoIV9iU1r9uCBiKsRy6m%2Fimage.png?alt=media\&token=e7e0fbba-44d7-4381-949e-ecec28852a61)

**Bước 2:** Cấu hình các thông tin sau:

<table><thead><tr><th>Section</th><th>Field</th><th>Description</th><th data-hidden></th></tr></thead><tbody><tr><td><strong>Credentials</strong></td><td><strong>Name</strong></td><td>Nhập tên profile hoặc mặc định hệ thống sẽ tự đặt cho người dùng.</td><td></td></tr><tr><td></td><td>Authentication</td><td><ul><li>Đối với <strong>Openstack Platform</strong>, người dùng sẽ có tùy chọn <strong>SSH</strong>. (Yêu cầu VPC đã có sẵn SSH Key)</li><li>Đối với <strong>VMware Platform</strong>, người dùng sẽ có tùy chọn <strong>Password.</strong></li><li>Ngoài ra, nếu người dùng không có nhu cầu sử dụng thì có thể chọn <strong>None</strong> để không áp dụng tùy chọn nào.</li></ul></td><td></td></tr><tr><td><strong>Configuration</strong></td><td> <strong>Image</strong></td><td>Mỗi nhóm OS sẽ gồm nhiều phiên bản khác nhau, mặc định là phiên bản mới nhất trên hệ thống. Ở đây ta sẽ chọn <strong>Custom</strong> và lựa chọn Custom Image phù hợp trong danh sách.</td><td></td></tr><tr><td></td><td><strong>Resource type</strong></td><td>Mỗi dòng máy sẽ cấu hình CPU, RAM khác nhau. Hoặc người dùng có thể tự tạo một dòng máy phù hợp nhất với nhu cầu.</td><td></td></tr><tr><td> <strong>Storage</strong></td><td><strong>Policy</strong></td><td>Chọn policy ổ đĩa phù hợp với nhu cầu. Mặc định sẽ là <em>Premium-SSD</em>.</td><td></td></tr><tr><td></td><td><strong>Size (GB)</strong></td><td>Tăng giảm dung lượng hoặc để dung lượng mặc định, mặc định tối thiểu sẽ là 40GB.default size will be 40GB.</td><td></td></tr><tr><td><strong>Network</strong></td><td><strong>Subnet</strong></td><td>Sẽ được tự động chọn dựa trên network của VPC, có thể thay đổi nếu muốn.</td><td></td></tr><tr><td></td><td><strong>Security Group</strong></td><td>Tương tự như Subnet, Security Group cũng sẽ được tự động lựa chọn, và người dùng cũng có thể thay đổi theo nhu cầu.d</td><td></td></tr><tr><td><strong>User data</strong></td><td></td><td>Nơi chứa <a href="https://cloudinit.readthedocs.io/en/latest/topics/examples.html"><strong>cloud-init script</strong></a>. Khi node khởi động, cloud-init sẽ đọc các metadata được cung cấp từ cloud, và khởi tạo hệ thống dựa trên chúng. Cloud-init thường được dùng với mục đích setup network, storage, SSH keys, và nhiều phần khác của hệ thống.</td><td></td></tr></tbody></table>

<figure><img src="https://2837260264-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F18Kpdo0VNH9pUQatMCfo%2Fuploads%2FIt6Irvt3jkfpCf2RVYw4%2Fimage.png?alt=media&#x26;token=e49a7909-f8ef-4958-81c5-a3f598fc12fe" alt=""><figcaption><p>VMware platform</p></figcaption></figure>

<figure><img src="https://2837260264-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F18Kpdo0VNH9pUQatMCfo%2Fuploads%2Fx6hq9BOA7mWU2QTzJBXz%2Fimage.png?alt=media&#x26;token=fe3a773a-3b07-4a13-8aad-6c37156f142d" alt=""><figcaption><p><em><strong>Openstack Platform</strong></em></p></figcaption></figure>

***Cloud-init script mẫu:** Với đoạn script mẫu này, các node trong group sẽ chạy một static website, người dùng có thể thực hiện Allocate Floating IP cho node và thực hiện truy cập vào website thông qua Floating IP đó.*

{% tabs %}
{% tab title="Ubuntu" %}

```
#cloud-config

# Update apt database on first boot (run 'apt-get update').
# Note, if packages are given, or package_upgrade is true, then
# update will be done independent of this setting.
package_update: true
chpasswd:
  list: |
    root:Welcome***123

# if packages are specified, this package_update will be set to true
# packages may be supplied as a single package name or as a list
# with the format [<package>, <version>] wherein the specific
# package version will be installed.
packages:
  - nginx
  - git
  
# runcmd contains a list of either lists or a string
# each item will be executed in order at rc.local like level with
# output to the console
# - runcmd only runs during the first boot
# - if the item is a list, the items will be properly executed as if
#   passed to execve(3) (with the first arg as the command).
# - if the item is a string, it will be simply written to the file and
#   will be interpreted by 'sh'
runcmd:
  - systemctl enable nginx
  - systemctl start nginx
  - git clone https://github.com/cloudacademy/static-website-example.git
  - cp -r ./static-website-example/* /var/www/html/
  - rm -r ./static-website-example
```

{% endtab %}

{% tab title="Second Tab" %}

{% endtab %}
{% endtabs %}

**Bước 4:** Chọn **Create Profile**.

Hệ thống sẽ xác nhận và tiến hành khởi tạo profile.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.fptcloud.com/autoscale/autoscale-profile/2.-tao-autoscale-profile-tu-cloud-init-script.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
