使用jenkins+maven+gitlab构建tomcat服务
使用jenkins+maven+gitlab构建tomcat服务
目录
1、安装tomcat服务
1.1、安装jdk
#1,上传jdk包到服务器
#2,上传以下到服务器
#3,执行脚本
#脚本类容
#!/bin/bash
#date:20210525
#author:vic
#version:v1
filedir=`pwd`
jdkpackage="jdk1.8.0_60.tar.gz"
jdkpath="/application/jdk1.8.0_60"
function install_jdk() {
java -version &>/dev/null
if [ $? -ne 0 ]
then
mkdir -p /application
tar -zxvf ${filedir}/${jdkpackage} -C $filedir &> /dev/null
ln -sv ${jdkpath} ${filedir}/jdk &> null
ln -sv ${filedir}/jdk/bin/java /usr/bin &>/dev/null
echo "export JAVA_HOME=${jdkpath}" >> /etc/profile
echo "export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH" >> /etc/profile
echo "export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib$JAVA_HOME/lib/tools.jar">>/etc/profile
echo -e "\n"
echo -e "\n"
source /etc/profile
java -version &>/dev/null
if [ $? -eq 0 ]
then
echo "jdk installed successfully!当前版本是:" && java -version|grep "java version"
else
echo "jdk installation failed! " && exit 8
fi
else
echo "当前环境已安装java环境,请确认后再进行安装!当前版本为:" && java -version|grep "java version"
fi
}
function test_jdk(){
java -version &>/dev/null
if [ $? -eq 0 ]
then
echo "jdk installed successfully!当前版本是:" && java -version
else
echo "jdk installation failed! " && exit 8
fi
}
install_jdk
1.2,安装及配置tomcat
- 下载tomat包,解压,更改配置
cd /application/ && tar -zxvf apache-tomcat-8.5.8.tar.gz && mv apache-tomcat-8.5.8 tomcat
- 添加账户认证
vim /application/tomcat/conf/tomcat-users.xml
<role rolename="tomcat"/>
<role rolename="role1"/>
<role rolename="manager-script"/>
<role rolename="manager-gui"/>
<role rolename="manager-status"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<user username="tomcat" password="123Aatomcat" roles="manager-gui,manager-script,tomcat,admin-gui,admin-script"/>
- 更改授权允许账户登录
vim /application/tomcat/webapps/manager/META-INF/context.xml
##注销以下两列代码
<!--
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
-->
1.3,启动tomcat服务
/application/tomcat/bin/startup.sh
- 访问管理界面
http://192.170.11.169:8080/manager/html
使用账号登录,确保无误
1.4,jenkins添加job
- 添加项目源
- 添加构建命令
- 添加构建操作(使用添加的manager user)