ubuntu下prometheus部署part1

韵味老鸟 2024-07-03 02:04:34

ubuntu下prometheus部署

prometheus

#创建目录

mkdir -p /data/prometheus/{conf,data}

#分配data权限

chmod -R 777 /data/prometheus/data

#docker-compose.yaml

version: '2.4'services: prometheus: container_name: prometheus image: prom/prometheus:v2.40.7 command: ["--config.file=/etc/prometheus/prometheus.yaml", "--storage.tsdb.path=/prometheus", "--web.console.libraries=/usr/share/prometheus/console_libraries", "--web.console.templates=/usr/share/prometheus/consoles", "--web.external-url=http://192.168.10.18:9090", "--storage.tsdb.retention.time=100d", "--storage.tsdb.retention.size=100GB", "--web.config.file=/etc/prometheus/web.yaml", "--web.enable-lifecycle"] volumes: - /data/prometheus/conf:/etc/prometheus:ro - /data/prometheus/data:/prometheus - /etc/localtime:/etc/localtime:ro ports: - "9090:9090" networks: - monitor restart: 'always' extra_hosts: - "sz-prom-dev.meng.com:192.168.10.14"networks: monitor: external: true

#编辑/etc/hosts文件

#monitor

192.168.10.14 sz-prom-dev.meng.com

#导入镜像

docker load < prom.prometheus.v2.40.7.tgz

#执行 basic 认证

# 安装工具 httpd-toolsapt-get install apache2-utilshtpasswd -nBC 12 '' | tr -d ':\n'# 输入密码,生成token,如:$2y$12$PXPGKbEWWzIHKXH/7eW1bOzVazIo.gGJa9Uw8lMMJ36NAV2XiLOWG

密码:meng@2022

加密串:$2y$12$zjSZ1rVXt4U.zfEBBFYBNu1YNUbN/./9yx7SM/z25hfI.COJT03na

#将生成的token写入文件/data/prometheus/conf/web.yml里,如下

basic_auth_users: admin: $2y$12$zjSZ1rVXt4U.zfEBBFYBNu1YNUbN/./9yx7SM/z25hfI.COJT03na

#密码文件

mkdir conf/password/prometheus.password

#密码文件内不能有多余字符,包括注释等

meng@2022

#主配置文件/data/monitor/prometheus/conf/prometheus.yaml

global: scrape_interval: 30s evaluation_interval: 1malerting: alertmanagers: - static_configs: - targets: - alertmanager:9093 basic_auth: username: admin password_file: /etc/prometheus/passwords/alertmanager.passwordrule_files: - /etc/prometheus/rules/*.yaml - /etc/prometheus/rules/*.yml - /etc/prometheus/rules-k8s/*.yaml - /etc/prometheus/rules-k8s/*.ymlscrape_configs: - job_name: prometheus scrape_interval: 60s static_configs: - targets: - localhost:9090 basic_auth: username: admin password_file: /etc/prometheus/passwords/prometheus.password - job_name: prometheus-federate scrape_interval: 30s honor_labels: true #为true表示可避免监控指标冲突 metrics_path: /federate params: "match[]": - '{job="prometheus"}' - '{__name__=~".*"}' static_configs: - targets:# - 192.168.102.238:31090 - sz-prom.meng.com - job_name: mysqld_exporter metrics_path: /probe params: auth_module: - client.servers file_sd_configs: - files: - /etc/prometheus/targets/mysqld_exporter/*.yaml relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance - target_label: __address__ replacement: 192.168.10.18:9104 - job_name: redis-exporter file_sd_configs: - files: - /etc/prometheus/targets/redis_exporter/*.yaml metrics_path: /scrape relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance - source_labels: [ cluster ] regex: sz-redis-sit target_label: __address__ replacement: 192.168.10.18:9122 - job_name: zookeeper file_sd_configs: - files: - /etc/prometheus/targets/zookeeper/*.yaml - job_name: kafka-exporter file_sd_configs: - files: - /etc/prometheus/targets/kafka-exporter/*.yaml - job_name: nacos metrics_path: '/nacos/actuator/prometheus' file_sd_configs: - files: - /etc/prometheus/targets/nacos/*.yaml - job_name: node-exporter file_sd_configs: - files: - /etc/prometheus/targets/node-exporter/*.yaml - job_name: cadvisor file_sd_configs: - files: - /etc/prometheus/targets/cadvisor/*.yaml

0 阅读:0