×ðÁú¿­Ê±

Nginx Proxy ManagerµÄÈÕÖ¾ÆÊÎöÓë¼à¿Ø

Nginx Proxy ManagerµÄÈÕÖ¾ÆÊÎöÓë¼à¿Ø £¬ÐèÒªÏêϸ´úÂëʾÀý

СÐò£º

Nginx Proxy ManagerÊÇÒ»¸ö»ùÓÚNginxµÄÊðÀíЧÀÍÆ÷ÖÎÀí¹¤¾ß £¬ËüÌṩÁËÒ»ÖÖ¼òÆÓ¶øÓÐÓõÄÒªÁìÀ´ÖÎÀíºÍ¼à¿ØÊðÀíЧÀÍÆ÷ ¡£ÔÚÏÖʵÔËÐÐÖÐ £¬ÎÒÃǾ­³£ÐèÒª¶ÔNginx Proxy ManagerµÄÈÕÖ¾¾ÙÐÐÆÊÎöºÍ¼à¿Ø £¬ÒÔ±ãʵʱ·¢Ã÷DZÔÚµÄÎÊÌâ»òÓÅ»¯ÐÔÄÜ ¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃһЩ³£ÓõŤ¾ßºÍ´úÂëʾÀýÀ´ÆÊÎöºÍ¼à¿ØNginx Proxy ManagerµÄÈÕÖ¾ ¡£

Ò»¡¢ÈÕÖ¾ÆÊÎö

ʹÓÃAwkͳ¼ÆÈÕÖ¾ÐÅÏ¢

AwkÊÇÒ»¸öÇ¿Ê¢µÄÎı¾´¦Öóͷ£¹¤¾ß £¬¿ÉÒÔÓÃÓÚ¶ÔNginx Proxy ManagerµÄÈÕÖ¾¾ÙÐÐͳ¼ÆºÍÆÊÎö ¡£ÒÔÏÂÊÇÒ»¸öʾÀýʹÓÃAwkͳ¼Æ»á¼û´ÎÊý×î¶àµÄIPµØµãµÄ´úÂ룺

awk '{print $1}' access.log | sort | uniq -c | sort -r | head -n 10

µÇ¼ºó¸´ÖÆ

Õâ¶Î´úÂë»á´Óaccess.logÎļþÖÐÌáÈ¡³öµÚÒ»ÁУ¨¼´IPµØµã£© £¬È»ºóʹÓÃsortÏÂÁîÅÅÐò¡¢uniqÏÂÁîÈ¥ÖØ £¬ÔÙ´ÎʹÓÃsortÏÂÁîƾ֤»á¼û´ÎÊý¾ÙÐÐÅÅÐò £¬²¢ÏÔʾǰ10ÐÐ ¡£

ʹÓÃLogstashÆÊÎöÈÕÖ¾

LogstashÊÇÒ»¸ö¿ªÔ´µÄÊý¾Ý´¦Öóͷ£¹¤¾ß £¬Ëü¿ÉÒÔ´ÓÖÖÖÖȪԴÍøÂçÈÕÖ¾²¢¾ÙÐд¦Öóͷ£ ¡£ÒÔÏÂÊÇÒ»¸öʹÓÃLogstashÆÊÎöNginx Proxy ManagerÈÕÖ¾µÄ´úÂëʾÀý£º

input {
  file {
    path => "/var/log/nginx/access.log"
    start_position => "beginning"
  }
}

filter {
  grok {
    match => { "message" => "%{IPORHOST:clientip} - %{USER:ident} [%{HTTPDATE:timestamp}] "%{WORD:verb} %{URIPATHPARAM:request} HTTP/%{NUMBER:httpversion}" %{NUMBER:response} %{NUMBER:bytes} "%{URI:referrer}" "%{DATA:agent}"" }
  }
}

output {
  elasticsearch {
    hosts => ["localhost:9200"]
    index => "nginx-access-log"
  }
  stdout {}
}

µÇ¼ºó¸´ÖÆ

Õâ¶ÎÉèÖÃÎļþÖ¸¶¨ÁËÈÕÖ¾ÎļþµÄ·¾¶ £¬È»ºóʹÓÃgrok²å¼þÀ´ÆÊÎöÈÕÖ¾µÄÃûÌà £¬²¢½«ÆÊÎöºóµÄÊý¾ÝÊä³öµ½Elasticsearch ¡£

¶þ¡¢ÈÕÖ¾¼à¿Ø

ʹÓÃELK¾ÙÐÐÈÕÖ¾¼à¿Ø

ELK£¨Elasticsearch + Logstash + Kibana£©ÊÇÒ»¸ö³£ÓõÄÈÕÖ¾ÆÊÎöºÍ¿ÉÊÓ»¯½â¾ö¼Æ»® ¡£ÒÔÏÂÊÇÒ»¸öʹÓÃELK¾ÙÐÐNginx Proxy ManagerÈÕÖ¾¼à¿ØµÄʾÀýÉèÖãº

