服务器配置 内存建议大于6G (Gitlab需要4G内存)
服务器安装 Jdk Maven Git
app 引用了本地第三方包,修改了pom.xml打包方式
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.12.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.lk</groupId>
<artifactId>zhibo-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>zhibo-app</name>
<description>zhibo project for Spring Boot</description>
<dependencies>
<!--腾讯ocr包,由qcloud-sdk-2.2.7-jar-with-dependencies.jar改变而来-->
<!--将qcloud-sdk-2.2.7-jar-with-dependencies.jar包使用命令
mvn install:install-file -DgroupId=com.tencent-ocr -DartifactId=tencent-ocr-sdk -Dversion=2.2.7 -Dpackaging=jar -Dfile=C:\tool\qcloud-sdk-2.2.7-jar-with-dependencies.jar
导入本地maven仓库中,工程doc目录中有这个jar包
-->
<dependency>
<groupId>com.tencent-ocr</groupId>
<artifactId>tencent-ocr-sdk</artifactId>
<version>2.2.7</version>
<scope>system</scope>
<systemPath>${project.basedir}/../jar/qcloud-sdk-2.2.7-jar-with-dependencies.jar</systemPath>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alipay.api/k12-alipay-sdk -->
<dependency>
<groupId>com.alipay.api</groupId>
<artifactId>k12-alipay-sdk</artifactId>
<version>0.0.1-beta</version>
<scope>system</scope>
<systemPath>${project.basedir}/../jar/k12-alipay-sdk-0.0.1-beta.jar</systemPath>
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.wxpay/wxpay-sdk -->
<dependency>
<groupId>com.sz.myjar</groupId>
<artifactId>randomName</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/../jar/randomName.jar</systemPath>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<!-- 复制资源 -->
<executions>
<execution>
<id>copy-resources</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<!-- 资源文件 输出目录 --><outputDirectory>${project.build.directory}/resources</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Jenkins 安装
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat- stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
#修改jenkins 权限
#将jenkins账号分别加入到root组中
gpasswd -a jenkins root
#将jenkins账号分别加入到root组中
修改/etc/sysconfig/jenkins文件中,
#user id to be invoked as (otherwise will run as root; not wise!)
JENKINS_USER=root
JENKINS_GROUP=root
启动Jenkins服务
systemctl start jenkins
Gitlab 安装
sudo docker pull gitlab/gitlab-ce
sudo docker run -d -p 443:443 -p 80:80 -p 222:22 --name gitlab --restart always -v /home/gitlab/config:/etc/gitlab -v /home/gitlab/logs:/var/log/gitlab -v /home/gitlab/data:/var/opt/gitlab gitlab/gitlab-ce
# -d:后台运行
# -p:将容器内部端口向外映射
# --name:命名容器名称
# -v:将容器内数据文件夹或者日志、配置等文件夹挂载到宿主机指定目录
# gitlab.rb文件内容默认全是注释
vi /home/gitlab/config/gitlab.rb
# 配置http协议所使用的访问地址,不加端口号默认为80
external_url 'http://192.168.146.133'
# 配置ssh协议所使用的访问地址和端口
gitlab_rails['gitlab_ssh_host'] = 'http://192.168.146.133'
gitlab_rails['gitlab_shell_ssh_port'] = 222 # 此端口是run时22端口映射的222端口
:wq #保存配置文件并退出
重启gitlab容器
docker restart gitlab
安装Jenkins插件
Gitlab Hook Plugin、Gitlab Plugin、Maven
进入全局配置中心
配置Jdk、Maven
新建Maven项目
项目配置
BUILD_ID=DONTKILLME
NAME=zhibo-app
OUT_DIR=/usr/local/zb/${NAME}
if [ ! -d ${OUT_DIR} ]; then
mkdir ${OUT_DIR}
fi
PIDs=`jps -l | grep $NAME | awk '{print $1}'`
#停止进程
if [ -n "$PIDs" ]; then
for PID in $PIDs; do
kill $PID
echo "kill $PID"
done
fi
#等待50秒
for i in 1 10; do
PIDs=`jps -l | grep $NAME | awk '{print $1}'`
if [ ! -n "$PIDs" ]; then
echo "stop server success"
echo -------------------------------------------
break
fi
echo "sleep 5s"
sleep 5
done
rm -rf ${OUT_DIR}/*
cp -r ${WORKSPACE}/app/target/${NAME}-0.0.1-SNAPSHOT.jar ${WORKSPACE}/app/target/resources ${OUT_DIR}/
nohup java -jar ${OUT_DIR}/${NAME}-0.0.1-SNAPSHOT.jar >> ${OUT_DIR}/log.${NAME}.log 2>&1 &