参考文档:https://www.prometheus.wang/quickstart/install-prometheus-server.html
一,部署prometheus
1.安装Prometheus Server(从二进制包安装)
prometheus-2.28.1.linux-amd64.tar.gz
解压,并将Prometheus相关的命令,添加到系统环境变量路径即可:
tar -xzf prometheus-2.28.1.linux-amd64.tar.gz -C /usr/local
mv prometheus-2.28.1.linux-amd64 prometheus_server
解压后当前目录会包含默认的Prometheus配置文件promethes.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: ['192.168.40.132:9090']
Promtheus作为一个时间序列数据库,其采集的数据会以文件的形似存储在本地中,默认的存储路径为data/,因此我们需要先手动创建该目录:
mkdir /usr/local/prometheus_server/data
启动服务
/usr/local/prometheus_server/prometheus --config.file=/usr/local/prometheus_server/prometheus.yml &
systemctl 启动方式
vim /etc/systemd/system/prometheus.service
[Unit]
Description=prometheus v2.20.1 for sccin production envirenment.
ConditionFileIsExecutable=/usr/local/prometheus_server/prometheus
Requires=network-online.target
After=network-online.target
[Service]
Type=simple
ExecStart=/usr/local/prometheus_server/prometheus --storage.tsdb.path=/data/prometheus_data --config.file=/usr/local/prometheus_server/prometheus.yml --web.enable-admin-api
ExecStop=/bin/killall -15 prometheus
PrivateTmp=true
StartLimitInterval=0
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
:wq保存退出
systemctl start prometheus-server
ps -efl |grep prometheus
netstat -antulp| grep 9090
浏览器访问
http://192.168.40.132:9090/ 就ok了
二,安装alertmanager告警
1.解压安装包
tar -xf alertmanager-0.22.2.linux-amd64.tar.gz -C /usr/local/
mv alertmanager-0.22.2.linux-amd64 alertmanager-server
2,编辑
3.systemctl 启动编写
vim /etc/systemd/system/alertmanager.service
[Unit]
Description=alertmanager v0.21.0 for sccin production envirenment.
ConditionFileIsExecutable=/usr/local/alertmanager-server/alertmanager
Requires=network-online.target
After=network-online.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/local/alertmanager-server/alertmanager
--config.file=/usr/local/alertmanager-server/alertmanager.yml
ExecStop=/bin/killall -15 alertmanager
PrivateTmp=true
StartLimitInterval=0
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
4.启动
systemctl start alertmanager.service
systemctl enable alertmanager.service
netstat -antulp | grep 9093
浏览器访问
http://192.168.40.134:9093/
三,安装可视化界面Grafana
参考文档 https://grafana.com/docs/grafana/latest/basics/
1.安装依赖包
yum install nano initscripts fontconfig freetype urw-fonts
2.编写grafana的yum源
vim /etc/yum.repos.d/grafana.repo
[grafana]
name=grafana
baseurl=https://packages.grafana.com/enterprise/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
:wq 保存
3.安装grafana企业版
yum install grafana-enterprise
4.启动grafana,并设置开机自启动
systemctl start grafana-server
systemctl enable grafana-server
5.查看端口
netstat -antulp | grep grafana
端口为3000
浏览器访问 http://192.168.40.132:3000
账号密码 admin/admin
6,升级grafana
备份
数据库备份
在升级之前,最好备份您的 Grafana 数据库。这将确保您始终可以回滚到以前的版本。在启动期间,Grafana 会自动迁移数据库架构(如果有更改或新表)。有时,如果您以后想要降级,这可能会导致问题。
sqlite
如果您使用 sqlite,您只需要备份您的grafana.db文件。这通常位于/var/lib/grafana/grafana.db
mysql
backup:
> mysqldump -u root -p[root_password] [grafana] > grafana_backup.sql
restore:
> mysql -u root -p grafana < grafana_backup.sql
postgres
backup:
> pg_dump grafana > grafana_backup
restore:
> psql grafana < grafana_backup
开始升级:
yum update grafana
四,安装node_exporter
1.安装
tar -xf /root/node_exporter-1.2.2.linux-amd64.tar.gz -C /usr/local/
mv node_exporter-1.2.2.linux-amd64.tar.gz node_exporter
2,配置自启动
vim /etc/systemd/system/node_exporter.service
[Unit]
Description=node_exporter v1.0.1 for sccin production envirenment.
ConditionFileIsExecutable=/usr/local/node_exporter/node_exporter
Requires=network-online.target
After=network-online.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/local/node_exporter/node_exporter
ExecStop=/bin/killall -15 node_exporter
PrivateTmp=true
StartLimitInterval=0
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
3.启动并开机自启动
systemctl start node_exporter
systemctl enable node_exporter
4.浏览器测试下
http://192.168.216.54:9100/metrics
五.安装mysqld_exporter
1.下载软件mysqld_exporter-0.13.0.linux-amd64.tar.gz
2.解压到/usr/local
tar -xf mysqld_exporter-0.13.0.linux-amd64.tar.gz -C /usr/local/
3.创建my.cnf
vim /usr/local/mysqld_exporter-0.13.0.linux-amd64/.my.cnf
[client]
host=192.168.80.56
port=3306
user=exporter
password=Sccin1qazCDE#
报存,拷贝一份到/root/.my.cnf
4.登录数据库创建授权用户和密码
mysql -uroot -p
输入密码
create user 'exporter'@'%' identified by 'Sccin1qazCDE#'
grant select,replication client,process on *.* to 'exporter'@'%';
flush privileges;
exit;
注意密码中右特殊字符,有可能mysqld_exporter 链接数据库存在问题,报错权限问题
5.启动mysqld_exporter
cat /etc/systemd/system/mysqld_exporter.service
[Unit]
Description=mysqld_exporter v1.0.1 for sccin production envirenment.
ConditionFileIsExecutable=/usr/local/mysqld_exporter-0.13.0.linux-amd64/mysqld_exporter
Requires=network-online.target
After=network-online.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/local/mysqld_exporter-0.13.0.linux-amd64/mysqld_exporter
ExecStop=/bin/killall -15 mysqld_exporter
PrivateTmp=true
StartLimitInterval=0
LimitNOFILE=65536
systemctl start mysqld_exporter
systemctl enable mysqld_exporter
netstat -antulp |grep 9104
6.浏览器测试下
http://192.168.80.56:9104/metrics
Prometheus监控部署完整部署
最新推荐文章于 2024-06-13 17:08:37 发布