本文主要介绍性能测试监控工具prometheus+node_export+grafana的安装配置
node_export的安装和配置
安装服务器:压测机、app服务器、数据库服务器都需要安装
1.下载安装包并解压
# 下载二进制包
wget https://github.com/prometheus/node_exporter/releases/download/v1.5.0/node_exporter-1.5.0.linux-amd64.tar.gz
#解压
tar -zxvf node_exporter-1.5.0.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/
mv node_exporter-1.5.0.linux-amd64 node_exporter
2.查看版本
#查看版本
cd /usr/local/node_exporter
./node_exporter --version #返回如下图
3.安装为系统服务
#安装为系统服务
cat > /usr/lib/systemd/system/node_exporter.service <<EOF
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
4.启动服务并设置开机自启动
# 检查服务
systemctl status node_exporter
# 启动服务
systemctl start node_exporter
# 设置开机自启动
systemctl enable node_exporter
5.检查服务
浏览器访问http://IP:9100/metrics,出现如下页面即表示启动成功
注:若无法访问,请检查防火墙设置并开放对应端口
#查询端口是否放行
firewall-cmd --query-port=9100/tcp
#添加放行端口
firewall-cmd --add-port=9100/tcp --permanent
#刷新
firewall-cmd --reload
prometheus的安装和配置
1.prometheus不能使用root账号启动,首先我们先创建一个用户和用户组
#先检查用户prometheus和组prometheus是否存在
#检查组是否存在
cat /etc/group | grep prometheus
#如果不存在,创建组
groupadd prometheus
#检查用户prometheus是否存在
cat /etc/passwd | grep prometheus
或者
id prometheus
#如果不存在,创建用户
#安全起见,将该用户设置为无法登录
useradd -g prometheus -s /sbin/nologin prometheus
2.下载安装包并配置
#使用wget下载,# 如果提示wget不存在则执行 yum install wget -y 安装wget即可
wget https://github.com/prometheus/prometheus/releases/download/v2.41.0/prometheus-2.41.0.linux-amd64.tar.gz
#解压
tar -zxvf prometheus-2.41.0.linux-amd64.tar.gz -C /usr/local/
#重命名
cd /usr/local
mv prometheus-2.41.0.linux-amd64/ prometheus
3.查看版本
cd /usr/local/prometheus/
#查看版本
./prometheus --version #如下图
4.创建数据目录和修改配置文件
#创建存放数据的目录
mkdir -p /var/lib/prometheus/data
#授权
chown -R prometheus:prometheus /usr/local/prometheus/
chown -R prometheus:prometheus /var/lib/prometheus/data
5.安装为系统服务
# 将服务设置为系统服务,并设置开机自启动
cat > /usr/lib/systemd/system/prometheus.service <<EOF
[Unit]
Description=Prometheus
After=network.target
[Service]
Restart=on-failure
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml
[Install]
WantedBy=multi-user.target
EOF
6.启动服务并设置开机自启动
# 检查服务
systemctl status prometheus
# 启动服务
systemctl start prometheus
# 设置开机自启动
systemctl enable prometheus
7.检查服务
浏览器访问 http://IP:9090/targets,出现如下则表示服务启动完成
注:若无法访问,请检查防火墙设置并开放对应端口
grafana的安装和配置
1.下载和解压
wget https://dl.grafana.com/oss/release/grafana-9.3.6.linux-amd64.tar.gz
tar -zxvf grafana-9.3.6.linux-amd64.tar.gz -C /usr/local/
# 修改文件夹名称
mv /usr/local/grafana-9.3.6 /usr/local/grafana
2.注册成系统服务
# 将服务设置为系统服务,并设置开机自启动
cat > /usr/lib/systemd/system/grafana.service <<EOF
[Service]
ExecStart=/usr/local/grafana/bin/grafana-server --config=/usr/local/grafana/conf/defaults.ini --homepath=/usr/local/grafana
[Install]
WantedBy=multi-user.target
[Unit]
Description=grafana
After=network.target
EOF
3.启动服务并设置开机自启动
# 检查服务
systemctl status grafana
# 启动服务
systemctl start grafana
# 设置开机自启动
systemctl enable grafana
4.检查服务
浏览器访问 http://IP:3000/login,出现如下则表示服务启动完成
注:若无法访问,请检查防火墙设置并开放对应端口
默认用户名密码:admin/admin
首次登陆需要改密码
grafana的使用
1.配置数据源
1.点击Configuration–Data sources,点击Add data source
2.数据源选择Prometheus
3.URL输入Prometheus的地址
4.点击Save & Test,数据源配置完成
2. 导入监控Dashboard 模板
1.查找模板地址:https://grafana.com/grafana/dashboards,可以在网站上找到各种类型的模板
比如监控linux资源使用模板:https://grafana.com/grafana/dashboards/1860-node-exporter-full/,点击复制模板ID
2.点击Dashboards–import,粘贴之前复制的信息,点击Load按钮
3.选择数据源,点击import,完成后自动跳转监控页面
4.检查页面展示,大功告成!