Promtheus实战系列(一)之环境部署与搭建

    xiaoxiao2022-06-27  172

    一、部署prometheus,grafana和node_exporter

    Prometheus开始教程:https://blog.csdn.net/Coffin_monkey/article/details/90404639

    1.1 环境(centos7)

    [root@localhost prometheus]# uname -a Linux localhost.localdomain 3.10.0-957.10.1.el7.x86_64 #1 SMP Mon Mar 18 15:06:45 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

    1.2 环境部署与服务启动

    // 安装prometheus wget https://github.com/prometheus/prometheus/releases/download/v2.9.2/prometheus-2.9.2.linux-amd64.tar.gz tar xzvf prometheus-2.9.2.linux-amd64.tar.gz mv prometheus-2.9.2.linux-amd64 /usr/local/prometheus // 添加prometheus用户,非必须 groupadd prometheus useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus

    对systemctl不熟的可以了解鸟哥的Linux私房菜

    // prometheus系统服务配置 vim /etc/systemd/system/prometheus.service [Unit] Description=prometheus After=network.target [Service] Type=simple User=prometheus ExecStart=/usr/local/prometheus/prometheus -config.file=/usr/local/prometheus/prometheus.yml -storage.local.path=/var/lib/prometheus Restart=on-failure [Install] WantedBy=multi-user.target // 启动prometheus systemctl start prometheus systemctl status prometheus

    node_exporter setup // 安装node_exporter wget https://github.com/prometheus/node_exporter/releases/download/v0.18.0/node_exporter-0.18.0.linux-amd64.tar.gz tar -zxvf node_exporter-0.18.0.linux-amd64.tar.gz mv node_exporter-0.18.0.linux-amd64 /usr/local/node_exporter // 系统服务配置node_exporter vim /etc/systemd/system/node_exporter.service [Unit] Description=node_exporter After=network.target [Service] Type=simple User=prometheus ExecStart=/usr/local/node_exporter/node_exporter Restart=on-failure [Install] WantedBy=multi-user.target systemctl start node_exporter systemctl status node_exporter

    3. add node_exporter to prometheus.yaml

    vim /usr/local/prometheus/prometheus.yml - job_name: 'linux' static_configs: - targets: ['localhost:9100'] labels: instance: node1 systemctl restart prometheus systemctl status prometheus grafana setup // 安装grafana wget https://dl.grafana.com/oss/release/grafana-6.1.6-1.x86_64.rpm yum localinstall grafana-6.1.6-1.x86_64.rpm // 启动grafana-server systemctl start grafana-server systemctl status grafana-server

    二、仪表化

    2.1 prometheus

    prometheus默认端口为9090,可以在浏览器中输入http://localhost:9090/

    2.2 granafa

    granafa默认端口为3000,可以在浏览器中输入http://localhost:3000/

    granafa首次登录账户名和密码admin/admin,可以修改配置数据源Data sources->Add data source -> Prometheus,输入prometheus数据源的信息,主要是输入name和url 添加DashboardNew Dashboard->Import Dashboard->输入8919,配置数据源为Prometheus,即上一步中的name 配置完保存后即可看到逼格非常高的系统主机节点监控信息,包括CPU、IO、网络等信息。

    三、tips

    iptables(端口不通) /sbin/iptables -I INPUT -p tcp --dport 9090 -j ACCEPT datetime(设置时区) timedatectl list-timezones timedatectl set-timezone Asia/Shanghai

    四、链接

    Prometheus官网地址:https://prometheus.io/ 我的Github:https://github.com/Alrights/prometheus


    最新回复(0)