架构说明:https://blog.csdn.net/beyond_qjm/article/details/81941820
一、基本架构
二、Filebeat安装
服务器 | 安装根目录 |
172.17.0.153 | /opt/filebeat-6.2.3-linux-x86_64 |
172.17.0.154 | /opt/filebeat-6.2.3-linux-x86_64 |
172.17.0.155 | /opt/filebeat-6.2.3-linux-x86_64 |
172.17.0.156 | /opt/filebeat-6.2.3-linux-x86_64 |
安装教程:https://blog.csdn.net/beyond_qjm/article/details/81944486
整合配置:
filebeat.prospectors: - type: log
|
三、Logstash安装
服务器 | 安装根目录 |
172.17.0.184 | /home/elk/logstash-6.2.3/ |
安装教程:https://blog.csdn.net/beyond_qjm/article/details/81945527
整合配置:
1. 添加 /home/elk/logstash-6.2.3/bin/config/log4j.cfg
input{ filter{ "message" , "%{TIMESTAMP_ISO8601:time} %{DATA:thread} %{LOGLEVEL:level} %{JAVACLASS:class} : %{GREEDYDATA:info}", date { mutate{ }
if [log_type] == "console" and [info] =~ /^\S/ { if [log_type] == "access" { |
2. 添加 /home/elk/logstash-6.2.3/bin/config/laccess.json
{ "template": "access*", "settings": { "index.number_of_shards": 5, "number_of_replicas": 1 }, "mappings": { "access": { "_all": { "enabled": false }, "properties": { "@timestamp": { "type": "date", }, "server_id": { "type": "string", "index": "not_analyzed" }, "source": { "type": "string", "index": "not_analyzed" }, "visitHost": { "type": "string", "index": "not_analyzed" }, "method": { "type": "string", "index": "not_analyzed" }, "request": { "type": "string", "index": "analyzed" }, "protocol": { "type": "string", "index": "not_analyzed" }, "responseCode": { "type": "integer", "index": "not_analyzed" }, "responseTime": { "type": "integer", "index": "not_analyzed" }, "log_type": { "type": "string", "index": "not_analyzed" } } } } } |
3. 添加 /home/elk/logstash-6.2.3/bin/config/console.json
{ "template": "console*", "settings": { "index.number_of_shards": 5, "number_of_replicas": 1 }, "mappings": { "console": { "_all": { "enabled": false }, "properties": { "@timestamp": { "type": "date", }, "server_id": { "type": "string", "index": "not_analyzed" }, "source": { "type": "string", "index": "not_analyzed" }, "thread": { "type": "string", "index": "not_analyzed" }, "level": { "type": "string", "index": "not_analyzed" }, "class": { "type": "string", "index": "not_analyzed" }, "info": { "type": "string", "index": "analyzed" }, "log_type": { "type": "string", "index": "not_analyzed" } } } } } |
四、Elasticsearch安装
服务器 | 安装根目录 | 节点类型 |
172.17.0.181 | /home/elk/elasticsearch-6.2.3 | data |
172.17.0.182 | /home/elk/elasticsearch-6.2.3 | data |
172.17.0.183 | /home/elk/elasticsearch-6.2.3 | master |
安装教程:https://blog.csdn.net/beyond_qjm/article/details/81943552
elasticsearch-head安装配置:https://blog.csdn.net/beyond_qjm/article/details/81947181
五、Kibana安装
服务器 | 安装根目录 |
172.17.0.183 | /home/elk/kibana-6.2.3-linux-x86_64 |
安装教程:https://blog.csdn.net/beyond_qjm/article/details/81946384
整合配置:
修改 /home/elk/kibana-6.2.3-linux-x86_64/config/kibana.yml 中的 server.host: "172.17.0.183"
六、log日志配置
1. Spring boot - logback(Spring boot项目)
(1)配置系统环境
dev、test为测试环境,prod为生产环境
(2)在resource目录下添加logback-spring.xml 配置文件
需要修改属性 APP_NAME 改为当前项目名,用对区别不同系统的日志
|
(3)加载logback配置文件
2. 整合log4j
(1)修改pom.xml文件
Springboot项目
<!--删除Spring boot默认使用的日志依赖--> |
非 Springboot项目
<!-- 加入log4j日志依赖 --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.21</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.21</version> </dependency> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.2</version> </dependency> |
(2)加入log4j.properties
将duban-home修改为当前项目名,用对区别不同系统的日志
log4j.rootLogger=info,ServerDailyRollingFile,stdout
log4j.appender.ServerDailyRollingFile=org.apache.log4j.DailyRollingFileAppender log4j.appender.ServerDailyRollingFile.DatePattern='-'yyyy-MM-dd'.log' log4j.appender.ServerDailyRollingFile.File=/logs/console/console_duban-home log4j.appender.DAILY_ROLLING_FILE.Append=true log4j.appender.ServerDailyRollingFile.layout=org.apache.log4j.PatternLayout log4j.appender.ServerDailyRollingFile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} %t %-5p %c : %m%n log4j.appender.ServerDailyRollingFile.Append=true
log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} %t %-5p %c : %m%n |
3. Tomcat access访问日志
Tomcat中默认的情况下,access log是没有设置的。在server.xml文件中配置如下。
<!-- Access log processes all example. Documentation at: /docs/config/valve.html --> <!-- <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/> --> |
改为
1. prefix中的duban-home为服务器名,用于识别不同的服务器
2. pattern为输出格式
<!-- Access log processes all example. Documentation at: /docs/config/valve.html -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="/logs/access/" prefix="access_duban-home_log." suffix=".txt" pattern="%h - - %t "%r" %s %D" resolveHosts="false"/>
|
pattern说明
pattern属性值由字符串常量和pattern标识符加上前缀"%"组合而成。pattern标识符加上前缀"%",用来代替当前请求/响应中的对应的变量值。目前支持如下的pattern: · %a - 远端IP地址 · %A - 本地IP地址 · %b - 发送的字节数,不包括HTTP头,如果为0,使用"-" · %B - 发送的字节数,不包括HTTP头 · %h - 远端主机名(如果resolveHost=false,远端的IP地址) · %H - 请求协议 · %l - 从identd返回的远端逻辑用户名(总是返回 '-') · %m - 请求的方法(GET,POST,等) · %p - 收到请求的本地端口号 · %q - 查询字符串(如果存在,以 '?'开始) · %r - 请求的第一行,包含了请求的方法和URI · %s - 响应的状态码 · %S - 用户的session ID · %t - 日志和时间,使用通常的Log格式 · %u - 认证以后的远端用户(如果存在的话,否则为'-') · %U - 请求的URI路径 · %v - 本地服务器的名称 · %D - 处理请求的时间,以毫秒为单位 · %T - 处理请求的时间,以秒为单位 |
七、添加为服务
将以上应用添加为服务方便管理
教程:https://blog.csdn.net/beyond_qjm/article/details/81947493