sudo useradd prometheus sudo mkdir /etc/prometheus sudo chown prometheus:prometheus /etc/prometheus
# 下载地址https://prometheus.io/download/ # 切换到Prometheus用户 sudo su - prometheus # 下载prometheus安装文件 wget https://github.com/prometheus/prometheus/releases/download/v2.6.0/prometheus-2.6.0.linux-amd64.tar.gz # 解压文件 tar xzf prometheus-2.0.0.linux-amd64.tar.gz # 将可执行文件复制到/usr/local/bin目录下 sudo cp prometheus-2.6.0.linux-amd64/prometheus /usr/local/bin/ sudo cp prometheus-2.6.0.linux-amd64/promtool /usr/local/bin/ # 将Prometheus的界面模版复制到/etc/prometheus目录下 cp -R prometheus-2.6.0.linux-amd64/consoles /etc/prometheus cp -R prometheus-2.6.0.linux-amd64/console_libraries /etc/prometheus
global: scrape_interval: 15s # By default, scrape targets every 15 seconds. # Attach these labels to any time series or alerts when communicating with # external systems (federation, remote storage, Alertmanager). external_labels: monitor: 'codelab-monitor' # A scrape configuration containing exactly one endpoint to scrape: # Here it's Prometheus itself. scrape_configs: # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. - job_name: 'prometheus' # Override the global default and scrape targets from this job every 5 seconds. scrape_interval: 5s static_configs: - targets: ['localhost:9090']
[Unit] Description=Prometheus Wants=network-online.target After=network-online.target [Service] User=prometheus Group=prometheus Type=simple ExecStart=/usr/local/bin/prometheus --config.file /etc/prometheus/prometheus.yml --storage.tsdb.path /home/prometheus/data/prometheus/ --web.console.templates=/etc/prometheus/consoles --web.console.libraries=/etc/prometheus/console_libraries --web.external-url=http://<monitor.domain.name> [Install] WantedBy=multi-user.target
# 启动服务 sudo systemctl start prometheus # 设置服务开机时自动重启 sudo systemctl enable prometheus # 查看服务配置状态 sudo systemctl status prometheus
upstream http_monitor { server localhost:9090; keepalive 300; } server { listen 80; server_name <prometheus.domain.name>; location / { auth_basic "Prometheus server authentication"; auth_basic_user_file /etc/nginx/.htpasswd; proxy_pass http://http_monitor; proxy_http_version 1.1; proxy_set_header Connection ""; proxy_buffers 4096 32k; proxy_buffer_size 32K; proxy_busy_buffers_size 32k; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_cache_bypass $http_upgrade; } }
sudo yum install httpd-tools sudo htpasswd -c /etc/nginx/.htpasswd user1
# 介绍页面https://grafana.com/grafana/download?platform=linux wget https://dl.grafana.com/oss/release/grafana-5.4.2-1.x86_64.rpm sudo yum localinstall grafana-5.4.2-1.x86_64.rpm
# Grafana的配置文件路径:/etc/grafana/grafana.ini
# Grafana数据文件路径:/var/lib/grafana
upstream http_grafana_monitor { server localhost:3000; keepalive 300; } server { listen 80; server_name <grafana.domain.name>; location / { proxy_pass http://http_grafana_monitor; proxy_http_version 1.1; proxy_set_header Connection ""; proxy_buffers 4096 32k; proxy_buffer_size 32K; proxy_busy_buffers_size 32k; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_cache_bypass $http_upgrade; } }