คู่มือการติดตั้ง OpenSearch บน Ubuntu Server 24.04 LTS
Installation Guide: OpenSearch 3.x on Ubuntu Server 24.04 LTS
เอกสารคู่มือการติดตั้งและตั้งค่าระบบ OpenSearch พร้อม OpenSearch Dashboards
ประเภทเอกสาร: Technical Installation Manual
ระบบปฏิบัติการ: Ubuntu Server 24.04 LTS
ซอฟต์แวร์: OpenSearch 3.x
วิธีติดตั้ง: APT Repository
วันที่จัดทำ: พฤศจิกายน 2569
1. วัตถุประสงค์
เอกสารฉบับนี้จัดทำขึ้นเพื่ออธิบายขั้นตอนการติดตั้ง OpenSearch บน Ubuntu Server 24.04 LTS โดยครอบคลุมการเตรียมระบบ การติดตั้ง การกำหนดค่าพื้นฐาน การเริ่มต้นบริการ และการตรวจสอบการทำงาน
OpenSearch เป็นระบบค้นหาและวิเคราะห์ข้อมูลแบบ Open Source สามารถนำไปประยุกต์ใช้กับระบบ Log Monitoring, Application Search, Security Analytics และการจัดเก็บข้อมูลเพื่อการค้นหา
2. ข้อมูลและความต้องการของระบบ
| รายการ | รายละเอียด |
|---|---|
| Operating System | Ubuntu Server 24.04 LTS |
| Architecture | x86_64 |
| OpenSearch | 3.x |
| OpenSearch Dashboards | 3.x |
| RAM | แนะนำ 8 GB ขึ้นไป |
| CPU | 2 vCPU ขึ้นไป |
| Disk | 30 GB ขึ้นไป |
| REST API | TCP 9200 |
| Node Communication | TCP 9300 |
| Dashboards | TCP 5601 |
หมายเหตุ: ทรัพยากรระบบจริงขึ้นอยู่กับปริมาณข้อมูล จำนวน Index และจำนวนผู้ใช้งาน
3. เตรียมความพร้อม Ubuntu Server
เข้าสู่ระบบ Ubuntu Server ด้วยบัญชีที่มีสิทธิ์ sudo
ตรวจสอบเวอร์ชันระบบปฏิบัติการ
lsb_release -a
อัปเดตแพ็กเกจระบบ
sudo apt update
sudo apt upgrade -y
ติดตั้ง Dependencies
sudo apt install -y curl wget gnupg2 ca-certificates lsb-release
4. ติดตั้ง OpenSearch
4.1 เพิ่ม GPG Key
สร้าง Directory สำหรับจัดเก็บ Repository Key
sudo mkdir -p /etc/apt/keyrings
ดาวน์โหลดและเพิ่ม GPG Key
curl -fsSL https://artifacts.opensearch.org/publickeys/opensearch-release.pgp | sudo gpg --dearmor -o /etc/apt/keyrings/opensearch.gpg
4.2 เพิ่ม OpenSearch Repository
เพิ่ม Repository ของ OpenSearch 3.x
echo "deb [signed-by=/etc/apt/keyrings/opensearch.gpg] https://artifacts.opensearch.org/releases/bundle/opensearch/3.x/apt stable main" | sudo tee /etc/apt/sources.list.d/opensearch-3.x.list
อัปเดตรายการแพ็กเกจ
sudo apt update
4.3 ติดตั้ง OpenSearch
กำหนดรหัสผ่าน 8 อักระสำหรับผู้ดูแลระบบ
sudo env OPENSEARCH_INITIAL_ADMIN_PASSWORD='Passwordroot123' apt install -y opensearch
หมายเหตุ: เปลี่ยนรหัสผ่านตัวอย่างเป็นรหัสผ่านจริงที่มีความปลอดภัย โดยต้องมีตัวพิมพ์ใหญ่ ตัวพิมพ์เล็ก ตัวเลข และอักขระพิเศษ
5. ตั้งค่า OpenSearch
แก้ไขไฟล์ Configuration
sudo vi /etc/opensearch/opensearch.yml
กำหนดค่าพื้นฐานสำหรับ Single Node
cluster.name: my-cluster
node.name: node-1
network.host: 127.0.0.1
http.port: 9200
discovery.type: single-node
รายละเอียดการตั้งค่า
- cluster.name: ชื่อ Cluster
- node.name: ชื่อ Node
- network.host: IP Address ที่ใช้รับการเชื่อมต่อ
- http.port: Port สำหรับ REST API
- discovery.type: กำหนดรูปแบบ Single Node
บันทึกไฟล์และออกจากโปรแกรมแก้ไข
6. ตั้งค่า JVM Memory
แก้ไขไฟล์ JVM Options
sudo vi /etc/opensearch/jvm.options
ตัวอย่างสำหรับเครื่องที่มี RAM 8 GB
-Xms4g
-Xmx4g
กำหนดค่า Heap Memory ให้เหมาะสมกับทรัพยากรเครื่อง โดยทั่วไปเริ่มต้นที่ประมาณ 50% ของ RAM และต้องเหลือ RAM สำหรับระบบปฏิบัติการและงานอื่นด้วย
7. เริ่มต้นบริการ OpenSearch
กำหนดให้บริการเริ่มต้นพร้อมระบบปฏิบัติการ
เริ่มต้นบริการ
sudo systemctl start opensearch
ตรวจสอบสถานะ
sudo systemctl status opensearch
หากแสดงสถานะ Active (running) หมายถึงบริการเริ่มทำงานเรียบร้อยแล้ว
8. ทดสอบการทำงาน OpenSearch
ทดสอบ REST API ผ่าน CURL
curl -k -u admin:'YourStrongPassword123!' https://localhost:9200
ตัวอย่างผลลัพธ์
{
"name": "node-1",
"cluster_name": "my-cluster",
"version": {
"distribution": "opensearch",
"number": "3.x.x"
},
"tagline": "The OpenSearch Project"
}
ตรวจสอบ Cluster Health
curl -k -u admin:'YourStrongPassword123!' https://localhost:9200/_cluster/health?pretty
ตรวจสอบ Node
curl -k -u admin:'YourStrongPassword123!' https://localhost:9200/_cat/nodes?v
ตรวจสอบ Index
curl -k -u admin:'YourStrongPassword123!' https://localhost:9200/_cat/indices?v
9. ติดตั้ง OpenSearch Dashboards
OpenSearch Dashboards เป็น Web Interface สำหรับบริหารจัดการและแสดงผลข้อมูลจาก OpenSearch
9.1 เพิ่ม Repository
echo "deb [signed-by=/etc/apt/keyrings/opensearch.gpg] https://artifacts.opensearch.org/releases/bundle/opensearch-dashboards/3.x/apt stable main" | sudo tee /etc/apt/sources.list.d/opensearch-dashboards-3.x.list
อัปเดตรายการแพ็กเกจ
sudo apt update
9.2 ติดตั้ง Dashboards
sudo apt install -y opensearch-dashboards
9.3 ตั้งค่า Dashboards
แก้ไข Configuration
sudo nano /etc/opensearch-dashboards/opensearch_dashboards.yml
กำหนดค่าดังนี้
server.host: "127.0.0.1"
server.port: 5601
opensearch.hosts: ["https://localhost:9200"]
opensearch.username: "kibanaserver"
opensearch.password: "REPLACE_WITH_CONFIGURED_PASSWORD"
หมายเหตุ: ต้องใช้รหัสผ่านของผู้ใช้ kibanaserver ที่ตั้งค่าไว้ใน OpenSearch Security Configuration ไม่ใช่รหัสผ่าน admin
9.4 เริ่มต้น Dashboards
sudo systemctl enable opensearch-dashboards
sudo systemctl start opensearch-dashboards
ตรวจสอบสถานะ
sudo systemctl status opensearch-dashboards
เข้าถึง Web Interface ผ่าน Browser
http://localhost:5601
หากติดตั้งบน Server ระยะไกล ให้กำหนด Server Host และการเชื่อมต่อผ่าน HTTPS/Reverse Proxy ตามความเหมาะสม
10. การตรวจสอบและจัดการ Service
| รายการ | คำสั่ง |
|---|---|
| Start OpenSearch | sudo systemctl start opensearch |
| Stop OpenSearch | sudo systemctl stop opensearch |
| Restart OpenSearch | sudo systemctl restart opensearch |
| Status OpenSearch | sudo systemctl status opensearch |
| Start Dashboards | sudo systemctl start opensearch-dashboards |
| Restart Dashboards | sudo systemctl restart opensearch-dashboards |
| Status Dashboards | sudo systemctl status opensearch-dashboards |
ตรวจสอบ Log
sudo journalctl -u opensearch -f
ตรวจสอบ Log Dashboards
sudo journalctl -u opensearch-dashboards -f
11. การแก้ไขปัญหาเบื้องต้น (Troubleshooting)
ปัญหา 1: OpenSearch ไม่สามารถ Start ได้
ตรวจสอบ Log
sudo journalctl -u opensearch -xe
ตรวจสอบ Configuration
sudo nano /etc/opensearch/opensearch.yml
ปัญหา 2: Memory ไม่เพียงพอ
ตรวจสอบ Memory
free -h
ตรวจสอบ JVM Heap
sudo nano /etc/opensearch/jvm.options
ปัญหา 3: ไม่สามารถเชื่อมต่อ Port 9200
ตรวจสอบ Port
sudo ss -tulpn | grep 9200
ตรวจสอบ Firewall
sudo ufw status
ปัญหา 4: Dashboards ไม่สามารถเชื่อมต่อ OpenSearch
ตรวจสอบว่า OpenSearch ทำงานอยู่
sudo systemctl status opensearch
ตรวจสอบการเชื่อมต่อ
curl -k -u admin:'YourStrongPassword123!' https://localhost:9200
ตรวจสอบ Username และ Password ของ Service Account ที่ใช้เชื่อมต่อ
12. การรักษาความปลอดภัย
ข้อควรปฏิบัติสำหรับการใช้งานจริง
- เปลี่ยนรหัสผ่านเริ่มต้นทั้งหมด
- ใช้ TLS Certificate ที่ถูกต้อง ไม่ใช้ Demo Certificate
- จำกัดการเข้าถึง Port 9200 และ 9300 ด้วย Firewall
- ไม่เปิด REST API สู่ Internet โดยตรง
- สำรองข้อมูล Index และ Snapshot อย่างสม่ำเสมอ
- กำหนดสิทธิ์ผู้ใช้งานตามหน้าที่
- ตรวจสอบ Log และสถานะระบบอย่างสม่ำเสมอ
13. สรุปผลการติดตั้ง
เมื่อดำเนินการตามขั้นตอนทั้งหมดเรียบร้อยแล้ว ระบบจะประกอบด้วย
- Ubuntu Server 24.04 LTS
- OpenSearch 3.x
- OpenSearch Dashboards 3.x
- OpenSearch REST API Port 9200
- OpenSearch Dashboards Port 5601
ผู้ดูแลระบบสามารถใช้ OpenSearch สำหรับจัดเก็บ ค้นหา และวิเคราะห์ข้อมูล รวมถึงบริหารจัดการผ่าน OpenSearch Dashboards
14. เอกสารอ้างอิง
- OpenSearch Official Documentation – Installing OpenSearch on Debian/Ubuntu
https://docs.opensearch.org/latest/install-and-configure/install-opensearch/debian/ - OpenSearch Dashboards Installation
https://docs.opensearch.org/latest/install-and-configure/install-dashboards/debian/ - OpenSearch Official Download
https://opensearch.org/downloads/
ไม่มีความคิดเห็น:
แสดงความคิดเห็น