1.从github下载 prometheus及相关安装包
2.创建 prometheus 用户
sudo groupadd prometheus
sudo useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
3.解压及安装
sudo tar -zxvf prometheus-2.27.1.linux-amd64.tar.gz -C /usr/local/
sudo mv /usr/local/prometheus-2.27.1.linux-amd64 /usr/local/prometheus-2.27.1
4.修改prometheus-2.27.1 的所属用户
sudo chown -R prometheus:prometheus prometheus-2.27.1
5.创建 /usr/lib/systemd/system 文件夹
sudo mkdir /usr/lib/systemd/system
6.创建prometheus.service 启动脚本
[Unit]
Description=prometheus
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/prometheus-2.27.1/prometheus --config.file=/usr/local/prometheus-2.27.1/prometheus.yml --storage.tsdb.path=/var/lib/prometheus --storage.tsdb.retention=15d --log.level=info
Restart=on-failure
[Install]
WantedBy=multi-user.target
7.使启动脚本及服务可用
systemctl enable prometheus.service
systemctl start prometheus.service
systemctl status prometheus.service
---------------------------------------------------------------------------------------------------------------
8. 解压及重命名 node_exporter
sudo tar -zxvf node_exporter-1.1.2.linux-amd64.tar.gz -C /usr/local/
sudo mv node_exporter-1.1.2.linux-amd64 node_exporter-1.1.2
9.修改node_exporter-1.1.2所属用户
sudo chown -R prometheus:prometheus node_exporter-1.1.2
10.创建 node_exporter.service 启动脚本
vim /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_export
Documentation=https://github.com/prometheus/node_exporter
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/node_exporter-1.1.2/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
11.启动脚本及服务可用
systemctl enable node_exporter.service
systemctl status node_exporter.service
systemctl start node_exporter.service
12. 查看node_exporter端口是否打开
ss -tnl | grep 9100
13.配置prometheus添加监控目标
vim prometheus.yml
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090','localhost:9100'] # 对本机node_exporter 监控
# 新添加的对其它node节点抓取数据
- job_name: '211'
#重写了全局抓取间隔时间,由15秒重写成5秒。
scrape_interval: 5s
static_configs:
- targets: ['192.168.1.211:9100']
14.访问 Prometheus WEB 查看我们定义的目标主机:http://192.168.1.210:9090/targets
15.安装grafana
sudo
apt-get
install
-y apt-transport-https
sudo
apt-get
install
-y software-properties-common
wget
wget
-q -O - https://packages.grafana.com/gpg.key
|
sudo
apt-key
add
-
echo
"deb https://packages.grafana.com/oss/deb stable main"
|
sudo
tee
-a /etc/apt/sources.list.d/grafana.list
sudo
apt-get
update
sudo
apt-get
install
grafana
sudo
systemctl daemon-reload
sudo
systemctl start grafana-server
sudo
systemctl status grafana-server
sudo
systemctl
enable
grafana-server.service
16.安装grafana插件
获取grafana插件列表
sudo grafana-cli plugins list-remote
饼状图形展示
sudo
grafana-cli plugins install grafana-piechart-panel
安装其他图形插件
sudo
grafana-cli plugins install grafana-clock-panel
钟表形展示
sudo
grafana-cli plugins install briangann-gauge-panel
字符型展示
sudo
grafana-cli plugins install natel-discrete-panel
服务器状态
sudo
grafana-cli plugins install vonage-status-panel
安装
DataSource Plugins
sudo grafana-cli plugins install vertamedia-clickhouse-datasource
插件卸载:
grafana-cli plugins uninstall vonage-status-panel
安装和卸载后需要重启
grafana
才能够生效
17. Grafana配置clickhouse数据源
18.配置Grafana的dashboard并引入官方的clickhouse模板
点击 ➕ ==> Import ==> 填写模板号13606 ==> 点击load
19.得到模板结果并保存
20. Grafana配置Prometheus数据源
21. Grafana配置导入官方主机监控指标模板
点击 ➕ ==> Import ==> 填写模板号8919 ==> 点击load
22.得到模板结果并保存