目录
Ubuntu and Debian(64 Bit)SHA256: f020b02f02765b850749469a9f083ba00384c7f5c4acd54337a59e54ab94762b
Alternative Docker container image for those who prefer an Ubuntu base image.
zabbix和prometheus的区别
1、监控的agent节点多
2、所需要的资源少(zabbix底层有一个LNMP环境)
ntpdate cn.ntp.org.cn
特点
强大的多维度数据模型
二进制安装(二进制安装、docker安装)
1. 上传压缩包
2. 安装prometheus
tar -xvf prometheus-2.34.0.linux-amd64.tar.gz -C /usr/local/
mv /usr/local/prometheus-2.34.0.linux-amd64/ /usr/local/prometheus
检查配置文件是否正确
./promtool check config prometheus.yml
3.1启动
/usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml" &
3.2添加系统服务管理
# vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=https://prometheus.io
[Service]
Restart=on-failure
ExecStart=/usr/local/prometheus/prometheus \
--storage.tsdb.path=/usr/local/prometheus/data \
--config.file=/usr/local/prometheus/prometheus.yml
[Install]
WantedBy=multi-user.target
4.查看端口
netstat -nplt | grep 9090
5.查看监控数据
localhost:9090/metrics
docker安装
# mkdir -p /data/prometheus/server/
# touch /data/prometheus/server/rules.yml
# chmod 777 /data/prometheus/server/rules.yml
# vim /data/prometheus/server/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).
external_labels:
monitor: 'codelab-monitor'
# 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'.
scrape_interval: 5s
static_configs:
- targets: ["localhost:9090"]
docker run -d -p 9090:9090 --name=prometheus -v /data/prometheus/server/prometheus.yml:/etc/prometheus/prometheus.yml -v /data/prometheus/server/rules.yml:/etc/prometheus/rules.yml prom/prometheus --config.file=/etc/prometheus/prometheus.yml --web.enable-lifecycle
监控linux主机(模板8919、9276)
1.在被监控主机上安装node_exporter组件
-
上传
-
解压安装重命名
tar -xvf node_exporter-1.3.1.linux-amd64.tar.gz
mv node_exporter-1.3.1.linux-amd64 node_exporter
-
启动
nohup /usr/local/node_exporter/node_exporter &
[root@prometheus node_exporter]# cat /usr/lib/systemd/system/node_exporter.service
[Unit]
Description= prometheus node_exporter
[Service]
User=nobody
ExecStart=/usr/local/node_exporter/node_exporter --log.level=error
ExecStop=/usr/bin/killall node_exporter
[Install]
WantedBy=default.target
-
查看端口
netstat -nplt | grep 9100
让server端可以拉取node节点信息
-
修改prometheus配置文件
vim /usr/local/prometheus/prometheus.yml
-
重启prometheus
pkill prometheus
/usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml" &
监控MySQL(模板7362)
-
上传
-
解压安装重命名
安装mariadb
yum -y install mariadb\*
systemctl start mariadb
创建mysql账号
MariaDB [(none)]> grant all on *.* to 'mysql_monitor'@'localhost' identified by '123456';
MariaDB [(none)]> flush privileges;
在mysqld_exporter组件中配置mysql信息
vim /usr/local/mysqld_exporter/.my.cnf
[client]
user=mysql_monitor
password=123456
启动mysqld_exporter
nohup /usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/.my.cnf &
[Unit]
Description=mysql Monitoring System
Documentation=mysql Monitoring System
[Service]
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter \
--collect.info_schema.processlist \
--collect.info_schema.innodb_tablespaces \
--collect.info_schema.innodb_metrics \
--collect.perf_schema.tableiowaits \
--collect.perf_schema.indexiowaits \
--collect.perf_schema.tablelocks \
--collect.engine_innodb_status \
--collect.perf_schema.file_events \
--collect.binlog_size \
--collect.info_schema.clientstats \
--collect.perf_schema.eventswaits \
--config.my-cnf=/usr/local/mysqld_exporter/.my.cnf
[Install]
WantedBy=multi-user.target
让prometheus可以拉取mariadb节点信息
-
修改prometheus配置文件
vim /usr/local/prometheus/prometheus.yml
- job_name: "mariadb"
static_configs:
- targets: ["192.168.32.132:9104"]
##MySQL主从监控
监控mysql主从模板7371
group:
- name: MySQL-rules
rules:
- alert: MySQL Status
expr: mysql_up == 0
labels:
severity: warning
annotations:
summary: "{{$labels.instance}}: MySQL has stop"
description: "检测MySQL数据库运行状态"
- alert: MySQL Slave IO Thread Status
expr: mysql_slave_status_slave_io_running == 0
for: 5s
lables:
severity: warning
annotations:
summary: "{{$labels.instance}}: MySQL Slave IO Thread has stop"
description: "检测MySQL主从IO线程运行状态"
- alert: MySQL Slave SQL Thread Status
expr: mysql_slave_status_slave_sql_running == 0
for: 5s
lables:
severity: warning
annotations:
summary: "{{$labels.instance}}: MySQL Slave SQL Thread has stop"
description: "检测MySQL主从SQL线程运行状态"
监控docker(模板193)
docker run \
--volume=/:/rootfs:ro \
--volume=/var/run:/var/run:ro \
--volume=/sys:/sys:ro \
--volume=/var/lib/docker/:/var/lib/docker:ro \
--volume=/dev/disk/:/dev/disk:ro \
--publish=8080:8080 \
--detach=true \
--name=cadvisor \
google/cadvisor:latest
pushgateway
1. 上传,解压安装
tar -xvf pushgateway-1.4.2.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/
mv pushgateway-1.4.2.linux-amd64/ pushgateway
####2. 启动
prometheus自动化监控
安装consul
wget https://releases.hashicorp.com/consul/1.11.5/consul_1.11.5_linux_amd64.zip
unzip consul_1.11.5_linux_amd64.zip
mv consul /usr/local/bin/
mkdir /data/
nohup consul agent -server -bootstrap-expect=3 -data-dir=/data/consul -node=192.168.32.131 -bind=192.168.32.131 -client=0.0.0.0 -datacenter=shenzhen -ui &
nohup consul agent -server -bootstrap-expect=3 -data-dir=/data/consul -node=192.168.32.132 -bind=192.168.32.132 -client=0.0.0.0 -datacenter=shenzhen -ui &
nohup consul agent -server -bootstrap-expect=3 -data-dir=/data/consul -node=192.168.32.133 -bind=192.168.32.133 -client=0.0.0.0 -datacenter=shenzhen -ui &
此时三台机器还未join,不能算是一个集群,三台机器上的consul均不能正常工作,因为leader还未选出。
集群节点加入
分别登录第2台,第3台服务器执行如下命令,让consul加入到集群:
192.168.32.132\192.168.32.132
consul join 192.168.32.131
查看集群状态
consul operator raft list-peers
查看集群成员
consul members
测试集群
consul kv put name liujie
consul kv get name
webUI
在consul中注册服务
curl -X PUT -d '{"id": "node_exporter","name": "node_exporter","address": "192.168.32.133","port": 9100,"tags": ["devops"],"check": [{"http://":"http://192.168.32.133:9100/metrics","interval": "5s"}]}' http://192.168.32.132:8500/v1/agent/service/register
Grafana可视化图形工具
####下载安装
######Red Hat, CentOS, RHEL, and Fedora(64 Bit)SHA256: 8c2f2420cd3f18b9d84ee7c529c2cd48fb30741210d1b34430ff1f5741992743
wget https://dl.grafana.com/enterprise/release/grafana-enterprise-8.4.6-1.x86_64.rpm
sudo yum install grafana-enterprise-8.4.6-1.x86_64.rpm
Ubuntu and Debian(64 Bit)SHA256: f020b02f02765b850749469a9f083ba00384c7f5c4acd54337a59e54ab94762b
sudo apt-get install -y adduser libfontconfig1
wget https://dl.grafana.com/enterprise/release/grafana-enterprise_8.4.6_amd64.deb
sudo dpkg -i grafana-enterprise_8.4.6_amd64.deb
OpenSUSE and SUSE
wget https://dl.grafana.com/enterprise/release/grafana-enterprise-8.4.6-1.x86_64.rpm
sudo rpm -i --nodeps grafana-enterprise-8.4.6-1.x86_64.rpm
Docker(Alpine base image)
######Lightweight Docker container image using an Alpine base image.
docker run -d --name=grafana -p 3000:3000 grafana/grafana-enterprise
######Docker(Ubuntu base image)
Alternative Docker container image for those who prefer an Ubuntu base image.
docker run -d --name=grafana -p 3000:3000 grafana/grafana-enterprise:8.4.6-ubuntu
启动服务
systemctl start grafana-server
systemctl enable grafana-server
登录web
localhost:3000
admin
admin
####添加prometheus的数据源
Grafana显示MySQL监控数据
修改配置文件
-
安装模板
#vim /etc/grafana/grafana.ini
[dashboards.json]
enabled = true
path = /var/lib/grafana/dashboards
#git clone https://github.com/percona/grafana-dashboards.git
#cp -r grafana-dashboards/dashboards/ /var/lib/grafana/
# systemctl restart grafana-server
-
导入模板 ####安装
alertmanager告警模块
tar -xvf alertmanager-0.24.0.linux-amd64.tar.gz
mv alertmanager-0.24.0.linux-amd64 ../alertmanager
启动
希望能够帮助到大家!!