安装prometheus并设置system启动程序

配置yum源

yum -y install wget
cd /etc/yum.repos.d/
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all
yum makecache
yum -y install lrzsz

配置prometheus

[root@localhost opt]# dir
prometheus-2.18.1.linux-amd64.tar.gz
[root@localhost opt]# tar -zxvf prometheus-2.18.1.linux-amd64.tar.gz
[root@localhost opt]# cp -r prometheus-2.18.1.linux-amd64 /usr/local/prometheus
[root@jgxxpt-nginx2 prometheus]# cat prometheus.yml 
# my global config
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:
            - 192.168.145.11:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  - "rules/*_rules.yml"
  - "rules/*_alerts.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
    static_configs:
      - targets: ["localhost:9090"]
      - targets: ["localhost:9093"]
  - job_name: "node_exporter"
    file_sd_configs:
      - files: ['/usr/local/prometheus/sd_config/*.yml']
        # 每过5秒动态发现服务配置
        refresh_interval: 5s

设置systemd服务

[root@localhost ~]# cat /usr/lib/systemd/system/prometheus.service 
[Unit]
Description=Prometheus server daemon
After=network.target

[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/local/prometheus/prometheus \
    --config.file=/usr/local/prometheus/prometheus.yml \
    --storage.tsdb.path="/usr/local/prometheus/data" \
    --storage.tsdb.retention=15d \
    --web.console.templates="/usr/local/prometheus/consoles" \
    --web.console.libraries="/usr/local/prometheus/console_libraries" \
    --web.max-connections=512 \
    --web.external-url "http://192.168.1.4:9090" \
    --web.listen-address=0.0.0.0:9090
Restart=on-failure

[Install]
WantedBy=multi-user.target

参数说明:
ExecStart=/usr/local/prometheus/prometheus #启动运行prometheus程序所在的路径
–config.file=/usr/local/prometheus/prometheus.yml #指定prometheus.yml配置文件路径
–storage.tsdb.path=”/usr/local/prometheus/data” #指定监控指标数据存储的路径
–storage.tsdb.retention=15d #历史数据最大保留时间,默认15天
–web.console.templates=”/usr/local/prometheus/consoles” #指定控制台模板目录路径
–web.console.libraries=”/usr/local/prometheus/console_libraries” #指定控制台库目录路径
–web.max-connections=512 #设置最大同时连接数
–web.external-url “http://192.168.1.4:9090” #用于生产返回prometheus相对的绝对链接地址,可以在后续告警通知内容中直接点击链接地址访问prometheus Web UI。其格式为:http://{ip或者域名}:9090
–web.listen-address=0.0.0.0:9090 #prometheus默认监控端口

systemctl命令介绍:
systemctl daemon-reload #通知systemctl重新加载配置文件
systemctl enable prometheus.service #设置为开机自启动
systemctl disable prometheus.service #如果不想设置为开机启动,可以关闭。关闭开机自启动
systemctl start prometheus.service #开启服务
systemctl status prometheus.service #查看服务状态
systemctl restart prometheus.service #重启服务
systemctl stop prometheus.service #关闭服务

声明: 本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
VMware vSphere

搭建VMware Horizon8私有云桌面虚拟化(七)Horizon 创建桌面池连接SqlServer数据库

2024-1-18 15:28:48

prometheus

云原生夜莺监控 v7 最终版来了,可以上车了

2024-11-21 4:47:00

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索