当前位置:网站首页>node_exporter部署
node_exporter部署
2022-07-04 17:40:00 【码道人】
首先查看当前服务器的centos的版本
cat /etc/centos-release
被监控的服务器操作:
一、下载安装包(解压、改名字)
centos7:
wget https://github.com/prometheus/node_exporter/releases/download/v1.3.0/node_exporter-1.3.0.linux-amd64.tar.gz
centos6:
可以直接去网页上https://github.com/prometheus/nodeexporter/releases/download/v1.3.0/nodeexporter-1.3.0.linux-amd64.tar.gz直接下载
上传到要被监控的服务器上解压至目录/usr/local/
解压:
tar xf node_exporter-1.3.0.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/
mv node_exporter-1.3.0.linux-amd64/ node_exporter
二、配置文件,分为centos6和centos7的方法
centos7的方法
没有则创建目录与文件/usr/lib/systemd/system/node_exporter.service
创建目录:mkdir
创建文件:touch
#vi /usr/lib/systemd/system/node_exporter.service
[unit]
Description=The node_exporter Server
After=network.target
[Service]
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure
RestartSec=15s
SyslogIdentifier=node_exporter
[Install]
WantedBy=multi-user.target
wq保存退出
#systemctl daemon-reload
#systemctl enable node_exporter
#systemctl restart node_exporter
# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 128 *:9100 *:*
centos6
vi /etc/init.d/node_exporte
里面的注释也要加进去,不加进去会报错
在文件中添加如下内容
#!/bin/bash
# chkconfig: 2345 10 90
# description: node_exporter
# 20220630
case "$1" in
start)
nohup /usr/local/node_exporter >/usr/local/logs/node_exporter.log 2>&1 &
echo "node_exporter started"
;;
stop)
ps -ef | grep node_exporter | grep -v grep | awk '{print "kill -9 "$2}' | sh
echo "node_exporter stoped"
;;
esac
:wq保存退出
配置文件可执行权限
#chmod +x /etc/init.d/node_exporter
将node_exporter添加到系统服务
#chkconfig --add node_exporter
开启或者关闭node_exporter
service node_exporter start
service node_exporter stop
开启node_exporter.service自启动
chkconfig node_exporter on
三、去配置prometheus主机上的/usr/local/prometheus/prometheus.yml增加被监控的服务器,以下是整个源码,localhost不需要改,只需要添加最后的ip
vim /usr/local/prometheus/prometheus.yml
global:
scrape_interval: 15s
scrape_timeout: 10s
evaluation_interval: 15s
alerting:
alertmanagers:
# static_configs:
#- targets: [localhost:9093]
# - localhost:9093
scrape_configs:
- job_name: prometheus
scrape_interval: 15s
scrape_timeout: 10s
metrics_path: /metrics
scheme: http
static_configs:
- targets:
- localhost:9090
- job_name: node
static_configs:
- targets: ['localhost:9100']
- job_name: node1
static_configs:
- targets: ['192.168.0.xxx:9100']
:wq保存退出
检查配置文件是否正确,有报错则修改
./promtool check config prometheus.yml
四、启动prometheus命令
在prometheus主机上启动:
/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml &
&
启动9100
docker run -d --name node_exporter --restart=always -p 9100:9100 prom/node-exporter
去网页上打开http://192.168.0.125:9090/targets?search= 有多个job_name生成且状态up则部署完成
若启动不成功:如报错err="error starting web server: listen tcp 0.0.0.0:9090: bind: address already in use则进行以下步骤;
lsof -i:9090
杀掉进程
kill -9 进程号
若还不成功则去/usr/local/prometheus/data/,一定是自己的安装prometheus/data目录下
rm -rf lock
【//我之前是用docker安装的所以也要在docker里面杀掉,
docker ps
docker stop 容器id
查看进程
docker ps -a
杀掉进程
docker rm 进程号
查看容器
docker images
删除容器
docker rmi 容器id
】
主机重新启动prometheus
/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml
比较有用的参考:
启动prometheus遇到的问题 :
https://blog.csdn.net/wyp257/article/details/118326062
https://zhuanlan.zhihu.com/p/66631919
https://blog.csdn.net/apple198942/article/details/119780818
Prometheus怎么用来帮助解决性能问题之入门篇: https://blog.csdn.net/shandeai520/article/details/102865729
理论知识 :https://yunlzheng.gitbook.io/prometheus-book/part-ii-prometheus-jin-jie/grafana/grafana-intro
ps:Prometheus的配置文件最好的是:直接用自带的,自己加参数,要注意空格与换行,每次改完参数之后校验:./promtool check config prometheus.yml
若所有的都没问题,网页上其他节点还是不出来,那就在主机 vim /etc/hosts 配置上被监控的ip和主机名,再重复以上的启动操作
边栏推荐
猜你喜欢
[2022 Jiangxi graduate mathematical modeling] curling movement idea analysis and code implementation
Torchdrug tutorial
Don't just learn Oracle and MySQL!
整理混乱的头文件,我用include what you use
LeetCode第300场周赛(20220703)
Scala基础教程--16--泛型
2022 ByteDance daily practice experience (Tiktok)
Scala基础教程--19--Actor
正则替换【JS,正则表达式】
Scala basic tutorial -- 18 -- set (2)
随机推荐
[mathematical basis of machine learning] (I) linear algebra (Part 1 +)
Cache é JSON uses JSON adapters
一、C语言入门基础
Wanghongru research group of Institute of genomics, Chinese Academy of Agricultural Sciences is cordially invited to join
C language printing exercise
ByteDance dev better technology salon was successfully held, and we joined hands with Huatai to share our experience in improving the efficiency of web research and development
Scala基础教程--14--隐式转换
Scala基础教程--13--函数进阶
LeetCode第300场周赛(20220703)
Improve the accuracy of 3D reconstruction of complex scenes | segmentation of UAV Remote Sensing Images Based on paddleseg
使用FTP
2021 合肥市信息学竞赛小学组
Using FTP
Wireshark抓包TLS协议栏显示版本不一致问题
输入的查询SQL语句,是如何执行的?
C#实现定义一套中间SQL可以跨库执行的SQL语句(案例详解)
Build your own website (15)
2022-07-04:以下go语言代码输出什么?A:true;B:false;C:编译错误。 package main import 'fmt' func
李迟2022年6月工作生活总结
Li Kou brush question diary /day1/2022.6.23