prometheus二进制安装和exporter配合监控,适合于监控独立应用或中间件

一、安装docker,用于运行exporter

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

sudo yum makecache fast

sudo yum -y install docker-ce

systemctl restart docker

systemctl enable docker

sudo mkdir -p /etc/docker

sudo tee /etc/docker/daemon.json <<-'EOF'

{

"registry-mirrors": ["https://res3lpuj.mirror.aliyuncs.com"]

}

EOF

sudo systemctl daemon-reload

sudo systemctl restart docker

二、安装docker-compose,用于管理docker

sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose

三、安装prometheus-server服务

安装rpm

yum -y install wget lrzsz net-tools vim

wget https://github.com/prometheus/prometheus/releases/download/v2.28.0/prometheus-2.28.0.linux-amd64.tar.gz

tar zxf prometheus-2.28.0.linux-amd64.tar.gz

mv prometheus-2.28.0.linux-amd64 /usr/local/prometheus

[root@prometheus-server157 ~]# ll /usr/local/prometheus/
total 181656
drwxr-xr-x 2 3434 3434       38 Jun 21  2021 console_libraries
drwxr-xr-x 2 3434 3434      173 Jun 21  2021 consoles
-rw-r--r-- 1 3434 3434    11357 Jun 21  2021 LICENSE
-rw-r--r-- 1 3434 3434     3646 Jun 21  2021 NOTICE
-rwxr-xr-x 1 3434 3434 98491188 Jun 21  2021 prometheus
-rw-r--r-- 1 3434 3434      926 Jun 21  2021 prometheus.yml
-rwxr-xr-x 1 3434 3434 87502544 Jun 21  2021 promtool
编辑systemd启动文件
[root@prometheus-server-custom ~]# vim /usr/lib/systemd/system/prometheus.service

[Unit]
Description=Prometheus: the monitoring system
Documentation=http://prometheus.io/docs/

[Service]
ExecStart=/usr/local/prometheus/prometheus \
        --config.file=/usr/local/prometheus/prometheus.yml \
        --storage.tsdb.path=/var/lib/prometheus \
        --storage.tsdb.retention.time=90d \
        --storage.tsdb.retention.size=163840MB \
        --web.console.templates=/usr/local/prometheus/consoles \
        --web.console.libraries=/usr/local/prometheus/console_libraries \
        --web.listen-address=0.0.0.0:9090 --web.external-url=  \
        --web.enable-lifecycle
Restart=always
StartLimitInterval=0
RestartSec=10

[Install]
WantedBy=multi-user.target
挂载数据盘

mkdir /var/lib/prometheus

mkfs.xfs /dev/sdb

mount /dev/sdb /var/lib/prometheus/

echo '/dev/sdb /var/lib/prometheus/ xfs defaults 0 0' >> /etc/fstab

mount -a

启动服务

systemctl daemon-reload

systemctl enable prometheus

systemctl restart prometheus

systemctl status prometheus

四、示例:监控es

下载esporter镜像

docker pull quay.io/prometheuscommunity/elasticsearch-exporter:latest

[root@yw-mon opt]# cat elasticsearch-exporter/docker-compose.yaml
version: '2'
services:
  prometheus-es1:
    container_name: elasticsearch-exporter-es
    image: quay.io/prometheuscommunity/elasticsearch-exporter:v202210
    restart: always
    command:
      --es.uri='http://elastic:密码@11.11.11.11:9200'
      --es.indices
      --es.cluster_settings
      --es.indices_settings
      --es.shards
      --es.snapshots
      --es.timeout=30s
      --web.listen-address=":9114"
      --es.all
    ports:
      - 127.0.0.1:9114:9114
    networks:
      - pronet
networks:
  pronet:
    external:
      name: prometheus-monitoring
[root@yw-mon opt]#

检测是否成功可以

curl http://127.0.0.1:9114

编辑prometheus.yml文件

  - job_name: 'elasticsearch_exporter_es'
    scrape_interval: 15s
    metrics_path: /metrics
    static_configs:
      - targets: ['127.0.0.1:9114']
        labels:
          server_exporter: elasticsearch_exporter'


重载
 curl -X POST "http://127.0.0.1:9090/-/reload"

六、此时查看prometheus的指标即可看到相关值

  • 28
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用二进制安装Prometheus 和 Grafana 来监控 Kubernetes,您需要按照以下步骤进行设置: 1. 首先,您需要在 Kubernetes 集群中运行 Prometheus。您可以在每个节点上运行一个 Prometheus 实例,也可以使用 Prometheus Operator 在整个集群中运行多个实例。您可以从 Prometheus 官方网站下载二进制文件。 2. 配置 Prometheus,指定要监控的 Kubernetes 组件和指标。您可以创建一个 Prometheus 配置文件,定义要监控的目标和抓取规则。例如,您可以监控 Kubernetes API 服务器、节点指标、容器指标等等。 3. 启动 Prometheus 实例,并确保它可以连接到 Kubernetes 集群和要监控的组件。您可以使用命令行参数或环境变量来指定 Prometheus 的配置文件和目标。 4. 确保 Prometheus 正确抓取和存储指标数据。您可以访问 Prometheus 的 Web UI 或使用 PromQL 查询语言来检查指标数据。 5. 安装和配置 Grafana,以便可视化 Prometheus 中的指标数据。您可以从 Grafana 官方网站下载二进制文件,并根据需要进行自定义配置。 6. 在 Grafana 中创建仪表盘,并添加 Prometheus 数据源。您可以使用 Grafana 的界面来创建和编辑仪表盘,并使用 PromQL 查询语言来检索和呈现数据。 7. 在仪表盘中添加面板,并选择要显示的指标和图表类型。您可以根据需要创建各种类型的面板,例如图表、表格、仪表盘等。 通过以上步骤,您应该能够使用 Prometheus 和 Grafana 来监控 Kubernetes 集群,并可视化指标数据。请注意,这只是一个简单的概述,具体的配置和设置可能会根据您的需求和环境而有所不同。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值