CAPTAINS - 监控
type: channel
link: https://www.captains.top/index.php/category/监控/
description: 用以记录监控服务
items: ES之监控nginx日志
items: NODE_EXPORTER 修改端口

ES之监控nginx日志
type: item
date: 2023-05-16T06:18:00+00:00
description: [TOC]1、概述通过通过filebeat收集nginx日志，写入到redis，然后通过logstash读取数据，输入到es集群存储，最后通过grafana读取es数据，展示出来。2、服务器信息序号ip配置系统服务1192.168.1.2014核8g512gcentos7.xnginx/filebeat2192.168.1.2024核8g512gcentos7.xredis/es/logstash/grafana3、安装3.1 nginx配置nginx安装略nginx日志配置# 新增以下日志配置，并选择新的日志配置格式 $ vim /etc/nginx/nginx.conf log_format aka_logs '{"@timestamp":"$time_iso8601",' '"host":"$hostname",' '"server_ip":"$server_addr",' '"client_ip":"$remote_addr",' '"xff":"$http_x_forwarded_for",' '"domain":"$host",' '"url":"$uri",' '"referer":"$http_referer",' '"args":"$args",' '"upstreamtime":"$upstream_response_time",' '"responsetime":"$request_time",' '"request_method":"$request_method",' '"status":"$status",' '"size":"$body_bytes_sent",' '"request_body":"$request_body",' '"request_length":"$request_length",' '"protocol":"$server_protocol",' '"upstreamhost":"$upstream_addr",' '"file_dir":"$request_filename",' '"http_user_agent":"$http_user_agent"' '}'; access_log /var/log/nginx/access.log aka_logs;重新加载nginx$ nginx -t && nginx -s reload4、安装es集群因服务器有限，采用docker方式安装es集群管理为docker-compose4.1 安装docker略4.2 安装docker-compose$ yum install epel-release $ yum install docker-compose4.3 编写es的docker-compose yaml文件参照https://www.elastic.co/guide/en/elasticsearch/reference/7.5/docker.html yaml文件如下：version: '2.2' services: elasticsearch: image: elasticsearch:7.8.0 container_name: grafana_es7_01 environment: - node.name=grafana_es7_01 - cluster.name=grafana_es-cluster - discovery.seed_hosts=grafana_es7_02,grafana_es7_01 - cluster.initial_master_nodes=grafana_es7_01,grafana_es7_02 - bootstrap.memory_lock=true - "ES_JAVA_OPTS=-Xms512m -Xmx512m" ulimits: memlock: soft: -1 hard: -1 volumes: - /data/es/data/es01:/usr/share/elasticsearch/data ports: - 9200:9200 - 9300:9300 networks: - elastic elasticsearch2: image: elasticsearch:7.8.0 container_name: grafana_es7_02 environment: - node.name=grafana_es7_02 - cluster.name=grafana_es-cluster - discovery.seed_hosts=grafana_es7_01,grafana_es7_02 - cluster.initial_master_nodes=grafana_es7…

NODE_EXPORTER 修改端口
type: item
date: 2021-08-11T06:55:00+00:00
description: 修改prometheus中node-exporter端口因其他业务已占用9100端口，需修改为其他端口# 启动时指定端口 $ nohup ./node_exporter --web.listen-address=:7100 &