linux下安装Prometheus一篇就够了

1. 下载Prometheus

2. 使用VirtualBox的共享文件夹将压缩包传入linux

  • 进入增强文件夹

    在这里插入图片描述

  • 启动终端并且切换root权限
# 新建一个挂载目录
mkdir /mnt/cdrom

# 将 /dev/cdrom 挂载到  /mnt/cdrom 目录上
mount /dev/cdrom /mnt/cdrom

  • 进入增强工具挂载的目录
cd /mnt/cdrom
  • 安装运行
sudo ./VBoxLinuxAdditions.run
  • 关机虚拟机,添加共享文件夹,设置自动挂载,并且设置挂载点(linux内的文件夹地址)

  • 将Prometheus压缩包通过增强功能传入虚拟机

3. 在linux安装Prometheus

  1. 安装Prometheus
    打开终端并且切换root账户
# 新建目录
mkdir -p /data/prometheus/
# 进入目标目录
cd /data/prometheus/
# 解压
tar -vxzf prometheus-2.28.1.linux-amd64.tar.gz
# 移动到安装目录
mv prometheus-2.28.1.linux-amd64 /usr/local/prometheus
# 进入目录
cd /usr/local/prometheus
  1. 将Prometheus配置为系统服务

进去systemd目录

cd /usr/lib/systemd/system

创建文件。这里的Vim语法,使用:wq保存

vim prometheus.service
 
# 添加如下内容
[Unit]
Description=https://prometheus.io
  
[Service]
Restart=on-failure
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml
 
[Install]                      
WantedBy=multi-user.target

生效systemd文件

systemctl daemon-reload

4. 启动Prometheus

# 进入解压后的文件夹
cd /data/prometheus/prometheus-2.28.1.linux-amd64
# 前台启动
./prometheus --config.file=prometheus.yml
# 前台指定端口启动
./prometheus --config.file=prometheus.yml --web.listen-address=:9099
# 后台启动prometheus,并且重定向输入日志到当前目录的prometheus.out
nohup ./prometheus --config.file=prometheus.yml > ./prometheus.log 2>&1 &

5. 访问Prometheus

这里使用修改后的端口访问:

http://127.0.0.1:9099

在这里插入图片描述

6. 使用外部主机访问内部linux的Prometheus

  1. 配置网络为NAT并且设置端口转发

    在这里插入图片描述

  2. 开放端口9099

firewall-cmd --zone=public --add-port=9099/tcp --permanent
  1. 重启防火墙生效
firewall-cmd --reload

其它的语句:

# 查看防火墙状态
systemctl status firewalld
# 开启防火墙
systemctl status firewalld
# 关闭防火墙
systemctl stop firewalld

7. 主机直接访问

http://127.0.0.1:9099

8. pushgateway的安装

方法同上,下载,解压,移动,启动

nohup ./pushgateway --web.listen-address :9091 > ./pushgateway.log 2>&1 &
# 查看状态
ps -ef|grep prometheus
#重启
systemctl restart prometheus
#对于后台启动的服务可以先查看状态然后使用kill命令杀死进程
kill 6330

9. 服务器时间不一致解决

https://blog.csdn.net/weixin_51659640/article/details/122616326

10. 防火墙常见命令

在这里插入图片描述


启动cansul:./consul agent -dev

启动pushgateway:nohup ./pushgateway --web.listen-address :9091 > ./pushgateway.log 2>&1 &

启动node_exporter: ./node_exporter

启动普罗米修斯:nohup ./prometheus --config.file=prometheus.yml > ./prometheus.log 2>&1 &

查看状态:ps -ef|grep prometheus

11. windows浏览器无法访问虚拟机上Linux部署的consul

  1. linux 8500端口已经开放
  2. 设置了端口转发
  3. 关闭防火墙
  4. 启动consul consul agent -dev -client 0.0.0.0 -ui

12. 虚拟机访问主机服务

  1. 不需要端口转发
  2. 直接使用10.0.2.2访问

相关文章

学习编程是顺着互联网的发展潮流,是一件好事。新手如何学习...
IT行业是什么工作做什么?IT行业的工作有:产品策划类、页面...
女生学Java好就业吗?女生适合学Java编程吗?目前有不少女生...
Can’t connect to local MySQL server through socket \'/v...
oracle基本命令 一、登录操作 1.管理员登录 # 管理员登录 ...
一、背景 因为项目中需要通北京网络,所以需要连vpn,但是服...