prometheus安装部署(一)
一、介绍
Prometheus(普罗米修斯)是一个最初在SoundCloud上构建的监控系统。自2012年成为社区开源项目,拥有非常活跃的开发人员和用户社区。为强调开源及独立维护,Prometheus于2016年加入云原生云计算基金会(CNCF),成为继Kubernetes之后的第二个托管项目。
官方网站:https://prometheus.io
项目托管:https://github.com/prometheus
二、特点
1、多维数据模型:由度量名称和键值对标识的时间序列数据
2、PromSQL:一种灵活的查询语言,可以利用多维数据完成复杂的查询
3、不依赖分布式存储,单个服务器节点可直接工作
4、基于HTTP的pull方式采集时间序列数据
5、推送时间序列数据通过PushGateway组件支持
6、通过服务发现或静态配置发现目标
7、多种图形模式及仪表盘支持(grafana)
8、适用于以机器为中心的监控以及高度动态面向服务架构的监控
三、安装
系统环境:Centos7.4
服务端:192.168.30.132
node端:192.168.30.131
1、服务端安装
下载地址:https://prometheus.io/download/
我的安装目录:/data/
一、下载解压安装文件
# 下载
wget https://github.com/prometheus/prometheus/releases/download/v2.32.1/prometheus-2.32.1.linux-amd64.tar.gz
# 解压
tar xf prometheus-2.32.1.linux-amd64.tar.gz
# 查看文件
[root@bogon prometheus-2.32.1.linux-amd64]# ll
总用量 193448
drwxr-xr-x. 2 3434 3434 38 12月 18 06:18 console_libraries
drwxr-xr-x. 2 3434 3434 173 12月 18 06:18 consoles
drwxr-xr-x. 10 root root 274 12月 31 09:00 data
-rw-r--r--. 1 3434 3434 11357 12月 18 06:18 LICENSE
-rw-r--r--. 1 3434 3434 3646 12月 18 06:18 NOTICE
-rwxr-xr-x. 1 3434 3434 103070626 12月 18 06:10 prometheus
-rw-r--r--. 1 3434 3434 1032 12月 30 15:52 prometheus.yml
-rwxr-xr-x. 1 3434 3434 94996583 12月 18 06:13 promtool
二、启动配置
# 直接启动(不用配置文件启动)
./prometheus
# 加配置文件启动(一般启动都要配置文件哈)
# 配置文件就是 同目录的 prometheus.yml 文件
./prometheus --config.file=prometheus.yml
三、配置文件
# 查看配置文件 (web端口默认是9090)
[root@bogon prometheus-2.32.1.linux-amd64]# 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: ["localhost:9090"]
四、配置启动文件
# 配置启动文件
vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=prometheus-server
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=simple
# 找到自己解压目录哈
ExecStart=/data/prometheus-2.32.1.linux-amd64/prometheus --config.file=/data/prometheus-2.32.1.linux-amd64/prometheus.yml --web.enable-lifecycle --storage.tsdb.path=/data/prometheus-2.32.1.linux-amd64/data --storage.tsdb.retention.time=7d --web.max-connections=512 --web.read-timeout=3m --query.max-concurrency=25 --query.timeout=2m
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
五、启动prometheus
# 启动prometheus
systemctl start prometheus
# 查看启动状态
[root@bogon prometheus-2.32.1.linux-amd64]# systemctl status prometheus
● prometheus.service - prometheus-server
Loaded: loaded (/usr/lib/systemd/system/prometheus.service; disabled; vendor preset: disabled)
Active: active (running) since 四 2021-12-30 15:59:52 CST; 18h ago
Process: 21069 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS)
Main PID: 21072 (prometheus)
CGroup: /system.slice/prometheus.service
└─21072 /data/prometheus-2.32.1.linux-amd64/prometheus --config.file=/data/prometheus-2.32.1.linux-amd64/prometheus.yml --web.enable-lifecycle --storage.tsdb.path=/data/prometheus-2.32.1.linux-amd64/data --storage.tsdb.retention.time=7d --web.max-connection...
12月 31 07:00:13 bogon prometheus[21072]: ts=2021-12-30T23:00:13.839Z caller=compact.go:518 level=info component=tsdb msg="write block" mint=1640894412370 maxt=1640901600000 ulid=01FR6S51V3XAQ918W68RXA4Y8F duration=43.373913ms
12月 31 07:00:13 bogon prometheus[21072]: ts=2021-12-30T23:00:13.841Z caller=head.go:812 level=info component=tsdb msg="Head GC completed" duration=1.267119ms
12月 31 07:00:13 bogon prometheus[21072]: ts=2021-12-30T23:00:13.845Z caller=checkpoint.go:98 level=info component=tsdb msg="Creating checkpoint" from_segment=9 to_segment=10 mint=1640901600000
12月 31 07:00:13 bogon prometheus[21072]: ts=2021-12-30T23:00:13.892Z caller=head.go:981 level=info component=tsdb msg="WAL checkpoint complete" first=9 last=10 duration=46.922566ms
12月 31 07:00:13 bogon prometheus[21072]: ts=2021-12-30T23:00:13.951Z caller=compact.go:459 level=info component=tsdb msg="compact blocks" count=3 mint=1640865612370 maxt=1640887200000 ulid=01FR6S51Y4Z37DKNF7H0KZ2A5J sources="[01FR5XP4VCPT3Q25NKCH...duration=58.467252ms
12月 31 07:00:13 bogon prometheus[21072]: ts=2021-12-30T23:00:13.952Z caller=db.go:1279 level=info component=tsdb msg="Deleting obsolete block" block=01FR5XP4VCPT3Q25NKCHRP7YQN
12月 31 07:00:13 bogon prometheus[21072]: ts=2021-12-30T23:00:13.953Z caller=db.go:1279 level=info component=tsdb msg="Deleting obsolete block" block=01FR64HW32RJWWR9521YCTGNPY
12月 31 07:00:13 bogon prometheus[21072]: ts=2021-12-30T23:00:13.954Z caller=db.go:1279 level=info component=tsdb msg="Deleting obsolete block" block=01FR6BDKB79DGNRZH0NTD6R88S
12月 31 09:00:13 bogon prometheus[21072]: ts=2021-12-31T01:00:13.853Z caller=compact.go:518 level=info component=tsdb msg="write block" mint=1640901612370 maxt=1640908800000 ulid=01FR700S3F5X8YJ503B564N7YB duration=45.651215ms
12月 31 09:00:13 bogon prometheus[21072]: ts=2021-12-31T01:00:13.856Z caller=head.go:812 level=info component=tsdb msg="Head GC completed" duration=1.369749ms
Hint: Some lines were ellipsized, use -l to show in full.
六、访问web页面
地址:ip:9090
2、增加node端配置
一、下载、解压文件
# 下载
wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz
#解压
tar xf node_exporter-1.3.1.linux-amd64.tar.gz
二、配置启动文件
vim /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=root
ExecStart=/data/node_exporter-1.3.1.linux-amd64/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
三、启动
启动之后端口是9100,IP+端口是可以访问的
# 启动
systemctl start node_exporter
# 查看启动状态
[root@localhost node_exporter-0.15.1.linux-amd64]# systemctl status node_exporter
● node_exporter.service - node_exporter
Loaded: loaded (/usr/lib/systemd/system/node_exporter.service; disabled; vendor preset: disabled)
Active: active (running) since 四 2021-12-30 15:58:53 CST; 19h ago
Docs: https://prometheus.io/
Main PID: 14571 (node_exporter)
CGroup: /system.slice/node_exporter.service
└─14571 /data/node_exporter-0.15.1.linux-amd64/node_exporter
12月 30 15:58:53 localhost node_exporter[14571]: time="2021-12-30T15:58:53+08:00" level=info msg=" - arp" source="node_exporter.go:52"
12月 30 15:58:53 localhost node_exporter[14571]: time="2021-12-30T15:58:53+08:00" level=info msg=" - uname" source="node_exporter.go:52"
12月 30 15:58:53 localhost node_exporter[14571]: time="2021-12-30T15:58:53+08:00" level=info msg=" - diskstats" source="node_exporter.go:52"
12月 30 15:58:53 localhost node_exporter[14571]: time="2021-12-30T15:58:53+08:00" level=info msg=" - filesystem" source="node_exporter.go:52"
12月 30 15:58:53 localhost node_exporter[14571]: time="2021-12-30T15:58:53+08:00" level=info msg=" - wifi" source="node_exporter.go:52"
12月 30 15:58:53 localhost node_exporter[14571]: time="2021-12-30T15:58:53+08:00" level=info msg=" - netstat" source="node_exporter.go:52"
12月 30 15:58:53 localhost node_exporter[14571]: time="2021-12-30T15:58:53+08:00" level=info msg=" - bcache" source="node_exporter.go:52"
12月 30 15:58:53 localhost node_exporter[14571]: time="2021-12-30T15:58:53+08:00" level=info msg=" - cpu" source="node_exporter.go:52"
12月 30 15:58:53 localhost node_exporter[14571]: time="2021-12-30T15:58:53+08:00" level=info msg=" - edac" source="node_exporter.go:52"
12月 30 15:58:53 localhost node_exporter[14571]: time="2021-12-30T15:58:53+08:00" level=info msg="Listening on :9100" source="node_exporter.go:76"
四、修改服务端配置文件
[root@bogon prometheus-2.32.1.linux-amd64]# vim prometheus.yml
在配置文件scrape_config模块下增加一个主机(看配置文件注释)
# 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: ["localhost:9090"]
# 这是新增的主机
- job_name: "ser-30.131"
static_configs:
- targets: ["192.168.30.131:9100"]
重启服务端
systemctl restart prometheus
访问:http://IP:9090/targets
可以看到监控的主机了,一个是本机,另一个是手动添加的node
其他配置下一章继续
正文到此结束
- 本文标签: Linux prometheus 监控
- 版权声明: 本站原创文章,于2021年12月31日由 发布,转载请注明出处
评论
登录后才能发表评论 登录/注册
0评论