安装exporter
下载安装node_exporter、mysqld_exporter。从官网下载https://prometheus.io/download/
版本分别为node_exporter-0.18.1、mysqld_exporter-0.12.1。
1) 安装node_exporter
wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
mkdir -p /opt/prometheus
tar xzvf node_exporter-0.18.1.linux-amd64.tar.gz
mv node_exporter-0.18.1.linux-amd64 /opt/prometheus/
ln -s /opt/prometheus/node_exporter-0.18.1.linux-amd64/ /opt/prometheus/node_exporter
添加系统服务启动.
先创建prometheus用户,用于启动node_exporter。
useradd -s /sbin/nologin -M prometheus
vim /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/opt/prometheus/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
启动node_exporter服务
systemctl status node_exporter.service
2) 安装mysqld_exporter
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
mkdir -p /opt/prometheus
mv /usr/local/mysqld_exporter-0.12.1.linux-amd64/ /opt/prometheus/
ln -s /opt/prometheus/mysqld_exporter-0.12.1.linux-amd64/ /opt/prometheus/mysqld_exporter
chown -R prometheus:prometheus /opt/prometheus/
添加系统服务启动.
先创建prometheus用户,用于启动mysqld_exporter。
useradd -s /sbin/nologin -M prometheus
vim /usr/lib/systemd/system/mysqld_exporter.service
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/opt/prometheus/mysqld_exporter/mysqld_exporter --config.my-cnf=/opt/prometheus/mysqld_exporter/.my.cnf
Restart=on-failure
[Install]
WantedBy=multi-user.target
启动参数:--config.my-cnf=".my.cnf" #指定配置文件
启动mysqld_exporter服务
systemctl status mysqld_exporter.service
mysqld_exporter需要连接到Mysql,所以需Mysql的权限,创建mysql_exporter用户并赋予所需的权限。
mysql> GRANT REPLICATION CLIENT,PROCESS ON *.* TO ‘mysql_exporter‘@‘localhost‘ identified by ‘xxxxxx‘;
mysql> GRANT SELECT ON *.* TO ‘mysql_exporter‘@‘localhost‘;
创建.my.cnf文件,并重启mysqld_exporter服务。
vim /opt/prometheus/mysqld_exporter/.my.cnf
[client]
user=mysql_exporter
password=xxxxxx