前置:
- Linux系统版本:CentOS Linux release 7.8.2003 (Core)
- 命令:cat /etc/redhat-release
- JMeter版本:apache-jmeter-5.4.1
- InfluxDB版本:InfluxDB shell version: 1.8.4
- JDK版本:openjdk version "1.8.0_292"
- Windows查看端口是否被占用:netstat -ano|findstr "3306",没有返回数据代表没被占用
C:\Users\小二哥>netstat -ano|findstr "3306"
C:\Users\小二哥>netstat -ano|findstr "6060"
- Centos查看端口是否被占用:netstat -tunlp | grep 8086
一、安装JDK
1.查看JDK可安装版本
yum search java|grep jdk
[root@iZwz9ga2spyeb5u9tdq8t5Z /]# yum search java|grep jdk
ldapjdk-javadoc.noarch : Javadoc for ldapjdk
java-1.6.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.6.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.6.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.6.0-openjdk-javadoc.x86_64 : OpenJDK API Documentation
java-1.6.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.7.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector
java-1.7.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.7.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.7.0-openjdk-headless.x86_64 : The OpenJDK runtime environment without
java-1.7.0-openjdk-javadoc.noarch : OpenJDK API Documentation
java-1.7.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.8.0-openjdk.i686 : OpenJDK Runtime Environment 8
java-1.8.0-openjdk.x86_64 : OpenJDK 8 Runtime Environment
java-1.8.0-openjdk-accessibility.i686 : OpenJDK accessibility connector
java-1.8.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector
java-1.8.0-openjdk-demo.i686 : OpenJDK Demos 8
java-1.8.0-openjdk-demo.x86_64 : OpenJDK 8 Demos
java-1.8.0-openjdk-devel.i686 : OpenJDK Development Environment 8
java-1.8.0-openjdk-devel.x86_64 : OpenJDK 8 Development Environment
java-1.8.0-openjdk-headless.i686 : OpenJDK Headless Runtime Environment 8
java-1.8.0-openjdk-headless.x86_64 : OpenJDK 8 Headless Runtime Environment
java-1.8.0-openjdk-javadoc.noarch : OpenJDK 8 API documentation
java-1.8.0-openjdk-javadoc-zip.noarch : OpenJDK 8 API documentation compressed
java-1.8.0-openjdk-src.i686 : OpenJDK Source Bundle 8
java-1.8.0-openjdk-src.x86_64 : OpenJDK 8 Source Bundle
java-11-openjdk.i686 : OpenJDK Runtime Environment 11
......
java-latest-openjdk-static-libs-fastdebug.x86_64 : OpenJDK 16 libraries for
ldapjdk.noarch : The Mozilla LDAP Java SDK
2.查安装JDK,这里安装的是open jdk,默认安装路径:/usr/lib/jvm/
yum install -y java-1.8.0-openjdk-devel.x86_64
3.配置JDK环境变量
1)进入配置文件:vim /etc/profile
2)在结尾处添加, G 快速移至最后一行:
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64
export CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
3)重新加载profile文件:source /etc/profile
4)验证JDK安装和配置成功:java -version
二、安装JMeter
1.官网下载到本地:http://jmeter.apache.org/download_jmeter.cgi
2.服务器创建安装目录
[root@iZwz9ga2spyeb5u9tdq8t5Z local] cd /usr/local
[root@iZwz9ga2spyeb5u9tdq8t5Z local] mkdir jmeter
3.上传并解压
1)上传方式很多,自行百度。上传到jmeter目录下
2)解压:unzip apache-jmeter-5.4.1.zip
[root@iZwz9ga2spyeb5u9tdq8t5Z jmeter]# unzip apache-jmeter-5.4.1.zip
[root@iZwz9ga2spyeb5u9tdq8t5Z jmeter]# ls
apache-jmeter-5.4.1 apache-jmeter-5.4.1.zip
4.配置JMeter环境变量
1)进入配置文件:vim /etc/profile
2)在结尾处添加, G 快速移至最后一行:
export JMETER_HOME=/usr/local/jmeter/apache-jmeter-5.4.1
export PATH=${JMETER_HOME}/bin:$PATH
3)重新加载profile文件:source /etc/profile
4)验证安装配置成功:jmeter -v
[root@iZwz9ga2spyeb5u9tdq8t5Z jmeter]# jmeter -v
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
_ ____ _ ____ _ _ _____ _ __ __ _____ _____ _____ ____
/ \ | _ \ / \ / ___| | | | ____| | | \/ | ____|_ _| ____| _ \
/ _ \ | |_) / _ \| | | |_| | _| _ | | |\/| | _| | | | _| | |_) |
/ ___ \| __/ ___ \ |___| _ | |___ | |_| | | | | |___ | | | |___| _ <
/_/ \_\_| /_/ \_\____|_| |_|_____| \___/|_| |_|_____| |_| |_____|_| \_\ 5.4.1
Copyright (c) 1999-2021 The Apache Software Foundation
二、安装InfluxDB
1.指定目录下下载InfluxDB,由于之前安装2.x的兼容不了,这里学习记录的是1.x:
- 1.0 wget https://dl.influxdata.com/influxdb/releases/influxdb-1.8.4.x86_64.rpm
- 2.0 wget https://dl.influxdata.com/influxdb/releases/influxdb2-2.0.4.x86_64.rpm
2.安装InfluxDB:yum localinstall influxdb-1.8.4.x86_64.rpm
,两个主要文件位置
influxdb.service: /usr/lib/influxdb/scripts/influxdb.service
influxdb.conf: /etc/influxdb/influxdb.conf
3.更改服务启动配置:vim influxdb.service
1)将User和Group值改成root
[Service]
User=root
Group=root
LimitNOFILE=65536
EnvironmentFile=-/etc/default/influxdb
ExecStart=/usr/bin/influxd -config /etc/influxdb/influxdb.conf $INFLUXD_OPTS
KillMode=control-group
Restart=on-failure
[Install]
WantedBy=multi-user.target
Alias=influxd.service
2)重新生效服务:systemctl daemon-reload
4.查看Influxdb安装成功:influx -version
[root@iZwz9ga2spyeb5u9tdq8t5Z scripts]# influx -version
InfluxDB shell version: 1.8.4
5.启动Influxdb服务
1)临时启动:systemctl start influxdb
2)开机启动:systemctl enable influxdb
3)查看运行状态:ps -ef | grep -i "influx"
或者service influxdb status
[root@iZwz9ga2spyeb5u9tdq8t5Z /]# ps -ef | grep -i "influx"
influxdb 18955 1 0 19:21 ? 00:00:00 /usr/bin/influxd -config /etc/influxdb/influxdb.conf
root 22749 18221 0 19:24 pts/0 00:00:00 grep --color=auto -i influx
[root@iZwz9ga2spyeb5u9tdq8t5Z /]# service influxdb status
Redirecting to /bin/systemctl status influxdb.service
● influxdb.service - InfluxDB is an open-source, distributed, time series database
Loaded: loaded (/usr/lib/systemd/system/influxdb.service; enabled; vendor preset: disabled)
Active: active (running) since 一 2021-05-03 19:21:06 CST; 4min 22s ago
Docs: https://docs.influxdata.com/influxdb/
Main PID: 18955 (influxd)
CGroup: /system.slice/influxdb.service
└─18955 /usr/bin/influxd -config /etc/influxdb/influxdb.conf
6.创建Influxdb数据库
1) 进入influx命令:influx
[root@iZwz9ga2spyeb5u9tdq8t5Z /]# influx
Connected to http://localhost:8086 version 1.8.4
InfluxDB shell version: 1.8.4
2)展示数据库,和mysql类似:show databases
> show databases
name: databases
name
----
_internal
3)创建/删除数据库: create/drop(删除) jmeter(库名)
> create database jmeter
> show databases
name: databases
name
----
_internal
jmeter
4)切换数据库:use jmeter(库名)
;展示表:show measurements
> use jmeter
Using database jmeter
> show measurements
>
5)创建measurements:influxdb中没有创建表的语句,是直接通过insert语句实现measurement
insert语法:insert measurementName,tag1=value1[,tag2=value2] field1=value1[,field2=value2] <时间戳>
- insert
> insert aliyun,name="lily",age=18 favourite="melon",job=800
> insert aliyun,name="harry",age=22 favourite="magic",job=666
> show measurements
name: measurements
name
----
aliyun
>
- 查询该表aliyun
> select * from aliyun
name: aliyun
time age favourite job name
---- --- --------- --- ----
1620047056397676385 18 melon 800 "lily"
1620047100232010422 22 magic 666 "harry"
>
※会发现查询出来的时间是时间戳,解决办法是:influx -precision rfc3339启动数据库
- 查询所有tag的key和value:
age name
keys:
> show tag keys from aliyun
name: aliyun
tagKey
------
age
name
>
values:
> show tag values from aliyun with key="name"
name: aliyun
key value
--- -----
name "harry"
name "lily"
>
- ※疑问:
a) 如何修改端口?2.x怎么安装?小二还没摸索明白~~
b)官网说的yum安装,还有密钥认证,小二也没成功
三、安装Chronograf
由于InfluxDB1.x以后就没有了webUI界面,所以需要Chronograf来实现可视化构建
1.下载安装Chronograf
wget https://dl.influxdata.com/chronograf/releases/chronograf-1.8.10.x86_64.rpm
sudo yum localinstall chronograf-1.8.10.x86_64.rpm
2.启动Chronograf:systemctl start chronograf
,同样可以设置开机启动
3.访问webUI界面,配置influxdb数据库:http://ip:8888
一路点到底,因为小二也不知道那些字段干什么的?/(ㄒoㄒ)/~~
四、安装Grafana
Grafana是一款用Go语言开发的开源数据可视化工具,可以做数据监控和数据统计,带有告警功能:https://grafana.com/grafana/download
1.切换到指定目录下rpm方式下载
wget https://dl.grafana.com/oss/release/grafana-7.4.3-1.x86_64.rpm
2.安装:sudo yum install grafana-7.4.3-1.x86_64.rpm
,配置文件grafana.ini位置
[root@iZwz9ga2spyeb5u9tdq8t5Z grafana]# ls
grafana.ini ldap.toml provisioning
[root@iZwz9ga2spyeb5u9tdq8t5Z grafana]# pwd
/etc/grafana
3.启动grafana
1)开机启动
启动服务:systemctl start grafana-server
开机启动:systemctl enable grafana-server
重新启动:systemctl restart grafana-server
2)查看启动状态
[root@iZwz9ga2spyeb5u9tdq8t5Z grafana]# service grafana-server status
● grafana-server.service - Grafana instance
Loaded: loaded (/usr/lib/systemd/system/grafana-server.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2021-05-05 17:56:30 CST; 1min 56s ago
Docs: http://docs.grafana.org
Main PID: 18383 (grafana-server)
CGroup: /system.slice/grafana-server.service
4.配置grafana:默认监听端口3000,账号admin/admin
1)添加数据源
Configration –>Data Sources –> Add data source 选择InfluxDB
点击 Save&Test 后出现绿色提示代表添加成功
2)寻找仪表盘Dashboard模板:https://grafana.com/dashboards?dataSource=influxdb
3)添加仪表盘Dashboard:Create→Import
※这里的measurement name要和jmeter里的一致~
五、安装Prometheus
1.官网下载:https://prometheus.io/docs/introduction/first_steps/
,以二进制方式安装
2.安装Prometheus和node_exporter
- 创建目录:
mkdir prometheus
- 上传压缩包
- 解压文件:
tar -zxvf prometheus.tar.gz
- 修改解压文件夹名称:
mv prometheus-2.26.0.linux-amd64 prometheus
- 进入prometheus目录下:
cd prometheus
3.启动服务:./prometheus --config.file=prometheus.yml &
level=info ts=2021-05-11T05:39:39.559Z caller=main.go:815 fs_type=EXT4_SUPER_MAGIC
level=info ts=2021-05-11T05:39:39.559Z caller=main.go:818 msg="TSDB started"
level=info ts=2021-05-11T05:39:39.559Z caller=main.go:944 msg="Loading configuration file" filename=prometheus.yml
level=info ts=2021-05-11T05:39:39.560Z caller=main.go:975 msg="Completed loading of configuration file" filename=prometheus.yml totalDuration=906.425µs remote_storage=7.891µs web_handler=543ns query_engine=1.073µs scrape=346.046µs scrape_sd=81.428µs notify=54.125µs notify_sd=30.896µs rules=4.826µs
level=info ts=2021-05-11T05:39:39.560Z caller=main.go:767 msg="Server is ready to receive web requests."
4.版本查询:./promethues --version
[root@iZwz9ga2spyeb5u9tdq8t5Z prometheus] ./prometheus --version
prometheus, version 2.26.0 (branch: HEAD, revision: 3cafc58827d1ebd1a67749f88be4218f0bab3d8d)
build user: root@a67cafebe6d0
build date: 20210331-11:56:23
go version: go1.16.2
platform: linux/amd64
4.访问UI界面:IP:9090
- 打开网页输入以下指令
rate(promhttp_metric_handler_requests_total{code="200"}[1m])
5.下载安装node_exporter:https://prometheus.io/download/
- 创建文件夹:
mkdir /etc/default/node_exporter
- 上传压缩文件
- 解压文件:
tar -zxvf node_exporter.1.1.2.linux-amd64.tar.gz
- 修改解压文件夹名称:
mv node_exporter.1.1.2.linux-amd64 node_exporter
- 进入目录:
cd node_exporter
- 启动服务:
nohup /etc/default/node_exporter/node_exporter/node_exporter &
- 打开UI:
IP:9100
,查看端口:lsof -i:9100
[root@iZwz9ga2spyeb5u9tdq8t5Z node_exporter]# lsof -i:9100
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node_expo 30994 root 3u IPv6 4015988 0t0 TCP *:jetdirect (LISTEN)
6.编辑Prometheus配置文件:
- 先杀掉prometheus:
pkill prometheus
level=info ts=2021-05-11T05:22:10.102Z caller=main.go:668 msg="Stopping scrape discovery manager..."
level=info ts=2021-05-11T05:22:10.102Z caller=main.go:682 msg="Stopping notify discovery manager..."
level=info ts=2021-05-11T05:22:10.102Z caller=main.go:704 msg="Stopping scrape manager..."
level=info ts=2021-05-11T05:22:10.102Z caller=main.go:664 msg="Scrape discovery manager stopped"
level=info ts=2021-05-11T05:22:10.102Z caller=main.go:678 msg="Notify discovery manager stopped"
level=info ts=2021-05-11T05:22:10.102Z caller=manager.go:934 component="rule manager" msg="Stopping rule manager..."
level=info ts=2021-05-11T05:22:10.102Z caller=manager.go:944 component="rule manager" msg="Rule manager stopped"
level=info ts=2021-05-11T05:22:10.103Z caller=main.go:698 msg="Scrape manager stopped"
level=info ts=2021-05-11T05:22:10.110Z caller=notifier.go:601 component=notifier msg="Stopping notification manager..."
level=info ts=2021-05-11T05:22:10.110Z caller=main.go:872 msg="Notifier manager stopped"
level=info ts=2021-05-11T05:22:10.111Z caller=main.go:884 msg="See you next time!"
- 然后
vim prometheus.yml
,在最后面添加:
[root@iZwz9ga2spyeb5u9tdq8t5Z prometheus]# vim prometheus.yml
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
- job_name: 'xxx.xx.xxx.xxx'
static_config:
- targets: ['xxx.xx.xxx.xx:9100']
参考:https://blog.csdn.net/qq_43417559/article/details/109012296
7.重启服务:./prometheus --config.file=prometheus.yml &
8.访问IP:9090,点击导航栏中的status→targets。显示如下图说明配置成功
※如果状态位DOWN,需要检查下防火墙是否关闭
9.在Grafana中配置prometheus
- 添加prometheus的data sources
- Import Dashboard,方法跟Influxdb类似,不做过多介绍
10.Jmeter非GUI命令运行
jmeter -n -t file.jmx -l result.jtl -e -o reopot
-
-n
:非GUI模式运行 -
-t
:指定jmx文件位置 -
-l
:指定生成jtl的格式结果 -
-e
:生成html报告 -
-o
:指定html报告文件夹(必须是空目录)