首页 > 系统相关 >Linux服务器系统监控

Linux服务器系统监控

时间:2023-10-23 23:22:23浏览次数:43  
标签:opt node exporter prometheus grafana 系统监控 systemctl Linux 服务器

1、Docker安装Prometheus

1.1、安装docker和docker-compose环境

https://www.cnblogs.com/hg-super-man/p/10908220.html

1.2、安装

拷贝配置
https://gitee.com/xiaohai008/docker-prometheus.git

1.3、启动服务

docker-compose up -d

2、二进制安装

https://prometheus.io/download/

2.1、安装Prometheus

# 下载prometheus二进制压缩包
wget https://github.com/prometheus/prometheus/releases/download/v2.45.1/prometheus-2.45.1.linux-amd64.tar.gz

# 解压
tar -zxvf prometheus-2.45.1.linux-amd64.tar.gz

# 移动到/opt
mkdir /opt/prometheus -p
mv prometheus-2.45.1.linux-amd64 /opt/prometheus/prometheus

# 创建一个专门的prometheus用户
useradd -M -s /usr/sbin/nologin prometheus

# 更改prometheus用户的文件夹权限
chown -R prometheus:prometheus /opt/prometheus

# 创建systemd 服务
cat > /etc/systemd/system/prometheus.service << "EOF"
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target

[Service]
Type=simple
User=prometheus
Group=prometheus
Restart=on-failure
ExecStart=/opt/prometheus/prometheus/prometheus \
  --config.file=/opt/prometheus/prometheus/prometheus.yml \
  --storage.tsdb.path=/opt/prometheus/prometheus/data \
  --storage.tsdb.retention.time=60d \
  --web.enable-lifecycle

[Install]
WantedBy=multi-user.target
EOF

# 启动Prometheus
systemctl daemon-reload
systemctl start prometheus.service

# 加入到开机自启动
systemctl enable prometheus.service

# 检查
systemctl status prometheus.service

# 查看Prometheus的日志以进行故障排除
journalctl -u prometheus.service -f

2.1.1、 访问地址

prometheus http://ip:9090
监控指标 http://ip:9090/metrics

2.2、安装altermanager

# 下载altermanager二进制压缩包
wget https://github.com/prometheus/alertmanager/releases/download/v0.26.0/alertmanager-0.26.0.linux-amd64.tar.gz

# 解压
tar -zxvf alertmanager-0.26.0.linux-amd64.tar.gz

# 移动到/opt
mv alertmanager-0.26.0.linux-amd64 /opt/prometheus/alertmanager

# 更改prometheus用户的文件夹权限
chown -R prometheus:prometheus /opt/prometheus/alertmanager

# 创建systemd 服务
cat > /etc/systemd/system/alertmanager.service << "EOF"
[Unit]
Description=Alert Manager
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=prometheus
Group=prometheus
ExecStart=/opt/prometheus/alertmanager/alertmanager \
  --config.file=/opt/prometheus/alertmanager/alertmanager.yml \
  --storage.path=/opt/prometheus/alertmanager/data

Restart=always

[Install]
WantedBy=multi-user.target
EOF

# 启动alertmanager
systemctl daemon-reload
systemctl start alertmanager.service

# 检查
systemctl status alertmanager.service

# 加入到开机自启动
systemctl enable alertmanager.service

2.2.1、 访问地址

http://ip:9093

2.2.2、修改prometheus配置

增加alertmanager配置

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          - localhost:9093
# 告警配置
rule_files:
  - "alert.yml"

2.2.3、增加触发器配置文件

cat > /opt/prometheus/prometheus/alert.yml <<"EOF"
groups:
- name: Prometheus alert
  rules:
  # 对任何实例超过30s无法联系的情况发出警报
  - alert: 服务告警
    expr: up == 0
    for: 30s
    labels:
      severity: critical
    annotations:
      instance: "{{ $labels.instance }}"
      description: "{{ $labels.job }} 服务已关闭"
