sudo useradd prometheussudo mkdir /etc/prometheussudo 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/prometheuscp -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=` 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=PrometheusWants=network-online.targetAfter=network-online.target[Service]User=prometheusGroup=prometheusType=simpleExecStart=/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://[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; 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-toolssudo htpasswd -c /etc/nginx/.htpasswd user1
# 介绍页面https://grafana.com/grafana/download?platform=linuxwget 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; 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; }}