prometheus學習系列二: Prometheus安裝

下載

prometheus的官網的download頁面,能夠找到prometheus的下載二進制包。 node

[root@node00 src]# cd /usr/src/ [root@node00 src]# wget https://github.com/prometheus/prometheus/releases/download/v2.12.0/prometheus-2.12.0.linux-amd64.tar.gz 
[root@node00 src]# mkdir /usr/local/prometheus/ [root@node00 src]# tar xf prometheus-2.12.0.linux-amd64.tar.gz  -C /usr/local/prometheus/ [root@node00 src]# cd /usr/local/prometheus/ [root@node00 prometheus]# ln -s prometheus-2.12.0.linux-amd64 prometheus [root@node00 prometheus]# ll total 0 lrwxrwxrwx 1 root root  29 Sep 20 05:06 prometheus -> prometheus-2.12.0.linux-amd64 drwxr-xr-x 4 3434 3434 132 Aug 18 11:40 prometheus-2.12.0.linux-amd64
[root@node00 prometheus]# cd prometheus

獲取配置幫助

[root@node00 prometheus]# ./prometheus  --help

啓動

# 啓動 [root@node00 prometheus]# ./prometheus level=info ts=2019-09-20T09:45:35.470Z caller=main.go:293 msg="no time or size retention was set so using the default time retention" duration=15d level=info ts=2019-09-20T09:45:35.470Z caller=main.go:329 msg="Starting Prometheus" version="(version=2.12.0, branch=HEAD, revision=43acd0e2e93f9f70c49b2267efa0124f1e759e86)" level=info ts=2019-09-20T09:45:35.470Z caller=main.go:330 build_context="(go=go1.12.8, user=root@7a9dbdbe0cc7, date=20190818-13:53:16)" level=info ts=2019-09-20T09:45:35.470Z caller=main.go:331 host_details="(Linux 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 node00 (none))" level=info ts=2019-09-20T09:45:35.470Z caller=main.go:332 fd_limits="(soft=1024, hard=4096)" level=info ts=2019-09-20T09:45:35.470Z caller=main.go:333 vm_limits="(soft=unlimited, hard=unlimited)" level=info ts=2019-09-20T09:45:35.473Z caller=main.go:654 msg="Starting TSDB ..." level=info ts=2019-09-20T09:45:35.473Z caller=web.go:448 component=web msg="Start listening for connections" address=0.0.0.0:9090 level=info ts=2019-09-20T09:45:35.519Z caller=head.go:509 component=tsdb msg="replaying WAL, this may take awhile" level=info ts=2019-09-20T09:45:35.520Z caller=head.go:557 component=tsdb msg="WAL segment loaded" segment=0 maxSegment=0 level=info ts=2019-09-20T09:45:35.520Z caller=main.go:669 fs_type=XFS_SUPER_MAGIC level=info ts=2019-09-20T09:45:35.520Z caller=main.go:670 msg="TSDB started" level=info ts=2019-09-20T09:45:35.520Z caller=main.go:740 msg="Loading configuration file" filename=prometheus.yml level=info ts=2019-09-20T09:45:35.568Z caller=main.go:768 msg="Completed loading of configuration file" filename=prometheus.yml level=info ts=2019-09-20T09:45:35.568Z caller=main.go:623 msg="Server is ready to receive web requests."

測試

 

配置開機自啓

# 進入systemd文件目錄
[root@node00 system]# cd /usr/lib/systemd/system
# 編寫prometheus systemd文件 [root@node00 system]#
cat prometheus.service [Unit] Description=prometheus After=network.target [Service] User=prometheus Group=prometheus WorkingDirectory=/usr/local/prometheus/prometheus ExecStart=/usr/local/prometheus/prometheus/prometheus [Install] WantedBy=multi-user.target
# 啓動 [root@node00 system]# systemctl restart prometheus
# 查看狀態 [root@node00 system]# systemctl status prometheus ● prometheus.service
- prometheus Loaded: loaded (/usr/lib/systemd/system/prometheus.service; disabled; vendor preset: disabled) Active: active (running) since Fri 2019-09-20 06:11:21 EDT; 4s ago Main PID: 32871 (prometheus) CGroup: /system.slice/prometheus.service └─32871 /usr/local/prometheus/prometheus/prometheus Sep 20 06:11:21 node00 prometheus[32871]: level=info ts=2019-09-20T10:11:21.634Z caller=head.go:509 component=tsdb msg="replaying WAL, this may take awhile" Sep 20 06:11:21 node00 prometheus[32871]: level=info ts=2019-09-20T10:11:21.640Z caller=head.go:557 component=tsdb msg="WAL segment loaded" segment=0 maxSegment=3 Sep 20 06:11:21 node00 prometheus[32871]: level=info ts=2019-09-20T10:11:21.640Z caller=head.go:557 component=tsdb msg="WAL segment loaded" segment=1 maxSegment=3 Sep 20 06:11:21 node00 prometheus[32871]: level=info ts=2019-09-20T10:11:21.641Z caller=head.go:557 component=tsdb msg="WAL segment loaded" segment=2 maxSegment=3 Sep 20 06:11:21 node00 prometheus[32871]: level=info ts=2019-09-20T10:11:21.641Z caller=head.go:557 component=tsdb msg="WAL segment loaded" segment=3 maxSegment=3 Sep 20 06:11:21 node00 prometheus[32871]: level=info ts=2019-09-20T10:11:21.642Z caller=main.go:669 fs_type=XFS_SUPER_MAGIC Sep 20 06:11:21 node00 prometheus[32871]: level=info ts=2019-09-20T10:11:21.642Z caller=main.go:670 msg="TSDB started" Sep 20 06:11:21 node00 prometheus[32871]: level=info ts=2019-09-20T10:11:21.642Z caller=main.go:740 msg="Loading configuration file" filename=prometheus.yml Sep 20 06:11:21 node00 prometheus[32871]: level=info ts=2019-09-20T10:11:21.686Z caller=main.go:768 msg="Completed loading of configuration file" filename=prometheus.yml Sep 20 06:11:21 node00 prometheus[32871]: level=info ts=2019-09-20T10:11:21.686Z caller=main.go:623 msg="Server is ready to receive web requests."

