Titirat Boonchuaychu

Titirat Boonchuaychu

Data Engineer Manager/ Data Architecture Manager Big Data Institute (Public Organization), BDI

บทความทั้งหมด

All Articles

Author Category Post Filter
รู้จักกับ ELK Stack เครื่องมือบริหารจัดการข้อมูลประวัติบันทึกการทำงาน (Log file) แบบรวมศูนย์
ELK Stack คืออะไร เพื่อน ๆ คนไหนเคยได้ยินคำว่า “ELK Stack” กันบ้าง ครั้งแรกที่ได้ยินรู้สึกเอ๊ะกันบ้างหรือเปล่าว่ามันคืออะไร มันมาจากไหน ใช้ทำอะไร… ทำไมคนถึงพูดถึงกัน บทความนี้จะพาเพื่อน ๆ มาทำความรู้จักกับเจ้า ELK Stack เพื่ออัปเดตเทคโนโลยีให้ตามทันโลกยุคดิจิทัลกันจ้า หากพูดถึงโลกยุคดิจิทัลที่ทุกอย่างถูกเติมเต็มด้วยเทคโนโลยีไม่ว่าจะเป็นเทคโนโลยีทางด้านการแพทย์ การเกษตร การท่องเที่ยว การสื่อสาร หรือแม้กระทั่งในชีวิตประจำวันที่เราสามารถแสกน QR โค้ดเพื่อชำระค่าสินค้า/บริการ ก็เป็นส่วนหนึ่งของเทคโนโลยี ด้วยเทคโนโลยีที่กระจายไปทุกหนแห่งทำให้เกิดการไหลเวียนของข้อมูลปริมาณมาก มีทั้งข้อมูลสำคัญ ข้อมูลที่รอการวิเคราะห์ รวมถึงการเชื่อมโยงข้อมูลเพื่อให้เกิดประโยชน์ ยกตัวอย่างเช่น ระบบเชื่อมโยงข้อมูลสุขภาพ Health Link ที่สามารถเชื่อมโยงข้อมูลประวัติการรักษาของคนไข้ระหว่างโรงพยาบาลต่าง ๆ ทั่วประเทศ หรือแม้แต่แอปพลิเคชันหรือระบบต่าง ๆ ที่มีการนำข้อมูลมาใช้ให้เกิดประโยชน์ นอกจากตัวเอกอย่างแอปพลิเคชันหรือระบบแล้ว สิ่งที่สำคัญอีกอย่างก็คือการดูแลระบบให้สามารถทำงานได้ตามปกติ สำหรับเครื่องมือที่ใช้ในการติดตาม ตรวจสอบการทำงานของระบบ (Monitoring) นั้นสามารถพบได้ทั่วไป แต่หากเป็นระบบที่มิได้ถูกติดตั้งบนระบบคลาวด์หรือเซิร์ฟเวอร์เพียงตัวเดียว การเข้าถึงเครื่องเพื่อตรวจสอบไฟล์บันทึกการทำงาน (Log file) และสถานะการทำงานของระบบคงไม่ใช่เรื่องง่าย ๆ อีกทั้งยังเสียแรงและเวลาในการเข้าถึงเครื่องต่าง ๆ ด้วยเหตุผลนี้จึงมีเครื่องมือที่จะสามารถช่วยคุณประหยัดแรงและเวลาในการเข้าถึงหลาย ๆ เครื่อง โดยการรวบรวมข้อมูลประวัติบันทึกการทำงาน (Log file) ไว้ที่ระบบกลาง เพื่อสะดวกต่อการติดตามและตรวจสอบการทำงานของระบบ เครื่องมือที่กล่าวมานั้นไม่ใช่สิ่งอื่นใด นั่นก็คือ ELK Stack นั่นเอง!!! ELK Stack เป็นเครื่องมือในการบริหารจัดการข้อมูลประวัติบันทึกการทำงานแบบรวมศูนย์ (Centralized Logging System) ซึ่งเป็นเครื่องมือที่ได้รับความนิยมอย่างมาก ประกอบด้วย Elasticsearch, Logstash, Kibana โดย Logstash ทำหน้าที่รองรับการนำเข้าข้อมูล ประมวลผลข้อมูลและบริหารจัดการข้อมูลไฟล์ Logs จากแหล่งต่าง ๆ สามารถคัดกรอง แปลงและเรียบเรียงข้อมูล (Parse, Filter, Transform) ก่อนส่งข้อมูลจัดเก็บลงฐานข้อมูล Elasticsearch ซึ่งเป็นฐานข้อมูล NoSQL และรองรับการทำงานแบบ Full-Text Search โดยสามารถ Query ข้อมูลจากฐานข้อมูล Elasticsearch เพื่อนำไปจัดทำและแสดงผลข้อมูลในรูปแบบ Data Visualization บนเครื่องมือ Kibana ได้ สำหรับกระบวนการขนส่งข้อมูลนั้นมีหลากหลายเครื่องมือที่ใช้ในการส่งข้อมูลไปยัง Logstash หรือ Elasticsearch ยกตัวอย่างเช่น สามารถใช้ Filebeat ที่เป็นเครื่องมือในการส่งข้อมูล Log file จากหลากหลายเครื่องไปยัง Logstash เพื่อรวบรวมข้อมูลดังกล่าวไว้ที่ระบบกลาง เป็นต้น มาถึงตรงนี้ใครอยากลองใช้งาน ELK Stack แล้วบ้าง สามารถลองทำตามขั้นตอนด้านล่างได้เลยจ้า ติดตั้ง ELK Stack ขั้นตอนที่ 1 เริ่มจากการติดตั้ง ELK Stack ซึ่งสามารถดาวน์โหลดไฟล์ docker-compose และ Configuration ได้จาก Repository ทั่วไป ในบทความนี้ดาวน์โหลดจาก https://github.com/deviantony/docker-elk โครงสร้างของ Repository และไฟล์ที่ใช้งานหลักๆ ประกอบด้วย ไฟล์ docker-compose.yml (based on github repository) มีการติดตั้ง Services ของ Elasticsearch, Logstash, Kibana โดยมีการเปิดใช้งาน Port ดังนี้ สำหรับการตั้งค่า ELK Stack เพิ่มเติมสามารถทำตามขั้นตอนดังต่อไปนี้ ขั้นตอนที่ 1.1 ทำการเพิ่ม Plugin logstash-input-beats เพื่อให้ Logstash สามารถเชื่อมต่อกับ Filebeat ได้ โดยเพิ่มคำสั่ง RUN logstash-plugin install logstash-input-beats ในไฟล์ Logstash Dockerfile ตามตัวอย่างด้านล่าง ขั้นตอนที่ 1.2 เพิ่มเติม/แก้ไข Logstash Pipeline ในไฟล์ logstash.conf โดยที่ตัวแปร input เป็นการกำหนดค่าการรับข้อมูลจาก filebeat ที่ port 5044 และส่งมายัง Logstash Pipeline เพื่อคัดกรอง แปลงและเรียบเรียงข้อมูล โดยข้อมูลที่ได้จาก Logstash จะอยู่ในรูปแบบ JSON และ output การส่งออกจะถูกจัดเก็บลงฐานข้อมูล Elasticsearch ที่มีกำหนดค่า hosts และ port เป็น elasticsearch:9200 ขั้นตอนที่ 1.3 เพิ่มการตั้งค่า port 5601 สำหรับ Kibana ในไฟล์ kibana.yml โดยหลังจากปรับการตั้งค่าเรียบร้อยแล้วให้รัน Container Services ขึ้นมาก็จะได้ Service ของ Elasticsearch, Logstash, Kibana ตามด้านล่าง สามารถเรียกดูข้อมูลใน Elasticsearch โดยใช้คำสั่ง ตัวอย่างข้อมูลที่ถูกจัดเก็บลงฐานข้อมูล Elasticsearch ในรูปแบบ JSON สามารถเข้าถึง Kibana ได้ที่ http://localhost:5601 (Server IP ที่ติดตั้ง Kibana) โดยตรวจสอบ Firewall และการเปิด port 5601 เพื่อให้สามารถเข้าถึง URL ดังกล่าว ติดตั้ง Filebeat ขั้นตอนที่ 2 การติดตั้ง Filebeat เพื่อส่งข้อมูล Log file ไปยัง Logstash สามารถทำตามขั้นตอนดังนี้ ขั้นตอนที่ 2.1 ดาวน์โหลด image ของ Filebeat โดยรันคำสั่ง ขั้นตอนที่ 2.2 เพิ่มเติม/แก้ไข การตั้งค่าในไฟล์ filebeat.yml โดยไปที่ตัวแปร filebeat.inputs เพื่อกำหนดที่อยู่ (paths) ของไฟล์ Log ที่จะถูกส่งจาก Filebeat ตัวอย่างเช่น /var/log/nginx/*.log ไปยัง Logstash โดยมีตัวแปร output.logstash ที่มีการกำหนดค่า...
13 June 2023
เชื่อมต่อ BigQuery ด้วย Python ใน 3 ขั้นตอน
การสำรองและกู้คืนข้อมูล PostgreSQL และการ sync ไฟล์ด้วย rsync แบบอัตโนมัติ
22 August 2022
ป้องกันไว้ดีกว่าแก้ สำรองข้อมูลไว้ก่อนหาย (PostgreSQL)
การสำรองและกู้คืนข้อมูล PostgreSQL และการ sync ไฟล์ด้วย rsync แบบอัตโนมัติ
31 January 2022
PDPA Icon

