下面是本次部署的架構圖
node
1.時間同步(時間同步必定要確認一下)
2.關閉防火牆,selinuxmysql
從 https://prometheus.io/download/ 下載相應版本,安裝到服務器上
官網提供的是二進制版,解壓就能用,不須要編譯linux
# 解壓安裝包 tar -xf prometheus-2.23.0.linux-amd64.tar.gz -C /opt # 建立連接目錄 cd /opt ln -s prometheus-2.23.0.linux-amd64 prometheus # 直接使用默認配置文件啓動 /opt/prometheus/prometheus --config.file="/opt/prometheus/prometheus.yml" & # 確認是否正常啓動(默認端口9090) [root@server ~]# netstat -lnptu | grep 9090 tcp6 0 0 :::9090 :::* LISTEN 103006/prometheus
下載地址: https://prometheus.io/download/git
# 解壓安裝包 tar -xf node_exporter-1.0.1.linux-amd64.tar.gz -C /opt # 建立連接目錄 cd /opt ln -s node_exporter-1.0.1.linux-amd64 node_exporter # 使用nohup後臺運行 nohup /opt/node_exporter/node_exporter & # 確認是否正常啓動(默認端口9100) [root@mysql01 ~]# netstat -lnptu | grep 9100 tcp6 0 0 :::9100 :::* LISTEN 20716/node_exporter 擴展: nohup命令: 若是把啓動node_exporter的終端給關閉,那麼進程也會 隨之關閉。nohup命令會幫你解決這個問題。
在主配置文件最後面添加被監控主機信息 [root@server ~]# vim /opt/prometheus/prometheus.yml - job_name: '10.0.3.105' # 給被監控主機取個名字,我這裏直接填的IP static_configs: - targets: ['10.0.3.105:9100'] # 這裏填寫被監控主機的IP和端口 - job_name: '10.0.3.115' static_configs: - targets: ['10.0.3.115:9100'] 有多少臺被監控主機就照格式添加在後面好了,我這裏監控了105/115兩臺主機
[root@server ~]# pkill prometheus [root@server ~]# /opt/prometheus/prometheus --config.file="/opt/prometheus/prometheus.yml" & [root@server ~]# netstat -lnptu | grep 9090
下載地址: https://prometheus.io/download/github
# 解壓安裝包 tar -xf mysqld_exporter-0.12.1.linux-amd64.tar.gz -C /opt # 建立連接目錄 cd /opt ln -s mysqld_exporter-0.12.1.linux-amd64 mysqld_exporter # 在MySQL服務器上建立監控用戶 mysql> grant select,replication client, process on *.* to 'mysql_monitor'@'localhost' identified by '123'; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.03 sec) mysql> exit Bye # 將上面建立的mysql用戶信息寫入mysqld_exporter配置文件(新建立一個) [root@mysql01 ~]# vim /opt/mysqld_exporter/.my.cnf [client] user=mysql_monitor password=123 # 啓動mysqld_exporter nohup /opt/mysqld_exporter/mysqld_exporter --config.my-cnf=/opt/mysqld_exporter/.my.cnf & # 確認是否正常啓動(默認端口9104) [root@mysql01 ~]# netstat -lnptu | grep 9104 tcp6 0 0 :::9104 :::* LISTEN 32688/mysqld_export
在主配置文件最後面添加被監控主機信息 [root@server ~]# vim /opt/prometheus/prometheus.yml - job_name: 'mysql-105' # 給被監控主機取個名字 static_configs: - targets: ['10.0.3.105:9104'] # 這裏填寫被監控主機的IP和端口 - job_name: 'mysql-115' static_configs: - targets: ['10.0.3.115:9104'] 有多少臺被監控MySQL服務器就照格式添加在後面好了,我這裏監控了105/115兩臺MySQL服務器
[root@server ~]# pkill prometheus [root@server ~]# /opt/prometheus/prometheus --config.file="/opt/prometheus/prometheus.yml" & [root@server ~]# netstat -lnptu | grep 9090
開頭已經講過了,官網:https://grafana.com/golang
下載地址:https://grafana.com/grafana/downloadweb
我這是使用的是CentOS系統,直接下載rpm包就好 yum localinstall grafana-7.3.5-1.x86_64.rpm 啓動服務並加入開機啓動 systemctl start grafana-server.service systemctl enable grafana-server.service 檢查服務狀態(默認使用3000端口) systemctl status grafana-server.service netstat -lnptu | grep 3000 tcp6 0 0 :::3000 :::* LISTEN 112219/grafana-serv
vim /etc/grafana/grafana.ini # 找到smtp關鍵字 #################################### SMTP / Emailing ########################## [smtp] enabled = true # 改爲true host = smtp.exmail.qq.com:465 # 發送服務器地址和端口 user = # 這裏填寫發件郵箱 # If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;""" password = # 這裏填寫發件郵箱密碼或受權密碼 ;cert_file = ;key_file = skip_verify = true # 改爲true from_address = # 這裏填寫發件郵箱 ;from_name = Grafana # EHLO identity in SMTP dialog (defaults to instance_name) ;ehlo_identity = dashboard.example.com # SMTP startTLS policy (defaults to 'OpportunisticStartTLS') ;startTLS_policy = NoStartTLS
easydb.net
微信公衆號:easydb
關注我,不走丟!