Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Play prometheus for the first time

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Install Prometheus Server to play prometheus for the first time

Because Prometheus is written based on GoLang, the compiled package does not depend on any third-party dependencies. Users only need to download the binary package of the corresponding platform, decompress and add basic configuration to start Prometheus server normally.

Binary installation and deployment

Download page: https://prometheus.io/download/

We choose the corresponding download version. Here we download the latest version 2.13.0 linux, which is downloaded from https://github.com/prometheus/prometheus/releases/download/v2.13.0/prometheus-2.13.0.linux-amd64.tar.gz.

We install the deployment on the server:

[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.gzprometheus-2.13.0.linux-amd64/prometheus-2.13.0.linux-amd64/ NOTICEprometheus-2.13.0.linux-amd64/promtoolprometheus-2.13.0.linux-amd64/consoles/prometheus-2.13.0.linux-amd64/consoles/prometheus.htmlprometheus-2.13.0.linux-amd64/consoles/node-overview.htmlprometheus-2.13.0.linux-amd64/consoles/node-cpu.htmlprometheus-2.13.0.linux-amd64/consoles/node.htmlprometheus-2.13.0.linux-amd64/consoles/index.html.exampleprometheus-2.13.0. Linux-amd64/consoles/prometheus-overview.htmlprometheus-2.13.0.linux-amd64/consoles/node-disk.htmlprometheus-2.13.0.linux-amd64/LICENSEprometheus-2.13.0.linux-amd64/console_libraries/prometheus-2.13.0.linux-amd64/console_libraries/prom.libprometheus-2.13.0.linux-amd64/console_libraries/menu.libprometheus-2.13.0.linux-amd64/tsdbprometheus-2.13.0.linux-amd64/prometheus.ymlprometheus-2.13.0.linux-amd64/prometheus

After decompression, you will see the prometheus.yml configuration file in the sibling directory.

# my global configglobal: scrape_interval: 15s # interval between capturing sampled data. Default is 15s to take an evaluation_interval: 15s # evaluation rule on the monitored host every 15 seconds. The default value is every minute. Frequency of evaluation of monitoring data rules (when we set the hard drive > 80% alarm this rule rule that prometheus will default to no 15s to execute this rule rule to check hard disk usage) # scrape_timeout is set to the global default (10s). # Alertmanager configuration (how to alarm Alarm message) 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= `to any timeseries scraped from this config. -job_name: 'prometheus' # metrics_path defaults to' / metrics' # scheme defaults to 'http'. Static_configs:-targets: ['localhost:9090'] # statically configured monitoring host

Start prometheus

[root@Prometheus prometheus-2.13.0.linux-amd64] #. / prometheus--config.file=prometheus.ymllevel=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=15dlevel=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 x 86 million 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:9090level=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=1level=info ts=2019-10-11T01:53:36.265Z caller=head.go:560 component=tsdb msg=" WAL segment loaded "segment=1 maxSegment=1level=info ts=2019-10-11T01:53:36.267Z caller=main.go:672 fs_type=XFS_SUPER_MAGIClevel=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.ymllevel=info ts=2019-10-11T01:53:36.285Z caller=main.go:771 msg=" Completed loading of configuration file "filename=prometheus.ymllevel=info ts=2019-10-11T01:53:36.285Z caller=main.go:626 msg=" Server is ready to receive web requests. "

We start after we specify the configuration file directly, but in actual work, we will not start like this, and we will add the following configuration parameters

-- config.file= "/ usr/local/prometheus/prometheus.yml" # startup configuration file-- web.listen-address= "0.0.0.0 web.listen-address= 9090" # listening address port-- web.max-connections=512 # maximum number of connections-- storage.tsdb.path= "data/" # locally stored Location-time that storage.tsdb.retention=15d # data is stored locally-storage.tsdb.no-lockfile # does not allow lock files to be created in the data directory-query.timeout=2m # query timeout-number of concurrency of query.max-concurrency=20 # simultaneous queries

So in production, we usually start prometheus like this.

Nohup prometheus-- config.file= "/ usr/local/prometheus/prometheus.yml"-- web.listen-address= "0.0.0.0 web.max-connections=512"-- storage.tsdb.path= "data/"-- storage.tsdb.retention=15d-- query.timeout=2m-- query.max-concurrency=20 & Docker installation and deployment

Now that docker is so convenient, we are sure to introduce how to install and deploy prometheus through docker.

Mkdir / usr/local/prometheus/datachmod 777 / usr/local/prometheus/datadocker run-id-- name prometheus- p 9090 id 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.0storage.tsdb.retention=15d 9090-web.max-connections=512-storage.tsdb.path=/prometheus_data-storage.tsdb.retention=15d query.timeout=2m-query.max-concurrency=20

Here is a trick. When I first started prometheus to specify the startup parameters, I couldn't find the specified configuration file when I started it. When we started it directly, it could start. Why did I prompt this when I added the other parameters? I was puzzled. When I saw the dockerfile of the prometheus image, I instantly understood why, the Prometheus_Dockerfile address.

ARG ARCH= "amd64" ARG OS= "linux" FROM quay.io/prometheus/busybox-$ {OS}-${ARCH}: latestLABEL maintainer= "The Prometheus Authors" ARG ARCH= "amd64" ARG OS= "linux" COPY .build / ${OS}-${ARCH} / prometheus/ bin/prometheusCOPY .build / ${OS}-${ARCH} / promtool / bin/promtoolCOPY documentation/examples/prometheus.yml / etc/prometheus/prometheus.ymlCOPY 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/ prometheusUSER nobodyEXPOSE 9090VOLUME ["/ prometheus"] WORKDIR / prometheusENTRYPOINT ["/ 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"]

We can not care about him now when we see this dockerfile. The main thing is on the last line of CMD. It turns out that when we appended parameters, we overwrote the parameters of CMD, so we couldn't find the path to the configuration file. We added OK to him at this time.

Introduce the prometheus web interface

No matter which way we start the prometheus service, we will log in to the prometheus dashboard interface as follows, with the login mode of http://IP:9090

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report