centos7.8如何安装prometheus和grafana

2023-04-19 06:41:00 centos7 grafana 安装

Centos7.8上安装Prometheus和Grafana的步骤如下:

一、安装Prometheus

1.下载Prometheus安装包:首先,我们需要从Prometheus官网下载最新的版本,当前最新版本为2.20.1,可以从https://prometheus.io/download/下载,下载完成后放在/usr/local/目录下,我们这里下载的是prometheus-2.20.1.linux-amd64.tar.gz。

2.解压安装包:解压安装包,解压后的文件夹名称为prometheus-2.20.1.linux-amd64,将其放在/usr/local/目录下。

3.创建Prometheus配置文件:在/usr/local/prometheus-2.20.1.linux-amd64/目录下创建一个名为prometheus.yml的文件,文件内容为:

global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # 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=` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 5s

    static_configs:
    - targets: ['localhost:9090']

4.启动Prometheus:在/usr/local/prometheus-2.20.1.linux-amd64/目录下执行./prometheus --config.file=prometheus.yml命令,启动Prometheus。

5.检查Prometheus是否启动成功:访问http://localhost:9090/graph查看Prometheus是否启动成功。

二、安装Grafana

1.下载Grafana安装包:从Grafana官网下载最新的版本,当前最新版本为7.3.3,可以从https://grafana.com/grafana/download下载,下载完成后放在/usr/local/目录下,我们这里下载的是grafana-7.3.3.linux-amd64.tar.gz。

2.解压安装包:解压安装包,解压后的文件夹名称为grafana-7.3.3,将其放在/usr/local/目录下。

3.创建Grafana配置文件:在/usr/local/grafana-7.3.3/conf/目录下创建一个名为grafana.ini的文件,文件内容为:

[server]
# Protocol (http, https, socket)
protocol = http

# The ip address to bind to, empty will bind to all interfaces
http_addr = 127.0.0.1

# The http port  to use
http_port = 3000

# The public facing domain name used to access grafana from a browser
domain = localhost

# Redirect to correct domain if host header does not match domain
# Prevents DNS rebinding attacks
enforce_domain = false

# The full public facing url
root_url = %(protocol)s://%(domain)s:%(http_port)s/

# Log web requests
router_logging = false

# the path relative working path
data_path = /usr/local/grafana-7.3.3/data

4.启动Grafana:在/usr/local/grafana-7.3.3/bin/目录下执行./grafana-server命令,启动Grafana。

5.检查Grafana是否启动成功:访问http://localhost:3000/查看Grafana是否启动成功。

以上就是Centos7.8上安装Prometheus和Grafana的步骤,希望能帮助到大家。

相关文章