|
一、yum安装prometheus
1、添加yum源
2、更新yum源
- yum clean all
- yum repolist
- yum search prometheus
复制代码 3、安装prometheus
- yum install -y prometheus2
复制代码 4、启动prometheus,并加入自启
- systemctl start prometheus
- systemctl enable prometheus
复制代码 二、二进制安装prometheus
1、下载prometheus
从 https://prometheus.io/download/ 下载相应版本,安装到服务器上官网提供的是二进制版,解压就能用,不需要编译
上传prometheus-2.28.1.linux-amd64.tar.gz
2、解压安装包
- tar -zxvf prometheus-2.28.1.linux-amd64.tar.gz -C /usr/local/
- mv /usr/local/prometheus-2.28.1.linux-amd64/ /usr/local/prometheus
复制代码 3、解压后当前目录会包含默认的Prometheus配置文件promethes.yml,下面配置文件做下简略的解析:
- # 全局配置
- global:
- scrape_interval: 15s # 设置抓取间隔,默认为1分钟
- evaluation_interval: 15s #估算规则的默认周期,每15秒计算一次规则。默认1分钟
- # scrape_timeout #默认抓取超时,默认为10s
- # Alertmanager相关配置
- alerting:
- alertmanagers:
- - static_configs:
- - targets:
- # - alertmanager:9093
- # 规则文件列表,使用'evaluation_interval' 参数去抓取
- rule_files:
- # - "first_rules.yml"
- # - "second_rules.yml"
- # 抓取配置列表
- scrape_configs:
- - job_name: 'prometheus'
- static_configs:
- - targets: ['localhost:9090']
复制代码 4、直接使用默认配置文件启动
- /usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml" &
复制代码 5、验证启动
- [root@prometheus opt]# netstat -nutlp|grep 9090
- tcp6 0 0 :::9090 :::* LISTEN 4726/prometheus
复制代码 6、访问prometheus界面
通过浏览器访问http://服务器IP:9090就可以访问到prometheus的主界面
7、做成服务,设置成开启自启动
- vim /etc/systemd/system/prometheus.service
- [Unit]
- Description=Prometheus Monitoring System
- Documentation=Prometheus Monitoring System
-
- [Service]
- ExecStart=/usr/local/prometheus/prometheus
- --storage.tsdb.path=/usr/local/prometheus/data
- --config.file=/usr/local/prometheus/prometheus.yml
- --web.listen-address=:9090
-
- [Install]
- WantedBy=multi-user.target
复制代码 8、创建目录
- mkdir /usr/local/prometheus/data
复制代码 9、设置开机自启
启动前先kill掉原来的服务,否则不能成功启动
- systemctl daemon-reload
- systemctl enable prometheus
- systemctl start prometheus
复制代码
|
|