(二)Prometheus 安裝部署

通過上一篇(一)prometheus 監控系統 的學習,我們已經對 prometheus 有了一個全面的瞭解,本篇詳細部署安裝 prometheus 監控系統。

準備環境

# 個人環境:centos 7
[root@fp-21 ~]# hostname -I
10.0.0.21 

# 時間校正,這裏是阿里雲標準時間
[root@fp-21 ~]# ntpdate ntp.aliyun.com
29 Mar 16:36:37 ntpdate[9790]: step time server 203.107.6.88 offset -43198.785235 sec

# 關閉防火牆
[root@fp-21 ~]# systemctl stop firewalld.service

# 修改 selinux 爲警告模式
[root@fp-21 ~]# setenforce 0

創建用戶

# 創建 prometheus 的組和用戶
[root@fp-21 ~]# groupadd prometheus
[root@fp-21 ~]# useradd -M -s /sbin/nologin prometheus -g prometheus

上傳安裝包,解壓,點擊下載

# 沒有本地安裝包,也可以進行下載
[root@fp-21 ~]# cd /opt/ ; mkdir prometheus ; cd prometheus
[root@fp-21 prometheus]# wget -c https://github.com/prometheus/prometheus/releases/download/v2.16.0/prometheus-2.16.0.linux-amd64.tar.gz

# 解壓
[root@fp-21 prometheus]# tar xf prometheus-2.16.0.linux-amd64.tar.gz 
[root@fp-21 prometheus]# ls
prometheus-2.16.0.linux-amd64  prometheus-2.16.0.linux-amd64.tar.gz

更改文件夾位置

[root@fp-21 prometheus]# mv prometheus-2.16.0.linux-amd64 /usr/local/prometheus

# 創建所需目錄
[root@fp-21 prometheus]# mkdir conf relus data

# 修改配置文件路徑
[root@fp-21 prometheus]# mv prometheus.yml conf

# 複製可執行文件至 /usr/local/bin
[root@fp-21 prometheus]# cp prometheus promtool tsdb /usr/local/bin/

# 授權
[root@fp-21 prometheus]# chown -R prometheus:prometheus /usr/local/prometheus

修改配置文件

[root@fp-21 prometheus]# cd conf
[root@fp-21 conf]# cp prometheus.yml prometheus.yml.bak
[root@fp-21 conf]# vim prometheus.yml
 23   - job_name: 'prometheus'		# 標籤,監控任務的名稱
 28     static_configs:		# 抓取的目標
 29     - targets: ['10.0.0.21:9090']

添加爲系統服務

[root@fp-21 ~]# vim /usr/lib/systemd/system/prometheus.service

[Unit]
Description=prometheus-server
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
 
[Service]
Type=simple
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/conf/prometheus.yml --web.enable-lifecycle --storage.tsdb.path=/usr/local/prometheus/data --storage.tsdb.retention.time=7d --web.max-connections=512 --web.read-timeout=3m --query.max-concurrency=25 --query.timeout=2m
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
 
[Install]
WantedBy=multi-user.target

添加開機自啓,啓動,查看

# 重新加載
[root@fp-21 ~]# systemctl daemon-reload

# 添加至開機自啓
[root@fp-21 ~]# systemctl enable prometheus.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/prometheus.service to /usr/lib/systemd/system/prometheus.service.

# 啓動服務
[root@fp-21 ~]# systemctl start prometheus.service 

# 查看端口
[root@fp-21 ~]# ss -lntp |grep prometheus
LISTEN     0      128         :::9090                    :::*                   users:(("prometheus",pid=10887,fd=7))

# 查看進程
[root@fp-21 ~]# ps -ef |grep prometheus
root      10887      1  3 19:59 ?        00:00:00 /usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/conf/prometheus.yml --web.enable-lifecycle --storage.tsdb.path=/usr/local/prometheus/data --storage.tsdb.retention.time=7d --web.max-connections=512 --web.read-timeout=3m --query.max-concurrency=25 --query.timeout=2m
root      10926   9766  0 20:00 pts/0    00:00:00 grep --color=auto prometheus

訪問 IP 進行查看 prometheus

[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-NxGayzPS-1585484514134)(E:\知識點總結\Prometheus\assets\prometheus_10.png)]

查看監控任務的狀態

[外鏈圖片轉存中...(img-tKJNUSkX-1585484514132)]

查看 prometheus 的配置信息

[外鏈圖片轉存中...(img-NxGayzPS-1585484514134)]

查看 prometheus 運行狀態

[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-dayCnRVl-1585484514135)(E:\知識點總結\Prometheus\assets\prometheus_11.png)]

只有注入思想的博客纔是好的博客

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章