如何解决 logstash 的 mysql 连接错误?
How can you solve the mysql connection error with logstash?
如何解决 mysql 与 logstash 的连接错误?
Google中的所有信息我都试过了。
然而,它继续失败,在堆栈溢出中留下问题。
请帮助我。
文件名:mysql.conf(logstash文件有相同的路径)
input {
jdbc {
clean_run => true
jdbc_driver_library => "C:\ElasticSearch\mysql-connector-java-8.0.23\mysql-connector-java-8.0.23.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_connection_string => "jdbc:mysql://localhost:3306/jobschema", "root","1234"
schedule => "* * * * *"
statement => "select jobid, jobname, executiontime, jobstatus from logstashplugin WHERE jobid > :sql_last_value"
use_column_value => true
tracking_column => "jobid"
}
}
output{
elasticsearch {
hosts => ["localhost:9200"]
index => "logstashmysql"
}
stdout {
codec => rubydebug
}
}
enter image description here
Mysql - 数据库
enter image description here
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| commerce |
| information_schema |
| jobschema |
| mysql |
| performance_schema |
| sakila |
| sys |
| world |
+--------------------+
8 rows in set (0.00 sec)
mysql> use jobschema;
Database changed
mysql> show tables;
+---------------------+
| Tables_in_jobschema |
+---------------------+
| logplugin |
+---------------------+
1 row in set (0.00 sec)
mysql> select * from logplugin;
+-------+---------+---------------+-----------+
| jobid | jobname | executiontime | jobstatus |
+-------+---------+---------------+-----------+
| 1 | job1 | 10 | Completed |
| 2 | job2 | 15 | Failed |
| 3 | job3 | 10 | Failed |
| 4 | job4 | 30 | Failed |
| 5 | job5 | 10 | Failed |
| 6 | job6 | 15 | Failed |
| 7 | job7 | 15 | Completed |
+-------+---------+---------------+-----------+
7 rows in set (0.00 sec)
logstash & db 连接错误文件图像
[2021-03-23T11:39:41,142][ERROR][logstash.agent ] Failed to execute action {:action=>LogStash::PipelineAction::Create/pipeline_id:main, :exception=>"LogStash::ConfigurationError", :message=>"Expected one of [ \t\r\n], \"#\", \"{\", \"}\" at line 6, column 74 (byte 282) after input {\n jdbc {\n clean_run => true\n jdbc_driver_library => \"C:\ElasticSearch\mysql-connector-java-8.0.23\mysql-connector-java-8.0.23.jar\"\n jdbc_driver_class => \"com.mysql.jdbc.Driver\"\n jdbc_connection_string => \"jdbc:mysql://localhost:3306/jobschema\"", :backtrace=>["C:/ElasticSearch/logstash-7.11.2/logstash-core/lib/logstash/compiler.rb:32:in `compile_imperative'", "org/logstash/execution/AbstractPipelineExt.java:184:in `initialize'", "org/logstash/execution/JavaBasePipelineExt.java:69:in `initialize'", "C:/ElasticSearch/logstash-7.11.2/logstash-core/lib/logstash/java_pipeline.rb:47:in `initialize'", "C:/ElasticSearch/logstash-7.11.2/logstash-core/lib/logstash/pipeline_action/create.rb:52:in `execute'", "C:/ElasticSearch/logstash-7.11.2/logstash-core/lib/logstash/agent.rb:371:in `block in converge_state'"]}
[2021-03-23T11:39:41,614][INFO ][logstash.agent ] Successfully started Logstash API endpoint {:port=>9600}
[2021-03-23T11:39:46,677][INFO ][logstash.runner ] Logstash shut down.
[2021-03-23T11:39:46,693][FATAL][org.logstash.Logstash ] Logstash stopped processing because of an error: (SystemExit) exit
org.jruby.exceptions.SystemExit: (SystemExit) exit
at org.jruby.RubyKernel.exit(org/jruby/RubyKernel.java:747) ~[jruby-complete-9.2.13.0.jar:?]
at org.jruby.RubyKernel.exit(org/jruby/RubyKernel.java:710) ~[jruby-complete-9.2.13.0.jar:?]
at C_3a_.ElasticSearch.logstash_minus_7_dot_11_dot_2.lib.bootstrap.environment.<main>(C:\ElasticSearch\logstash-7.11.2\lib\bootstrap\environment.rb:89) ~[?:?]
enter image description here
如果您阅读错误消息,您会看到它说
:exception=>"LogStash::ConfigurationError", :message=>"Expected one of [ \t\r\n], \"#\", \"{\", \"}\" at line 6, column 74 (byte 282) after
input {\n
jdbc {\n
clean_run => true\n
jdbc_driver_library => \"C:\ElasticSearch\mysql-connector-java-8.0.23\mysql-connector-java-8.0.23.jar\"\n
jdbc_driver_class => \"com.mysql.jdbc.Driver\"\n
jdbc_connection_string => \"jdbc:mysql://localhost:3306/jobschema\""
你的配置显示的是
jdbc_connection_string => "jdbc:mysql://localhost:3306/jobschema", "root","1234"
我想你的意思是
jdbc_connection_string => "jdbc:mysql://localhost:3306/jobschema"
jdbc_user => "root"
jdbc_password => "1234"
如何解决 mysql 与 logstash 的连接错误?
Google中的所有信息我都试过了。
然而,它继续失败,在堆栈溢出中留下问题。
请帮助我。
文件名:mysql.conf(logstash文件有相同的路径)
input {
jdbc {
clean_run => true
jdbc_driver_library => "C:\ElasticSearch\mysql-connector-java-8.0.23\mysql-connector-java-8.0.23.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_connection_string => "jdbc:mysql://localhost:3306/jobschema", "root","1234"
schedule => "* * * * *"
statement => "select jobid, jobname, executiontime, jobstatus from logstashplugin WHERE jobid > :sql_last_value"
use_column_value => true
tracking_column => "jobid"
}
}
output{
elasticsearch {
hosts => ["localhost:9200"]
index => "logstashmysql"
}
stdout {
codec => rubydebug
}
}
enter image description here
Mysql - 数据库 enter image description here
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| commerce |
| information_schema |
| jobschema |
| mysql |
| performance_schema |
| sakila |
| sys |
| world |
+--------------------+
8 rows in set (0.00 sec)
mysql> use jobschema;
Database changed
mysql> show tables;
+---------------------+
| Tables_in_jobschema |
+---------------------+
| logplugin |
+---------------------+
1 row in set (0.00 sec)
mysql> select * from logplugin;
+-------+---------+---------------+-----------+
| jobid | jobname | executiontime | jobstatus |
+-------+---------+---------------+-----------+
| 1 | job1 | 10 | Completed |
| 2 | job2 | 15 | Failed |
| 3 | job3 | 10 | Failed |
| 4 | job4 | 30 | Failed |
| 5 | job5 | 10 | Failed |
| 6 | job6 | 15 | Failed |
| 7 | job7 | 15 | Completed |
+-------+---------+---------------+-----------+
7 rows in set (0.00 sec)
logstash & db 连接错误文件图像
[2021-03-23T11:39:41,142][ERROR][logstash.agent ] Failed to execute action {:action=>LogStash::PipelineAction::Create/pipeline_id:main, :exception=>"LogStash::ConfigurationError", :message=>"Expected one of [ \t\r\n], \"#\", \"{\", \"}\" at line 6, column 74 (byte 282) after input {\n jdbc {\n clean_run => true\n jdbc_driver_library => \"C:\ElasticSearch\mysql-connector-java-8.0.23\mysql-connector-java-8.0.23.jar\"\n jdbc_driver_class => \"com.mysql.jdbc.Driver\"\n jdbc_connection_string => \"jdbc:mysql://localhost:3306/jobschema\"", :backtrace=>["C:/ElasticSearch/logstash-7.11.2/logstash-core/lib/logstash/compiler.rb:32:in `compile_imperative'", "org/logstash/execution/AbstractPipelineExt.java:184:in `initialize'", "org/logstash/execution/JavaBasePipelineExt.java:69:in `initialize'", "C:/ElasticSearch/logstash-7.11.2/logstash-core/lib/logstash/java_pipeline.rb:47:in `initialize'", "C:/ElasticSearch/logstash-7.11.2/logstash-core/lib/logstash/pipeline_action/create.rb:52:in `execute'", "C:/ElasticSearch/logstash-7.11.2/logstash-core/lib/logstash/agent.rb:371:in `block in converge_state'"]}
[2021-03-23T11:39:41,614][INFO ][logstash.agent ] Successfully started Logstash API endpoint {:port=>9600}
[2021-03-23T11:39:46,677][INFO ][logstash.runner ] Logstash shut down.
[2021-03-23T11:39:46,693][FATAL][org.logstash.Logstash ] Logstash stopped processing because of an error: (SystemExit) exit
org.jruby.exceptions.SystemExit: (SystemExit) exit
at org.jruby.RubyKernel.exit(org/jruby/RubyKernel.java:747) ~[jruby-complete-9.2.13.0.jar:?]
at org.jruby.RubyKernel.exit(org/jruby/RubyKernel.java:710) ~[jruby-complete-9.2.13.0.jar:?]
at C_3a_.ElasticSearch.logstash_minus_7_dot_11_dot_2.lib.bootstrap.environment.<main>(C:\ElasticSearch\logstash-7.11.2\lib\bootstrap\environment.rb:89) ~[?:?]
enter image description here
如果您阅读错误消息,您会看到它说
:exception=>"LogStash::ConfigurationError", :message=>"Expected one of [ \t\r\n], \"#\", \"{\", \"}\" at line 6, column 74 (byte 282) after
input {\n
jdbc {\n
clean_run => true\n
jdbc_driver_library => \"C:\ElasticSearch\mysql-connector-java-8.0.23\mysql-connector-java-8.0.23.jar\"\n
jdbc_driver_class => \"com.mysql.jdbc.Driver\"\n
jdbc_connection_string => \"jdbc:mysql://localhost:3306/jobschema\""
你的配置显示的是
jdbc_connection_string => "jdbc:mysql://localhost:3306/jobschema", "root","1234"
我想你的意思是
jdbc_connection_string => "jdbc:mysql://localhost:3306/jobschema"
jdbc_user => "root"
jdbc_password => "1234"