当前位置:网站首页>Deployment of JVM sandbox repeater

Deployment of JVM sandbox repeater

2022-07-04 22:23:00 Wu_ Candy

1. What is? jvm-sandbox-repeater?

jvm-sandbox-repeater yes JVM-Sandbox An important module under the ecosystem , It has JVM-Sandbox All the characteristics of , The plug-in design is easy to quickly adapt to various middleware , Encapsulate request recording / Playback basic protocol , It also provides a variety of common and extensible resources API.jvm-sandbox Refer to JVM Sandbox container , A kind of JVM Non intrusive operation period of AOP Solution .

2. What is its core competence ?

2.1 Universal recording / Playback capability

(1). No intrusive recording HTTP/Java/Dubbo Enter the reference / Return value recording capability ( Business systems have no perception )

(2). be based on TTL Provide multi line program sub call tracing , Fully trace the call path of a request

(3). Entry request (HTTP/Dubbo/Java) Traffic playback 、 Child call (Java/Dubbo) Return value Mock Ability

2.2 Fast and scalable API Realization

(1). Recording / Playback plug-in architecture

(2). Provide standard interface , configurable / Simple coding to realize a kind of general plug-in

2.3. standalone Working mode

No need to rely on any server / Storage , Can work alone , Provide recording / Playback capability

3. How to deploy ?

3.1 Console Deploy

setp1: Download the source code

git clone https://github.com/alibaba/jvm-sandbox-repeater

step2: Configuration database information application.properties And initialization related to the initialization database sql The file address is :

./jvm-sandbox-repeater/repeater-console/repeater-console-dal/src/main/resources/database.sql

step3: Configure on server mvn command

If it is configured yum Source , You can use the following command to directly install maven

yum install maven

step4: Compile and start console command

cd ./jvm-sandbox-repeater
mvn install -DskipTests && nohup java -jar repeater-console/repeater-console-start/target/repeater-console.jar > console.log 2>&1 &

3.2 Repeater Deploy

setp1: In the source download directory above

cd ./jvm-sandbox-repeater/bin  && sh install-local.sh

install-local.sh The script is as follows :

