1、如果需要部署到Linux,需要把StdCallCallback全部改为Callback
如果需要部署到Linux,需要把StdCallCallback全部改为Callback
2、在使用jar包直接部署没问题,但是使用dockerfile部署时出现了许多错误。
解决方式
jar包直接部署(start.sh):
ps -ef | grep -v grep | grep " /bin/java -Xms256m -Xmx256m -Xmn128m -Xss256k -server -jar ./visualization-service.jar" | awk '{print $2}' | xargs kill -9
nohup /bin/java -Xms256m -Xmx256m -Xmn128m -Xss256k -server -jar ./visualization-service.jar >> ./log-dev.log 2>&1 &
tail -f ./log-dev.log
原始为:
FROM openjdk:8-jdk-alpine
LABEL GitRepo=#GIT_URL
ADD Shanghai /etc/localtime
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories \
&& apk update \
&& apk add ttf-dejavu;apk add fontconfig
WORKDIR /app/
COPY target/lib/ /app/lib/
COPY target/*.jar /app/app.jar
COPY target/conf/ /app/conf/
COPY elastic-apm-agent-1.34.1.jar /app/elastic-apm-agent-1.34.1.jar
COPY start-app.sh /usr/bin/start-app.sh
RUN chmod +x /usr/bin/start-app.sh && echo "Asia/Shanghai" > /etc/timezone
ENTRYPOINT /usr/bin/start-app.sh
修改为:
FROM openjdk:8-jdk-buster
LABEL GitRepo=#GIT_URL
ADD Shanghai /etc/localtime
RUN sed -i 's/http:\/\/deb.debian.org\/debian\//http:\/\/mirrors.tuna.tsinghua.edu.cn\/debian\//g' /etc/apt/sources.list \
&& apt-get update \
&& apt-get install -y fonts-dejavu fontconfig
WORKDIR /app/
COPY target/lib/ /app/lib/
COPY target/*.jar /app/app.jar
COPY target/conf/ /app/conf/
COPY target/linux64/ /app/linux64/
COPY elastic-apm-agent-1.34.1.jar /app/elastic-apm-agent-1.34.1.jar
COPY start-app.sh /usr/bin/start-app.sh
RUN chmod +x /usr/bin/start-app.sh && echo "Asia/Shanghai" > /etc/timezone
ENTRYPOINT /usr/bin/start-app.sh
直接修改成如下也能成功运行(个人测试修改,因为一开始判断为jdk版本问题,修改jdk版本后可成功运行)
FROM centos:7.6.1810
RUN yum install -y wget tar
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US.UTF-8
# 下载并解压 JDK 到 /opt 目录
WORKDIR /opt
RUN wget https://download.java.net/openjdk/jdk8u41/ri/openjdk-8u41-b04-linux-x64-14_jan_2020.tar.gz
RUN tar -zxvf openjdk-8u41-b04-linux-x64-14_jan_2020.tar.gz
RUN rm openjdk-8u41-b04-linux-x64-14_jan_2020.tar.gz
# 设置环境变量
ENV JAVA_HOME /opt/java-se-8u41-ri
ENV PATH $PATH:$JAVA_HOME/bin
LABEL GitRepo=#GIT_URL
ADD Shanghai /etc/localtime
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories \
&& apk update \
&& apk add ttf-dejavu;apk add fontconfig
WORKDIR /app/
COPY target/lib/ /app/lib/
COPY target/*.jar /app/app.jar
COPY target/conf/ /app/conf/
COPY target/linux64/ /app/linux64/
COPY elastic-apm-agent-1.34.1.jar /app/elastic-apm-agent-1.34.1.jar
COPY start-app.sh /usr/bin/start-app.sh
RUN chmod +x /usr/bin/start-app.sh && echo "Asia/Shanghai" > /etc/timezone
ENTRYPOINT /usr/bin/start-app.sh
3、打包格式从jar包变为dockerfile配置的pom.xml修改
<profiles>
<profile>
<id>test</id>
<properties>
<env-name>test</env-name>
</properties>
</profile>
<profile>
<id>pre</id>
<properties>
<env-name>pre</env-name>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<env-name>prod</env-name>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- <configuration>-->
<!-- <layout>ZIP</layout>-->
<!-- <executable>true</executable>-->
<!-- <includes>-->
<!-- <include>-->
<!-- <groupId>com.tengyun.ykt</groupId>-->
<!-- <artifactId>base-common</artifactId>-->
<!-- </include>-->
<!-- <include>-->
<!-- <groupId>com.tengyun.ykt</groupId>-->
<!-- <artifactId>service-client</artifactId>-->
<!-- </include>-->
<!-- </includes>-->
<!-- </configuration>-->
<!-- </plugin>-->
<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-dependency-plugin</artifactId>-->
<!-- <version>3.1.1</version>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <id>copy-dependencies</id>-->
<!-- <phase>package</phase>-->
<!-- <goals>-->
<!-- <goal>copy-dependencies</goal>-->
<!-- </goals>-->
<!-- <configuration>-->
<!-- <excludeGroupIds>-->
<!-- com.tengyun.ykt-->
<!-- </excludeGroupIds>-->
<!-- <outputDirectory>${project.build.directory}/lib/</outputDirectory>-->
<!-- </configuration>-->
<!-- </execution>-->
<!-- </executions>-->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<encoding>UTF-8</encoding>
<!-- <outputDirectory>${project.build.directory}/conf</outputDirectory>-->
<!-- <resources>-->
<!-- <resource>-->
<!-- <directory>src/main/resources/conf/es-${env-name}</directory>-->
<!-- </resource>-->
<!-- </resources>-->
<!-- </configuration>-->
<!-- </execution>-->
<!-- <execution>-->
<!-- <id>copy-resources2</id>-->
<!-- <phase>package</phase>-->
<!-- <goals>-->
<!-- <goal>copy-resources</goal>-->
<!-- </goals>-->
<!-- <configuration>-->
<!-- <encoding>UTF-8</encoding>-->
<outputDirectory>${project.build.directory}/linux64</outputDirectory>
<resources>
<resource>
<directory>src/main/resources/conf/linux64</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
注释的打包方式为dockerfile配套打包方式
visualization-service.jar打包后实际大小为56M
4、使用socketio后,docker服务器找不到端口
server:
port: 8008
socketio:
host: 0.0.0.0
port: 8009
maxFramePayloadLength: 1048576
maxHttpContentLength: 1048576
bossCount: 1
workCount: 1
allowCustomRequests: true
upgradeTimeout: 10000
pingTimeout: 60000
pingInterval: 25000
socketio从localhost/127.0.0.1,改为0.0.0.0
5、在Linux下,大华摄像头打出的中文log为乱码,并且保存也是乱码,无法根据乱码的中文匹配es数据
原始为:
trafficInfo.m_PlateNumber = new String(msg.stuObject.szText, "GBK").trim();
修改后:
try {
boolean isWindows = System.getProperty("os.name").toLowerCase().contains("win");
if (isWindows){
log.info("车牌号GBK:" + new String(msg.stuObject.szText, "GBK").trim());
trafficInfo.m_PlateNumber = new String(msg.stuObject.szText, "GBK").trim();
}else {
log.info("车牌号UTF8:"+new String(msg.stuObject.szText, StandardCharsets.UTF_8).trim());
trafficInfo.m_PlateNumber = new String(msg.stuObject.szText, StandardCharsets.UTF_8).trim();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}