ubuntu20.04-通过docker安装jenkins并自动化发布java
前言jenkins需要git、maven和node,其中maven和node手动添加,git和git环境是jenkins镜像自带了的。
如果删除了docker对应的jenkins容器后(删除前一定备份jenkins_home整个文件夹,否则怕前功尽弃:
tar -czvf jenkins_home.tar.gz /var/jenkins_home)
如果删除了容器,需要重新安装并配置maven,
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311133447920-222567383.png
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311133531243-2062030844.png
docker cp /home/maven myjenkins:/opt/maven
上面的作用是从宿主机的/home/maven复制数据到容器名myjenkins的容器里面的/opt/maven中
同理,如果删除了容器需要重新安装和配置node
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311133550014-786184019.png
最后三台主机要做免密登录,比较简单这里就不展开了
apt update && apt install -y vim
apt install wget
wget https://nodejs.org/dist/v18.16.1/node-v18.16.1-linux-x64.tar.gz
tar -zxvf node-v18.16.1-linux-x64.tar.gz
vim /etc/profile
export PATH=/home/node-v18.16.1-linux-x64/bin:$PATH
source /etc/profile
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311133637885-940620403.png
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311133649546-61305914.png
一、拉最新的dockerhub版本的docker
docker pull jenkins/jenkins
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311133728720-146614992.png
二、跑docker以root账户
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311133746074-1054444848.png
docker run -itd -u root --restart=always -p 8080:8080 -p 50000:50000 -v /var/jenkins_home:/var/jenkins_home -v
/etc/localtime:/etc/localtime -e TZ=Asia/Shanghai --name myjenkins jenkins/jenkins
三、查密码
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311133751124-1962151778.png
选默认(安装推荐的插件)
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311133800970-431809669.png
使用admin用户继续
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311133807474-350346293.png
安装如下非docker自带的,必要的插件,完成后再点下面的重启
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311133812649-2083210451.png
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311133817544-1016050130.png
安装jdk
容器里面的jdk默认位置为:
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311133823278-610015708.png
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311133828649-384869796.png
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311133833237-292577509.png
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311133836984-1503461186.png
wget https://archive.apache.org/dist/maven/maven-3/3.8.5/binaries/apache-maven-3.8.5-bin.tar.gz
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311133843497-1743704475.png
tar -vxf apache-maven-3.8.5-bin.tar.gz
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311133848617-972266958.png
移除容器后,卷的信息都还在
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311133855095-1246253111.png
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311133922706-1570485136.png
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311133928127-168204118.png
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311133933923-1727751492.png
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311133939000-458545040.png
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311133944512-676311935.png
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311133948624-248559590.png
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311133955087-701158516.png
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311134005552-139820318.png
scp成功后,开始配置后台java启动服务
root@zhgd-develop-01:/usr/local/shell_scripts# cat startUpAfter.sh
#!/bin/bash
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH
#项目名称
PROJECT_NAME=$1
#先停止应用
COUNT=`ps --no-heading -C java -f --width 1000 | grep -v "8882\|8872" | grep "${PROJECT_NAME}" | awk '{print $2}' | wc -l`
if [ $COUNT -gt 0 ]; then
SERVER_PID=`ps --no-heading -C java -f --width 1000 | grep -v "8882\|8872"| grep ${PROJECT_NAME} | awk '{print $2}'`
kill -9 $SERVER_PID
fi
echo "pre run success"
#启动类的全类名
APP_MAINCLASS=$2
#项目的端口
SERVER_PORT=$3
#任务调度器的端口
#SCHEDULE_PORT=$4
#项目监控的端口
#APP_MONITOR_PORT=$5
#环境标识
APP_ENV=$4
DIR_OF_APPLICATION=$5
#项目部署的家目录
SERVERS_HOME=/application/spring_servers
#项目部署的目录
DEPLOY_DIR=${SERVERS_HOME}'/'${DIR_OF_APPLICATION}
#再启动应用
cd ${DEPLOY_DIR}
nohup $JAVA_HOME/bin/java -jar ${SERVERS_HOME}/${DIR_OF_APPLICATION}/${PROJECT_NAME}.jar --spring.profiles.active=${APP_ENV} $APP_MAINCLASS >/dev/null 2>&1 &
#启动成功
echo "nohup java -jar ${SERVERS_HOME}/${DIR_OF_APPLICATION}/${PROJECT_NAME}.jar --spring.profiles.active=${APP_ENV} $APP_MAINCLASS >${PROJECT_NAME}.log 2>&1 &"
echo "success"
exit 0
root@zhgd-develop-01:/usr/local/shell_scripts# sh /usr/local/shell_scripts/startUpAfter.sh admin com.ruoyi.Application 8090 dev
pre run success
nohup java -jar /application/spring_servers//admin.jar --spring.profiles.active=dev com.ruoyi.Application >admin.log 2>&1 &
success
root@zhgd-develop-01:/usr/local/shell_scripts# nohup java -jar /application/spring_servers//admin.jar --spring.profiles.active=dev com.ruoyi.Application >admin.log 2>&1 &
39980
后端配置java可以参考:https://blog.csdn.net/weixin_43202160/article/details/134416447
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311134249946-1714856594.png
docker exec -uroot -it myjenkins bash
/var/jenkins_home/workspace
scp admin.jar root@192.168.20.84:/application/spring_servers/ruoyi/
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311134847496-478776686.png
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311134852082-1257840784.png
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311134858326-346277670.png
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311134903172-1488201104.png
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311134908160-1974756905.png
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311134913906-1027312844.png
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311134919795-800654722.png
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311134925204-1240181735.png
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311134930296-1165058875.png
系统配置:
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311134943631-1847615052.png
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311134949344-304556521.png
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311134953639-2069910003.png
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311135013627-1433409817.png
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311135020280-1390489518.png
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311135025665-1952396972.png
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311135033046-1617462842.png
https://img2024.cnblogs.com/blog/1344353/202403/1344353-20240311135054318-431315471.png
docker安装配置jenkins启动java项目完毕
来源:https://www.cnblogs.com/CarlJohnson9527/p/18065906
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!
页:
[1]