Elastic + logstash + filebeat Nginx 로그 분석

3988 단어 elasticnginx
1. Elasticserach 설치 1, 설치 (elastic 6.3.2 버 전 은 자바 JDK 8 에 의존)
적합 한 버 전 다운로드: curl - L - Ohttps://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.0.tar.gztar -xvf elasticsearch-6.4.0.tar.gzcd elasticsearch-6.4.0/bin./elasticsearch
2. 집단 건강 검진 curl - XGEThttp://127.0.0.1:9200/_cat / health? v 클 러 스 터 건강 보기 curl - XGEThttp://127.0.0.1:9200/_cat / nodes? v 노드 상태 보기 curl - XGEThttp://127.0.0.1:9200/_cat / indices? v 색인 컬 보기 - XPUThttp://127.0.0.1:9200/customer?pretty customer 인덱스 컬 추가 - XDELETEhttp://127.0.0.1:9200/customer?pretty 색인 삭제
3. Config cluster. name: 클 러 스 터 이름 node. name: 노드 이름 path. data: 데이터 저장 경로 path. logs: 로그 저장 경로 network. host: 감청 주소 http. port: 감청 포트 JVM 설정, logging 설정 은 공식 문서 의 중요 한 매개 변 수 를 참고 합 니 다.
Path settingsCluster nameNode nameNetwork hostDiscovery settingsHeap sizeHeap dump pathGC loggingTemp directory 중요 한 시스템 매개 변수:
Disable swappingIncrease file descriptorsEnsure sufficient virtual memoryEnsure sufficient threadsJVM DNS cache settings
4. Running as daemon. / bin / elasticsearch - d - p pid 시작 kill cat pid 정지
5 、 Set up X - Pack 참고 x - pack 해독 방법
2. kibana 설치 및 설정
        wget https://artifacts.elastic.co/downloads/kibana/kibana-6.4.0-linux-x86_64.tar.gz

tar -xzf kibana-6.4.0-linux-x86_64.tar.gzcd kibana-6.4.0-linux-x86_64/
        1、    ./bin/kibana   

        2、config:

server.port: 5601server.host: "192.168.12.81"kibana.index: ".kibana"elasticsearch.username: "elastic"elasticsearch.password: "dinpay"
3. logstash 설치 및 설정 wgethttps://artifacts.elastic.co/downloads/logstash/logstash-6.4.0.tar.gz
filebeat 설정 Nginx 로그 수집: (Nginx. conf)
input {beats {port => 5044 codec => "json" } }
output { elasticsearch { hosts => ["127.0.0.1:9200"] index => "test1-nginx-access-%{+YYYY.MM.dd}" template_overwrite => true user => elasticpassword => dinpay } }
logstash. yml elastic 을 이 컴퓨터 에 설치 하도록 설정 합 니 다 (https 설정 하지 않 음)
xpack.monitoring.enabled: true xpack.monitoring.elasticsearch.username: elastic xpack.monitoring.elasticsearch.password: dinpay xpack.monitoring.elasticsearch.url: ["http://127.0.0.1:9200"]
4. filebeat 설치 및 설정
wget https://artifacts.elastic.co/downloads/beats/filebeat/https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.4.0-linux-x86_64.tar.gz
tar -xf filebeat-6.4.0-linux-x86_64.tar.gz
cd filebeat-6.4.0-linux-x86_64
filebeat. yml 설정
  • type: logpaths:
  • /var/log/nginx/access.log


  • output.logstash:
    hosts: ["192.168.12.81:5044"]
    xpack.monitoring:enabled: trueelasticsearch: hosts: ["http://192.168.12.81:9200", "http://192.168.12.81:9200"]username: elasticpassword: dinpay
    5. Nginx 로그 형식 설정:
    log_format json '{"@timestamp":"$time_iso8601",' '"host":"$server_addr",''"clientip":"$clientRealIp",''"remote_user":"$remote_user",''"request":"$request",' '"http_user_agent":"$http_user_agent",''"size":$body_bytes_sent,' '"responsetime":$request_time,''"upstreamtime":"$upstream_response_time",' '"upstreamhost":"$upstream_addr",''"http_host":"$host",''"url":"$uri",''"domain":"$host",''"xff":"$http_x_forwarded_for",''"referer":"$http_referer",' '"status":"$status",''"ss":"$upstream_status"}';
    access_log  /var/log/nginx/access.log  json;
    
    map $http_x_forwarded_for $clientRealIp {
    
    ""  $remote_addr;
    
    ~^(?P[0-9\.]+),?.*$    $firstAddr;
    
    }

    좋은 웹페이지 즐겨찾기