EOF

2.2.4、检查配置

cd /opt/prometheus/prometheus
./promtool check config prometheus.yml

2.2.5、重启prometheus

systemctl restart prometheus

2.3、安装grafana

https://grafana.com/grafana/download

# 下载grafana二进制压缩包
wget https://dl.grafana.com/enterprise/release/grafana-enterprise-10.1.5.linux-amd64.tar.gz

# 解压
tar -zxvf grafana-enterprise-10.1.5.linux-amd64.tar.gz

# 移动到/opt
mv grafana-enterprise-10.1.5 /opt/prometheus/grafana

# 更改prometheus用户的文件夹权限
chown -R prometheus:prometheus /opt/prometheus/grafana

# 创建systemd 服务
cat > /etc/systemd/system/grafana-server.service << "EOF"
[Unit]
Description=Grafana Server
Documentation=http://docs.grafana.org

[Service]
Type=simple
User=prometheus
Group=prometheus
Restart=on-failure
ExecStart=/opt/prometheus/grafana/bin/grafana-server \
  --config=/opt/prometheus/grafana/conf/defaults.ini \
  --homepath=/opt/prometheus/grafana

[Install]
WantedBy=multi-user.target
EOF

# 启动grafana
systemctl daemon-reload
systemctl start grafana-server

# 检查
systemctl status grafana-server.service

# 加入到开机自启动
systemctl enable grafana-server.service

2.3.1、 访问地址

http://ip:3000

2.4、安装node_exporter

https://prometheus.io/download/

# 下载node_exporter二进制压缩包
wget https://github.com/prometheus/node_exporter/releases/download/v1.6.1/node_exporter-1.6.1.linux-amd64.tar.gz

# 解压
tar -zxvf node_exporter-1.6.1.linux-amd64.tar.gz

# 移动到/opt
mv node_exporter-1.6.1.linux-amd64 /opt/prometheus/node_exporter

# 更改prometheus用户的文件夹权限
chown -R prometheus:prometheus /opt/prometheus/node_exporter

# 创建systemd 服务
cat > /etc/systemd/system/node_exporter.service << "EOF"
[Unit]
Description=node_exporter
Documentation=https://prometheus.io
After=network.target

[Service]
Type=simple
User=prometheus
Group=prometheus
Restart=on-failure
ExecStart=/opt/prometheus/node_exporter/node_exporter

[Install]
WantedBy=multi-user.target
EOF

# 启动grafana
systemctl daemon-reload
systemctl start node_exporter

# 检查
systemctl status node_exporter

# 加入到开机自启动
systemctl enable node_exporter

2.3.1、 访问地址

http://ip:9100/metrics

2.3.2、修改prometheus配置

在scrape_config这行下面添加如下配置
vi /opt/prometheus/prometheus/prometheus.yml

  # node_exporter配置
  - job_name: "node_exporter"
    scrape_interval: 15s
    static_configs:
    - targets: ["localhost:9100"]
      labels:
        instance: Prometheus服务器

2.3.3、重载prometheus

curl -X POST http://localhost:9090/-/reload

2.4、从Grafana.com导入仪表盘

https://grafana.com/grafana/dashboards/

3、通过git安装

# 生成服务
cd /opt/prometheus
https://gitee.com/xiaohai008/prometheus.git
mv *.service /etc/systemd/system/

# 创建一个专门的prometheus用户
useradd -M -s /usr/sbin/nologin prometheus

# 更改prometheus用户的文件夹权限
chown -R prometheus:prometheus /opt/prometheus

# 启动
systemctl daemon-reload
systemctl start prometheus
systemctl start grafna0server
systemctl start node_exporter
systemctl start alertmanager

# 设置开机自启
systemctl enable prometheus
systemctl enable grafna0server
systemctl enable node_exporter
systemctl enable alertmanager