[email protected] bin # more sh install-local.sh
#!/usr/bin/env bash
# repeater's target dir
REPEATER_TARGET_DIR=../target/repeater
# exit shell with err_code
# $1 : err_code
# $2 : err_msg
exit_on_err()
{
    [[ ! -z "${2}" ]] && echo "${2}" 1>&2
    exit ${1}
}
# package
sh ./package.sh || exit_on_err 1 "install failed cause package failed"  # Here we call package.sh  Script , The following will be analyzed separately 
# extract sandbox to ${HOME}
curl -s http://sandbox-ecological.oss-cn-hangzhou.aliyuncs.com/sandbox-1.2.1-bin.tar | tar xz -C ${HOME} || exit_on_err 1 "extract sandbox failed" # Download and unzip sandbox Package 
# copy module to ~/.sandbox-module
mkdir -p ${HOME}/.sandbox-module || exit_on_err 1 "permission denied, can not mkdir ~/.sandbox-module"  # Create directory 
cp -r ${REPEATER_TARGET_DIR}/* ${HOME}/.sandbox-module  || exit_on_err 1 "permission denied, can not copy module to ~/.sandbox-module" # Copy ../target/repeater All the files in the directory are in the directory created by the previous command 

package.sh The script is as follows :

[email protected] bin # more package.sh 
#!/usr/bin/env bash
# repeater's target dir
REPEATER_TARGET_DIR=../target/repeater  # Defining variables 
# exit shell with err_code
# $1 : err_code
# $2 : err_msg
exit_on_err()
{
    [[ ! -z "${2}" ]] && echo "${2}" 1>&2
    exit ${1}
}
# maven package the sandbox
mvn clean package -Dmaven.test.skip=true -f ../pom.xml || exit_on_err 1 "package repeater failed."   # Compile the package 

mkdir -p ${REPEATER_TARGET_DIR}/plugins  # Create directory 
mkdir -p ${REPEATER_TARGET_DIR}/cfg # Create directory 
cp ./repeater-logback.xml ${REPEATER_TARGET_DIR}/cfg/repeater-logback.xml \  # Copy files to repeater Catalog 
    && cp ./repeater.properties ${REPEATER_TARGET_DIR}/cfg/repeater.properties \
    && cp ./repeater-config.json ${REPEATER_TARGET_DIR}/cfg/repeater-config.json \
    && cp ../repeater-module/target/repeater-module-*-jar-with-dependencies.jar ${REPEATER_TARGET_DIR}/repeater-module.jar \
    && cp ../repeater-console/repeater-console-start/target/repeater-console.jar ${REPEATER_TARGET_DIR}/repeater-bootstrap.jar \
    && cp ../repeater-plugins/ibatis-plugin/target/ibatis-plugin-*-jar-with-dependencies.jar ${REPEATER_TARGET_DIR}/plugins/ibatis-plugin.jar \
    && cp ../repeater-plugins/java-plugin/target/java-plugin-*-jar-with-dependencies.jar ${REPEATER_TARGET_DIR}/plugins/java-plugin.jar \
    && cp ../repeater-plugins/mybatis-plugin/target/mybatis-plugin-*-jar-with-dependencies.jar ${REPEATER_TARGET_DIR}/plugins/mybatis-plugin.jar \
    && cp ../repeater-plugins/dubbo-plugin/target/dubbo-plugin-*-jar-with-dependencies.jar ${REPEATER_TARGET_DIR}/plugins/dubbo-plugin.jar \
    && cp ../repeater-plugins/redis-plugin/target/redis-plugin-*-jar-with-dependencies.jar ${REPEATER_TARGET_DIR}/plugins/redis-plugin.jar \
    && cp ../repeater-plugins/http-plugin/target/http-plugin-*-jar-with-dependencies.jar ${REPEATER_TARGET_DIR}/plugins/http-plugin.jar \
    && cp ../repeater-plugins/hibernate-plugin/target/hibernate-plugin-*-jar-with-dependencies.jar ${REPEATER_TARGET_DIR}/plugins/hibernate-plugin.jar \
    && cp ../repeater-plugins/spring-data-jpa-plugin/target/spring-data-jpa-plugin-*-jar-with-dependencies.jar ${REPEATER_TARGET_DIR}/plugins/spring-data-jpa-plugin.jar

repeater The log configuration file is as follows :

repeater The log path of is :~/logs/sandbox/repeater/repeater.log --》 This is because logback.xml Configuration determines repeater-logback.xml The contents of the document are as follows :

[email protected] bin #more repeater-logback.xml 
<?xml version="1.0" encoding="UTF-8" ?>
<configuration scan="true" scanPeriod="10000">
    <appender name="REPEATER-FILE-APPENDER" class="ch.qos.logback.core.rolling.Ro
llingFileAppender">
        <file>${user.home}/logs/sandbox/repeater/repeater.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">        <FileNamePattern>${user.home}/logs/sandbox/repeater/repeater.log.%d{y
yyy-MM-dd}</FileNamePattern>
            <MaxHistory>30</MaxHistory>
        </rollingPolicy>
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss} %-5level %msg%n</pattern>
            <charset>UTF-8</charset>
        </encoder>
    </appender>
    <root level="info">
        <appender-ref ref="REPEATER-FILE-APPENDER"/>
    </root>
</configuration>

3.3 Sandbox Deploy

https://github.com/alibaba/jvm-sandbox
  1. JVM-SANDBOX( The sandbox ) It realizes a method without restarting 、 Don't invade the target JVM Applied AOP Solution
  2. Operation steps : Download the latest version of JVM-SANDBOX
wget http://ompc.oss-cn-hangzhou.aliyuncs.com/jvm-sandbox/release/sandbox-stable-bin.zip

#  decompression 
unzip sandbox-stable-bin.zip

#  Enter the sandbox to execute the script 
cd sandbox/bin
 
# stay ~/sandbox/bin/sandbox.sh  Starting up cfg There is a sandbox.properties file , The catalogue is /root/sandbox/cfg
sandbox.properties  The document specifies user_module=~/.sandbox-module

#  Mount target JVM process , Here we use console Apply as an example to mount , One command is done :
sh ~/sandbox/bin/sandbox.sh -p `ps -ef | grep "console" | grep -v grep | awk '{print $2}'` -P 12250  【 This order will console JVM Mount the process 】

~/.sandbox-module You can see :

[email protected] .sandbox-module # tree
.
├── cfg
│   ├── repeater-config.json
│   ├── repeater-logback.xml # This repeater  Log configuration file after startup 
│   └── repeater.properties  # hold repeater.properties Inside ip and port  It is amended as follows console  The machine started ip and port 
├── plugins
│   ├── dubbo-plugin.jar
│   ├── hibernate-plugin.jar
│   ├── http-plugin.jar
│   ├── ibatis-plugin.jar
│   ├── java-plugin.jar
│   ├── mybatis-plugin.jar
│   ├── redis-plugin.jar
│   └── spring-data-jpa-plugin.jar
├── repeater-bootstrap.jar
└── repeater-module.jar #repeater  Module startup jar

Sandbox Log configuration :

#more sandbox-logback.xml 
<?xml version="1.0" encoding="UTF-8" ?>
<configuration scan="true" scanPeriod="10000">
    <appender name="SANDBOX-FILE-APPENDER" class="ch.qos.logback.core.rolling.Rol
lingFileAppender">
        <file>${user.home}/logs/sandbox/sandbox.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"
>
<FileNamePattern>${user.home}/logs/sandbox/sandbox.log.%d{yyyy-MM-dd}
</FileNamePattern>
            <MaxHistory>30</MaxHistory>
        </rollingPolicy>
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss} %SANDBOX_NAMESPACE %-5level %msg%n</
pattern>
            <charset>UTF-8</charset>
        </encoder>
    </appender>

    <root level="info">
        <appender-ref ref="SANDBOX-FILE-APPENDER"/>
    </root>
</configuration>

4.Console The deployed launch page is shown in the following figure

end

原网站

版权声明
本文为[Wu_ Candy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/185/202207042157284441.html