prometheus 安装
从 prometheus 官网下载:下载地址
cd /opt wget -c https://github.com/prometheus/prometheus/releases/download/v2.9.2/prometheus-2.9.2.linux-amd64.tar.gz tar xzf *.linux-amd64.tar.gz rm -f *.linux-amd64.tar.gz mv prometheus* prometheus
-
设置prometheus启动账号并赋权
groupadd prometheus useradd -g prometheus -s /sbin/nologin prometheus chown -R prometheus:prometheus /opt/prometheus/
-
创建prometheus data目录并赋权
mkdir -p /opt/prometheus/data chown -R prometheus:prometheus /opt/prometheus/data
-
设置开机自启动
cat > /usr/lib/systemd/system/prometheus.service << 'EOF' [Unit] Description=Prometheus Documentation=https://prometheus.io/ After=network.target [Service] # Type设置为notify时,服务会不断重启 Type=simple User=prometheus # --storage.tsdb.path是可选项,默认数据目录在运行目录的./dada目录中 ExecStart=/opt/prometheus/prometheus --config.file=/opt/prometheus/prometheus.yml --storage.tsdb.path=/opt/prometheus/data Restart=on-failure [Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl start prometheus systemctl enable prometheus
grafana 安装
-
从 grafana 官网下载:下载地址
cd /opt wget https://dl.grafana.com/oss/release/grafana-6.1.6.linux-amd64.tar.gz tar -zxf grafana-6.1.6.linux-amd64.tar.gz rm -f *.linux-amd64.tar.gz mv grafana* grafana
-
设置开机自启动
cat > /usr/lib/systemd/system/grafana-server.service << 'EOF' [Unit] Description=Grafana After=network.target [Service] Type=notify ExecStart=/opt/grafana/bin/grafana-server -homepath /opt/grafana Restart=on-failure [Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl start grafana-server systemctl enable grafana-server
关联prometheus 和 grafana
登录grafana,默认端口:3000,默认账号密码:admin/admin
-
添加prometheus数据源到grafana
-
导入dashboard模板
8919
1860
这两个模板比较常用
prometheus node安装
从 prometheus 官网下载:下载地址
cd /opt wget -c https://github.com/prometheus/node_exporter/releases/download/v0.17.0/node_exporter-0.17.0.linux-amd64.tar.gz tar xzf *.linux-amd64.tar.gz rm -f *.linux-amd64.tar.gz mv node_exporter* node_exporter
-
创建prometheus启动账号并赋权
groupadd node_exporter useradd -g node_exporter -s /sbin/nologin node_exporter chown -R node_exporter:node_exporter /opt/node_exporter/
-
设置开机自启动
cat > /usr/lib/systemd/system/node_exporter.service << 'EOF' [Unit] Description=node_exporter After=network.target [Service] Type=simple User=node_exporter ExecStart=/opt/node_exporter/node_exporter Restart=on-failure [Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl start node_exporter systemctl enable node_exporter
-
添加node到prometheus
- 到prometheus机器,在配置文件scrape_configs:标签下添加以下内容
- job_name: 'xxxx' static_configs: - targets: ['192.168.xxx.xxx:9100']
- 重启prometheus
-
登录grafana,查看效果