配置node节点
- 各组件默认端口
node 默认端口:9100
mysql默认端口:9104
redis 默认端口:9121
process默认端口:9256
alertmanager默认端口:9093
在系统层用作系统监控exporter
同样在官网先下载上传好二进制包
解压并启动
[root@prometheus_node01 ~]# tar xf node_exporter-0.18.1.linux-amd64.tar.gz -C /usr/local/
[root@prometheus_node01 ~]# ln -sv /usr/local/node_exporter-0.18.1.linux-amd64/ /usr/local/Prometheus_node/
[root@prometheus_node01 ~]# nohup /usr/local/Prometheus_node/node_exporter &
- 配置systemd启动node_exporter
[root@prometheus_node01 ~]# vim /lib/systemd/system/node_exporter.service
[Unit]
Description=Node_exporter
After=network.target
[Service]
ExecStart=/usr/local/Prometheus_node/node_exporter
[Install]
WantedBy=multi-user.target
# 重载配置并设置开机自启
[root@prometheus_node01 ~]# systemctl daemon-reload
[root@prometheus_node01 ~]# systemctl start node_exporter
[root@prometheus_node01 ~]# systemctl enable node_exporter
- 在Prometheus的server端添加job任务
[root@prometheus ~]# vim /usr/local/Prometheus/prometheus/prometheus.yml
- job_name: 'node_exporter'
static_configs:
- targets: [ 172.16.214.140:9100 ]
去监控界面下的Targets刷新一下,这时候node节点红色的down会变成绿色的up,说明配置成功。
配置mysql_exporter组件
- 下载上传二进制包,执行如下命令:
[root@prometheus_mysqld ~]# tar xf mysqld_exporter-0.12.1.linux-amd64.tar.gz -C /usr/local/
[root@prometheus_mysqld ~]# ln -sv /usr/local/mysqld_exporter-0.12.1.linux-amd64/ /usr/local/Prometheus_mysqld
- 在mysql中用作监控的用户,并授权
mysql> CREATE USER 'mysqld_exporter'@'%' IDENTIFIED BY 'mysqld_exporter';
mysql> GRANT REPLICATION CLIENT,PROCESS ON *.* TO 'mysqld_exporter'@'%' identified by 'mysqld_exporter';
mysql> GRANT SELECT ON *.* TO 'mysqld_exporter'@'%';
# 如果提示密码太简单,那就修改的复杂点,或者取消密码负责规则
- 写一个mysqld_exporter的配置文件
[root@prometheus_mysqld ~]# vim /usr/local/Prometheus_mysqld/.my.cnf
[client]
user=mysqld_exporter
password=mysqld_exporter
port=3307
- 启动mysqld_exporter组件
[root@prometheus_mysqld ~]# nohup /usr/local/Prometheus_mysqld/mysqld_exporter --config.my-cnf=/usr/local/Prometheus_mysqld/.my.cnf &
去监控界面下的Targets刷新一下,如果down变成up,说明此节点监控对象配置成功。
- 配置systemd启动mysqld_exporter
[root@prometheus_mysqld ~]# vim /lib/systemd/system/mysqld_exporter.service
[Unit]
Description=Mysqld_exporter
After=network.target
[Service]
ExecStart=/usr/local/Prometheus_mysqld/mysqld_exporter --config.my-cnf=/usr/local/Prometheus_mysqld/.my.cnf
[Install]
WantedBy=multi-user.target
# 重载配置并设置开机自启
[root@prometheus_mysqld ~]# systemctl daemon-reload
[root@prometheus_mysqld ~]# systemctl start mysqld_exporter
[root@prometheus_mysqld ~]# systemctl enable mysqld_exporter
- 在Prometheus的server端添加job任务
[root@prometheus ~]# vim /usr/local/Prometheus/prometheus/prometheus.yml
- job_name: 'node_mysqld'
static_configs:
- targets: [ 172.16.214.140:9104 ]
配置redis_exporter组件
- 下载地址
wget https://github.com/oliver006/redis_exporter/releases/download/v1.3.4/redis_exporter-v1.3.4.linux-amd64.tar.gz
想安装指定历史版本,点此进入:redis_exporter组件库
- json包下载地址
https://grafana.com/api/dashboards/763/revisions/1/download
- 配置redis_exporter
[root@prometheus_redis ~]# tar xf redis_exporter-v1.3.4.linux-amd64.tar.gz -C /usr/local/
[root@prometheus_redis ~]# ln -sv /usr/local/redis_exporter-v1.3.4.linux-amd64/ /usr/local/Prometheus_redis
[root@prometheus_redis ~]# nohup /usr/local/Prometheus_redis/redis_exporter redis//localhost:6379 -web.listenaddress 0.0.0.0:9121 &
- 配置systemd启动redis_exporter
[root@prometheus_redis ~]# vim /lib/systemd/system/redis_exporter.service
[Unit]
Description=Redis_exporter
After=network.target
[Service]
ExecStart=/usr/local/Prometheus_redis/redis_exporter redis//localhost:6379 -web.listenaddress 0.0.0.0:9121
[Install]
WantedBy=multi-user.target
# 重载配置并设置开机自启
[root@prometheus_redis ~]# systemctl daemon-reload
[root@prometheus_redis ~]# systemctl start redis_exporter
[root@prometheus_redis ~]# systemctl enable redis_exporter
- 在Prometheus的server端添加job任务
[root@prometheus ~]# vim /usr/local/Prometheus/prometheus/prometheus.yml
- job_name: 'node_redis'
static_configs:
- targets: [ 172.16.214.140:9121 ]
配置process-exporter
- 下载地址
wget https://github.com/ncabatoff/process-exporter/releases/download/v0.4.0/process-exporter-0.4.0.linux-amd64.tar.gz
- 配置文件路径
[root@prometheus ~]# tar xf process-exporter-0.4.0.linux-amd64.tar.gz -C /usr/local/
[root@prometheus ~]# ln -sv /usr/local/process-exporter-0.4.0.linux-amd64/ /usr/local/Prometheus_process
- 修改配置文件
[root@prometheus ~]# vim /usr/local/Prometheus_process/process-exporter-ncabatoff.yaml
process_names:
- name: "{{.Matches}}"
cmdline:
- 'redis-server'
- name: "{{.Matches}}"
cmdline:
- 'mysqld'
- name: "{{.Matches}}"
cmdline:
- 'org.apache.zookeeper.server.quorum.QuorumPeerMain'
- name: "{{.Matches}}"
cmdline:
- 'org.apache.hadoop.mapreduce.v2.hs.JobHistoryServer'
- name: "{{.Matches}}"
cmdline:
- 'org.apache.hadoop.hdfs.qjournal.server.JournalNode'
注 cmdline: 所选进程的唯一标识,ps -ef 可以查询到。如果该进程不存在,则不会有该进程的数据采集到。
- 启动process-exporter
[root@prometheus ~]# nohup /usr/local/Prometheus_process/process-exporter -config.path=/usr/local/Prometheus_process/process-exporter-ncabatoff.yaml &
- 配置systemd启动process-exporter
[root@prometheus_redis ~]# vim /lib/systemd/system/process-exporter.service
[Unit]
Description=Redis_exporter
After=network.target
[Service]
ExecStart=/usr/local/Prometheus_process/process-exporter -config.path=/usr/local/Prometheus_process/process-exporter-ncabatoff.yaml
[Install]
WantedBy=multi-user.target
# 重载配置并设置开机自启
[root@prometheus_redis ~]# systemctl daemon-reload
[root@prometheus_redis ~]# systemctl start process-exporter
[root@prometheus_redis ~]# systemctl enable process-exporter
- 在Prometheus的server端添加job任务
[root@prometheus ~]# vim /usr/local/Prometheus/prometheus/prometheus.yml
- job_name: ‘process’
static_configs:
- targets: ['192.168.137.128:9256']
扩展
- export组件修改监听端口
# 如果需要修改export组件的监听端口或其他配置,建议使用--help查看配置参数
# 修改监听端口的参数大多数都是--web.listen-address=":xxxx"
# 在启动命令中添加配置参数
usage: mysqld_exporter [<flags>]
Flags:
-h, --help Show context-sensitive help (also try --help-long and --help-man).
--web.listen-address=":9104"
Address to listen on for web interface and telemetry.
# 示例
/usr/local/Prometheus_node/node_exporter --web.listen-address=":9200"