一 Prometheus + node_exporter + Grafana 安装和部署

1 ) Prometheus Server 端安装

# 1.1 ) Promethrus Server 端下载:
cd /data/src/
wget https://github.com/prometheus/prometheus/releases/download/v2.23.0/prometheus-2.23.0.linux-amd64.tar.gz
tar -zxf  prometheus-2.23.0.linux-amd64.tar.gz 

# 1.2 Prometheus server 部署:
mv prometheus-2.23.0.linux-amd64 /data/soft/
cd /data/soft/
ln -sv /data/soft/prometheus-2.23.0.linux-amd64 /data/soft/prometheus

2 ) 创建 Prometheus 启动脚本:

# 2.1 ) 启动脚本:
    vim /etc/systemd/system/prometheus.service

[Unit]
Description=Prometheus Server
Documentation=https:/prometheus.io/docs/introduction/overview/
After=network.target

[Service]
Type=simple
User=work               # 此处注意 用户一定要存在并且有proemtheus 目录读写权限,否则用root也可以.
Restart=on-failure
WorkingDirectory=/data/soft/prometheus/        # 注意路径
ExecStart=/data/soft/prometheus/prometheus --config.file=/data/soft/prometheus/prometheus.yml   # 配置文件可以复制一份起这个名字.

[Install]
WantedBy=multi-user.target

3 ) 启动prometheus服务:

# 3.1 ) 启动Prometheus server:

 systemctl daemon-reload
 systemctl restart prometheus
 systemctl enable prometheus

4 ) 验证是否启动:

# 4.1 ) 检查端口(9090):
     ss -tunkpa | grep 9090   or  lsof -i: 9090

# 4.2 ) 访问Prometheus Web页面:
http://IP:9090/                        #如果安装成功界面就会出来

*** 首页截图 ***

5 ) Prometheus 配置文件:





6 ) 安装 Prometheus client (node_exporter):

# 6.1 ) 下载并安装node_exporter:
cd /data/src/
wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz
tar -zxf node_exporter-1.0.1.linux-amd64.tar.gz && mv node_exporter-1.0.1.linux-amd64 /data/soft/ 
ln -sv /data/soft/node_exporter-1.0.1.linux-amd64 /data/soft/node_exporter

# 6.2 ) 添加运行用户:
groupadd 1010 work
usreadd -g 1010 -u 1010 work -S /sbin/nologin
echo "qwe123" | passwd --stdin  work

# 6.3 ) 给目录赋予权限:
chown -R work.work /data/soft/node_exporter-1.0.1.linux-amd64 /data/soft/node_exporter
*** 以上添加用户添加很关键 *** 

7 ) node_exporter 启动脚本:

# 7.1 ) node_exporter 启动脚本内容:
    vim /etc/systemd/system/node-exporter.service

[Unit]
Description=Prometheus Node Exporter
After=network.targat

[Service]
Type=simple
User=work                  # 注意用户
Restart=on-failure
WorkingDirectory=/data/soft/node_exporter/   #注意目录
ExecStart=/data/soft/node_exporter/node_exporter

[Install]
WantedBy=multi-user.target

8 ) node_exporter 启动命令:

# 8.1 ) 启动 node_exporter :
   systemctl daemon-reload
   systemctl enable node-exporter
   systemctl start node-exporter
   systemctl status node-exporter

9 ) 验证是否启动:

## 9.1 ) 查看端口是否被占用:
   ss -tunlpa | grep 9100    or lsof -i:9100

## 9.2 ) 访问Node 节点页面:
   http://IP:9100/metrics
   

10 ) Grafana Web 安装:

主页: https://grafana.com/docs/

# 10.1 ) 下载并安装grafana-7.3.5:
cd /data/src/
wget https://dl.grafana.com/oss/release/grafana-7.3.5.linux-amd64.tar.gz
tar -zxvf grafana-7.3.5.linux-amd64.tar.gz
mv /data/src/grafana-7.3.5 /data/soft/grafana-7.3.5
ln -sv /data/soft/grafana-7.3.5 /data/soft/grafana

cd /data/soft/grafana-7.3.5/conf

# 10.3 ) Grafana 用户添加,如存在请略过这步,直接下一步:
groupadd 1010 work
usreadd -g 1010 -u 1010 work 
echo "qwe123" | passwd --stdin  work

chown -R work.work /data/soft/grafana
*** 以上添加用户很关键 *** 


# 10.4 ) Grafana 启动命令:
/data/soft/grafana/bin/grafana-server -config=/data/soft/grafana/conf/defaults.ini

11 ) Grafana 启动脚本:

# 11.1 ) node_exporter 启动脚本内容:
   vim /etc/systemd/system/grafana.service

[Unit]
Description=grafane web ui
After=network.targat

[Service]
Type=simple
User=work
Restart=on-failure
WorkingDirectory=/data/soft/grafana/
ExecStart=/data/soft/grafana/bin/grafana-server -config=/data/soft/grafana/conf/defaults.ini

[Install]
WantedBy=multi-user.target

12 ) 启动 Grafana-server :

 # 12.1 ) 启动 Grafana server:
sudo systemctl daemon-reload
sudo systemctl start grafana.server
sudo systemctl status grafana.server

上一篇:azkaban3.9.0安装教程


下一篇:shell安装kettle