yum install -y curl policycoreutils-python openssh-server
。如果已经安装了,这一步可以省略。https://packages.gitlab.com/gitlab/gitlab-ce
。电商项目中采用的Linux服务器,就可以选择下载gitlab-ce-15.1.0-ce.0.el7.x86_64.rpm
rpm -Uvh gitlab-ce-15.1.0-ce.0.el7.x86_64.rpm
开始安装gitlab-ctl reconfig
这个过程耗时比较长gitlab-ctl reconfigure
重新配置gitlab。gitlab-ctl start
启动gitlabgitlab-ctl stop
停止gitlabgitlab-ctl restart
重启gitlabgitlab-ctl status
查看gitlab服务状态gitlab-ctl tail
查看gitlab服务日志。Jenkins是企业最常用的一个自动化部署软件。下载地址为https://www.jenkins.io/download/
建议下载LTS(长期支持)版本的war包部署jenkins.war
nohup java -jar jenkins.war --httpPort=8080 &
端口默认就是8080端口xxxxxxxxxxxxxxxxxxxxxxx
http://x.x.x.x:8080/
第一次访问时,前端页面会引导进行一些初始化工作。例如,需要输入admin用户的默认密码,这个密码就在启动日志当中。Manage Jenkins-> Manage Plugins
包括Git 、Git client、NodeJS Plugin、Maven integration plugin、 Localization:Chinese(Simplified)中文插件pom.xml
pacakge -Dmaven.test.skip=true
类似 mvn package -Dmaven.test.skip=true
npm run build
指令来构建xx/tarter/xx-exec.jar
xx/tarter
/xxx
ps -ef | grep *demo* | grep -v grep | awk '{print $2}' | xargs kill -9
nohup java -jar ../../xx-exec.jar > /app/xxx/xxx.log 2 > &1 %
nginx -s reload
所有的依赖都打在了一个包中, 包太大, 但是可以直接使用Java -jar指令执行
。这么大的Jar包,编译会很耗时,并且在网络中传输非常麻烦, 其实大部分依赖包是不会变的jdbc,mybatis等<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
<version>2.3.12.RELEASEversion>
<executions>
<execution>
<goals>
<goal>repackagegoal>
goals>
execution>
executions>
<configuration>
<classifier>execclassifier>
configuration>
plugin>
依赖的jar包都放到export文件夹中
,target目录下的jar包只包含当前项目的源码
,文件大小就会小很多<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-dependency-pluginartifactId>
<version>2.10version>
<executions>
<execution>
<id>copy-dependenciesid>
<phase>packagephase>
<goals>
<goal>copy-dependenciesgoal>
goals>
<configuration>
<outputDirectory>exportoutputDirectory>
<excludeTransitive>falseexcludeTransitive>
<stripVersion>truestripVersion>
configuration>
execution>
executions>
plugin>
java -cp 指定Classpath 和 启动类
& 新增依赖通过工具 rsync
#!/bin/sh
#执行jar包
RUN_LIBS=""
#依赖jar包 自行制定目录
SUPPORT_LIBS=""
RUN_LIB_PATH="/app/lib"
SUPPORT_LIB_PATH="/app/support"
#加载程序包
for i in ${RUN_LIB_PATH}/* ; do
RUN_LIBS=${RUN_LIBS}:$i
done
#加载依赖包
for i in ${SUPPORT_LIB_PATH}/* ; do
SUPPORT_LIBS=${SUPPORT_LIBS}:$i
done
#整合classpath
CLASSPATH=${RUN_LIBS}:${SUPPORT_LIBS}
export CLASSPATH
#调用java指令执行。-D输入参数 java中可以用 System.getProperties读取。同时指定执行入口类 SpringBootApplication 这是一个典型的Springboot的执行方式。
java -Xdebug -Xnoagent -Djava.compiler=NONE - Xrunjdwp:transport=dt_socket,server=y,address=27899,suspend=n -cp $CLASSPATH - Dspring.profiles.active=prod com.demo.DemoAdminApplication -D user.timezone=GMT+08 1>demo-admin.out 2>demo-admin.err & echo Start App Success!
https://maven.apache.org/plugins/index.html
pmd可以定义自己的规则 https://maven.apache.org/plugins/maven-pmd-plugin/examples/multi-module-config.html
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-pmd-pluginartifactId>
<version>3.19version>
<executions>
<execution>
<phase>packagephase>
<goals>
<goal>aggregate-pmdgoal>
goals>
execution>
executions>
plugin>
jar
<modelVersion>4.0.0modelVersion>
<artifactId>demo-commonartifactId>
<packaging>jarpackaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-jar-pluginartifactId>
<version>2.4version>
plugin>
plugins>
build>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-jar-pluginartifactId>
<version>3.2.2version>
<configuration>
<archive>
<manifest>
<addClasspath>trueaddClasspath>
<classpathPrefix>support/classpathPrefix>
<mainClass>com.myapp.MyAppApplicationmainClass>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MFmanifestFile>
manifest>
archive>
configuration>
<executions>
<execution>
<id>myapp1-jarid>
<phase>packagephase>
<goals>
<goal>jargoal>
goals>
<configuration>
<classifier>myappclassifier>
<includes>
<include>com/myapp/**include>
<include>mybatis/**include>
<include>templates/**include>
<include>*.propertiesinclude>
<include>dubbo.xmlinclude>
includes>
configuration>
execution>
<execution>
<id>myapp2-jarid>
<phase>packagephase>
<goals>
<goal>jargoal>
goals>
<configuration>
<classifier>myapp2classifier>
<includes>
<include>com/myapp2/crawler/*include>
<include>com/myapp2/crawler/*include>
<include>com/myapp2/utils/**include>
<include>log4j.propertiesinclude>
includes>
configuration>
execution>
executions>
plugin>
mvn deploy -P release
在distributionManagement中配置snapshot快照库和release发布库地址
<distributionManagement>
<repository>
<id>maven-publicid>
<name>releasename>
<url>http://x.x.x.x:8081/repository/maven-releases/url>
repository>
<snapshotRepository>
<id>maven-public-snapshotid>
<name>snapshotname>
<url>http://x.x.x.x:8081/repository/maven-snapshots/url>
snapshotRepository>
distributionManagement>
maven ~/.m2/settings.xml
<server>
<id>nexus-releasesid>
<username>adminusername>
<password>admin123password>
server>
<server>
<id>nexus-snapshotsid>
<username>adminusername>
<password>admin123password>
server>
ELK 架构: https://blog.csdn.net/menxu_work/article/details/126032167
自动化监控 Prometheus、Grafana: https://blog.csdn.net/menxu_work/article/details/125776376
logstash-logback-encoder
<dependency>
<groupId>org.apache.skywalkinggroupId>
<artifactId>apm-toolkit-logback-1.xartifactId>
<version>8.9.0version>
dependency>
<dependency>
<groupId>net.logstash.logbackgroupId>
<artifactId>logstash-logback-encoderartifactId>
<version>6.3version>
dependency>
net.logstash.logback.appender.LogstashTcpSocketAppender
<configuration>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%tid] [%thread] %-5level %logger{36} -%msg%nPattern>
layout>
encoder>
appender>
<appender name="grpc-log" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%tid] [%thread] %-5level %logger{36} -%msg%nPattern>
layout>
encoder>
appender>
<appender name="async" class="ch.qos.logback.classic.AsyncAppender">
<discardingThreshold>0discardingThreshold>
<queueSize>1024queueSize>
<neverBlock>trueneverBlock>
<appender-ref ref="console"/>
appender>
<conversionRule conversionWord="tid" converterClass="org.apache.skywalking.apm.toolkit.log.logback.v1.x.LogbackPatternConverter"/>
<conversionRule conversionWord="sw_ctx" converterClass="org.apache.skywalking.apm.toolkit.log.logback.v1.x.LogbackSkyWalkingContextPatternConverter"/>
<appender name="logstash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>logstash.localhost.com:5055destination>
<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<timestamp>
<timeZone>UTCtimeZone>
timestamp>
<pattern>
<pattern>
{
"level": "%level",
"tid": "%tid",
"skyWalkingContext": "%sw_ctx",
"thread": "%thread",
"class": "%logger{1.}:%L",
"message": "%message",
"stackTrace": "%exception{10}"
}
pattern>
pattern>
providers>
encoder>
appender>
<root level="INFO">
<appender-ref ref="console"/>
<appender-ref ref="grpc-log"/>
<appender-ref ref="async"/>
<appender-ref ref="logstash" />
root>
configuration>