version: '3.1' services: jenkins: image: jenkins/jenkins:lts volumes: - /data/jenkins/:/var/jenkins_home - /var/run/docker.sock:/var/run/docker.sock - /usr/bin/docker:/usr/bin/docker - /usr/lib/x86_64-linux-gnu/libltdl.so.7:/usr/lib/x86_64-linux-gnu/libltdl.so.7 ports: - "8080:8080" expose: - "8080" - "50000" privileged: true user: root restart: always container_name: jenkins environment: JAVA_OPTS: '-Djava.util.logging.config.file=/var/jenkins_home/log.properties'
root@zpl:/opt/jenkins# docker-compose up -d
然后ip+端口访问
root@zpl:/opt/jenkins# cat /data/jenkins/secrets/initialAdminPassword
然后将密码粘贴到页面中
这一步非常慢,需要耐心等待
安装插件:
所需的插件:
• Maven插件 Maven Integration plugin
• 发布插件 Deploy to container Plugin
需要安装插件如下:
安装插件Deploy to container ---支持自动化代码部署到tomcat容器
Git 插件 可能已经安装
Maven Integration :jenkins利用Maven编译,打包所需插件
Publish Over SSH :通过ssh连接
ssh 插件
安装过程:
系统管理--->插件管理---->可选插件--->过滤Deploy to container---->勾选--->直接安装
拉到最下面
项目地址改为 https://github.com/bingyue/easy-springmvc-maven.git
[root@java-server ~]# mkdir -p /data/application
上传jdk
[root@java-server ~]# tar xzf jdk-8u191-linux-x64.tar.gz -C /usr/local/
[root@java-server ~]# cd /usr/local/
[root@java-server local]# mv jdk1.8.0_191/ java
下载tomcat
[root@java-server ~]# wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.42/bin/apache-tomcat-8.5.42.tar.gz
[root@java-server ~]# tar xzf apache-tomcat-8.5.42.tar.gz -C /data/application/
[root@java-server ~]# cd /data/application/
[root@java-server application]# mv apache-tomcat-8.5.42/ tomcat
设置环境变量
[root@java-server ~]# vim /etc/profile
export JAVA_HOME=/usr/local/java
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar
export TOMCAT_HOME=/data/application/tomcat
[root@java-server ~]# source /etc/profile
测试:
[root@java-server ~]# java -version
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
删除tomcat默认发布目录下面的内容:
[root@java-server ~]# rm -rf /data/application/tomcat/webapps/*
[root@java-server ~]# cd /data/application/tomcat/webapps/
[root@java-server webapps]# ls
创建目录和脚本:
[root@java-server ~]# mkdir /opt/script #创建脚本目录
[root@java-server ~]# vim app-jenkins.sh #创建脚本
i[root@java-server ~]# vim app-jenkins.sh
脚本内容在后面
[root@java-server ~]# chmod +x app-jenkins.sh #添加执行权限
[root@java-server ~]# mv app-jenkins.sh /opt/script/