由於Prometheus是基於GoLang編寫,編譯後的軟件包,不依賴於任何的第三方依賴。用戶只須要下載對應平臺的二進制包,並解壓添加基本配置便可正常啓動Prometheus server。html
下載頁面:https://prometheus.io/download/
咱們選擇對應的下載版本,這裏咱們下載的是最新版本2.13.0 linux版本,下載地址爲:https://github.com/prometheus/prometheus/releases/download/v2.13.0/prometheus-2.13.0.linux-amd64.tar.gznode
咱們在服務器上安裝部署:linux
[root@Prometheus ~]# mkdir /usr/local/prometheus [root@Prometheus ~]# cd /usr/local/prometheus [root@Prometheus prometheus]# wget https://github.com/prometheus/prometheus/releases/download/v2.13.0/prometheus-2.13.0.linux-amd64.tar.gz [root@Prometheus prometheus]# tar xvf prometheus-2.13.0.linux-amd64.tar.gz prometheus-2.13.0.linux-amd64/ prometheus-2.13.0.linux-amd64/NOTICE prometheus-2.13.0.linux-amd64/promtool prometheus-2.13.0.linux-amd64/consoles/ prometheus-2.13.0.linux-amd64/consoles/prometheus.html prometheus-2.13.0.linux-amd64/consoles/node-overview.html prometheus-2.13.0.linux-amd64/consoles/node-cpu.html prometheus-2.13.0.linux-amd64/consoles/node.html prometheus-2.13.0.linux-amd64/consoles/index.html.example prometheus-2.13.0.linux-amd64/consoles/prometheus-overview.html prometheus-2.13.0.linux-amd64/consoles/node-disk.html prometheus-2.13.0.linux-amd64/LICENSE prometheus-2.13.0.linux-amd64/console_libraries/ prometheus-2.13.0.linux-amd64/console_libraries/prom.lib prometheus-2.13.0.linux-amd64/console_libraries/menu.lib prometheus-2.13.0.linux-amd64/tsdb prometheus-2.13.0.linux-amd64/prometheus.yml prometheus-2.13.0.linux-amd64/prometheus
解壓後同級目錄裏面會看到prometheus.yml
配置文件git
# my global config global: scrape_interval: 15s #抓去採樣數據的時間間隔,默認15s去被監控主機上採起一次 evaluation_interval: 15s # 每15秒評估一次規則。 默認值爲每1分鐘。 監控數據規則的評估頻率(當咱們設置硬盤> 80%報警 這條rule規則 那個prometheus會默認沒15S來執行這個rule規則檢查硬盤使用狀況) # scrape_timeout is set to the global default (10s). # Alertmanager configuration(如何報警,報警信息) alerting: alertmanagers: - static_configs: - targets: # - alertmanager:9093 # Load rules once and periodically evaluate them according to the global 'evaluation_interval'.() rule_files: # - "first_rules.yml" # - "second_rules.yml" # A scrape configuration containing exactly one endpoint to scrape: # Here it's Prometheus itself. scrape_configs: # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. - job_name: 'prometheus' # metrics_path defaults to '/metrics' # scheme defaults to 'http'. static_configs: - targets: ['localhost:9090'] #靜態配置的監控主機
啓動prometheusgithub
[root@Prometheus prometheus-2.13.0.linux-amd64]# ./prometheus --config.file=prometheus.yml level=info ts=2019-10-11T01:53:36.252Z caller=main.go:296 msg="no time or size retention was set so using the default time retention" duration=15d level=info ts=2019-10-11T01:53:36.252Z caller=main.go:332 msg="Starting Prometheus" version="(version=2.13.0, branch=HEAD, revision=6ea4252299f542669aca11860abc2192bdc7bede)" level=info ts=2019-10-11T01:53:36.252Z caller=main.go:333 build_context="(go=go1.13.1, user=root@f30bdad2c3fd, date=20191004-11:25:34)" level=info ts=2019-10-11T01:53:36.252Z caller=main.go:334 host_details="(Linux 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 Prometheus (none))" level=info ts=2019-10-11T01:53:36.252Z caller=main.go:335 fd_limits="(soft=1024, hard=4096)" level=info ts=2019-10-11T01:53:36.252Z caller=main.go:336 vm_limits="(soft=unlimited, hard=unlimited)" level=info ts=2019-10-11T01:53:36.254Z caller=main.go:657 msg="Starting TSDB ..." level=info ts=2019-10-11T01:53:36.256Z caller=web.go:450 component=web msg="Start listening for connections" address=0.0.0.0:9090 level=info ts=2019-10-11T01:53:36.258Z caller=head.go:512 component=tsdb msg="replaying WAL, this may take awhile" level=info ts=2019-10-11T01:53:36.265Z caller=head.go:560 component=tsdb msg="WAL segment loaded" segment=0 maxSegment=1 level=info ts=2019-10-11T01:53:36.265Z caller=head.go:560 component=tsdb msg="WAL segment loaded" segment=1 maxSegment=1 level=info ts=2019-10-11T01:53:36.267Z caller=main.go:672 fs_type=XFS_SUPER_MAGIC level=info ts=2019-10-11T01:53:36.267Z caller=main.go:673 msg="TSDB started" level=info ts=2019-10-11T01:53:36.267Z caller=main.go:743 msg="Loading configuration file" filename=prometheus.yml level=info ts=2019-10-11T01:53:36.285Z caller=main.go:771 msg="Completed loading of configuration file" filename=prometheus.yml level=info ts=2019-10-11T01:53:36.285Z caller=main.go:626 msg="Server is ready to receive web requests."
咱們直接指定配置文件以後就啓動起來了,可是在實際工做中我門不會這樣啓動,還會加上以下一些配置參數web
--config.file="/usr/local/prometheus/prometheus.yml" #啓動的配置文件 --web.listen-address="0.0.0.0:9090" #監聽的地址端口 --web.max-connections=512 #最大鏈接數 --storage.tsdb.path="data/" #本地存儲的位置 --storage.tsdb.retention=15d #數據在本地存儲的時間 --storage.tsdb.no-lockfile #不容許在數據目錄裏面建立鎖文件 --query.timeout=2m #查詢超時時間 --query.max-concurrency=20 #同時查詢的併發數
因此在生產中咱們通常這樣啓動prometheusdocker
nohup prometheus --config.file="/usr/local/prometheus/prometheus.yml" --web.listen-address="0.0.0.0:9090" --web.max-connections=512 --storage.tsdb.path="data/" --storage.tsdb.retention=15d --query.timeout=2m --query.max-concurrency=20 &
在當前docker這麼方便的狀況下,咱們確定要來介紹下經過docker是如何來安裝部署prometheus;bash
mkdir /usr/local/prometheus/data chmod 777 /usr/local/prometheus/data docker run -id --name prometheus -p 9090:9090 -v /etc/localtime:/etc/localtime:ro -v /usr/local/prometheus/data:/prometheus_data -v /usr/local/prometheus/prometheus-2.13.0.linux-amd64/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus --config.file=/etc/prometheus/prometheus.yml --web.listen-address=0.0.0.0:9090 --web.max-connections=512 --storage.tsdb.path=/prometheus_data --storage.tsdb.retention=15d --query.timeout=2m --query.max-concurrency=20
這裏講訴一個技巧,當我第一次啓動prometheus
指定啓動的參數的時候一致啓動不起來報 找不到指定的配置文件, 咱們直接啓動的時候他都是能啓動的了的,爲何我加上其他的參數以後,就提示這個呢?百思不得其解,知道我看了prometheus
鏡像的dockerfile的時候,我瞬間明白是爲何了,Prometheus_Dockerfile地址服務器
ARG ARCH="amd64" ARG OS="linux" FROM quay.io/prometheus/busybox-${OS}-${ARCH}:latest LABEL maintainer="The Prometheus Authors <prometheus-developers@googlegroups.com>" ARG ARCH="amd64" ARG OS="linux" COPY .build/${OS}-${ARCH}/prometheus /bin/prometheus COPY .build/${OS}-${ARCH}/promtool /bin/promtool COPY documentation/examples/prometheus.yml /etc/prometheus/prometheus.yml COPY console_libraries/ /usr/share/prometheus/console_libraries/ COPY consoles/ /usr/share/prometheus/consoles/ RUN ln -s /usr/share/prometheus/console_libraries /usr/share/prometheus/consoles/ /etc/prometheus/ RUN mkdir -p /prometheus && \ chown -R nobody:nogroup etc/prometheus /prometheus USER nobody EXPOSE 9090 VOLUME [ "/prometheus" ] WORKDIR /prometheus ENTRYPOINT [ "/bin/prometheus" ] CMD [ "--config.file=/etc/prometheus/prometheus.yml", \ "--storage.tsdb.path=/prometheus", \ "--web.console.libraries=/usr/share/prometheus/console_libraries", \ "--web.console.templates=/usr/share/prometheus/consoles" ]
看到這個dockerfile 前面的咱們如今能夠不關心他,主要的就是在最後一行CMD
,原來是咱們在追加參數的時候把CMD
的參數給覆蓋掉了,因此找不到配置文件的路徑,咱們這個時候再給他加上就OK了。併發
無論咱們經過哪一種方式來啓動的prometheus service
端,咱們都經過以下的方式登錄prometheus dashboard
界面,登錄方式爲http://IP:9090