赞
踩
Metersphere文档地址:https://metersphere.io/docs/dev_manual/
代码地址:
#下载指定版本metersphere源码,最新版本可能要根据实际情况稍有改动
git clone https://github.com/metersphere/metersphere.git
git reset --hard df1d5d7608b3e8cc9c45e63b648a2b8a84e03d42 (v1.19.3版本)
- 后端框架: Spring Boot
- 前端框架: Vue.js
- 代码地址:https://github.com/metersphere/metersphere
- 本地开发需安装:JDK、Node.js、Idea
- 后端框架: Spring Boot
- 代码地址:https://github.com/metersphere/node-controller
- 本地开发需安装:JDK、Docker、Kafka
- 后端框架: Spring Boot
- 代码地址:https://github.com/metersphere/data-streaming
- 本地开发需安装:JDK、Kafka
https://github.com/metersphere
环境准备(本人环境如下):
安装前端依赖
cd metersphere/frontend
#安装前端依赖
npm install
#构建dist
npm run build
安装后端依赖
sudo mkdir -p /opt/jmeter/
cd metersphere/
sudo cp -rf backend/src/main/resources/jmeter/bin /opt/jmeter
初始化配置:
- #创建配置文件
- sudo vi /etc/my.cnf
-
- #文件内容如下
-
- [mysqld]
- default-storage-engine=INNODB
- lower_case_table_names=1
- table_open_cache=128
- max_connections=2000
- max_connect_errors=6000
- innodb_file_per_table=1
- innodb_buffer_pool_size=1G
- max_allowed_packet=64M
- transaction_isolation=READ-COMMITTED
- innodb_flush_method=O_DIRECT
- innodb_lock_wait_timeout=1800
- innodb_flush_log_at_trx_commit=0
- sync_binlog=0
-
- server-id=1
- log-bin=mysql-bin
- expire_logs_days = 2
- binlog_format=mixed
-
- sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
- skip-name-resolve
-
- #文件赋权
- sudo chmod 664 /etc/my.cnf
-
- #重启mysql 配置文件就能生效了

请参考文档中的建库语句创建 MeterSphere 使用的数据库,metersphere-server 服务启动时会自动在配置的库中创建所需的表结构及初始化数据。
CREATE DATABASE `metersphere_dev` /*!40100 DEFAULT CHARACTER SET utf8mb4 */
配置Metersphere
1)创建Metersphere目录
- sudo mkdir -p /opt/metersphere/conf
- sudo mkdir -p /opt/metersphere/logs
2)添加Metersphere配置文件
输入:sudo vi /opt/metersphere/conf/metersphere.properties,添加如下内容:
- # 数据库配置
- spring.datasource.url=jdbc:mysql://localhost:3306/metersphere_dev?autoReconnect=false&useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false
- spring.datasource.username=root
- spring.datasource.password=123456
-
- # kafka 配置,node-controller 以及 data-streaming 服务需要使用 kafka 进行测试结果的收集和处理
- kafka.partitions=1
- kafka.replicas=1
- kafka.topic=JMETER_METRICS
- kafka.test.topic=JMETER_TESTS
- kafka.bootstrap-servers=localhost:9092
- kafka.log.topic=JMETER_LOGS
- kafka.report.topic=JMETER_REPORT
-
- # node-controller 所使用的 jmeter 镜像版本
- jmeter.image=registry.fit2cloud.com/metersphere/jmeter-master:0.0.6
-
- # TCP Mock 端口范围
- tcp.mock.port=10000-10010
-
- # Redis 配置
- spring.redis.host=localhost
- spring.redis.port=6379
- spring.redis.password=123456
-
- # 启动模式,lcoal 表示以本地开发模式启动
- run.mode=local

启动:
本人从系统偏好设置-mysql里面启动
- cd /usr/local/Homebrew/Cellar/kafka/2.8.0/bin
- ./zookeeper-server-start /usr/local/Homebrew/etc/kafka/zookeeper.properties
- #另起终端
- cd /usr/local/Homebrew/Cellar/kafka/2.8.0/bin
- ./kafka-server-start /usr/local/Homebrew/etc/kafka/server.properties
brew services start redis
redis默认无密码,设置密码配置/usr/local/Homebrew/etc/redis.conf文件,找到# requirepass foobared,将其改为requirepass 你的密码。
注意:由于上诉操作更改了redis.conf文件,所以下次再启动的时候,要手动加载一下redis.conf文件。例如
进入到redis根目录,启动如下
redis-server /usr/local/Homebrew/etc/redis.conf
- #进入Metersphere后端目录
- cd metersphere/backend
- #运行spring-boot项目
- sudo mvn spring-boot:run
执行如下操作:
use mysql;
update user set host = '%' where user = 'root';
这一句执行完可能会报错,不用管它。执行FLUSH PRIVILEGES;
经过上面4步,就可以解决这个问题了。
- Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
- 2022-03-10 11:41:11,920 ERROR g.springframework.boot.SpringApplication: 830 - Application run failed
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'schedulerStarter': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.api.FlywayException: Schema `metersphere_dev` contains a failed migration to version 68 !
- cd metersphere/frontend/
- npm run serve
账号:admin
密码:metersphere
如果看到以下画面说明Metersphere搭建成功!
其他:
backend/src/main/resources/base.properties中
spring.flyway.enabled=true时启动服务会自动执行sql语句,建表完成想加快启动速度改为false即可。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。