Prometheus基础

本文涉及的产品
可观测可视化 Grafana 版,10个用户账号 1个月
简介: prometheus

1.监控维度

  • 系统监控 CPU,内存,磁盘,网卡流量,TCP状态,进程数。
  • 应用监控 Nginx,Tomcat,PHP,MySQL,Redis 等。
  • 日志监控 系统日志,服务日志,访问日志,错误日志。
  • 安全监控 WAF,敏感文件监控。
  • API监控 可用性,接口请求,响应时间。
  • 流量分析 根据流量获取用户相关信息,例如:某页面访问状况,页面停留时间等。

1、grafana 安装
官方下载地址:
https://grafana.com/grafana/download/7.1.0

二进制安装

wget https://dl.grafana.com/oss/release/grafana-7.1.0.linux-amd64.tar.gz
tar xf grafana-7.1.0.linux-amd64.tar.gz && cd grafana-7.1.0/
nohup bin/grafana-server &

# yum 安装
wget https://dl.grafana.com/oss/release/grafana-7.1.0-1.x86_64.rpm
yum  -y  install grafana-7.1.0-1.x86_64.rpm

[root@localhost ~]# cat /etc/yum.repos.d/grafana.repo 
[grafana]
name=grafana
baseurl=https://packages.grafana.com/oss/rpm
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packages.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt

yum -y install grafana-7.5.10
# 配置文件目录
二进制文件     /usr/sbin/grafana-server
启动脚本         /etc/init.d/grafana-server
环境变量         /etc/sysconfig/grafana-server
配置文件         /etc/grafana/grafana.ini
systemd服务  grafana-server.service
日志                 /var/log/grafana/grafana.log

# 服务详情
启动用户 grafana
服务名称 grafana-server
默认端口 3000
账号        admin
密码        admin

# 启动服务、添加开机启动
grafana-cli plugins install grafana-piechart-panel
systemctl daemon-reload && systemctl start grafana-server
systemctl status grafana-server && systemctl enable grafana-server.service

# 访问
http://server IP :3000

2、修改端口
1、给予grafana二进制权限(推荐使用)

sudo setcap 'cap_net_bind_service=+ep' /usr/sbin/grafana-server

2、将端口80重定向到Grafana端口3000

sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 3000

3、在Grafana面前放一个像Nginx或Apache这样的服务器,让它们代理请求Grafana

然后,修改配置文件/etc/grafana/grafana.ini中端口为80,并重启
2、prometheus 安装部署
https://github.com/prometheus/prometheus/tags

wget https://github.com/prometheus/prometheus/releases/download/v2.19.1/prometheus-2.19.1.linux-amd64.tar.gz
tar xf  prometheus-2.4.3.linux-amd64.tar.gz
mv prometheus-2.4.3.linux-amd64 prometheus-2.4.3
cd prometheus-2.4.3/
##### Prometheus 的本地存储被称为 Prometheus TSDB。
 ## TSDB 的设计有两个核心:block 和 WAL;
(1) block 又包含 chunk、index、meta.json、tombstones 
(2) WAL(Write-Ahead Logging,预写日志)是关系型数据库中利用日志
来实现事务性和持久性的一种技术
即在进行某个操作之前先将这件事情记录下来,
以便之后对数据进行回滚、重试等操作并保证数据的可靠性 
### prometheus的设计是使用pull方式由服务端主动拉取监控数据 
# 启动文件
vi /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus
After=network.target
[Service]
ExecStart=/montion/prometheus-2.4.3/prometheus --config.file=/montion/prometheus-2.4.3/prometheus.yml --storage.tsdb.path=/montion/prometheus-2.4.3/data  --storage.tsdb.retention=90d
User=root
[Install]
WantedBy=multi-user.target

注意:主要修改ExecStart和User

# 启动和开机自启
systemctl daemon-reload
systemctl enable prometheus
systemctl start prometheus
# 重新加载配置
kill -SIGHUP $(pidof prometheus)

# 访问
http://server IP :9090

3、consul 注册中心安装

# 历史版本
https://releases.hashicorp.com/consul/

wget https://releases.hashicorp.com/consul/1.9.0/consul_1.9.0_linux_amd64.zip

unzip consul_1.9.0_linux_amd64.zip

# 启动服务
nohup ./consul agent -ui -server -bootstrap -data-dir=/workspace/service/consul_cluster/data -pid-file=/workspace/service/consul_cluster/consul.pid -client=0.0.0.0 -advertise=10.106.59.153 -join=10.106.59.153 -node=consul-c1 &
-ui 启动 web ui 服务,默认端口8500
-server 服务器模式(开发环境可以使用-dev,不写入磁盘,内存存储)
-data-dir 数据存储路径
-pid-file PID文件路径
-client 绑定的客户端IP
-advertise
-join  本机ip
-node   名字随便起

#  访问
http://ip:8500

# 常用命令
# 检查当前成员
./consul members  

# 配置 promethues.yml 
  - job_name: 'consul'
    consul_sd_configs:
#consul服务地址
      - server: 'x.x.x.x:8500'
#services是微服务名的数组,如果什么都不填,则默认取consul上注册的所有微服务
        services: ['redis', 'mysql', 'linux']
#  redis 即为注册服务的名字


  - job_name: 'consul-prometheus'
     consul_sd_configs:
       - server: 'x.x.x.x:8502'
         services: []
         
         
  - job_name: 'consul'
    consul_sd_configs:
      - server: 'x.x.x.x:8500'
相关文章
|
6月前
|
Prometheus 监控 Cloud Native
基于k8s+Prometheus+Alertmanager+Grafana构建企业级监控告警系统(下)
基于k8s+Prometheus+Alertmanager+Grafana构建企业级监控告警系统
|
6月前
|
Prometheus Kubernetes 监控
k8s中部署Grafana-prometheus系列文章第二篇
k8s中部署Grafana-prometheus系列文章第二篇
|
6月前
|
存储 Prometheus 监控
【Prometheus】什么是prometheus?prometheus简介
【Prometheus】什么是prometheus?prometheus简介
57 0
|
2月前
|
存储 Prometheus 监控
Prometheus基础
Prometheus基础
48 2
|
6月前
|
存储 Prometheus 监控
基于k8s+Prometheus+Alertmanager+Grafana构建企业级监控告警系统(上)
基于k8s+Prometheus+Alertmanager+Grafana构建企业级监控告警系统
|
6月前
|
Prometheus 监控 Kubernetes
k8s中部署prometheus监控告警系统-prometheus系列文章第一篇
k8s中部署prometheus监控告警系统-prometheus系列文章第一篇
|
8月前
|
Prometheus 监控 Cloud Native
【Prometheus简介】
【Prometheus简介】
87 0
|
8月前
|
存储 Prometheus Cloud Native
Prometheus(一)之基础安装
Prometheus(一)之基础安装
93 0
|
9月前
|
Prometheus 监控 Cloud Native
Prometheus+Grafana构建监控平台
Prometheus+Grafana构建监控平台
227 0