# 检查
systemctl status prometheus
systemctl status grafna0server
systemctl status node_exporter
systemctl status alertmanager

标签:opt,node,exporter,prometheus,grafana,系统监控,systemctl,Linux,服务器
From: https://www.cnblogs.com/hg-super-man/p/17781924.html

相关文章

  • Linux课堂小结(1)
    本周Linux课堂学习了基本权限ACL和高级权限的相关知识。其中基本权限ACL包含了ACL基本用法和ACL的高级特性。UGO权限只针对一个用户、一个组与其他用户,使用上有局限性,ACL主要提供传统的UGO的r、w、x权限之外的具体权限设置,可以对单一用户、单一文件或目权限设置。①.ACL文件权......
  • Linux p8 找回root密码
    【学习课程】:【【小白入门通俗易懂】2021韩顺平一周学会Linux】https://www.bilibili.com/video/BV1Sv411r7vd/?p=14&share_source=copy_web&vd_source=2c07d62293f5003c919b2df9b2e0549e找回root密码(CentOS7.6)首先,启动系统,进入开机界面,在界面中按"e"进入编辑界面,如图......
  • Linux绝对路径和相对路径
    在Linux中,简单的理解一个文件的路径,指的就是该文件存放的位置。只要我们告诉Linux系统某个文件存放的准确位置,那么它就可以找到这个文件。指明一个文件存放的位置,有2种方法,分别是使用绝对路径和相对路径。我们知道,Linux系统中所有的文件(目录)都被组织成以根目录“/”开始的倒......
  • Nginx的安装-Linux
    下载地址#如果没有gcc环境,需要安装gcc:[root@localhostlocal]#yuminstallgcc-c++-y#安装依赖包[root@localhostlocal]#yum-yinstallgcczlibzlib-develpcre-developensslopenssl-devel#进入文件夹[root@localhostlocal]#cd/usr/local#在线下载或者上传......
  • 上传文件到服务器
    上传附件至linux服务器:controller层:点击查看代码@OverridepublicResult<?>uploadFile(MultipartHttpServletRequestrequest,@RequestParam(value="businessTable")StringbusinessTable,......
  • linux常规命令
    1、cd上图,直接输入cd,会进入根目录2、treea/3、创建多个目录4、touch5、rm6、编译过程......
  • 更改Kali Linux系统语言以及安装zenmap
    更改KaliLinux系统语言以及安装zenmap在使用kali的过程中,会遇到许多问题,其中一个就是看不懂英语,下面是如何更换语言的步骤。更改KaliLinux系统语言首先,打开kali,以root用户打开终端,如图1-1所示,然后输入密码kali,如图1-2所示,再打开终端如图1-3所示,最后就看到如图1-4所示。 图......
  • Linux /proc和/sys
    在Linux系统中,/proc和/sys都是特殊的文件系统,数据内容是存放在内存中,这两个目录文件中的内容由内核动态生成,查看这个文件中的内容,实际上就是查询内核的某些状态或信息。可以将这两个目录文件理解为虚拟的目录,即在硬盘上不存在。/proc文件系统proc是process(进程)的缩写。这个......
  • 怎样将SQL Server数据库迁移到新服务器
    一、在老的服务器上打开SQLServerManagementStudio,输入数据库用户名和密码后登录数据库。二、打开对象资源管理器,打开数据库找到需要迁移的数据库,比如这里的test数据库。三、选中需要迁移的数据库,右键点击数据,打开数据库属性,点击文件,查看并记录数据库的路径,然后关......
  • Linux账号密码安全运维
    前言随着云计算厂商的兴起,云资源如ECS不再只有企业或者公司才会使用,普通人也可以自己买一台ECS来搭建自己的应用或者网站。虽然云计算厂商帮我们做了很多安全相关的工作,但并不代表我们的机器资源就绝对是安全的。要知道有很多事情是云计算厂商不能为我们做的,就比如账号密码的安......