安装Prometheus和Grafana

本文档详细介绍了如何安装Prometheus和Grafana。首先通过wget下载并解压Prometheus,然后编辑prometheus.yml文件添加job,并将Prometheus设为systemd服务。接着,文章说明了Prometheus默认监听的9090端口可用性。其次,按照官方文档安装Grafana,并确保开放3000端口以允许访问,通过iptables设置防火墙规则。最后,强调了初次登录Grafana时需使用admin账号和初始密码admin,并在首次登录后更改密码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

(一) 安装prometheus install

$ wget https://github.com/prometheus/prometheus/releases/download/v2.4.3/prometheus-2.4.3.linux-amd64.tar.gz

$ tar zxvf prometheus-2.4.3.linux-amd64.tar.gz

$ cd prometheus-2.4.3.linux-amd64

如果需要添加新的job,在这个文件添加

$ vim prometheus.yml   

global:
  scrape_interval:     15s
  evaluation_interval: 15s
  # scrape_timeout is set to the global default (10s).
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093
rule_files:

scrape_configs:

  - job_name: 'prometheus'
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    static_configs:
    - targets: ['localhost:9090']

  - job_name: 'linux1'
    static_configs:
      - targets: ['192.xxx.xx.xx:9100']
        labels:
          instance: server1
  - job_name: 'linux2'
    static_configs:
      - targets: ['192.xxx.xx.xx:9100']
        labels:
          instance: server2
运行 start Prometheus
$ nohup ./prometheus &  

改成systemd服务

$ cd ..
$ sudo mv prometheus-2.4.3.linux-amd64 /usr/local/prometheus

$ sudo groupadd prometheus
$ sudo useradd -g prometheus -m -d /usr/local/prometheus -s /sbin/nologin prometheus

$ sudo chown -R prometheus:prometheus /usr/local/prometheus

$ sudo vim /etc/systemd/system/prometheus.service  # 写入如下内容
[Unit]
Description=prometheus
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/usr/local/prometheus
Restart=on-failure
[Install]
WantedBy=multi-user.target

Prometheus自带一个Web网站,默认端口为9090, http://ip:9090.可以查看表达式搜索结果、报警配置、prometheus配置,exporter状态等. 

(二) 安装配置Grafana

官方安装文档: https://grafana.com/grafana/download?platform=linux

http://docs.grafana.org/installation/

$ wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana_5.3.0_amd64.deb 
$ sudo dpkg -i grafana_5.3.0_amd64.deb 

$ sudo systemctl status grafana-server    #默认进入了运行的状态

$ sudo systemctl enable grafana-server

关闭
sudo service grafana-server stop
启动
sudo service grafana-server start

需要开放3000端口的访问权限 https://blog.youkuaiyun.com/zbljz98/article/details/80464761

$ iptables -A INPUT -p tcp --dport 3000 -j ACCEPT

我开始的时候就是没做这一步,导致无法在ip:3000端口访问

进入登录页面,首次访问的用户名是admin,  密码是 admin

首次登录之后会要求你更换密码

 

 

要在Windows上安装PrometheusGrafana,可以按照以下步骤进行操作: 1. 首先,进入Prometheus官网(引用[1])或者其他可信的下载源,下载适用于Windows的Prometheus安装包。根据你的系统架构选择正确的版本,比如64位系统选择prometheus-2.20.1.windows-amd64.tar.gz(引用[1])。 2. 下载完成后,解压缩安装包。你可以选择将解压后的文件夹放在任意位置。 3. 进入解压后的目录,运行prometheus.exe。这将启动Prometheus服务。 4. 打开浏览器,访问http://localhost:9090,即可进入Prometheus的Web界面。在这里,你可以查看监控的对象列表,可以通过点击"Status",然后选择"Targets"来查看(引用[1])。 5. 接下来,你可以根据自己的需求编辑prometheus.yml文件,来配置你的监控数据源。这个文件位于解压后的目录中,你可以使用任何文本编辑器进行编辑。 6. 对于Grafana安装,你可以访问Grafana官方网站或其他可信的下载源,下载适用于Windows的Grafana安装包。 7. 下载完成后,运行安装包进行安装。按照安装向导的指示进行操作,选择安装位置其他选项。 8. 安装完成后,运行Grafana。默认情况下,Grafana会在本地的3000端口启动。 9. 打开浏览器,访问http://localhost:3000,即可进入Grafana的Web界面。 10. 在Grafana中,你可以配置数据源、创建仪表盘图表,以展示Prometheus收集到的监控数据。 请注意,以上步骤仅提供了基本的安装配置指南。具体的安装配置步骤可能会因版本个人需求而有所不同。建议参考官方文档(引用[2])或其他可靠的资源,以获取更详细的指导说明。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值