- prometheus
-
下载地址:https://prometheus.io/download/,选择自己要下载的平台。
-
启动服务:服务目录下的对应平台启动入口文件,这里以win为例 prometheus.exe
-
启动服务 ./prometheus.exe --config.file=“prometheus.yml” ,等待1分钟后可在prometheus的status->prometheus的信息了。
-
监控其他主机
- 下载node_exporter
- https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz
- tar -zxvf node_exporter-1.3.1.linux-amd64.tar.gz
- mv node_exporter-1.3.1.linux-amd64 /usr/local/node_exporter
- 启动 nohup /usr/local/node_exporter/node_exporter & [ 记得放行端口9100]
- prometheus增加配置
- job_name: '192.168.0.199' scrape_interval: 10s static_configs: - targets: - 192.168.0.199:9100
- 重启服务
-
监控nacos
- nacos服务的配置文件中打开management.endpoints.web.exposure.include=*,并启动服务
- prometheus配置文件增加一下内容
- job_name: 'nacos' scrape_interval: 10s metrics_path: '/nacos/actuator/prometheus' static_configs: - targets: - localhost:8848
- 检查文件配置文件是否正确 ./promtool check config prometheus.yml
- 重启服务
-
监控Mysql
- mysqld_exporter
- 下载地址 : wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.13.0/mysqld_exporter-0.13.0.linux-amd64.tar.gz
- 解压:tar -zxvf mysqld_exporter-0.13.0.linux-amd64.tar.gz
- 移动目录: mv ./mysqld_exporter-0.13.0.linux-amd64 /usr/local/mysqld_exporter
- 增加msyql授权用户
mysql> GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'%' identified by 'exporter'; mysql> flush privileges;
- 增加exporter的配置文件
cd /usr/local/mysqld_exporter vim .my.cnf [client] host=localhost user=exporter password=exporter
- 启动文件
cat > /usr/lib/systemd/system/mysqld_exporter.service <<EOF [Unit] Description=mysqld_exporter After=network.target [Service] Type=simple User=root ExecStart=/usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/.my.cnf Restart=on-failure [Install] WantedBy=multi-user.target EOF
这里是使用root启动的,如果需要调整用户权限组的话可以自行处理,如果有防火墙请自行处理9104端口放行
启动成功后会看到9104端口的服务已经起来了。- prometheus增加配置
- job_name: 'mysql-192.168.0.199' scrape_interval: 10s static_configs: - targets: [ '192.168.0.199:9104' ] labels: instance: mysql-199
- 重启服务
-
监控redis
- redis_exporter
- 下载地址:https://github.com/oliver006/redis_exporter/releases/tag/v1.35.1
- tar zxvf redis_exporter-v1.35.1.linux-amd64.tar.gz
- mv redis_exporter-v1.35.1.linux-amd64 /usr/local/redis_exporter
- 启动
- nohup ./redis_exporter -redis.addr localhost:6379 & 【无密码】
- nohup ./redis_exporter -redis.addr localhost:6379 -redis.password 123456 & 【有密码】
- 开放端口9121
- prometheus增加配置
- job_name: 'redis-192.168.0.199' scrape_interval: 10s static_configs: - targets: [ '192.168.0.199:9121' ] labels: instance: redis-199
- 重启服务
-
- grafana
- 下载地址:https://grafana.com/grafana/download(这里选择centos平台进行安装)
- 安装:wget https://dl.grafana.com/enterprise/release/grafana-enterprise-8.4.2-1.x86_64.rpm
&& sudo yum install grafana-enterprise-8.4.2-1.x86_64.rpm
-启动:systemctl start grafana-server
-打开浏览器,输入IP+端口,3000为Grafana的默认侦听端口【注意防火墙】,默认账号密码admin
-设置数据源为prometheus
-configuration->datasources->add data source -> 选择Prometheus
-导入官网模板- 地址:https://grafana.com/grafana/dashboards
- 查看导入的相应的dashboard即可