Professional Documents
Culture Documents
Logstash ດຶງຂມູ
ໍ້
ຂັນຕອນການເຮັ
ດ:
ໍ້
ຈະມ 3 ຂັນຕອນ
1
input {
jdbc {
jdbc_connection_string => "jdbc:mysql://localhost:3306/my_database"
jdbc_user => "root"
jdbc_password => ""
jdbc_driver_library => "D:\ELASTICSEARCH\logstash-conf\mysql-connector-
java-8.0.30.jar"
jdbc_driver_class => "com.mysql.cj.jdbc.Driver"
statement => "SELECT * FROM products"
}
}
User , password
filter {
grok {
match => {
}
}
}
ໍ້ ນ ຫລ ຈັດການ ID ຫ ລາຍລະອຽດ ບິ່ ໃຫໍ້ຊາກັ
ກອງຂມູ ໍ້ ນ ຖໍ້າເຄຍ pipeline ແລໍ້ວ
2
output {
elasticsearch {
hosts => ["localhost:9200"]
index => "testcsv"
user => "elastic"
password => "E2HC=MBvYnpnDe*ZUZTX"
}
stdout { codec => json_lines }
}
Password: ຂອງ ES
ໍ້
ຂັນຕອນ run file .conf
set TZ=Asia/Bangkok
D:\ELASTICSEARCH\logstash-8.9.1-windows-x86_64\logstash-8.9.1\bin\logstash -f
D:\ELASTICSEARCH\logstash-8.9.1-windows-x86_64\logstash-8.9.1\config\ຊິ່ ທິ່ ຕັງ.conf
ໍ້
3
Run ທິ່ ຢູິ່ໃນ folder bin > logstash -f
Use_column_value: ຕວດສອບການປິ່ຽນແປງ
Tracking_coloumn: ຕດຕາມການປິ່ຽນແປງ
Filter{}
4
Output: ແຕິ່ ລະແບບ
output {
elasticsearch {
hosts => ["localhost:9200"]
index => "testcsv"
user => "elastic"
password => "E2HC=MBvYnpnDe*ZUZTX"
document_id => "%{id}" # ใช้ค่า ID จาก SQL เป็นคีย์ของเอกสารใน
Elasticsearch
action => "create" # ใช้การสร้างเอกสารใน Elasticsearch
document_type => "_doc"
}
stdout { codec => json_lines }
}
ແບບກາລດ ID index ໃຫໍ້ ຕງກັບ ID SQL
output {
elasticsearch {
hosts => ["localhost:9200"]
index => "testcsv"
user => "elastic"
password => "E2HC=MBvYnpnDe*ZUZTX"
document_id => "%{id}" # ใช้ค่า ID จาก SQL เป็นคีย์ของเอกสารใน
Elasticsearch
action => "create" # ใช้การสร้างเอกสารใหม่ใน Elasticsearch
document_id => "%{id}" # ใช้ค่า ID จาก SQL เป็นคีย์ของเอกสารใน
Elasticsearch
}
stdout { codec => json_lines }
}
ແບບ index ສໍ້າງ ID ໃຫໍ້ 20 ໂຕ
5
output {
elasticsearch {
hosts => ["localhost:9200"]
index => "testcsv"
user => "elastic"
password => "E2HC=MBvYnpnDe*ZUZTX"
document_id => "%{id}" # ใช้ค่า ID จาก SQL เป็นคีย์ของเอกสารใน Elasticsearch
action => "update" # ใช้การอัปเดตเอกสารใน Elasticsearch
doc_as_upsert => true # ให้เพิ่มเอกสารใหม่หากไม่พบเอกสารที่ตรงกับ document_id
}
stdout { codec => json_lines }
}
ໍ້ ນໃນ SQL ແລໍ້ວ run .conf ຂມູ
ຖໍ້າ update ຂມູ ໍ້ ນໃນ index ກຈະປິ່ຽນແຕິ່ ID ເກິ່ າ
ສິ່ ວນ input {}
ສິ່ ວນ filter {}
ສິ່ ວນ output {}
ຫ check timezone TZ
jdk-20_windows-x64_bin.exe
jre-8u381-windows-x64.exe
6
logstash.yml
7
api.auth.basic.username: "logstash-user"
api.auth.basic.password: "s3cUreP4$$w0rD"
8
กําหนดค่าอินสแตนซ์ Logstash ของคุณเพื่อใช้ปลั๊กอินอินพุต Beats
beats {
port => "5044"
}
คุณจะกําหนดค่า Logstash ให้เขียนไปยัง Elasticsearch ในภายหลัง สําหรับ
ตอนนี้คุณสามารถเพิ่มบรรทัดต่อไปนี้ ไปยังส่วนเพื่อให้ผลลัพธ์ถูกพิมพ์ไปยัง stdout เมื่อ
คุณเรียกใช้ Logstash:output
stdout { codec => rubydebug }
เมื่อคุณทําเสร็จแล้วเนื้อหาของควรมีลักษณะดังนี้:first-pipeline.conf
input {
beats {
port => "5044"
}
}
# The filter part of this file is commented out to indicate that it is
# optional.
# filter {
#
# }
output {
stdout { codec => rubydebug }
}
Run
D:\ELASTICSEARCH\logstash-8.9.1-windows-
x86_64\logstash-8.9.1\bin\logstash -f
D:\ELASTICSEARCH\logstash-8.9.1-windows-
9
x86_64\logstash-8.9.1\bin\first-pipeline.conf --
config.test_and_exit
ตัวเลือกจะแยกวิเคราะห์ไฟล์การกําหนดค่าของคุณและรายงานข้อผิดพลาดใดๆ--
config.test_and_exit
D:\ELASTICSEARCH\logstash-8.9.1-windows-
x86_64\logstash-8.9.1\bin\logstash -f
D:\ELASTICSEARCH\logstash-8.9.1-windows-
x86_64\logstash-8.9.1\bin\first-pipeline.conf --
config.reload.automatic
ตัวเลือกเปิดใช้งานการโหลด config อัตโนมัติเพื่อที่คุณจะได้ไม่ต้องหยุดและรีสตาร์ท
Logstash ทุกครั้งที่คุณแก้ไขไฟล์การกําหนดค่า--config.reload.automatic
10