[root@VM-0-9-centos system]# cat /usr/lib/systemd/system/prometheusd.service [Unit] Description=Prometheus [Service] ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --web.enable-lifecycle Restart=on-failure [Install] WantedBy=multi-user.target [root@VM-0-9-centos system]# systemctl daemon-reload [root@VM-0-9-centos system]# systemctl start prometheusd
[root@VM-0-9-centos node_exporter-1.3.1.linux-amd64]# vim /usr/lib/systemd/system/node-exporter.service [Unit] Description=This is prometheus node exporter After=node_exporter.service [Service] Type=simple ExecStart=/usr/local/node_exporter-1.3.1.linux-amd64/node_exporter ExecReload=/bin/kill -HUP KillMode=process Restart=on-failure [Install] WantedBy=multi-user.target [root@VM-0-9-centos node_exporter-1.3.1.linux-amd64]# systemctl daemon-reload [root@VM-0-9-centos node_exporter-1.3.1.linux-amd64]# systemctl start node-exporter.service
PromQL可以理解为MySQL中的SQL
prometheus_http_requests_total{code="200"}
prometheus_http_requests_total{code=~"200|400"} prometheus_http_requests_total{code!~"200"}
node_memory_MemTotal_bytes / 1024 / 1024 / 1024 (node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes) / node_memory_MemTotal_bytes * 100
sum(prometheus_http_requests_total{code!="200"}) by (job)
4.1 启动mysql
# 下载MySQL的源 [root@VM-0-3-centos ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-5.noarch.rpm [root@VM-0-3-centos ~]# rpm -ivh mysql80-community-release-el7-5.noarch.rpm warning: mysql80-community-release-el7-5.noarch.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql80-community-release-el7-5 ################################# [100%] [root@VM-0-3-centos ~]# yum install mysql-community-server -y # 启动 [root@VM-0-3-centos ~]# systemctl start mysqld #修改密码 [root@localhost ~]# grep 'password' /var/log/mysqld.log 2022-01-21T06:47:01.557043Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Eqfrluvm)4gf [root@localhost ~]# mysql -uroot -p'Eqfrluvm)4gf' mysql> alter user root@localhost identified by 'Test123!'; # 下载mysqld_exporter(prometheus.io——downloadmysqld_exporter,选择linux版本的) [root@VM-0-3-centos ~]# wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.13.0/mysqld_exporter-0.13.0.linux-amd64.tar.gz [root@VM-0-3-centos ~]# tar -xf mysqld_exporter-0.13.0.linux-amd64.tar.gz -C /usr/local/ [root@localhost local]# cd /usr/local/mysqld_exporter-0.13.0.linux-amd64/ [root@localhost mysqld_exporter-0.13.0.linux-amd64]# ll -rwxr-xr-x 1 3434 3434 14955898 May 31 2021 mysqld_exporter [root@localhost mysqld_exporter-0.13.0.linux-amd64]# ./mysqld_exporter [root@VM-0-3-centos mysqld_exporter-0.13.0.linux-amd64]# vim /usr/local/mysqld_exporter/.my.cnf [client] user=root password=Test123! #可看出端口是9104 [root@localhost mysqld_exporter-0.13.0.linux-amd64]# ./mysqld_exporter [root@localhost ~]# curl 127.0.0.1:9104 #metrics接口 [root@localhost ~]# curl 127.0.0.1:9104/metrics #后台运行 [root@VM-0-3-centos mysqld_exporter-0.13.0.linux-amd64]# ln -s /usr/local/mysqld_exporter-0.13.0.linux-amd64 /usr/local/mysqld_exporter [root@VM-0-3-centos mysqld_exporter-0.13.0.linux-amd64]# vim /usr/lib/systemd/system/mysqld-exporter.service [Unit] Description=Prometheus [Service] ExecStart=/usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/.my.cnf --web.listen-address=:9104 Restart=on-failure [Install] WantedBy=multi-user.target [root@VM-0-3-centos mysqld_exporter-0.13.0.linux-amd64]# systemctl daemon-reload [root@VM-0-3-centos mysqld_exporter-0.13.0.linux-amd64]# systemctl restart mysqld-exporter.service
4.2 加入prometheus
[root@prometheus ~]# vim /usr/local/prometheus/prometheus.yml [root@prometheus ~]# systemctl restart prometheusd 此时可访问http://192.168.15.113:9090/targets,查看mysql状态是否是up