[root@dev1613 study]# sudo -u logstash ../bin/logstash --version Using bundled JDK: /opt/logstash/jdk logstash 7.12.1
sudo -u logstash ../bin/logstash -e 'input { stdin { } } output { stdout {} }'
2022-07-06 18:48:37.453 ERROR 14677 --- [ dispatcher 108] c.a.c.s.dashboard.metric.MetricFetcher : Failed to fetch metric from <http://10.32.4.230:8719/metric?startTime=1657104506000&endTime=1657104512000&refetch=false>: socket timeout 2022-07-06 18:48:44.439 ERROR 14677 --- [ dispatcher 109] c.a.c.s.dashboard.metric.MetricFetcher : Failed to fetch metric from <http://10.32.4.230:8719/metric?startTime=1657104513000&endTime=1657104519000&refetch=false>: socket timeout 2022-07-06 18:48:51.514 ERROR 14677 --- [ dispatcher 110] c.a.c.s.dashboard.metric.MetricFetcher : Failed to fetch metric from <http://10.32.4.230:8719/metric?startTime=1657104520000&endTime=1657104526000&refetch=false>: socket timeout
input { file { path => "/opt/logstash/study/outlog.log" start_position => "beginning" stat_interval => "3" type => "sentinel-log" } } filter { grok { match => ["message","%{TIMESTAMP_ISO8601:datetime} %{LOGLEVEL:loglevel} %{NUMBER:textid} %{GREEDYDATA:errormsg}"] } json { source => "request" } } output { stdout { codec => rubydebug } }
CREATE TABLE `study_logstash_es` ( `id` int NOT NULL AUTO_INCREMENT COMMENT '自增主鍵', `study_code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '編碼', `study_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '名稱', `study_tag` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '標籤', `study_level` smallint NOT NULL DEFAULT '0' COMMENT '等級,如1,2,3', `is_delete` tinyint unsigned NOT NULL DEFAULT '0' COMMENT '0 未刪除 1 刪除', `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '建立時間', `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新時間', `operate_user` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '操作人', PRIMARY KEY (`id`), UNIQUE KEY `uniq_study_code` (`study_code`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='學習-logstash同步msql資料到es';
PUT /study_logstash_es { "settings": { "index": { "number_of_shards": 1, "number_of_replicas": 1 } }, "mappings": { "properties": { "id": { "type": "integer" }, "study_code": { "type": "text" }, "study_name": { "type": "text" }, "operate_user": { "type": "text" }, "study_tag": { "type": "keyword" }, "is_delete": { "type": "integer" }, "study_level": { "type": "integer" }, "mark_time": { "type": "date", "format": "epoch_millis" }, "update_time": { "type": "date" } } } }
input { jdbc { jdbc_driver_library => "/opt/logstash/study/mysql-connector-java-8.0.30.jar" jdbc_driver_class => "com.mysql.cj.jdbc.Driver" jdbc_connection_string => "jdbc:mysql://xxx.xxx.xx.x:3306/study_database?serverTimezone=Asia/Shanghai&allowMultiQueries=true&characterEncoding=utf-8" jdbc_user => "root" jdbc_password => "xxxxx" jdbc_paging_enabled => true jdbc_page_size => "2" use_column_value => true tracking_column => "mark_time" tracking_column_type => "numeric" schedule => "* * * * *" statement => "SELECT id,study_code,study_name,study_tag,study_level,operate_user,update_time,UNIX_TIMESTAMP(update_time) as mark_time from study_logstash_es where UNIX_TIMESTAMP(update_time)>:sql_last_value AND update_time < NOW()" } } output{ elasticsearch{ hosts => ["xxx.xxx.16.4:9200","xxx.xxx.16.xx:9200","192.xxx.xx.xx:9200"] index => "study_logstash_es" timeout => 300 user => "xxx" password => "xxxxx" } }
input { kafka { bootstrap_servers => "xxx.xxx.xx.4:9092,xxx.xxx.16.4:9093,xxx.xxx.16.4:9094" #kafka伺服器地址 topics => "xxxlog" # batch_size => 5 codec => "json" group_id => "logstash" consumer_threads => 3 } } filter { # 丟棄所有的header請求 if [request][method] == "HEAD" { drop { } } # 因為[request][querystring]這個玩意中的欄位型別可能不一樣,所以全部幹成字串 ruby { code => "event.set('[request][querystring]', event.get('[request][querystring]').to_s) if event.get('[request][querystring]')" } if [request][uri] =~ "^/ucenter-admin-view/v3(.*)" { mutate { add_field => { "log_source" => "使用者中心管理後臺" } add_field => { "log_source_id" => "1" } } } else if [request][uri] =~ "^/ucenter-org-view/v3/(.*)" { mutate { add_field => { "log_source" => "使用者中心工作臺" } add_field => { "log_source_id" => "2" } } } else if [request][uri] =~ "^/safety-admin-api(.*)" { mutate { add_field => { "log_source" => "安全管理平臺" } add_field => { "log_source_id" => "3" } } } else{ mutate { add_field => { "log_source" => "其他" } add_field => { "log_source_id" => "0" } } } grok { match => { "[request][uri]" => "%{URIPATH:[request][path]}" } named_captures_only => false } } output{ # stdout { # codec => json # } elasticsearch{ hosts => ["xxx.xxx.xx.4:9200","xxx.xxx.16.13:9200","xxx.xxx.16.14:9200"] index => "apisixlog" timeout => 300 user => "elastic" password => "HApn2xCJMuRlg0UOIV0P" }
sudo -u logstash ../bin/logstash -f study-file-es.conf 表示當前視窗啟動,關閉或退出命令列時,logstash範例關閉。 sudo -u logstash ../bin/logstash -f study-file-es.conf --config.reload.automatic 表示當前視窗啟動,組態檔變化時,不用重新啟動範例,可自動載入。關閉或退出命令列時,logstash範例關閉。 sudo -u logstash ../bin/logstash -f study-mysql-es.conf & test.out --config.reload.automatic 表示後臺啟動,關閉退出命令,範例在後臺一直執行。 ps -ef|grep logstash kill-9 程序號, 關閉對應的範例
微信讚賞
支付寶讚賞