CentOS环境搭建压测平台JMeter+Grafana+Influxdb

1、环境说明

CentOS 7.8 ,JDK1.8,Docker 19.03.8, Influxdb 1.8.0,Grafana 6.7.3。

2、influxdb 下载安装配置

2.1 influxdb 下载安装

wget https://dl.influxdata.com/influxdb/releases/influxdb-1.8.0.x86_64.rpm
sudo yum localinstall influxdb-1.8.0.x86_64.rpm

2.2 influxdb 配置

2.2.1 找到 influxdb 配置文件
find / -name influxdb.conf
2.2.2 编辑 influxdb.conf 文件
vim /etc/influxdb/influxdb.conf
#找到 [http] 部分,配置如下
[http]
   enabled = true
   bind-address = ":8086"
   auth-enabled = false
   log-enabled = true
   write-tracing = false
   pprof-enabled = false
   https-enabled = false
   https-certificate = "/etc/ssl/influxdb.pem"
   max-row-limit = 10000

2.3 启动 influxdb

systemctl start influxdb
systemctl daemon-reload

2.4 创建数据库

influx -port 8086
create database jmeter
use jmeter
#创建jmeter数据库的用户名和密码
CREATE USER "jmeter" WITH PASSWORD 'jmeter' WITH ALL PRIVILEGES

3、Grafana 中文粗略版在Docker中安装

来源:https://github.com/WangHL0927/grafana-chinese

3.1 下载或编写 tool.sh 文件

vim tool.sh

#!/usr/bin/env bash
grafana_version='6.7.3'
docker_user='w958660278'

console() {
  content=$2
  case $1 in
  "br") echo -e "\033[36m------------------------------\033[0m" ;;
  "info") echo -e "\033[36m$content\033[0m" ;;
  "action") echo -e "\033[36m$content\033[0m" ;;
  "success") echo -e "\033[32m$content\033[0m" ;;
  "error") echo -e "\033[31m$content\033[0m" ;;
  "warning") echo -e "\033[33m$content\033[0m" ;;
  "danger") echo -e "\033[35m$content\033[0m" ;;
  esac
}

initDevProject() {
  console br
  console info 'Init-tool'
  console br
  console action 'Clone source from https://github.com/WangHL0927/grafana.git'
  git clone https://github.com/WangHL0927/grafana.git
  cd ./grafana
  console action 'Run yarn install...'
  yarn install
  console success 'Init dev success!'
}

releaseDockerDev() {
  console br
  console info "Release Dev version and push to DockerHub"
  console danger "The full tag name like grafana-cn:$grafana_version.0001-dev"
  console danger "Input build version and press ENTER:[eg. 0002]"
  read version
  tag="$docker_user/grafana-cn:$grafana_version.$version-dev"
  tag2="$docker_user/grafana-cn:latest-dev"
  console action "Build and push $grafana_version.$version-dev..."
  rm -rf ./grafana/public/build/*.js.map
  docker build -t $tag .
  docker push $tag
  console action "Push latest-dev..."
  docker tag $tag $tag2
  docker push $tag2
  console success 'Release success!'
}

releaseDocker() {
  console br
  console info "Release Latest version and push to DockerHub"
  console danger "The full tag name like grafana-cn:$grafana_version.0001"
  console danger "Input build version and press ENTER:[eg. 0002]"
  read version
  tag="$docker_user/grafana-cn:$grafana_version.$version"
  tag2="$docker_user/grafana-cn:latest"
  console action "Build and push $grafana_version.$version..."
  rm -rf ./grafana/public/build/*.js.map
  docker build -t $tag .
  docker push $tag
  console action "Push latest..."
  docker tag $tag $tag2
  docker push $tag2
  console success 'Release success!'
}

printMenu() {
  console br
  console info "Tool Script"
  console br
  console info "1. Start dev-server."
  console info "2. Stop/Remove dev-server."
  console info "3. Restart dev-server."
  console info "4. Release to DockerHub with dev tag."
  console info "5. Release to DockerHub with latest tag."
  console info "6. Init dev project."
  console br
  console danger "Input number and press ENTER:"
}

main() {
  printMenu

  read num
  case $num in
  "1") ./dev-server/dev-server.sh ;;
  "2") ./dev-server/remove-dev-server.sh ;;
  "3") ./dev-server/restart-dev-server.sh ;;
  "4") releaseDockerDev ;;
  "5") releaseDocker ;;
  "6") initDevProject ;;
  *)
    console error "ERROR: undefined function!"
    exit;;
  esac
}

main

#在当前目录下执行 ./tool.sh

3.2 在 Docker 中运行 Grafana

docker run -d -p 3000:3000 --name=grafana-cn w958660278/grafana-cn:latest-dev

3.3 导入 Grafana Dashboard

#参考:https://www.kancloud.cn/owenwangwen/open-capacity-platform/1217389
#jmeter-grafana-dashboard.json 链接:https://pan.baidu.com/s/1LPc5fpw5yUsX9RJOcjFQng 
#提取码:2c4d

4、JMeter 下载安装

wget https://mirror.bit.edu.cn/apache//jmeter/binaries/apache-jmeter-5.3.tgz
tar -zxvf apache-jmeter-5.3.tgz

5、JMeter 使用

5.1 新建 test 目录

mkdir test && cd test

#编写一个project.jmx,参考:https://www.kancloud.cn/owenwangwen/open-capacity-platform/1217389
#链接:https://pan.baidu.com/s/1r9LqoMBC-fnp2ZasXyrMXQ 
#提取码:3qp3 

5.2 在 test 目录下编写 test.sh文件

vim test.sh

cd /root/test/temp/ && rm *
cd /root/test/result/ && rm *
/root/jmeter-5.3/bin/jmeter.sh -n -t  /root/test/project.jmx  -l  /root/test/temp/result.jtl  -e -o  /root/test/result

5.3 执行 test.sh

./test.sh

5.4 登陆Grafana进行查看

你可能感兴趣的:(CentOS环境搭建压测平台JMeter+Grafana+Influxdb)