第一章:通过二进制的方式安装prometheus

1、从官网下载最新版本

官网地址:https://prometheus.io/download/访问界面如下,我们需要注意的是,要选择带有“LTS”样式的版本,这是稳定版本,推荐。5b39010965e77d737f8dec3a79e00e27.png

2、上传解压

[root@loaclhost home]# ls
prometheus-2.45.5.linux-amd64.tar.gz 
[root@loaclhost home]# tar xf prometheus-2.45.5.linux-amd64.tar.gz 
[root@loaclhost home]# ls
prometheus-2.45.5.linux-amd64  prometheus-2.45.5.linux-amd64.tar.gz
[root@loaclhost home]# mv prometheus-2.45.5.linux-amd64 prometheus
[root@loaclhost home]# ls
prometheus  prometheus-2.45.5.linux-amd64.tar.gz
[root@loaclhost home]# cd prometheus
[root@loaclhost prometheus]# ll
total 229792
drwxr-xr-x 2 1001 127      4096 May  2 17:42 console_libraries
drwxr-xr-x 2 1001 127      4096 May  2 17:42 consoles
-rw-r--r-- 1 1001 127     11357 May  2 17:42 LICENSE
-rw-r--r-- 1 1001 127      3773 May  2 17:42 NOTICE
-rwxr-xr-x 1 1001 127 121066245 May  2 17:00 prometheus
-rw-r--r-- 1 1001 127       934 May  2 17:42 prometheus.yml
-rwxr-xr-x 1 1001 127 114206977 May  2 17:01 promtool
[root@loaclhost prometheus]#

3、启动prometheus

[root@loaclhost prometheus]# nohup ./prometheus &
[1] 25427
[root@loaclhost prometheus]# nohup: ignoring input and appending output to ‘nohup.out’

[root@loaclhost prometheus]#

这是最简单的启动方式,直接使用nohup命令就启动了,但是线上不推荐使用这种方式;

查看进程,是否启动成功了;

[root@loaclhost prometheus]# ps -ef | grep prometheus
root     25427 16342  0 14:41 pts/0    00:00:00 ./prometheus
root     25481 16342  0 14:42 pts/0    00:00:00 grep --color=auto prometheus
[root@loaclhost prometheus]# netstat -tunlp | grep 25427
tcp6       0      0 :::9090                 :::*                    LISTEN      25427/./prometheus  
[root@loaclhost prometheus]#

可以看到进程存在,且端口号存在,那么我们在“防火墙”关闭的情况下,使用浏览器访问一下看看结果。 浏览器访问地址:http://10.1.5.56:9090/13c0555f196e5a1c75c7f86b410682c6.png可以看到访问到了,但是有一个warning,提示我们prometheus服务所在的服务器时间存在偏差,那么我们解决一下子;

时间同步

[root@loaclhost prometheus]# yum -y install ntp ntpdate
[root@loaclhost prometheus]# ntpdate cn.pool.ntp.org
 3 Jun 14:32:11 ntpdate[25705]: step time server 84.16.73.33 offset -826.640694 sec
[root@loaclhost prometheus]#

然后我们再次浏览器刷新一下访问界面,就会发现这个warning提示消失了。eff09973725b7b734b4bb8095d431c17.png关闭程序:

[root@loaclhost home]# ps -ef | grep prometheus
root     18614 16771  0 11:07 pts/0    00:00:00 grep --color=auto prometheus
root     25427     1  0 Jun03 ?        00:01:36 ./prometheus
[root@loaclhost home]# kill -9 25427
[root@loaclhost home]# ps -ef | grep prometheus
root     18620 16771  0 11:07 pts/0    00:00:00 grep --color=auto prometheus
[root@loaclhost home]#

4、使用systemctl命令来控制prometheus

4.1 文件编写

首先我们应该知道systemctl默认service的目录在哪儿,如下:

/usr/lib/systemd/system

所以我们应该创建一个文件,在这个目录下,如下:

[root@loaclhost home]# vim prometheus.service
[Unit]
Description=Prometheus service
After=network-online.target

[Service]
Type=simple
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --log.level=warn --storage.tsdb.path=/usr/local/prometheus/data/
Restart=on-failure
ExecStop=/usr/bin/kill -9 MAINPID

[Install]
WantedBy=multi-user.target
[root@loaclhost home]# mv prometheus.service /usr/lib/systemd/system/
[root@loaclhost home]# ls /usr/lib/systemd/system/prometheus.service 
/usr/lib/systemd/system/prometheus.service
[root@loaclhost home]# systemctl daemon-reload

可以看到上面我们指定的目录是/usr/loca/prometheus,所以我们首先移动一下目录,然后重新加载一下。

[root@loaclhost home]# pwd
/home
[root@loaclhost home]# mv prometheus /usr/local/
[root@loaclhost home]# cd /usr/local/prometheus/
[root@loaclhost prometheus]# ls
console_libraries  consoles  data  LICENSE  nohup.out  NOTICE  prometheus  prometheus.yml  promtool
[root@loaclhost prometheus]# systemctl daemon-reload

而后我们尝试用systemctl命令来控制prometheus,验证一下。

4.2 systemctl控制

查看状态:

