Prometheus搭建以及使用

安装 prometheus:

1.创建用户以及组:useradd -m -s /bin/false prometheus

2.创建目录:

mkdir /etc/prometheus

mkdir /var/lib/prometheus

3.授权:chown prometheus /var/lib/prometheus/

4.下载安装包:

wget https://github.com/prometheus/prometheus/releases/download/v2.23.0/prometheus-2.23.0.linux-amd64.tar.gz

5.解压:tar zxvf prometheus-2.23.0.linux-amd64.tar.gz

6.进入解压目录:cd prometheus-2.23.0.linux-amd64

7.复制文件到路径:

cp prometheus /usr/local/bin

cp promtool /usr/local/bin

8.编辑配置:vim /etc/prometheus/prometheus.yml

global: scrape_interval:15s #设置间隔为每15秒。默认值为每1分钟

Evaluation_interval:15s #每15秒评估一次规则。默认值为每1分钟

scrape_timeout:15s #scrape_timeout设置为全局默认值(10s)

9.防火墙放行:iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 9090 -j ACCEPT

10.保存:service iptables save

11.重启:/bin/systemctl restart iptables.service

12.创建文件:vi /etc/systemd/system/prometheus.service

[Unit] Description=Prometheus Time Series Collection and Processing Server Wants=network-online.target After=network-online.target

[Service] User=prometheus Group=prometheus Type=simple ExecStart=/usr/local/bin/prometheus \ --config.file /etc/prometheus/prometheus.yml \ --storage.tsdb.path /var/lib/prometheus/ \ --web.console.templates=/etc/prometheus/consoles \ --web.console.libraries=/etc/prometheus/console_libraries

[Install] WantedBy=multi-user.target

13.重载 systemctl :systemctl daemon-reload

14.启动以及开机自启:systemctl start prometheus && systemctl enable prometheus

15.查看:systemctl status prometheus

16.访问:http://ip:9090

安装 node_exporter :(收集数据程序)

1.创建用户:useradd -m -s /bin/false node_exporter

2.下载安装包:

wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz

3.解压:tar zxvf node_exporter-1.0.1.linux-amd64.tar.gz

4.复制文件到路径:cp node_exporter-1.0.1.linux-amd64/node_exporter /usr/local/bin

5.授权:chown node_exporter:node_exporter /usr/local/bin/node_exporter

6.编辑启动服务文件:vi /etc/systemd/system/node_exporter.service

[Unit] Description=Prometheus Node Exporter Wants=network-online.target After=network-online.target

[Service] User=node_exporter Group=node_exporter Type=simple ExecStart=/usr/local/bin/node_exporter

[Install] WantedBy=multi-user.target

7.重载 systemctl :systemctl daemon-reload

8.启动以及开机自启:systemctl start node_exporter && systemctl enable node_exporter

9.启动并使节点导出器在系统引导时运行:systemctl enable --now node_exporter.service

10.查看:systemctl status node_exporter

11.防火墙放行:iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 9100 -j ACCEPT

12.保存:service iptables save

13.重启:/bin/systemctl restart iptables.service

14.prometheus 修改配置:vim /etc/prometheus/prometheus.yml

- job_name: 'node_exporter' #名字

static_configs:

- targets: ['localhost:9090']

- targets: ['192.168.6.160:9100'] #ip加端口

15.重启服务:systemctl restart prometheus

16.网页可打开测试:http://ip:9100/metrics

安装 mysql_exporter:(监控数据库)

一、文件安装:

1.下载安装包:

wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz

2.解压:tar zxvf mysqld_exporter-0.12.1.linux-amd64.tar.gz

3.移动加重命名:mv mysqld_exporter-0.12.1.linux-amd64 /usr/local/mysql_exporter

4.编辑文件:vim /usr/local/mysql_exporter/.my.cnf

[client] user=账号 password=密码

host=ip

port=端口

注意:数据库要有一个授权的账号

5.进入目录:cd /usr/local/mysql_exporter/

6.防火墙放行:iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 9104 -j ACCEPT

7.保存:service iptables save

8.重启:/bin/systemctl restart iptables.service

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值