Linux部署Prometheus+Grafana
在Linux上部署Prometheus和Grafana的步骤如下:
- 安装Prometheus:
# 添加Prometheus仓库
wget https://dl.grafana.com/oss/release/grafana-7.5.1.linux-amd64.tar.gz
# 安装Prometheus
sudo apt-get install -y adduser libltdl7
tar xvzf prometheus-2.27.1.linux-amd64.tar.gz
sudo mv prometheus-2.27.1.linux-amd64 /usr/local/prometheus
# 创建服务文件
echo "[Unit]
Description=Prometheus Monitoring System
After=network.target
[Service]
User=nobody
Type=simple
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml
[Install]
WantedBy=multi-user.target" | sudo tee /etc/systemd/system/prometheus.service
# 启动Prometheus服务
sudo systemctl start prometheus
sudo systemctl enable prometheus
- 安装Grafana:
# 添加Grafana仓库
wget https://dl.grafana.com/oss/release/grafana-7.5.1.linux-amd64.tar.gz
# 安装Grafana
sudo apt-get install -y adduser libltdl7
tar xvzf grafana-7.5.1.linux-amd64.tar.gz
sudo mv grafana-7.5.1.linux-amd64 /usr/local/grafana
# 创建服务文件
echo "[Unit]
Description=Grafana
After=network.target
AssertFileIsExecutable=/usr/local/grafana/bin/grafana-server
[Service]
User=nobody
Type=simple
ExecStart=/usr/local/grafana/bin/grafana-server -homepath /usr/local/grafana/usr/share/grafana
Restart=on-failure
[Install]
WantedBy=multi-user.target" | sudo tee /etc/systemd/system/grafana.service
# 启动Grafana服务
sudo systemctl start grafana
sudo systemctl enable grafana
- 配置Prometheus数据源:
- 打开Grafana的网址,例如 http://your-server-ip:3000。
- 登录并添加Prometheus数据源。
- 导入Grafana仪表盘:
- 导入Prometheus默认仪表盘或者社区提供的仪表盘。
确保防火墙和安全组设置允许访问Prometheus和Grafana的端口(默认情况下Prometheus是9090端口,Grafana是3000端口)。
评论已关闭