下载地址: https://prometheus.io/download/ wget https://github.com/prometheus/prometheus/releases/download/v2.34.0/prometheus-2.34.0.linux-amd64.tar.gz wget https://github.com/prometheus/alertmanager/releases/download/v0.24.0/alertmanager-0.24.0.linux-amd64.tar.gz wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz
root_node1--> useradd -M -s /sbin/nologin prometheus root_node1--> tar xvf prometheus-2.34.0.linux-amd64.tar.gz? root_node1--> mv prometheus-2.34.0.linux-amd64 /opt/prometheus root_node1--> mkdir /opt/prometheus/data/ root_node1--> chown -R prometheus:prometheus /opt/prometheus
root_node1--> tar xvf node_exporter-1.3.1.linux-amd64.tar.gz root_node1--> mv node_exporter-1.3.1.linux-amd64 node_exporter root_node1--> mv node_exporter /opt/ root_node1--> chown -R prometheus:prometheus /opt/node_exporter
root_node1--> cat /usr/lib/systemd/system/prometheus.service [Unit] Description=Prometheus After=network.target
[Service] Type=simple Environment="GOMAXPROCS=4" User=prometheus Group=prometheus ExecReload=/bin/kill -HUP $MAINPID ExecStart=/opt/prometheus/prometheus \ ? --config.file=/opt/prometheus/prometheus.yml \ ? --storage.tsdb.path=/opt/prometheus/data \ ? --storage.tsdb.retention=30d \ ? --web.console.libraries=/opt/prometheus/console_libraries \ ? --web.console.templates=/opt/prometheus/consoles \ ? --web.listen-address=0.0.0.0:9090 \ ? --web.read-timeout=5m \ ? --web.max-connections=10 \ ? --query.max-concurrency=20 \ ? --query.timeout=2m \ ? --web.enable-lifecycle PrivateTmp=true PrivateDevices=true ProtectHome=true NoNewPrivileges=true LimitNOFILE=infinity ReadWriteDirectories=/opt/prometheus/data ProtectSystem=full
SyslogIdentifier=prometheus Restart=always
[Install] WantedBy=multi-user.target
root_node1--> systemctl restart prometheus
访问:http://192.168.1.2:9090/
root_node1--> systemctl restart prometheus root_node1--> cat /usr/lib/systemd/system/node_exporter.service [Unit] Description=node_exporter After=network.target
[Service] Type=simple User=prometheus Group=prometheus ExecStart=/opt/node_exporter/node_exporter \ ? --web.listen-address=0.0.0.0:9100 \ ? --web.telemetry-path=/metrics \ ? --log.level=info \ ? --log.format=logfmt Restart=always
[Install] WantedBy=multi-user.target
root_node1--> systemctl restart node_exporter
访问:http://192.168.1.2:9100/metrics
修改 prometheus.yml
scrape_configs: ? - job_name: "prometheus" ? ? static_configs: ? ? ? - targets: ["192.168.1.2:9090"]
? - job_name: "node" ? ? static_configs: ? ? ? - targets: ["192.168.1.2:9100"]
重启prometheus systemctl restart prometheus
访问:http://192.168.1.2:9090/targets
root_node1--> tar xvf alertmanager-0.24.0.linux-amd64.tar.gz root_node1--> mv alertmanager-0.24.0.linux-amd64 /opt/alertmanager root_node1--> mkdir /opt/alertmanager/data root_node1--> chown -R prometheus.prometheus /opt/alertmanager root_node1--> systemctl restart alertmanager
root_node1--> cat /usr/lib/systemd/system/alertmanager.service [Unit] Description=Alertmanager After=network.target
[Service] Type=simple User=prometheus Group=prometheus ExecStart=/opt/alertmanager/alertmanager \ ? --config.file=/opt/alertmanager/alertmanager.yml \ ? --storage.path=/opt/alertmanager/data \ ? --web.listen-address=0.0.0.0:9093 \ ? --cluster.listen-address=0.0.0.0:9094 \ ? --log.level=info \ ? --log.format=logfmt Restart=always
[Install] WantedBy=multi-user.target
修改 prometheus.yml
- job_name: "alertmanager" ? static_configs: ? ? - targets: ["192.168.1.2:9093"]
重启prometheus systemctl restart prometheus
访问: http://192.168.1.2:9090/targets
grafana 安装 下载地址:https://mirror.tuna.tsinghua.edu.cn/grafana/yum/rpm/ root_node1--> yum install fontconfig urw-fonts root_node1--> wget https://mirror.tuna.tsinghua.edu.cn/grafana/yum/rpm/grafana-8.4.6-1.x86_64.rpm --no-check-certificate root_node1--> rpm -ivh grafana-8.4.6-1.x86_64.rpm root_node1--> systemctl start grafana-server
访问grafana,默认密码admin/admin http://192.168.1.2:3000/login
导入prometheus数据源: Configuration → Data Sources → Prometheus → Select,填入http://192.168.1.2:9090,保存即可
导入模板,输入模板id 8919 ?(https://grafana.com/grafana/dashboards/8919)
进程监控: https://github.com/ncabatoff/process-exporter/releases/download/v0.7.10/process-exporter-0.7.10.linux-amd64.tar.gz
root_node1--> tar xvf process-exporter-0.7.10.linux-amd64.tar.gz root_node1--> mv process-exporter-0.7.10.linux-amd64 process-exporter root_node1--> cat config.yml?? ?# 监控所有进程 process_names: ? - name: "{{.Comm}}" ? ? cmdline: ? ? - '.+' ?
系统监控效果
|