[root@loaclhost home]# systemctl status prometheus
● prometheus.service - Prometheus service
   Loaded: loaded (/usr/lib/systemd/system/prometheus.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
[root@loaclhost home]#

启动:

[root@loaclhost home]# systemctl daemon-reload
[root@loaclhost home]# systemctl start prometheus
[root@loaclhost home]# 
[root@loaclhost home]# systemctl status prometheus
● prometheus.service - Prometheus service
   Loaded: loaded (/usr/lib/systemd/system/prometheus.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2024-06-04 11:17:11 CST; 3s ago
 Main PID: 19169 (prometheus)
    Tasks: 9
   Memory: 29.5M
   CGroup: /system.slice/prometheus.service
           └─19169 /usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --log.level=warn --storage.tsdb.path=/usr/local/prometheus/data/

Jun 04 11:17:11 loaclhost systemd[1]: Started Prometheus service.
Jun 04 11:17:11 loaclhost prometheus[19169]: ts=2024-06-04T03:17:11.780Z caller=dir_locker.go:77 level=warn component=tsdb msg="A lockfile from a previous exec.../data/lock
Hint: Some lines were ellipsized, use -l to show in full.
[root@loaclhost home]#

页面访问验证:6cb84b2e2b03a8aa52489d0b3f07a77b.png停止:

[root@loaclhost home]# systemctl stop prometheus
[root@loaclhost home]# systemctl status prometheus
● prometheus.service - Prometheus service
   Loaded: loaded (/usr/lib/systemd/system/prometheus.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2024-06-04 11:18:35 CST; 6s ago
  Process: 19244 ExecStop=/usr/bin/kill -9 MAINPID (code=exited, status=1/FAILURE)
  Process: 19169 ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --log.level=warn --storage.tsdb.path=/usr/local/prometheus/data/ (code=exited, status=0/SUCCESS)
 Main PID: 19169 (code=exited, status=0/SUCCESS)

Jun 04 11:17:11 loaclhost systemd[1]: Started Prometheus service.
Jun 04 11:17:11 loaclhost prometheus[19169]: ts=2024-06-04T03:17:11.780Z caller=dir_locker.go:77 level=warn component=tsdb msg="A lockfile from a previous exec.../data/lock
Jun 04 11:18:35 loaclhost systemd[1]: Stopping Prometheus service...
Jun 04 11:18:35 loaclhost kill[19244]: kill: cannot find process "MAINPID"
Jun 04 11:18:35 loaclhost systemd[1]: prometheus.service: control process exited, code=exited status=1
Jun 04 11:18:35 loaclhost prometheus[19169]: ts=2024-06-04T03:18:35.137Z caller=main.go:854 level=warn msg="Received SIGTERM, exiting gracefully..."
Jun 04 11:18:35 loaclhost systemd[1]: Stopped Prometheus service.
Jun 04 11:18:35 loaclhost systemd[1]: Unit prometheus.service entered failed state.
Jun 04 11:18:35 loaclhost systemd[1]: prometheus.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
[root@loaclhost home]#

领取红包,能省则省

“🎉🎁 独家福利来啦!美团、饿了么、滴滴打车、菜鸟裹裹、电影票红包大放送!每天都有哦!🎁🎉

👀 快来瞅瞅,动动手指就能省下一笔!别错过,赶紧按照下方操作领取你的专属红包吧!👇

ce718e8177b52a5c4327d6a4e016eb1d.png

💬 如果你还有其他想要的红包类型,记得留言告诉我们哦,我们会尽力满足大家的需求!🎁💖”

要使用二进制安装Prometheus 和 Grafana 来监控 Kubernetes,您需要按照以下步骤进行设置: 1. 首先,您需要在 Kubernetes 集群中运行 Prometheus。您可以在每个节点上运行一个 Prometheus 实例,也可以使用 Prometheus Operator 在整个集群中运行多个实例。您可以从 Prometheus 官方网站下载二进制文件。 2. 配置 Prometheus,指定要监控的 Kubernetes 组件和指标。您可以创建一个 Prometheus 配置文件,定义要监控的目标和抓取规则。例如,您可以监控 Kubernetes API 服务器、节点指标、容器指标等等。 3. 启动 Prometheus 实例,并确保它可以连接到 Kubernetes 集群和要监控的组件。您可以使用命令行参数或环境变量来指定 Prometheus 的配置文件和目标。 4. 确保 Prometheus 正确抓取和存储指标数据。您可以访问 Prometheus 的 Web UI 或使用 PromQL 查询语言来检查指标数据。 5. 安装和配置 Grafana,以便可视化 Prometheus 中的指标数据。您可以从 Grafana 官方网站下载二进制文件,并根据需要进行自定义配置。 6. 在 Grafana 中创建仪表盘,并添加 Prometheus 数据源。您可以使用 Grafana 的界面来创建和编辑仪表盘,并使用 PromQL 查询语言来检索和呈现数据。 7. 在仪表盘中添加面板,并选择要显示的指标和图表类型。您可以根据需要创建各种类型的面板,例如图表、表格、仪表盘等。 通过以上步骤,您应该能够使用 Prometheus 和 Grafana 来监控 Kubernetes 集群,并可视化指标数据。请注意,这只是一个简单的概述,具体的配置和设置可能会根据您的需求和环境而有所不同。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

运维家

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值