Cải thiện hiệu suất và độ tin cậy Improve performance and reliability ការបង្កើនប្រសិទ្ធិភាពនិងភាពងាយស្រួល
Hướng dẫn chi tiết đồng bộ từ docs Cloudflare — mỗi section có backlink tới đúng vị trí trên trang gốc. Detailed guide synced from Cloudflare docs — each section links to the matching anchor on the official page. មគ្គុទ្ទេសក៍លម្អិតធ្វើសមកាលពី docs Cloudflare — ផ្នែកនីមួយៗមានតំណទៅទីតាំងត្រូវគ្នានៅទំព័រផ្លូវការ។
← Danh mục ← Catalog ← បញ្ជីGiải thích nhanh Quick context បរិបទរហ័ស
Thuộc nhóm Application Services — tập trung bảo vệ, tăng tốc và vận hành ứng dụng/web phía trước origin. Tutorial «4 – Improve performance» giúp bạn làm quen luồng triển khai thật — phù hợp đọc trước khi mở tài liệu gốc tiếng Anh. Docs gốc chia khoảng 2 bước chính; bản tóm tắt dưới đây giúp bạn nắm khung trước khi làm theo từng lệnh.
Learn how to use Terraform with Cloudflare Load Balancing product to fail traffic over as needed.
តើធ្វើដូចម្តេចដើម្បីប្រើ Terraform ជាមួយនឹងផលិតផល Cloudflare Load Balancing ដើម្បីកាត់បន្ថយការដឹកជញ្ជូនដែលត្រូវការ។
Lưu ý Note ចំណាំ
Lưu ý trước khi làm Notes before you start ចំណាំមុនពេលចាប់ផ្តើម
- Đây là bản tóm tắt trên Orange Cloud Learning Hub — không thay thế tài liệu chính thức.
- Luôn mở liên kết «Tài liệu gốc» bên dưới khi cần lệnh CLI, snippet code và ảnh minh họa đầy đủ.
- Kiểm tra token/API và state backend trước khi chạy trên môi trường production.
- Docs Cloudflare cập nhật thường xuyên — đối chiếu ngày «Rà soát lần cuối» trên trang gốc khi triển khai production.
- This is a summary on Orange Cloud Learning Hub — it does not replace the official documentation.
- Open the Official docs link below for CLI commands, code snippets, and full screenshots.
- Verify API tokens and the state backend before running against production.
- Cloudflare docs change frequently — verify the Last reviewed date on the official page before production use.
- នេះគឺជាការបញ្ជាក់អំពី Orange Cloud Learning Hub — វាគឺជាការផ្លាស់ប្តូរនៃឯកសារផ្លូវការ។
- ចុចតំណភ្ជាប់ Docs Official នៅខាងក្រោមសម្រាប់ការបញ្ជា CLI, សៀវភៅកូដនិងរូបថតពេញលេញ។
- សូមពិនិត្យមើល API tokens និងការបង្វិលប្រព័ន្ធប្រតិបត្តិការមុនពេលធ្វើការប្រឆាំងនឹងការផលិត។
- Cloudflare បានផ្លាស់ប្តូរជាធម្មតានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅពេលវេលានៅ។
Overview Overview Overview
Phần «Tổng quan» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.
Read the "Overview" section below — open the official docs link for full screenshots and configuration tabs.
អានផ្នែក «Overview» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។
Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs) តំណពាក់ព័ន្ធ (docs Cloudflare)
Điều kiện Prerequisites គោលបំណង
Phần «Yêu cầu trước» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.
Read the "Prerequisites" section below — open the official docs link for full screenshots and configuration tabs.
អានផ្នែក «គោលបំណង» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។
- Hoàn thành Tutorial 1, Tutorial 2 và Tutorial 3
- Load Balancing được kích hoạt trên tài khoản Cloudflare của bạn
- Completed Tutorial 1, Tutorial 2 and Tutorial 3
- Load Balancing enabled on your Cloudflare account
- ការបញ្ចប់ Tutorial 1, Tutorial 2 និង Tutorial 3
- Load Balancing ត្រូវបានអនុញ្ញាតនៅលើគណនីរបស់អ្នក Cloudflare
Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs) តំណពាក់ព័ន្ធ (docs Cloudflare)
1.Điều Thêm bản ghi DNS khác cho www 1. Add another DNS record for www 1 ។ Add another DNS record for កុំព្យូទ័រ
Tạo new branch and add a DNS record for your Asia server:
Read the "1. Add another DNS record for www" section below — open the official docs link for full screenshots and configuration tabs.
អានផ្នែក «1 ។ Add another DNS record for កុំព្យូទ័រ» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។
git checkout -b step4-configure-load-balancing 198.51.100.15. Thêm bản ghi DNS thứ hai vào main.tf của bạn:198.51.100.15. Add the second DNS record to your main.tf:198.51.100.15 ។ បន្ថែមប្រកាសទីពីរ DNS ទៅ main.tf របស់អ្នក:# Asia origin server
resource "cloudflare_dns_record" "www_asia" {
zone_id = var.zone_id
name = "www"
content = "198.51.100.15"
type = "A"
ttl = 300
proxied = true
comment = "Asia origin server"
} resource là khác nhau bởi vì Terraform tài nguyên cùng loại phải được đặt tên duy nhất, tên DNS, hoặc những gì khách hàng của bạn sẽ gõ trong trình duyệt của họ, là như nhau: www.resource is different because Terraform resources of the same type must be uniquely named, the DNS name, or what your customers will type in their browser, is the same: www.resource is different because Terraform resources of the same type must be uniquely named, the DNS name, or what your customers will type in their browser, is the same: www.terraform plan
terraform apply # Make several requests to see both origins
for i in {1..4}; do
curl https://www.example.com
sleep 1
done Hello, this is 203.0.113.10!
Hello, this is 203.0.113.10!
Hello, this is 198.51.100.15!
Hello, this is 203.0.113.10! Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs) តំណពាក់ព័ន្ធ (docs Cloudflare)
2.Đối với Chuyển sang sử dụng sản phẩm Cloudflare của Load Balancing 2. Switch to using Cloudflare's Load Balancing product 2 ។ ការផ្លាស់ប្តូរទៅប្រើផលិតផល Cloudflare នៃ Load Balancing
Phần «Switch to using Cloudflare's Load Balancing product» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.
Read the "2. Switch to using Cloudflare's Load Balancing product" section below — open the official docs link for full screenshots and configuration tabs.
អានផ្នែក «2 ។ ការផ្លាស់ប្តូរទៅប្រើផលិតផល Cloudflare នៃ Load Balancing» ខាងក្រោម — បើកតំណ docs ផ្លូវការសម្រាប់រូបភាព និង tab កំណត់។
- Tạo một màn hình để chạy kiểm tra sức khỏe chống lại máy chủ nguồn của bạn.
- Tạo một nhóm một hoặc nhiều máy chủ nguồn sẽ nhận được lưu lượng truy cập cân bằng tải.
- Tạo load balancer với tên máy chủ bên ngoài – ví dụ,
www.example.com– và một hoặc nhiều nhóm.
- Create a monitor to run health checks against your origin servers.
- Create a pool of one or more origin servers that will receive load balanced traffic.
- Create a load balancer with an external hostname — for example,
www.example.com— and one or more pools.
- បង្កើតម៉ាស៊ីនត្រួតពិនិត្យដើម្បីដំណើរការការត្រួតពិនិត្យសុខភាពប្រឆាំងនឹងសេវាកម្មដើមរបស់អ្នក។
- បានបង្កើតក្រុមប្រឹក្សាភិបាលមួយឬច្រើននៃសេវាកម្មដើមមួយដែលនឹងទទួលបានការដឹកជញ្ជូនផ្ទុករលាយ។
- បានបង្កើត load balancer ជាមួយនឹងឈ្មោះក្រុមហ៊ុនផ្គត់ផ្គង់ខាងក្រៅ - ដូចជា
www.example.com- និងក្រុមមួយឬច្រើន។
www-origins với hai nguồn gốc được thêm vào nó:www-origins with two origins added to it:www-origins ជាមួយនឹងការបន្ថែមទីពីរទៅវា:www-us(203.0.113.10) #Ph0# (203.0.113.10)www-asia(198.51.100.15) #Ph0# (198.51.100.15)
www-us(203.0.113.10)www-asia(198.51.100.15)
www-us(203.0.113.10)www-asia(198.51.100.15)
www.example.com load balancer bên dưới, nó sẽ thay thế hai bản ghi www DNS mà bạn đã xác định trước đó. Một lợi thế của việc để lại các bản ghi DNS là nếu bạn tạm thời vô hiệu hóa load balancing, kết nối với tên máy chủ này vẫn có thể.www.example.com load balancer below, it will supersede the two www DNS records that you previously defined. One benefit of leaving the DNS records in place is that if you temporarily disable load balancing, connections to this hostname are still possible.www.example.com load balancer នៅខាងក្រោមនេះ, វាត្រូវបានផ្លាស់ប្តូរទាំងពីរ www DNS សៀវភៅដែលអ្នកបានកំណត់មុនពេលមុន។ អត្ថប្រយោជន៍មួយនៃការផ្លាស់ប្តូរប្រកាស DNS គឺថា ប្រសិនបើអ្នកផ្លាស់ប្តូរប្រកាស load balancing ដោយឥតគិតថ្លៃអ្នកអាចចូលទៅក្នុងប្រកាសនេះទេ។main.tf:main.tf:main.tf:# Health check monitor
resource "cloudflare_load_balancer_monitor" "health_check" {
account_id = var.account_id
expected_body = "alive"
expected_codes = "2xx"
method = "GET"
timeout = 5
path = "/health"
interval = 60
retries = 2
description = "Health check for www origins"
type = "https"
header = {
Host = ["${var.domain}"]
}
}
# Origin pool
resource "cloudflare_load_balancer_pool" "www_pool" {
account_id = var.account_id
name = "www-origins"
monitor = cloudflare_load_balancer_monitor.health_check.id
origins = [{
name = "www-us"
address = "203.0.113.10"
enabled = true
}, {
name = "www-asia"
address = "198.51.100.15"
enabled = true
}]
description = "Primary www server pool"
enabled = true
minimum_origins = 1
notification_email = "<YOUR_EMAIL>"
check_regions = ["WEU", "EEU", "WNAM", "ENAM", "SEAS", "NEAS"]
}
# Load balancer
resource "cloudflare_load_balancer" "www_lb" {
zone_id = var.zone_id
name = "www.${var.domain}"
default_pools = [cloudflare_load_balancer_pool.www_pool.id]
fallback_pool = cloudflare_load_balancer_pool.www_pool.id
description = "Load balancer for www.${var.domain}"
proxied = true
} terraform plan
terraform apply # Test load distribution with health monitoring
for i in {1..6}; do
echo "Request $i:"
curl -s https://www.example.com
sleep 2
done Request 1:
Hello, this is 198.51.100.15!
Request 2:
Hello, this is 203.0.113.10!
Request 3:
Hello, this is 198.51.100.15!
Request 4:
Hello, this is 203.0.113.10!
Request 5:
Hello, this is 203.0.113.10!
Request 6:
Hello, this is 198.51.100.15! git add main.tf
git commit -m "Step 4 - Create load balancer (LB) monitor, LB pool, and LB"
git push - Phân phối giao thông thông minh giữa các nguồn gốc
- Tự động định tuyến xung quanh các máy chủ không lành mạnh
- Cung cấp giám sát sức khỏe thời gian thực
- Distribute traffic intelligently between origins
- Automatically route around unhealthy servers
- Provide real-time health monitoring
- ការផ្គត់ផ្គង់ការដឹកជញ្ជូនដោយគួរឱ្យចាប់អារម្មណ៍រវាងដើម
- ការធ្វើដំណើរដោយស្វ័យប្រវត្តិនៅជុំវិញសេវាកម្មដែលមិនមានប្រសិទ្ធិភាព
- ការត្រួតពិនិត្យសុខភាពក្នុងអំឡុងពេលពិតប្រាកដ
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"item":{"@id":"/directory/","name":"Directory"}},{"@type":"ListItem","position":2,"item":{"@id":"/terraform/","name":"Terraform"}},{"@type":"ListItem","position":3,"item":{"@id":"/terraform/tutorial/","name":"Tutorials"}},{"@type":"ListItem","position":4,"item":{"@id":"/terraform/tutorial/use-load-balancing/","name":"4 – Improve performance"}}]} Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs) តំណពាក់ព័ន្ធ (docs Cloudflare)
Xem bản đầy đủ trên developers.cloudflare.com (ảnh, tab cấu hình). View the full guide on developers.cloudflare.com (images, config tabs). មើលមគ្គុទ្ទេសក៍ពេញលើ developers.cloudflare.com (រូបភាព, tab កំណត់)។
Tài liệu gốc ↗ Official docs ↗ ឯកសារផ្លូវការ ↗