* 2023.12.21 ์ ๋ฐ์ดํธ - Docker ELK๋ก PostgreSQL๊ณผ Elastic Stack ์ฐ๋ ํฌ์คํ
์ด์ ํฌ์คํ ์ ๋จผ์ ์ธ๊ธํ๋ค์ถ์ด RDBMS์ Elasticsearch๋ฅผ ์ ์ฉํ๊ธฐ ์ํ ๋ฐฉ๋ฒ์ ๊ฒ์ํ์ ๋ ๊ฐ์ฅ ๋ง์ด ์ถ์ฒํ๋ ๋ฐฉ๋ฒ์ด Logstash๋ฅผ ์ด์ฉํ ๋ชจ๋ํฐ๋ง์ด์๋ค.
RDBMS์ ๋ณํ๋ฅผ ์ฃผ๊ธฐ์ ์ผ๋ก ๋ชจ๋ํฐ๋งํด์ Elastic Stack์ ์ฌ๋ ค์ฃผ๋ฉด Elasticsearch๋ฅผ ๊ทธ ์์์ ์ฌ์ฉํ ์ ์๋๋ก ํ๋ ๋ฐฉ๋ฒ์ธ ๊ฒ ๊ฐ๋ค. ๋ฐ๋ผ์ ์ด๋ฒ ํฌ์คํ ์์๋ JDBC input plugin์ logstash์ ์ฌ์ฉํด์ RDBMS์ ๋ฐ์ดํฐ๋ฅผ ์ฃผ๊ธฐ์ ์ผ๋ก ๋ฐ์์์! kibana์์ ๋ฐ์ดํฐ๋ฅผ ํ์ธํ๋ ๊ฒ๊น์ง ๋ฌ๋ ค๋ณด๋๋ก ํ๊ฒ ๋ค.
๋ฏธ๋ฆฌ ๋ง์๋๋ฆฌ์ง๋ง ๊ฑฐ์ ์ฝ์ง๋ก๊ทธ์ด๋ค.
1. RDBMS ์ค์
๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ฌ RDBMS๊ฐ ์์ด์ผํ๋ค. ๋๋ postgres๋ฅผ ์ฌ์ฉํ๊ณ ์์ผ๋ฏ๋ก, ๋ฐ๋ชจ๋ก ๋ง๋ค์ด๋ ๊ฒ์ํ DB๋ฅผ ์ฌ์ฉํ ๊ฒ์ด๋ค. ๋ณ๋ก ๋ฐ์ดํฐ๊ฐ ๋ง์ง๋ ์๋ค.
pgAdmin์์ ์ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋ง๋ค์ด์ค๋ค.
๋ฐ์ดํฐ๋ฒ ์ด์ค ์ด๋ฆ๋ง ์ ํ๋ฉด ๋๋ค. ๊ทธ๋ฆฌ๊ณ ๋์shemes ํ์์ Tables์์ ์ฐํด๋ฆญํด์ table์ ํ๋ ๋ง๋ค์ด์ค๋ค. ๋ด๊ฐ ์ฌ์ฉํ๊ณ ์๋ ํ ์ด๋ธ์ ๊ฐ๋จํ ํฌ์คํ ๋ ๊ธ์ ๋ฐ์ดํฐ๋ฅผ ํํํ๊ณ ์๋ค. column ์ค์ ์ ์ฌ์ง์ฒ๋ผ ํ๋ค.
๊ทธ๋ฆฌ๊ณ ๋์ถฉ ๋ฐ์ดํฐ ๋ช ๊ฐ๋ฅผ ๋ฃ์ด์ค๋ค.
์ด ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ fastapi๋ก ๊ฐ๋จํ๊ฒ ๋ง๋ ์น ์๋น์ค๋ ์ฐ๋์ด ๋์ด ์์ด์
์ด ๋ชน์ ๋์ถฉ๋ง๋ localhost ์ฌ์ดํธ์์ add new ๋๋ฅด๊ณ postingํ๋ฉด ๋ฐ์ดํฐ๊ฐ ์์ธ๋ค. ๋์ค์ ๋ชจ๋ํฐ๋ง ํ ์คํธํ ๋ ํ์ธํด๋ณด๋๋ก ํ๊ฒ ๋ค.
2. JDBC ๋๋ผ์ด๋ฒ ์ค์น
์ฌ์ฉํ๋ ค๋ RDBMS์ ๋ง๋ JDBC ๋๋ผ์ด๋ฒ๋ฅผ ์ค์นํด์ผํ๋ค. ๋๋ postgreSQL์ ์ฌ์ฉํ๋ฏ๋ก postgreSQL JDBC driver๋ผ๊ณ ์น๋ฉด ์ค์นํ ์ ์๋ ์ฌ์ดํธ๊ฐ ๋์จ๋ค.
JDK 17์ ์ฌ์ฉ์ค์ธ ๋ด ๊ธฐ์ค 42.6.0 ๋ฒ์ ์ ์ฌ์ฉํ๊ณ ์๋ค. jar ํ์ผ ๋ค์ด๋ก๋๊ฐ ์๋ฃ๋๋ฉด, logstash ์ค์น๊ฒฝ๋ก์ logstash-core\lib\jars ์ ์ฎ๊ฒจ์ค๋ค. ํน์๋ jar ํ์ผ์ด ๋น์ด์์ง๋ ์์์ง ์ ๋ณด๊ณ ๋ฃ์ด์ค์ผํ๋ค.
์ด๋ฌ๋ฉด ๋๋ผ์ด๋ธ ์ค์น๋ ๋์ด๋ค. ์์ถํ๊ฑฐ๋ ํ ํ์ ์๋ค. ์ด์ config ํ์ผ์ ์์ฑํด๋ณด์.
3. Logstash config ํ์ผ ์์ฑ
input {
jdbc {
jdbc_driver_library => "C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/logstash-core/lib/jars/postgresql-42.6.0.jar"
jdbc_driver_class => "org.postgresql.Driver"
jdbc_connection_string => "jdbc:postgresql://localhost:5432/{database_name}"
jdbc_user => "{username}"
jdbc_password => "{password}"
schedule => "* * * * *"
statement => "select * from contents"
}
}
output {
elasticsearch {
hosts => ["https://localhost:9200"]
}
stdout { codec => rubydebug }
}
๋ ๋ค ์ฝ๋๋ถํฐ ๋์ง๊ณ ์ค๋ช ํ๊ธฐ.
a. input
์ฐ์ input์ jdbc input plugin์ ํ์ฉํด์ postgres์์ ๋ฐ์ดํฐ๋ฅผ ์ฝ์ด์ค๋ ๊ฒ์ด input์ด ๋ ๊ฒ์ด๋ค.
- jdbc_driver_library์ ์๊น ๋ค์ด๋ก๋ํ JDBC Driver์ ์ ๋๊ฒฝ๋ก๋ฅผ ๋ฃ์ด์ค๋ค.
- ์ ๋๊ฒฝ๋ก๋ก ์ก์์ฃผ์ง ์์ผ๋ฉด ์๋์ ๊ฐ์ ๊ธธ๊ณ ๋ฌด์๋ฌด์ํ ์๋ฌ๋ฅผ ๋ง๋๋ค.
- ์์ฝํ๋ฉด unable to load postgresql-42.6.0.jar from :jdbc_driver_library, file not readable. ๋ชป ์ฝ์ด์จ๋ค๋ ๊ฑฐ๋ค.
[2023-06-27T16:57:08,718][ERROR][logstash.javapipeline ][main]
Pipeline error {
:pipeline_id=>"main",
:exception=>#<LogStash::PluginLoadingError:
unable to load postgresql-42.6.0.jar from :jdbc_driver_library,
file not readable (please check user and group permissions for the path)>,
:backtrace=>[
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/logstash-integration-jdbc-5.4.3/lib/logstash/plugin_mixins/jdbc/common.rb:59:in `block in load_driver_jars'",
"org/jruby/RubyArray.java:1865:in `each'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/logstash-integration-jdbc-5.4.3/lib/logstash/plugin_mixins/jdbc/common.rb:54:in `load_driver_jars'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/logstash-integration-jdbc-5.4.3/lib/logstash/plugin_mixins/jdbc/common.rb:34:in `load_driver'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/logstash-integration-jdbc-5.4.3/lib/logstash/inputs/jdbc.rb:307:in `register'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/logstash-mixin-ecs_compatibility_support-1.3.0-java/lib/logstash/plugin_mixins/ecs_compatibility_support/target_check.rb:48:in `register'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/logstash-core/lib/logstash/java_pipeline.rb:237:in `block in register_plugins'",
"org/jruby/RubyArray.java:1865:in `each'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/logstash-core/lib/logstash/java_pipeline.rb:236:in `register_plugins'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/logstash-core/lib/logstash/java_pipeline.rb:395:in `start_inputs'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/logstash-core/lib/logstash/java_pipeline.rb:320:in `start_workers'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/logstash-core/lib/logstash/java_pipeline.rb:194:in `run'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/logstash-core/lib/logstash/java_pipeline.rb:146:in `block in start'"],
"pipeline.sources"=>["C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/bin/test.conf"],
:thread=>"#<Thread:0x33d68228@C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/logstash-core/lib/logstash/java_pipeline.rb:134 run>"}
- jdbc_driver_class๋ ๊ฐ RDBMS์ ๋ง๋ driver class๋ฅผ ๋ฃ์ด์ค๋ค.
- jdbc_connection_string์ ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฃผ์๋ฅผ ๋ฃ์ด์ฃผ๋๋ฐ, postgres๋ 5432 port์ด๋ค.
- jdbc_user๊ณผ jdbc_password๋ pgAdmin ๋ค์ด๊ฐ์ ๋ ์ ์ผ ๋จผ์ ์น๋ admin user์ด๋ฆ๊ณผ ๋น๋ฐ๋ฒํธ๋ก ์ค์ ํด์ค๋ค.
- schedule์ ์ง๊ธ์ ์ ๊ฒฝ์ธ ๊ฑฐ ์๋ค.
- statement๋ query๋ฌธ์ ์์ฑํด์ค๋ค.
b. output
output์ elasticsearch์ console ํ์ค ์ถ๋ ฅ์ผ๋ก ๋ฃ์ด์ ๋ฐ์ดํฐ๊ฐ ์ ๋ฝํ๋์ค๋์ง ํ์ธํด๋ณผ ๊ฒ์ด๋ค. elasticsearch์ host ์๋ฒ ์ฃผ์๋ฅผ ๋ฃ์ด์ค๋ค.
์ฌ๊ธฐ๊น์ง ์ฐ๊ณ ์คํํด๋ณด์.
.\bin\logstash.bat -f .\config\test.conf
์คํํด๋ณด๋ฉด ๋์ ํ๋ฅ ๋ก ์คํ์ด ์๋ฌ๋ฅผ ๋ง๋๋ค. ํด.. ๋๋ฒ๊น ์ ์์์ด๋ค.
C. DisallowedClass: Tried to load unspecified class: Time ํด๊ฒฐ ๋ฐฉ๋ฒ
- data/plugins/inputs/jdbc ๊ฒฝ๋ก ์๋ logstash_jdbc_last_run ํ์ผ์ ์ง์์ฃผ๊ณ ์๋ก ์คํํด์ผ ํ๋ค. ํน์๋ํด์...
[2023-06-28T11:47:21,480][ERROR][logstash.javapipeline ][main]
Pipeline error {
:pipeline_id=>"main",
:exception=>#<Psych::DisallowedClass: Tried to load unspecified class: Time>,
:backtrace=>[
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/psych-5.1.0-java/lib/psych/class_loader.rb:99:in `find'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/psych-5.1.0-java/lib/psych/class_loader.rb:28:in `load'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/psych-5.1.0-java/lib/psych/scalar_scanner.rb:116:in `parse_time'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/psych-5.1.0-java/lib/psych/scalar_scanner.rb:59:in `tokenize'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/psych-5.1.0-java/lib/psych/visitors/to_ruby.rb:69:in `deserialize'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/psych-5.1.0-java/lib/psych/visitors/to_ruby.rb:130:in `visit_Psych_Nodes_Scalar'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/venpt'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/psych-5.1.0-java/lib/psych/visitors/to_ruby.rb:35:in `accept'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/psych-5.1.0-java/lib/psych/visitors/to_ruby.rb:320:in `visit_Psych_Nodes_Document'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/psych-5.1.0-java/lib/psych/visitors/visitor.rb:30:in `visit'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/psych-5.1.0-java/lib/psych/visitors/visitor.rb:6:in `accept'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/psych-5.1.0-java/lib/psych/visitors/to_ruby.rb:35:in `accept'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/psych-5.1.0-java/lib/psych.rb:334:in `safe_load'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/psych-5.1.0-java/lib/psych.rb:369:in `load'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/logstash-integration-jdbc-5.4.3/lib/logstash/plugin_mixins/jdbc/value_tracking.rb:115:in `read'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/logstash-integration-jdbc-5.4.3/lib/logstash/plugin_mixins/jdbc/value_tracking.rb:48:in `common_set_initial'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/logstash-integration-jdbc-5.4.3/lib/logstash/plugin_mixins/jdbc/value_tracking.rb:87:in `set_initial'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/logstash-integration-jdbc-5.4.3/lib/logstash/plugin_mixins/jdbc/value_tracking.rb:31:in `initialize'",
"org/jruby/RubyClass.java:890:in `new'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/logstash-integration-jdbc-5.4.3/lib/logstash/plugin_mixins/jdbc/value_tracking.rb:19:in `build_last_value_tracker'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/logstash-integration-jdbc-5.4.3/lib/logstash/inputs/jdbc.rb:285:in `register'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/logstash-mixin-ecs_compatibility_support-1.3.0-java/lib/logstash/plugin_mixins/ecs_compatibility_support/target_check.rb:48:in `register'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/logstash-core/lib/logstash/java_pipeline.rb:237:in `block in register_plugins'",
"org/jruby/RubyArray.java:1865:in `each'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/logstash-core/lib/logstash/java_pipeline.rb:236:in `register_plugins'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/logstash-core/lib/logstash/java_pipeline.rb:395:in `start_inputs'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/logstash-core/lib/logstash/java_pipeline.rb:320:in `start_workers'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/logstash-core/lib/logstash/java_pipeline.rb:194:in `run'",
"C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/logstash-core/lib/logstash/java_pipeline.rb:146:in `block in start'"],
"pipeline.sources"=>["C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/config/test.conf"],
:thread=>"#<Thread:0x276aa43a@C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/logstash-core/lib/logstash/java_pipeline.rb:134 run>"}
4. Logstash ์ Elastic ์ฌ์ด์ ๋ณด์ ๊ธฐ๋ฅ(authentication and TLS) ๋ฌธ์ ํด๊ฒฐํ๊ธฐ
๋ ๊ฐ์ง ์๋ฌ๊ฐ ๋ฐ์ํ ์ ์๋ค.
- elasticsearch.yml ํ์ผ์ xpack security ํญ๋ชฉ์ ์ ๋ถ false๋ก ์คํํ๋ ๊ฒฝ์ฐ
- elasticsearch.yml ํ์ผ์ xpack security ํญ๋ชฉ์ ์ ๋ถ true๋ก ์คํํ๋ ๊ฒฝ์ฐ
1๋ฒ์ ๊ฒฝ์ฐ kibana์์ ๋ฌธ์ ๊ฐ ์๊ธด๋ค.
FATAL Error: [config validation of [server].ssl]: must specify [certificate] and [key] -- or [keystore.path] -- when ssl is enabled
2๋ฒ์ ๊ฒฝ์ฐ logstash์์ ๋ฌธ์ ๊ฐ ์๊ธด๋ค.
[2023-06-28T14:26:08,204][INFO ][logstash.outputs.elasticsearch][main] Failed to perform request {:message=>"localhost:9200 failed to respond", :exception=>Manticore::ClientProtocolException, :cause=>#<Java::OrgApacheHttp::NoHttpResponseException: localhost:9200 failed to respond>}
[2023-06-28T14:26:08,205][WARN ][logstash.outputs.elasticsearch][main] Attempted to resurrect connection to dead ES instance, but got an error {:url=>"http://elastic:xxxxxx@localhost:9200/", :exception=>LogStash::Outputs::ElasticSearch::HttpClient::Pool::HostUnreachableError, :message=>"Elasticsearch Unreachable: [http://localhost:9200/][Manticore::ClientProtocolException] localhost:9200 failed to respond"}
2๋ฒ์ ๊ฒฝ์ฐ์๋ kibana์ elastic ์ฌ์ด์์๋ ๋ฌธ์ ๊ฐ ์๋ค. localhost:5601๋ก ์ ์ํ๋ฉด kibana์ ๋ค์ด๊ฐ ์ ์๋ค. ์ด ์ํ๋ฅผ ๊ธฐ์ค์ผ๋ก! logstash์ ๊ถํ์ ์ฃผ์ด์ผํ๋ค. Logstash ๊ณต์๋ฌธ์์ ํด๊ฒฐ ๋ฐฉ๋ฒ์ด ์จ์๊ธฐ๋ ํ๋ค. ์ฐฌ์ฐฌํ ๋ฐ๋ผ๊ฐ๋ณด๋๋ก ํ๊ฒ ๋ค.
A. ํ์ฌ yaml ํ์ผ ์ ๊ฒ
- kibana.yml
server.port: 5601
server.host: "localhost"
server.publicBaseUrl: "<https://{ip_address}:5601>"
elasticsearch.hosts: ["<https://{ip_address}:9200>"]
elasticsearch.serviceAccountToken: {service token}
elasticsearch.ssl.certificateAuthorities:
['C:\\kibana\\kibana-8.8.1\\data\\ca_1687845426792.crt']
xpack.fleet.outputs:
[
{
id: fleet-default-output,
name: default,
is_default: true,
is_default_monitoring: true,
type: elasticsearch,
hosts: ["<https://{ip_address}:9200>"],
ca_trusted_fingerprint: {fingerprint},
},
]
- elasticsearch.yml
xpack.security.enabled: true
xpack.security.enrollment.enabled: true
xpack.security.http.ssl:
enabled: true
keystore.path: certs/http.p12
xpack.security.transport.ssl:
enabled: true
verification_mode: certificate
keystore.path: certs/transport.p12
truststore.path: certs/transport.p12
cluster.initial_master_nodes: ["DESKTOP-85ERSCL"]
http.host: 0.0.0.0
- logstash.yml
xpack.monitoring.enabled: false
xpack.monitoring.elasticsearch.username: elastic
xpack.monitoring.elasticsearch.password: elastic
xpack.monitoring.elasticsearch.ssl.certificate_authority: "C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/config/certs/http_ca.crt"
- xpack.monitoring.enabled ์ต์ ์ fasle๋ก ์ง์ ํ๋๋ฐ ๋ค๊ฐ ์๋ํ๋…๋ผ๊ณ ๋ฌผ์ผ์๋ฉด ์์ง ๋๋ ์ ๋ชจ๋ฅด๊ฒ ๋ค.
B. elasticsearch์ security certificates and keys ๋ฅผ ๋ฐ๋ผ xpack ๊ด๋ จ keystore ์ป๊ธฐ
Start the Elastic Stack with security enabled automatically | Elasticsearch Guide [8.8] | Elastic
- http.p12
bin/elasticsearch-keystore show xpack.security.http.ssl.keystore.secure_password
- transport.p12
bin/elasticsearch-keystore show xpack.security.transport.ssl.keystore.secure_password
์ ๋ ๊ฐ๋ฅผ ์คํํ๋ฉด elasticsearch/config์ ์ธ์ฆ์๊ฐ ์์ฑ๋๋ค. http.p12์ transport.p12 ์ธ์ฆ์ + http_ca.crt๋ฅผ elastic/config/certs๋ก ์ด๋์ํจ๋ค.
๊ทธ๋ฆฌ๊ณ logstash์ elasticsearch output plugin์์ cacert์ ์ธ์ฆ์ ๊ฒฝ๋ก๋ฅผ ์ถ๊ฐํ๋ค.
input {
jdbc {
jdbc_driver_library => "C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/logstash-core/lib/jars/postgresql-42.6.0.jar"
jdbc_driver_class => "org.postgresql.Driver"
jdbc_connection_string => "jdbc:postgresql://localhost:5432/postgres"
jdbc_user => "postgres"
jdbc_password => "keti1234"
schedule => "* * * * *"
statement => "select test1, test2, test3 from tn_test"
}
}
output {
elasticsearch {
hosts => ["https://localhost:9200"]
cacert => 'C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/config/certs/http_ca.crt'
ssl => true
}
stdout { codec => rubydebug }
}
๋ค์ logstash๋ฅผ ์คํํด๋ณด๋ฉด ์๋ฌ ๋ฉ์ธ์ง๊ฐ ๋ฐ๋์๋ค.
[2023-06-28T15:07:36,086][WARN ][logstash.outputs.elasticsearch]
[main] Attempted to resurrect connection to dead ES instance, but got an error {
:url=>"https://localhost:9200/",
:exception=>LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError, :message=>"Got response code '401' contacting Elasticsearch at URL 'https://localhost:9200/'"}
Attempted to resurrect connection to dead ES instance / Got response code '401' contacting Elasticsearch at URL 'https://localhost:9200/', ์ฌ๋ฐ๋ฅธ ์์ฒญ์ด ์๋๋ผ๋ ๊ฒ ๊ฐ๋ค. ์ด์ฐ๋์๋ ๊ณ์ ๋จ๊ณ๋ฅผ ์งํํด๋ณด์.
C. kibana์์ logstash ๊ถํ ์ค์ ํด์ฃผ๊ธฐ
1. kibana์ roles์์ ์ role api๋ฅผ ์์ฑ
- ๊ฒ์์ฐฝ์ roles์น๋ฉด ๋์จ๋ค.
- ๋ง๊ฒํ ๊ฑด์ง๋ ๋ชจ๋ฅด๊ฒ ์ผ๋ ์ผ๋จ ํด๋ด…
- cluster privileges์ manage_index_templates์ monitor๋ฅผ ์ถ๊ฐํ๋ค.
- Index privileges์ Indices๋ฅผ ๊ธฐ๋ณธ์ผ๋ก logstash-*๋ก ๋ฃ๊ณ , write, create, create_index, manage, manage_lim ๊ถํ์ ์ฃผ์ด์ ์์ฑํ๋ค.
2. logstash_internal ์ ์ ์์ฑ
Username๊ณผ password, full name์ ์ ๋นํ ์์ฑํ๊ณ roles์ ๋ฐฉ๊ธ ์์ฑํ logstash_write๋ผ๋ role์ ์ค๋ค.
elasticsearch๋ฅผ ์คํํ๊ณ ์๋ ํ๋กฌํํธ๋ฅผ ๋ณด๋ฉด ์ ์ ์์ฑ ๋ฑ์ ๋ก๊ทธ๊ฐ ์๋ค.
D. ์์ฑํ ์ ์ ๋ฅผ logstash config ํ์ผ์ ์ถ๊ฐ
input {
jdbc {
jdbc_driver_library => "C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/logstash-core/lib/jars/postgresql-42.6.0.jar"
jdbc_driver_class => "org.postgresql.Driver"
jdbc_connection_string => "jdbc:postgresql://localhost:5432/{database_name}"
jdbc_user => "{username}"
jdbc_password => "{password}"
schedule => "* * * * *"
statement => "select test1, test2, test3 from tn_test"
}
}
output {
elasticsearch {
hosts => ["https://localhost:9200"]
cacert => 'C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/config/certs/http_ca.crt'
ssl => true
user => "logstash_internal"
password => "x-pack-test-password"
}
stdout { codec => rubydebug }
}
๋ค์ ์คํ์ ํด๋ณด๋ฉด, ๋ญ๊ฐ ์๋ฌ๋ฉ์ธ์ง๊ฐ ๋ ๋ฐ๋์๋ค. ๊ทธ๋๋ ์ผ๋จ ๋ฐ์ดํฐ๋ฒ ์ด์ค์์ ๋ญ๊ฐ๋ฅผ ์ก์์ค๊ณ ์๋ ๊ฒ ๊ฐ๊ธฐ๋ ํ๋ค.
[2023-06-28T15:28:14,291][INFO ][logstash.outputs.elasticsearch][main][a519652ef2db6cf2dbe5a0a521b676ed993c53d55dd2601c5ee833499749c4e1]
Retrying individual bulk actions that failed or were rejected by the previous bulk request {:count=>1}
[2023-06-28T15:28:26,542][ERROR][logstash.licensechecker.licensereader]
Unable to retrieve license information from license server {:message=>"No Available connections"}
[2023-06-28T15:28:30,300][INFO ][logstash.outputs.elasticsearch][main][a519652ef2db6cf2dbe5a0a521b676ed993c53d55dd2601c5ee833499749c4e1]
Retrying failed action {:status=>403, :action=>["create", {:_id=>nil, :_index=>"logs-generic-default", :routing=>nil}, {"test1"=>"?๋ฏ๋ช??-3", "test2"=>"?๋ฏ๋ช??-3", "@timestamp"=>2023-06-28T06:28:00.118973Z, "test3"=>"?๋ฏ๋ช??-3", "@version"=>"1", "data_stream"=>{"type"=>"logs", "dataset"=>"generic", "namespace"=>"default"}}], :error=>{"type"=>"security_exception", "reason"=>"action [indices:data/write/bulk[s]] is unauthorized for user [logstash_internal] with effective roles [logstash_writer] on indices [logs-generic-default], this action is granted by the index privileges [create_doc,create,delete,index,write,all]"}}
์ฌ๊ธฐ์์ Retrying failed action ๋ถ๋ถ์ ์ ์ฝ์ด๋ณด๋ฉด, :_index=>"logs-generic-default" ๋ถ๋ถ์ด ์๊ณ , user [logstash_internal ์๊ฒ๋ indices [logs-generic-default]์ ๋ํ ๊ถํ์ด ์๋ค๊ณ ํ๋ค.
์ด๋ผ
๊ทธ๋์ role์ ๋ค์ ์ดํด๋ดค๋ค.
์ด์ ๋ฅผ ์์๋ค!
์ด์ ์ ๋๋ ๋ฏธ๋ฆฌ Discover ์์ ์ view๋ฅผ ๋ง๋ค์ด๋์๋ค. my-data-view๋ผ๋ ์ด๋ฆ์ผ๋ก!
์ค๋ฅธ์ชฝ์ ๋ณด๋ฉด log-generic-default ๋ผ๋ source๊ฐ ๋ณด์ด๋๋ฐ, ์๊ฐ logstash์๋ค.
data view๋ฅผ ์์ฑํ ๋ Index Pattern์ด๋ผ๋ ๊ฒ์ ๋ง๋๋๋ฐ, ๋๋ logs-generic-default์ ๋ง์ถฐ logs-generic-* ์ผ๋ก ์ค์ ํ๋ค. ๊ทธ๋ฌ๋ roles์ ์ ๊ทผ๊ถํ์ ์ค indices๋ ์ ์น๊ตฌํํ ์ค์ผํ๋ ๊ฒ์ด๋ค!!!!!!!!!!!!
๊ณง์ฅ logstash-writer role์ indices๋ฅผ logs-generic-* ๋ก ๋ณ๊ฒฝํด์ฃผ์๋ค.
๋ก๊ทธ์ ๋ด๋ ๊ถํ๋ค๋ ์ ๋ถ ์ถ๊ฐํด์ฃผ์๋ค.
๊ทธ๋ฌ๋๋!
[2023-06-29T11:45:33,371][INFO ][logstash.javapipeline ][main] Pipeline started {"pipeline.id"=>"main"}
[2023-06-29T11:45:33,385][INFO ][logstash.agent ] Pipelines running {:count=>1, :running_pipelines=>[:main], :non_running_pipelines=>[]}
[2023-06-29T11:46:00,466][INFO ][logstash.inputs.jdbc ][main][9f22664126814c4ea4b60ab70187a8c440fb2fa44c66183ec9c5d1aa937200be] (0.009056s) select * from contents
C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/manticore-0.9.1-java/lib/manticore/client.rb:284: warning: already initialized constant Manticore::Client::HttpPost
C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/manticore-0.9.1-java/lib/manticore/client.rb:284: warning: already initialized constant Manticore::Client::HttpPost
C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/manticore-0.9.1-java/lib/manticore/client.rb:284: warning: already initialized constant Manticore::Client::HttpPost
C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/manticore-0.9.1-java/lib/manticore/client.rb:284: warning: already initialized constant Manticore::Client::HttpPost
C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/manticore-0.9.1-java/lib/manticore/client.rb:536: warning: already initialized constant Manticore::Client::StringEntity
C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/manticore-0.9.1-java/lib/manticore/client.rb:536: warning: already initialized constant Manticore::Client::StringEntity
C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/manticore-0.9.1-java/lib/manticore/client.rb:536: warning: already initialized constant Manticore::Client::StringEntity
C:/Users/dk866/Downloads/logstash-8.8.1/logstash-8.8.1/vendor/bundle/jruby/2.6.0/gems/manticore-0.9.1-java/lib/manticore/client.rb:536: warning: already initialized constant Manticore::Client::StringEntity
{
"@timestamp" => 2023-06-29T02:46:00.473770200Z,
"id" => 1,
"content" => "test post",
"time" => 2023-06-27T01:05:41.000Z,
"title" => "hello",
"writer" => "admin",
"@version" => "1"
}
{
"@timestamp" => 2023-06-29T02:46:00.475770400Z,
"id" => 4,
"content" => "not admin / test ",
"time" => 2023-06-27T04:28:06.000Z,
"title" => "hello world this is test account",
"writer" => "test",
"@version" => "1"
}
{
"@timestamp" => 2023-06-29T02:46:00.475770400Z,
"id" => 5,
"content" => "did you get this? ",
"time" => 2023-06-28T07:46:48.000Z,
"title" => "elastic search",
"writer" => "admin",
"@version" => "1"
}
{
"@timestamp" => 2023-06-29T02:46:00.475770400Z,
"id" => 3,
"content" => "test1 ",
"time" => 2023-06-27T04:11:36.000Z,
"title" => "test",
"writer" => "admin",
"@version" => "1"
}
{
"@timestamp" => 2023-06-29T02:46:00.474768600Z,
"id" => 2,
"content" => "this is test post 2 ",
"time" => 2023-06-27T01:49:12.000Z,
"title" => "test post 2",
"writer" => "admin",
"@version" => "1"
}
์ผ์์์ console์ ๋ฐ์ดํฐ๊ฐ ์ถ๋ ฅ๋๊ณ ์๋ค!
๋ฐ๋ก kibana์์๋ ํ์ธํด๋ณด์. dataview๋ฅผ ๋ง๋ค์ง ์์๋ค๋ฉด ๊ท์น์ ๋ฐ๋ผ ํ๋ ๋ง๋ค์ด์ฃผ๊ณ , discover๋ฅผ ํ์ธํด๋ณธ๋ค.
!!!!!!!!! ๋๋ค!!!!!!!!!! 1๋ถ์ ํ ๋ฒ์ฉ ์ ๋ฐ์ดํธํ ๋ฐ์ดํฐ๋ฅผ ์ฌ๋ ค์ฃผ๋ ๊ฒ์ด ๋ณด์ธ๋ค.... ๊ฐ๊ฒฉ ๊ทธ ์์ฒด
์ค์๊ฐ ๋ชจ๋ํฐ๋ง์ด ๋ง๋์ง ํ์ธ์ฐจ ์ ๋ฐ์ดํฐ๋ฅผ ํ๋ db์ ์ถ๊ฐํด๋ณธ๋ค.
์ ๋ ดํ ๋ฐ์ดํฐ ์ถ๊ฐ... ๊ทธ๋ฆฌ๊ณ ์ด์ ๋ก๊ทธ๋ฅผ ๋ณด๋ฉด!
์ฌ๋ผ์จ๋ค!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
ํด ์ฌ์ ํ ๋ฐ์ดํฐ ์ค๋ณต ์ ์ฌ ๋ฑ์ ๋ฌธ์ ๊ฐ ์กด์ฌํ๊ณ ๋ ์์ง๋ง, ์ผ๋จ ์ค์๊ฐ ๋ชจ๋ํฐ๋ง์ด ๋๋ค๋ ๊ฒ๋ถํฐ ๊ฐ๊ฒฉ ๊ทธ ์์ฒด... ์ด ์ฝ์ง ๋ก๊ทธ๊ฐ elasticsearch๋ฅผ ์๋ํ๋ ๋๊ตฐ๊ฐ์๊ฒ ๋์์ด ๋๊ธธ ๋ฐ๋๋ค........................
๋ค์ ํฌ์คํ ์์๋ ๋ฐ์ดํฐ ์ค๋ณต์ ์ฌ๋ฅผ ๋ง์๋ณด๋๋ก ํ๊ฒ ...๋ค....
'๐ฅ Web > โ Back-end | etc.' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Elasticsearch] Index Template ๊ตฌ์ฑํ๊ธฐ with Kibana & Logstash (2) - Mapping ๊ธฐ์ด (0) | 2023.07.14 |
---|---|
[Elasticsearch] Index Template ๊ตฌ์ฑํ๊ธฐ with Kibana & Logstash (1) - Setting (0) | 2023.07.06 |
[Elasticsearch] Logstash ์ฌ์ฉํด๋ณด๊ธฐ (0) | 2023.06.29 |
[Elasticsearch] Elasticsearch ๊ธฐ๋ณธ ๊ฐ๋ ๋ฐ ์ค์น, kibana ์ฐ๋ํ๊ธฐ (1) | 2023.06.29 |
[SQL] SQL ์ค๊ธ (0) | 2021.08.22 |