location / {
proxy_pass ;
}
}
配置用户名及密码:
printf "admin:$(openssl passwd -crypt 123456)\n" >/etc/nginx/htdpasswd
测试nginx配置:
nginx -t
重载nginx配置:
nginx -s reload
4、安装filebeat
下载安装filebeat
yum install libpcap
curl -L -O https://artifacts.elastic.co/downloads/beats/packetbeat/packetbeat-5.3.0-x86_64.rpm
sudo rpm -vi packetbeat-5.3.0-x86_64.rpm
Nginx日志采用json
log_format htdlog '{"@timestamp":"$time_iso8601",'
'"host":"$server_addr",'
'"clientip":"$remote_addr",'
'"size":$body_bytes_sent,'
'"responsetime":$request_time,'
'"upstreamtime":"$upstream_response_time",'
'"upstreamhost":"$upstream_addr",'
'"http_host":"$host",'
'"url":"$uri",'
'"xff":"$http_x_forwarded_for",'
'"referer":"$http_referer",'
'"agent":"$http_user_agent",'
'"status":"$status"}';
配置nginx的filebeat参数
filebeat.prospectors:
- input_type: log
paths:
- /home/htd/nginx_logs/*.log
document_type: "nginx-public"
output.logstash:
hosts: ["171.16.45.13:5044"]
配置tomcat的filebeat参数
filebeat.prospectors:
- input_type: log
paths:
- /home/htd/logs/mallcenter/error.log
document_type: "mallcenter-error"
multiline.pattern: '^[[:space:]]+|^Caused by:' 多行合并
multiline.negate: false
multiline.match: after
output.logstash:
hosts: ["171.16.45.14:5044"]
启动filebeat
/etc/init.d/filebeat start
/etc/init.d/filebeat stop
基于CentOS 6.9搭建ELK环境指南