一竟秫、部署prometheus,grafana和node_exporter
Prometheus開始教程:https://github.com/Alrights/prometheus/blob/master/introductions/FirstSteps.md
1.1 環(huán)境(centos7)
[root@localhost prometheus]# uname -a
Linux localhost.localdomain 3.10.0-957.10.1.el7.x86_64 #1 SMP Mon Mar 18 15:06:45 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
1.2 環(huán)境部署與服務啟動
// 安裝prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.9.2/prometheus-2.9.2.linux-amd64.tar.gz
tar xzvf prometheus-2.9.2.linux-amd64.tar.gz
mv prometheus-2.9.2.linux-amd64 /usr/local/prometheus
// 添加prometheus用戶贤徒,非必須
groupadd prometheus
useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
對systemctl不熟的可以了解鳥哥的Linux私房菜
// prometheus系統(tǒng)服務配置
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.local.path=/var/lib/prometheus
Restart=on-failure
[Install]
WantedBy=multi-user.target
// 啟動prometheus
systemctl start prometheus
systemctl status prometheus
- node_exporter setup
// 安裝node_exporter
wget https://github.com/prometheus/node_exporter/releases/download/v0.18.0/node_exporter-0.18.0.linux-amd64.tar.gz
tar -zxvf node_exporter-0.18.0.linux-amd64.tar.gz
mv node_exporter-0.18.0.linux-amd64 /usr/local/node_exporter
// 系統(tǒng)服務配置node_exporter
vim /etc/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
systemctl start node_exporter
systemctl status node_exporter
- add node_exporter to prometheus.yaml
vim /usr/local/prometheus/prometheus.yml
- job_name: 'linux'
static_configs:
- targets: ['localhost:9100']
labels:
instance: node1
systemctl restart prometheus
systemctl status prometheus
- grafana setup
// 安裝grafana
wget https://dl.grafana.com/oss/release/grafana-6.1.6-1.x86_64.rpm
yum localinstall grafana-6.1.6-1.x86_64.rpm
// 啟動grafana-server
systemctl start grafana-server
systemctl status grafana-server
二、儀表化
2.1 prometheus
prometheus默認端口為9090,可以在瀏覽器中輸入http://localhost:9090/
2.2 granafa
granafa默認端口為3000竹挡,可以在瀏覽器中輸入http://localhost:3000/
- granafa首次登錄賬戶名和密碼
admin/admin
趾疚,可以修改 - 配置數(shù)據(jù)源
Data sources->Add data source -> Prometheus
,輸入prometheus數(shù)據(jù)源的信息猩谊,主要是輸入name
和url
- 添加Dashboard
New Dashboard->Import Dashboard->輸入8919
千劈,配置數(shù)據(jù)源為Prometheus,即上一步中的name
-
配置完保存后即可看到逼格非常高的系統(tǒng)主機節(jié)點監(jiān)控信息牌捷,包括CPU墙牌、IO、網(wǎng)絡等信息暗甥。
三喜滨、tips
- iptables(端口不通)
/sbin/iptables -I INPUT -p tcp --dport 9090 -j ACCEPT
- datetime(設置時區(qū))
timedatectl list-timezones
timedatectl set-timezone Asia/Shanghai
四、鏈接
Prometheus官網(wǎng)地址:https://prometheus.io/
我的Github:https://github.com/Alrights/prometheus