# 開機自啓配置
[root@node00 system]# systemctl enable prometheus Created symlink from /etc/systemd/system/multi-user.target.wants/prometheus.service to /usr/lib/systemd/system/prometheus.service.

 後端存儲配置

默認狀況下prometheus會將採集的數據防止到本機的data目錄的, 存儲數據的大小受限和擴展不便,這是使用influxdb做爲後端的數據庫來存儲數據。linux

 influxdb安裝配置

influxdb的官方文檔地址爲: https://docs.influxdata.com/influxdb/v1.7/introduction/downloading/ 根據不一樣系統進行下載,這裏使用官方提供的rpm進行安裝。git

# 下載rpm
wget
https://dl.influxdata.com/influxdb/releases/influxdb-1.7.8.x86_64.rpm
# 本地安裝rpm
sudo yum localinstall influxdb-1.7.8.x86_64.rpm
# 查看安裝的文件 [root@node00 influxdb]# rpm
-ql influxdb /etc/influxdb/influxdb.conf /etc/logrotate.d/influxdb /usr/bin/influx /usr/bin/influx_inspect /usr/bin/influx_stress /usr/bin/influx_tsm /usr/bin/influxd /usr/lib/influxdb/scripts/influxdb.service /usr/lib/influxdb/scripts/init.sh /usr/share/man/man1/influx.1.gz /usr/share/man/man1/influx_inspect.1.gz /usr/share/man/man1/influx_stress.1.gz /usr/share/man/man1/influx_tsm.1.gz /usr/share/man/man1/influxd-backup.1.gz /usr/share/man/man1/influxd-config.1.gz /usr/share/man/man1/influxd-restore.1.gz /usr/share/man/man1/influxd-run.1.gz /usr/share/man/man1/influxd-version.1.gz /usr/share/man/man1/influxd.1.gz /var/lib/influxdb /var/log/influxdb
# 備份默認的默認的配置文件,這裏能夠對influxdb的數據存放位置作些設置
[root@node00 influxdb]# cp /etc/influxdb/influxdb.conf  /etc/influxdb/influxdb.conf.default

# 啓動 [root@node00 influxdb]# systemctl restart influxdb
# 查看狀態 [root@node00 influxdb]# systemctl status influxdb

# 客戶端登錄測試, 建立一個prometheus的database供後續的prometheus使用。 [root@node00 influxdb]# influx Connected to http:
//localhost:8086 version 1.7.8 InfluxDB shell version: 1.7.8 > show databases; name: databases name ---- _internal > create database prometheus; > show databases; name: databases name ---- _internal prometheus > exit

 配置prometheus集成infludb

官方的幫助文檔在這裏: https://docs.influxdata.com/influxdb/v1.7/supported_protocols/prometheus/github

[root@node00 prometheus]# pwd
/usr/local/prometheus/prometheus cp prometheus.yml prometheus.yml.default vim prometheus.yml # 添加以下幾行 remote_write: - url: "http://localhost:8086/api/v1/prom/write?db=prometheus" remote_read: - url: "http://localhost:8086/api/v1/prom/read?db=prometheus" systemctl restart prometheus systemctl status prometheus

注意: 若是influxdb配置有密碼, 請參考上面的官方文檔地址進行配置。web

測試數據是否存儲到influxdb中

[root@node00 prometheus]# influx Connected to http://localhost:8086 version 1.7.8
InfluxDB shell version: 1.7.8
> show databases; name: databases name ---- _internal prometheus > use prometheus Using database prometheus > show measures; ERR: error parsing query: found measures, expected CONTINUOUS, DATABASES, DIAGNOSTICS, FIELD, GRANTS, MEASUREMENT, MEASUREMENTS, QUERIES, RETENTION, SERIES, SHARD, SHARDS, STATS, SUBSCRIPTIONS, TAG, USERS at line 1, char 6
> show MEASUREMENTS; name: measurements name ---- go_gc_duration_seconds go_gc_duration_seconds_count go_gc_duration_seconds_sum go_goroutines go_info go_memstats_alloc_bytes # 後面仍是有不少,這裏不粘貼了。 # 作個簡單查詢 > select * from prometheus_http_requests_total limit 10 ; name: prometheus_http_requests_total time __name__ code handler instance job value ----                --------                       ---- -------  --------       ---        -----
1568975686217000000 prometheus_http_requests_total 200  /metrics localhost:9090 prometheus 1
1568975701216000000 prometheus_http_requests_total 200  /metrics localhost:9090 prometheus 2
1568975716218000000 prometheus_http_requests_total 200  /metrics localhost:9090 prometheus 3
1568975731217000000 prometheus_http_requests_total 200  /metrics localhost:9090 prometheus 4
1568975746216000000 prometheus_http_requests_total 200  /metrics localhost:9090 prometheus 5
1568975761217000000 prometheus_http_requests_total 200  /metrics localhost:9090 prometheus 6
1568975776217000000 prometheus_http_requests_total 200  /metrics localhost:9090 prometheus 7
1568975791217000000 prometheus_http_requests_total 200  /metrics localhost:9090 prometheus 8
1568975806217000000 prometheus_http_requests_total 200  /metrics localhost:9090 prometheus 9
1568975821216000000 prometheus_http_requests_total 200  /metrics localhost:9090 prometheus 10
相關文章
相關標籤/搜索