We use cookies to optimize your browsing experience and improve our website’s performance. Learn more at our Privacy Policy and adjust your cookie settings at Settings

Privacy Preferences

You can choose your cookie settings by turning on/off each type of cookie as needed, except for necessary cookies.

Accept all
Manage Consent Preferences
  • Strictly Necessary Cookies
    Always Active

    This type of cookie is essential for providing services on the website of the Personal Data Protection Committee Office, allowing you to access various parts of the site. It also helps remember information you have previously provided through the website. Disabling this type of cookie will result in your inability to use key services of the Personal Data Protection Committee Office that require cookies to function.
    Cookies Details

  • Performance Cookies

    This type of cookie helps the Big Data Institute (Public Organization) understand user interactions with its website services, including which pages or areas of the site are most popular, as well as analyze other related data. The Big Data Institute (Public Organization) also uses this information to improve website performance and gain a better understanding of user behavior. Although the data collected by these cookies is non-identifiable and used solely for statistical analysis, disabling them will prevent the Big Data Institute (Public Organization) from knowing the number of website visitors and from evaluating the quality of its services.

  • Functional Cookies

    This type of cookie enables the Big Data Institute (Public Organization)’s website to remember the choices you have made and deliver enhanced features and content tailored to your usage. For example, it can remember your username or changes you have made to font sizes or other customizable settings on the page. Disabling these cookies may result in the website not functioning properly.

  • Targeting Cookies

    "This type of cookie helps the Big Data Institute (Public Organization) understand user interactions with its website services, including which pages or areas of the site are most popular, as well as analyze other related data. The Big Data Institute (Public Organization) also uses this information to improve website performance and gain a better understanding of user behavior. Although the data collected by these cookies is non-identifiable and used solely for statistical analysis, disabling them will prevent the Big Data Institute (Public Organization) from knowing the number of website visitors and from evaluating the quality of its services.

Save settings
This site is registered on wpml.org as a development site. Switch to a production site key to remove this banner.