使有prometheus監控redis,mongodb,nginx,mysql,jmx


以下操作在CENTOS7環境。

使用prometheus做監控,使用grafana做dashboard的界面展示:

因prometheus自帶的監控web界面圖形化展示方面比較弱,推薦使用grafana集成prometheus展示;

一、軟件安裝

1)granafa的安裝:

官方安裝指南:https://grafana.com/grafana/download?platform=linux
wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.2.2-1.x86_64.rpm 
sudo yum localinstall grafana-5.2.2-1.x86_64.rpm

service grafana-server start

2)prometheus的安裝:

官方下載地址:https://prometheus.io/download/

安裝prometheus主程序

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

tar -zxvf prometheus-2.3.2.linux-amd64.tar.gz -C /usr/local/prometheus

cd /usr/local/prometheus 

nohup ./prometheus >/dev/null &

安裝 prometheus的告警程序

wget https://github.com/prometheus/alertmanager/releases/download/v0.15.2/alertmanager-0.15.2.linux-amd64.tar.gz

tar -zxvf alertmanager-0.15.2.linux-amd64.tar.gz -C /usr/local/prometheus

cd /usr/local/prometheus

nohup ./alertmanager >/dev/null &

3)需在各監控節點安裝prometheus的node程序;

wget https://github.com/prometheus/node_exporter/releases/download/v0.16.0/node_exporter-0.16.0.linux-amd64.tar.gz

tar -zxvf node_exporter-0.16.0.linux-amd64.tar.gz -C /usr/local/prometheus

cd /usr/local/prometheus

nohup ./node_exporter >/dev/null &

二、安裝exporter

prometheus可以理解為一個數據庫+數據抓取工具,工具從各處抓來統一的數據,放入prometheus這一個時間序列數據庫中。那如何保證各處的數據格式是統一的呢?就是通過這個exporter。exporter也是用GO寫的程序,它開放一個http接口,對外提供格式化的數據。所以在不同的環境下,需要編寫不同的exporter。好在已經有很多寫好的exporter,我們可以直接使用,(本句是一句廢話為了更好的排版顯示)(https://github.com/prometheus這里可以找到很多exporter)我們這里直接使用mysqld_exporter(prometheus.io/download/#mysqld_exporter)。當然也要下載對應系統的版本。

2.1、mysql

解壓后的內容如下:

wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.11.0/mysqld_exporter-0.11.0.linux-amd64.tar.gz
tar -zxvf mysqld_exporter-0.11.0.linux-amd64.tar.gz -C /usr/local/prometheus

這里的mysqld_exporter是啟動文件,.my.cnf是配置文件。想要正確的導出mysql的狀態數據,必須在配置文件中正確的配置mysql的連接信息。我的配置如下:

配置.my.cnf文件

[client]
host = 127.0.0.1
user = REPL
password = Pbu4@123
socket = /mysqldata/data/mysqld.sock
[mysqladmin]
host = 127.0.0.1
user = zabbix
password = Zabbix@123
socket = /mysqldata/data/mysqld.sock

nohup ./mysqld_exporter --config.my-cnf=/etc/zabbix/.my.cnf --collect.binlog_size --collect.info_schema.processlist --collect.info_schema.innodb_metrics --collect.engine_innodb_status --collect.perf_schema.file_events --collect.perf_schema.eventswaits --collect.perf_schema.indexiowaits --collect.perf_schema.tableiowaits --collect.info_schema.tables --collect.info_schema.tablestats --collect.auto_increment.columns --collect.info_schema.userstats --collect.info_schema.innodb_cmp --collect.info_schema.innodb_cmpmem --collect.perf_schema.replication_group_member_stats >/dev/null &

可到grafana下載percona APP dashboard.

配置好了,就可以啟動了。成功如下所示: 

通過localhost:9104,就可以看到exporter導出的數據了: 

 

在Prometheus中配置mysqld_exporter

exporter啟動了,需要在Prometheus中正確的配置。修改prometheus目錄中的prometheus.yml,增加配置如下: 

重啟prometheus,點擊導航欄中的status->targets可以看到,mysql的exporter已經集成進來了。 如下圖:

至此,prometheus這邊監控mysql的環境搭建基本完成了。

 

2.2、mongodb的插件安裝:

wget https://github.com/dcu/mongodb_exporter/releases/download/v1.0.0/mongodb_exporter-linux-amd64

tar -zxvf mongodb_exporter-linux-amd64 -C /usr/local/prometheus

cd /usr/local/prometheus

mongod配置副本集啟動

./mongodb_exporter -mongodb.uri mongodb://192.168.152.128:27017,192.168.152.128:27018,192.168.152.128:27019

mongodb配置單機啟動

/mongodb_exporter -mongodb.uri mongodb://192.168.152.128:27017

2.3、redis的插件安裝:

redis 在redis服務器安裝node_exporter和redis_exporter。

wget https://github.com/oliver006/redis_exporter/releases/download/v0.10.8/redis_exporter-v0.10.8.linux-amd64.tar.gz

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


tar -zxvf node_exporter-0.13.0.linux-amd64.tar.gz -C /opt/prometheus_exporters --strip-components=1
tar -zxvf redis_exporter-v0.10.8.linux-amd64.tar.gz -C /opt/prometheus_exporters --strip-components=1
啟動
nohup /opt/prometheus_exporters/node_exporter & 
nohup /opt/prometheus_exporters/redis_exporter redis//192.168.0.17:6379 &
 
配置prometheus.yml 加入
- job_name: redis_exporter
  static_configs:
  - targets: ['192.168.0.17:9121']

下載grafana的redis的prometheus-redis_rev1.json模板

wget  https://grafana.com/api/dashboards/763/revisions/1/download

在grafana中導入json模板

 

2.4、nginx的插件安裝:

下載源碼nginx,再下載nginx-module-vts moudle進行編譯安裝。

git clone git://github.com/vozlt/nginx-module-vts.git

./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_sysguard_module --with-stream --add-module=nginx-module-vts

make &&make install

更改Nginx Conf的配置,添加監控接口/status/:

http {
vhost_traffic_status_zone;
    vhost_traffic_status_filter_by_host on;

...

server {

    ...

    location /status {
        vhost_traffic_status_display;
        vhost_traffic_status_display_format html;
    }
}
}

 

2.5、jmx的插件安裝:

注意只對Oracle原生的jdk的相關指標可監控,openjdk的只能監控部分指標。

wget https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.3.1/jmx_prometheus_javaagent-0.3.1.jar

tar -zxvf jmx_prometheus_javaagent-0.3.1.jar

配置config.yml文件

---
startDelaySeconds: 0
hostPort: localhost:58888 #master為本機IP(一般可設置為localhost);1234為想設置的jmx端口(可設置為未被占用的端口)
ssl: false
lowercaseOutputName: false
lowercaseOutputLabelNames: false
啟動jar

java -Djava.security.egd=file:/dev/./urandom -javaagent:/var/lib/prometheus/jmx_prometheus_javaagent-0.3.1.jar=9157:/etc/prometheus/config.yml -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=58888 -Djava.rmi.server.hostname=localhost -jar /app.jar

三、最后在安裝后的granfa里,配置prometheus 源,再到granfa里下載相關的dashboard進行配置。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM