(一) 安裝prometheus install
$ wget https://github.com/prometheus/prometheus/releases/download/v2.4.3/prometheus-2.4.3.linux-amd64.tar.gz
$ tar zxvf prometheus-2.4.3.linux-amd64.tar.gz
$ cd prometheus-2.4.3.linux-amd64
如果需要添加新的job,在這個文件添加
$ vim prometheus.yml
global:
scrape_interval: 15s
evaluation_interval: 15s
# scrape_timeout is set to the global default (10s).
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
rule_files:
scrape_configs:
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
- job_name: 'linux1'
static_configs:
- targets: ['192.xxx.xx.xx:9100']
labels:
instance: server1
- job_name: 'linux2'
static_configs:
- targets: ['192.xxx.xx.xx:9100']
labels:
instance: server2
運行 start Prometheus $ nohup ./prometheus &
改成systemd服務
$ cd ..
$ sudo mv prometheus-2.4.3.linux-amd64 /usr/local/prometheus
$ sudo groupadd prometheus
$ sudo useradd -g prometheus -m -d /usr/local/prometheus -s /sbin/nologin prometheus
$ sudo chown -R prometheus:prometheus /usr/local/prometheus
$ sudo vim /etc/systemd/system/prometheus.service # 寫入如下內容
[Unit]
Description=prometheus
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/usr/local/prometheus
Restart=on-failure
[Install]
WantedBy=multi-user.target
Prometheus自帶一個Web網站,默認端口爲9090, http://ip:9090.可以查看表達式搜索結果、報警配置、prometheus配置,exporter狀態等.
(二) 安裝配置Grafana
官方安裝文檔: https://grafana.com/grafana/download?platform=linux
http://docs.grafana.org/installation/
$ wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana_5.3.0_amd64.deb
$ sudo dpkg -i grafana_5.3.0_amd64.deb
$ sudo systemctl status grafana-server #默認進入了運行的狀態
$ sudo systemctl enable grafana-server
需要開放3000端口的訪問權限 https://blog.csdn.net/zbljz98/article/details/80464761
$ iptables -A INPUT -p tcp --dport 3000 -j ACCEPT
我開始的時候就是沒做這一步,導致無法在ip:3000端口訪問
進入登錄頁面,首次訪問的用戶名是admin, 密碼是 admin
首次登錄之後會要求你更換密碼