安装 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