这里先简单介绍下二进制安装,可以了解一下自己玩玩,之后会讲Kube-Prometheus这个在k8s里面更好用的东西。
1.1 Prometheus server获取
[root@prometheus-server ~]# wget https://github.com/prometheus/prometheus/releases/download/v2.37.8/prometheus-2.37.8.linux-amd64.tar.gz
1.2 Prometheus安装
[root@prometheus-server ~]# tar xf prometheus-2.37.8.linux-amd64.tar.gz
[root@prometheus-server ~]# mv prometheus-2.37.8.linux-amd64 /usr/local/src/prometheus
1.3 Prometheus启动
1.3.1 修改Prometheus配置文件
[root@prometheus-server ~]# cd /usr/local/src/prometheus/
[root@prometheus-server prometheus]# ls
console_libraries consoles LICENSE NOTICE prometheus prometheus.yml promtool
[root@prometheus-server prometheus]# vim prometheus.yml
[root@prometheus-server 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:
# - alertmanager:9093# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.static_configs:
- targets: ["192.168.10.170:9090"] #把localhost修改为192.168.10.170
1.3.2 启动Prometheus
[root@prometheus-server prometheus]# nohup ./prometheus --config.file=prometheus.yml &
[root@prometheus-server prometheus]# ps aux | grep prometheus
root 29940 0.6 1.6 791544 67268 pts/1 Sl 19:31 0:00 ./prometheus --config.file=prometheus.yml
可以把Prometheus托管给systemd,如下所示:
注册为系统服务
[root@prometheus-server prometheus]# vim /usr/lib/systemd/system/prometheus.service
[root@prometheus-server prometheus]# cat > /usr/lib/systemd/system/prometheus.service << EOF
[Service]
ExecStart=/usr/local/src/prometheus/prometheus --config.file=/usr/local/src/prometheus/prometheus.yml
[Install]
WantedBy=multi-user.target
[Unit]
Description=prometheus
After=network.target
EOF
重载/开机自启/查看状态/启动
[root@prometheus-server prometheus]# systemctl daemon-reload
[root@prometheus-server prometheus]# systemctl enable prometheus
[root@prometheus-server prometheus]# systemctl status prometheus
[root@prometheus-server prometheus]# systemctl start prometheus
[root@prometheus-server prometheus]# lsof -i:9090
[root@prometheus-server prometheus]# ps -ef | grep prometheus
可以通过运行Prometheus server节点IP+9090端口对Prometheus进行访问。