logstash 收集nginx 日志 linux
linux:
1 2 | log_format main 'remote_user=$remote_user&ip=$remote_addr&real_ip=$http_x_forwarded_for&log_time=$time_local&request_time=$request_time&host=$http_host&$args&statusbody_bytes_sent=$body_bytes_sent&referer=$http_referer&user_agent=$http_user_agent&forwarded_for=$http_x_forwarded_for' ; #access_log logs/access.log main; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | server { listen 443 ssl; server_name t-log.xiyakj.com; ssl_certificate /usr/local/nginx/ssl/5879047__xiyakj.com.pem; ssl_certificate_key /usr/local/nginx/ssl/5879047__xiyakj.com.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})" ) { set $year $ 1 ; set $month $ 2 ; set $day $ 3 ; } location = /s.gif { empty_gif; } access_log /data/logs/nginx/t-log.access_${year}${month}${day}.log main; } |
logstash:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | input { file { # windows 中也使用 "/" , 而非"\" path => "/data/logs/nginx/t-log.access_*.log" type => "nginx_access_log" start_position => "beginning" sincedb_path => "/usr/local/logstash/log_txt/tlog.txt" sincedb_write_interval => 15 stat_interval => "2" } } filter{ urldecode{ field => message } kv{ field_split => "&" } } output { datahub { access_id => "xxxxx" access_key => "xxxxxxxxxxxxxxxx" endpoint => "http://dh-cn-hangzhou-int-vpc.aliyuncs.com" project_name => "ad_log_test" topic_name => "ad_test" #shard_id => "0" #shard_keys => [ "thread_id" ] dirty_data_continue => true dirty_data_file => "/usr/local/logstash/log_data/tlog.data" dirty_data_file_max_size => 1000 } } |
命令地动: ./bin/logstash -f log_conf/
后台启动: nohup ./bin/logstash -f log_conf/ >/dev/null 2>&1 &
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通