input {
  file {
    path => "/var/log/nginx/access.log"
    sincedb_path => "/dev/null"
    start_position => "beginning"
  }
}

filter {
  grok {
    match => { "message" => "%{IPORHOST:clientip} - %{USER:ident} [%{HTTPDATE:timestamp}] "%{WORD:verb} %{URIPATHPARAM:request} HTTP/%{NUMBER:httpversion}" %{NUMBER:response} %{NUMBER:bytes} "%{URI:referrer}" "%{DATA:agent}"" }
  }
}

output {
  elasticsearch {
    hosts => ["localhost:9200"]
    index => "nginx-access-log"
  }
}

µÇ¼ºó¸´ÖÆ

Õâ¶ÎÉèÖÃÎļþÓëÇ°ÃæµÄLogstashʾÀýÀàËÆ £¬Ö»ÊDz»ÐèÒªÊä³öµ½stdout²å¼þ ¡£È»ºó £¬ÔÚKibanaÖн¨ÉèÒ»¸ö¿ÉÊÓ»¯ÒDZí°å £¬ÓÃÓÚʵʱ¼à¿ØºÍÆÊÎöÈÕÖ¾Êý¾Ý ¡£

ʹÓÃPrometheusºÍGrafana¾ÙÐÐÈÕÖ¾¼à¿Ø

PrometheusÊÇÒ»¸ö¿ªÔ´µÄ¼à¿Øϵͳ £¬¶øGrafanaÊÇÒ»¸ö¿ÉÊÓ»¯¹¤¾ß ¡£ÒÔÏÂÊÇÒ»¸öʹÓÃPrometheusºÍGrafana¾ÙÐÐNginx Proxy ManagerÈÕÖ¾¼à¿ØµÄʾÀýÉèÖãº

- job_name: 'nginx'
  scrape_interval: 5s
  metrics_path: /nginx_status
  static_configs:
    - targets:
      - 'localhost:8080'

- job_name: 'log_exporter'
  scrape_interval: 60s
  static_configs:
    - targets:
      - 'localhost:9100'

  relabel_configs:
    - source_labels: [__address__]
      target_label: __param_target
    - source_labels: [__param_target]
      target_label: instance
    - target_label: __address__
      replacement: 'localhost:9090'

µÇ¼ºó¸´ÖÆ

Õâ¶ÎÉèÖÃÎļþ½ç˵ÁËÁ½¸ö×÷Òµ£¨job£© £¬Ò»¸öÓÃÓÚ´ÓNginx»ñȡ״ָ̬±ê £¬ÁíÒ»¸öÓÃÓÚ´Ólog_exporter»ñÈ¡ÈÕÖ¾Ö¸±ê ¡£È»ºó £¬Ê¹ÓÃGrafana½¨ÉèÒ»¸öÒDZí°å £¬Õ¹Ê¾Nginx Proxy ManagerµÄÈÕÖ¾¼à¿ØÊý¾Ý ¡£

½áÂÛ£º

±¾ÎÄÏÈÈÝÁËÔõÑùʹÓÃAwk¡¢Logstash¡¢ELK¡¢PrometheusºÍGrafanaµÈ¹¤¾ßºÍ´úÂëʾÀýÀ´¾ÙÐÐNginx Proxy ManagerÈÕÖ¾µÄÆÊÎöºÍ¼à¿Ø ¡£Í¨Ì«¹ýÎöÈÕÖ¾ £¬ÎÒÃÇ¿ÉÒÔʵʱ·¢Ã÷DZÔÚµÄÎÊÌâºÍÐÔÄÜÆ¿¾± £»Í¨¹ý¼à¿ØÈÕÖ¾ £¬ÎÒÃÇ¿ÉÒÔʵʱÏàʶÊðÀíЧÀÍÆ÷µÄÔËÐÐ״̬ £¬²¢×ö³öÏìÓ¦µÄµ÷½âºÍÓÅ»¯ ¡£Ï£Íû±¾ÎÄÄܶԳõѧÕß¾ßÓÐÒ»¶¨µÄ²Î¿¼¼ÛÖµ £¬ÓÐÖúÓÚ¸üºÃµØÃ÷È·ºÍʹÓÃNginx Proxy Manager ¡£

ÒÔÉϾÍÊÇNginx Proxy ManagerµÄÈÕÖ¾ÆÊÎöÓë¼à¿ØµÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼ ¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±ÊµÊ±ÐÞÕý»òɾ³ý ¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
¡¾ÍøÕ¾µØͼ¡¿¡¾sitemap¡¿