centeros7 安装配置环境jdk1.8
1.先卸载centeros自带jdk
rpm-qa|grepopenjdk
查询出来的自带的openjdk
2.删除
rpm-e--nodeps
3.再次查询
rpm-qa|grepjdk
4.在usr/local创建文件夹
cd/usr/localmkdirjava
5.将jdk1.8放到刚刚创建的文件中
cd/usr/local/java
用xftp上传后解压
tar-zxvfjdk-8u181-linux-x64.tar.gz
6.进入刚刚解压的文件夹
cdjdk1.8.0_181/pwd#(这一步记录jdk1.8的路径,一会配置环境用)
7.配置环境
vim/etc/profile
按i插入下面路径
exportJAVA_HOME=/usr/local/java/jdk1.8.0_181exportCLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jarexportPATH=$PATH:$JAVA_HOME/bin
按Esc后:wq退出后
source/etc/profile
8.查看是否成功
java-version
maven 环境配置
1.在/usr/local 下创建maven文件夹
cd/usr/localmkdirmaven
2.进去新建的文件夹
cdmaven
上传 apache-maven-3.5.4-bin.zip
3.解压
unzipapache-maven-3.5.4-bin.zip
4.进入解压的文件夹
cdapache-maven-3.5.4/
pwd#(记录下这个路径,一会配置环境用到)
5.配置环境
vim/etc/profile
按i插入下面
exportMAVEN_HOME=/usr/local/maven/apache-maven-3.5.4exportPATH=$PATH:$MAVEN_HOME/bin
按Esc后:wq保存后
source/etc/profile
6.查看是否成功
mvn-v
centeros7安装git
yuminstallgit
一路下来y即可
查看是否是成功
git--version
查看git命令地址
which-agit
到此环境已经搭建好,开始对maven私服,gitlab搭建。
gitlab搭建
1.新建 /etc/yum.repos.d/gitlab-ce.repo
vim/etc/yum.repos.d/gitlab-ce.repo
后按下 i 键 插入下面内容
[gitlab-ce]name=GitlabCERepositorybaseurl=https://mirrors.tuna./gitlab-ce/yum/el$releasever/gpgcheck=0enabled=1
2.
sudoyummakecachesudoyuminstallgitlab-ce#(安装最新的)或sudoyuminstallgitlab-ce-12.0.4#(指定版本号)
3.配置 external_url
vim/etc/gitlab/gitlab.rb
修改external_url地址 为:http://本机地址:端口号/
本机地址查看:ifconfig
查看端口号运行的应用 lsof -i:端口号
4.
gitlab-ctlreconfigure
5.
gitlab-ctlrestart#启动gitlab-ctlstart|stop|status|restart#其他操作
6.访问
http://本机地址:端口号/
常见问题gitlab502
: 这个是端口被占用
确保端口不被占用后从4开始继续来一遍
centeros7 搭建maven私服
下载nexus3.x:
/download-oss-sonatype
1.在/usr/local下创建nexus文件
cd/usr/localmkdirnexuscdnexus
2.上传刚刚下载的nexus压缩包并解压
tar-zxvfnexus-3.18.1-01-unix.tar.gz
3.
cdnexus-3.18.1-01/bin/ls
4.启动
./nexusrun&
5.开启远程访问端口
firewall-cmd--zone=public--add-port=8081/tcp--permanentfirewall-cmd--reload
浏览器访问
6.设置开机自启动
1.创建服务
vim/usr/lib/systemd/system/nexus.service
2.按i将下面复制进去
[Unit]Description=nexusservice[Service]Type=forkingLimitNOFILE=65536#警告处理ExecStart=/usr/local/nexus/nexus-3.7.1-02/bin/nexusstartExecReload=/usr/local/nexus/nexus-3.7.1-02/bin/nexusrestartExecStop=/usr/local/nexus/nexus-3.7.1-02/bin/nexusstopRestart=on-failure[Install]WantedBy=multi-user.target
3.将服务加入开机启动
systemctlenablenexus.service
4.重新加载配置文件
systemctldaemon-reload
7.运行用户为root (编辑nexus bin下的nexus.rc)
cd/usr/local/nexus/nexus-3.18.1-01/bin/vimnexus.rc
内容改为:
run_as_user="root"
8.修改nexus3启动时要使用的jdk版本
cd/usr/local/nexus/nexus-3.18.1-01/bin/vimnexus
按i将下面添加进去
INSTALL4J_JAVA_HOME_OVERRIDE=/usr/local/java/jdk1.8.0_181
java_home地址可以用echo $JAVA_HOME 输出 (前提是/etc/profile有export)
9.修改nexus3默认端口
文件在nexus-xx
etc/nexus-default.properties
这里已经搭建好了,下面是deploy到私服和从私服上下载下来测试
1.创建facade 上传到私服
在/usr下创建projects
cd/usrmkdirprojects
将改zip解压到projects进入到pom.xml所在目录
mvndeploy-Dmaven.test.skip=true-U
已经上传成功
这里要把Allow anonymous users to access the server(允许匿名用户访问服务器)
因为本地maven没有配置用户
也可以用idea maven命令depoly
<?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="/POM/4.0.0"xmlns:xsi="/2001/XMLSchema-instance"xsi:schemaLocation="/POM/4.0.0/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>ease</groupId><artifactId>maven_test_demo</artifactId><version>1.0.0-SNAPSHOT</version><packaging>jar</packaging><!--定义常量--><properties><java.version>1.8</java.version><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven-compiler-plugin.version>3.6.1</maven-compiler-plugin.version><nexus.host>192.168.20.143:8081</nexus.host></properties><!--定义deploy私服地址及id(这里的id应该和mavenconf中settings中server标签中的一致)--><distributionManagement><repository><id>nexus-releases</id><name>NexusPrivateReleaseRepository</name><url>http://${nexus.host}/repository/maven-releases</url></repository><snapshotRepository><id>nexus-snapshots</id><name>NexusPrivateSnapshotRepository</name><url>http://${nexus.host}/repository/maven-snapshots</url></snapshotRepository></distributionManagement><!--定义编译:/jiachunchun/article/details/90235498--><build><finalName>${project.artifactId}-${project.version}</finalName><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>${maven-compiler-plugin.version}</version><configuration><source>${java.version}</source><target>${java.version}</target><encoding>${project.build.sourceEncoding}</encoding></configuration></plugin></plugins></build></project>
settings.xml中servers中定义的id一致
在settings 添加下面镜像
<mirror><id>Central</id><url>/maven2</url><mirrorOf>central</mirrorOf></mirror>
最后settings文件。到这儿jar包已经可以发布到私服上去了
再看怎么拉取的
maven_demo_impl项目的pom.xml
<?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="/POM/4.0.0"xmlns:xsi="/2001/XMLSchema-instance"xsi:schemaLocation="/POM/4.0.0/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>ease</groupId><artifactId>maven_demo_impl</artifactId><version>1.0-SNAPSHOT</version><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.0.5.RELEASE</version><relativePath/><!--lookupparentfromrepository--></parent><!--定义常量--><properties><java.version>1.8</java.version><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven-compiler-plugin.version>3.6.1</maven-compiler-plugin.version><nexus.host>192.168.20.143:8081</nexus.host><spring-cloud.version>Finchley.SR1</spring-cloud.version></properties><!--定义仓库地址--><repositories><repository><id>nexus-aliyun-repo</id><name>nexusaliyunrepo</name><url>/nexus/content/groups/public</url></repository><!--私服--><repository><id>maven-public</id><name>mavenpublic</name><url>http://192.168.20.143:8081/repository/maven-public/</url></repository></repositories><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><!--依赖--><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-server</artifactId></dependency><dependency><groupId>ease</groupId><artifactId>maven_test_demo</artifactId><version>1.0.0-SNAPSHOT</version></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>
配置完成后就会自动去私服下载jar了
jenkins搭建
1.查看环境版本
java-version#没有的话查看上文jdk1.8安装mvn-v#没有的话查看上文maven安装git--version#没有的话查看上文git安装
2.安装jenkenis
添加Jenkins源:
sudowget-O/etc/yum.repos.d/jenkins.repohttp://jenkins-/redhat/jenkins.reposudorpm--importhttp://pkg.jenkins-/redhat/jenkins-.key
3.安装
yuminstalljenkins
4.启动
sudoservicejenkinsstart
5.访问
http://ip:8080/#jenkenis默认是8080
第一次密码:
vim /var/lib/jenkins/secrets/initialAdminPassword
点安装推荐的插件(后面的选择安装不知道安装什么)
修改jenkins端口
vim/etc/sysconfig/jenkins
将JENKINS_PORT="8080" ===> 修改成未占用想修改的端口 JENKINS_PORT="8089"
重启服务
servicejenkinsrestart
遇到的问题:重装了JDK, java地址变了
启动jenkins报错: Job for jenkins.service failed because the control process exited with error code. See "systemctl status jenkins.service" and "journalctl -xe" for details.
按提示输入systemctl status jenkins.service
解决方法:
1> 查看当前Java的环境变量
echo$JAVA_HOME
2> 复制Java的环境变量地址, 编辑/etc/init.d/jenkins文件, 指定位置添加该地址, 后缀附上/bin/java
vim/etc/init.d/jenkins
重点是配置Jenkins:
1.配置全局jdk maven git
点Manage Jenkins(系统管理) --> Global Tool Configuaration(全局工具配置)
1.maven配置:配置settings.xml地址
2.配置jdk地址 (可以用echo $JAVA_HOME
获取)
3.git配置地址 可以用(which -a git查看)
4.maven配置地址
2.新建任务
3.配置任务
1.配置源码管理 下面version是gitlab的版本号
Repository URL:访问的仓库名称
Credentials:访问账目密码或者ssh证书
Branch Specifier (blank for ‘any’):访问的分支,可以多个
源码库浏览器:选择源码库服务器
URL:源码仓库url
Version:源码库服务器版本号
2.配置构建
cleancompilepackageinstalldeploy-Dmaven.test.skip=true-U#将jar发布
然后应用,配置完成!
3.在my view(我的视图) -> 找到新建的项目 --> 点击build now(立即构建)
在构建历史中点击刚刚的构建如下图: #1 : 是构建的id ,控制台输出: 可以看到具体的输出
下面是输入日志 可以看到以前拉取到指定的项目master分支
StartedbyuserrootRunningasSYSTEMBuildinginworkspace/var/lib/jenkins/workspace/firstusingcredentialfad2813a-c894-4386-ae16-11d6e6d349d4CloningtheremoteGitrepositoryCloningrepositoryhttp://192.168.20.137:9029/root/wx-ssm.git>/usr/local/git/bin/gitinit/var/lib/jenkins/workspace/first#timeout=10Fetchingupstreamchangesfromhttp://192.168.20.137:9029/root/wx-ssm.git>/usr/local/git/bin/git--version#timeout=10usingGIT_ASKPASStosetcredentials>/usr/local/git/bin/gitfetch--tags--progresshttp://192.168.20.137:9029/root/wx-ssm.git+refs/heads/*:refs/remotes/origin/*>/usr/local/git/bin/gitconfigremote.origin.urlhttp://192.168.20.137:9029/root/wx-ssm.git#timeout=10>/usr/local/git/bin/gitconfig--addremote.origin.fetch+refs/heads/*:refs/remotes/origin/*#timeout=10>/usr/local/git/bin/gitconfigremote.origin.urlhttp://192.168.20.137:9029/root/wx-ssm.git#timeout=10Fetchingupstreamchangesfromhttp://192.168.20.137:9029/root/wx-ssm.gitusingGIT_ASKPASStosetcredentials>/usr/local/git/bin/gitfetch--tags--progresshttp://192.168.20.137:9029/root/wx-ssm.git+refs/heads/*:refs/remotes/origin/*>/usr/local/git/bin/gitrev-parserefs/remotes/origin/master^{commit}#timeout=10>/usr/local/git/bin/gitrev-parserefs/remotes/origin/origin/master^{commit}#timeout=10CheckingoutRevision47d13c3ca0bc12fc0465c3e4c582b2c542276eb6(refs/remotes/origin/master)>/usr/local/git/bin/gitconfigcore.sparsecheckout#timeout=10>/usr/local/git/bin/gitcheckout-f47d13c3ca0bc12fc0465c3e4c582b2c542276eb6Commitmessage:"更新pom.xml"Firsttimebuild.Skippingchangelog.[first]$/project/java/maven/apache-maven-3.6.1/bin/mvn-s/project/java/maven/apache-maven-3.6.1/conf/settings.xml-gs/project/java/maven/apache-maven-3.6.1/conf/settings.xmlcleanpackage[INFO]Scanningforprojects...[WARNING][WARNING]Someproblemswereencounteredwhilebuildingtheeffectivemodelforcom.guojin:gjmetal-wx-ssm:jar:1.0.0.1-SNAPSHOT[WARNING]'dependencies.dependency.(groupId:artifactId:type:classifier)'mustbeunique:org.apache.httpcomponents:httpclient:jar->version(?)vs4.5.6@line155,column21[WARNING][WARNING]Itishighlyrecommendedtofixtheseproblemsbecausetheythreatenthestabilityofyourbuild.[WARNING][WARNING]Forthisreason,futureMavenversionsmightnolongersupportbuildingsuchmalformedprojects.[WARNING][INFO][INFO]---------------------<com.guojin:gjmetal-wx-ssm>----------------------[INFO]Buildinggjmetal-wx-ssm1.0.0.1-SNAPSHOT[INFO]--------------------------------[jar]---------------------------------[INFO][INFO]---maven-clean-plugin:2.5:clean(default-clean)@gjmetal-wx-ssm---[INFO][INFO]---jacoco-maven-plugin:0.7.9:prepare-agent(pre-test)@gjmetal-wx-ssm---[INFO]argLinesetto-javaagent:/var/lib/jenkins/.m2/repository/org/jacoco/org.jacoco.agent/0.7.9/org.jacoco.agent-0.7.9-runtime.jar=destfile=/var/lib/jenkins/workspace/first/target/jacoco.exec,includes=com.gjmetal.*[INFO][INFO]---maven-resources-plugin:2.6:resources(default-resources)@gjmetal-wx-ssm---[INFO]Using'UTF-8'encodingtocopyfilteredresources.[INFO]Copying1resource[INFO][INFO]---maven-compiler-plugin:3.6.1:compile(default-compile)@gjmetal-wx-ssm---[INFO]Changesdetected-recompilingthemodule![INFO]Compiling27sourcefilesto/var/lib/jenkins/workspace/first/target/classes[INFO]-------------------------------------------------------------[ERROR]COMPILATIONERROR:[INFO]-------------------------------------------------------------[ERROR]/var/lib/jenkins/workspace/first/src/main/java/com/gjmetal/Swagger2.java:[4,40]程序包org.fuelteam.springboot.swagger2不存在[ERROR]/var/lib/jenkins/workspace/first/src/main/java/com/gjmetal/Swagger2.java:[21,2]找不到符号符号:类EnableSwagger2[INFO]2errors[INFO]-------------------------------------------------------------[INFO]------------------------------------------------------------------------[INFO]BUILDFAILURE[INFO]------------------------------------------------------------------------[INFO]Totaltime:9.183s[INFO]Finishedat:-08-23T17:05:09+08:00[INFO]------------------------------------------------------------------------[ERROR]Failedtoexecutegoalorg.apache.maven.plugins:maven-compiler-plugin:3.6.1:compile(default-compile)onprojectgjmetal-wx-ssm:Compilationfailure:Compilationfailure:[ERROR]/var/lib/jenkins/workspace/first/src/main/java/com/gjmetal/Swagger2.java:[4,40]程序包org.fuelteam.springboot.swagger2不存在[ERROR]/var/lib/jenkins/workspace/first/src/main/java/com/gjmetal/Swagger2.java:[21,2]找不到符号[ERROR]符号:类EnableSwagger2[ERROR]->[Help1][ERROR][ERROR]Toseethefullstacktraceoftheerrors,re-runMavenwiththe-eswitch.[ERROR]Re-runMavenusingthe-Xswitchtoenablefulldebuglogging.[ERROR][ERROR]Formoreinformationabouttheerrorsandpossiblesolutions,pleasereadthefollowingarticles:[ERROR][Help1]/confluence/display/MAVEN/MojoFailureExceptionBuildstep'Invoketop-levelMaventargets'markedbuildasfailureFinished:FAILURE
上面报错是项目问题,可以看到已经拉取到项目了。所以要保证项目的正确性。
下面是正确的两个项目运行实例
在搭建好gitlab nexus jenkins后实现自动发jar到私服及启动jar项目
背景: gitlab nexus jenkins都已经完成了
1.从gitlab下载项目后发布jar到私服
重新配置gitlab地址:
配置maven命令:
cleancompilepackageinstalldeploy-Dmaven.test.skip=true-U
点击build now 然后看控制台输出如下
StartedbyuserrootRunningasSYSTEMBuildinginworkspace/var/lib/jenkins/workspace/maven_homeusingcredentialfad2813a-c894-4386-ae16-11d6e6d349d4>/usr/local/git/bin/gitrev-parse--is-inside-work-tree#timeout=10FetchingchangesfromtheremoteGitrepository>/usr/local/git/bin/gitconfigremote.origin.urlhttp://192.168.20.143:8083/root/maven_demo.git#timeout=10Fetchingupstreamchangesfromhttp://192.168.20.143:8083/root/maven_demo.git>/usr/local/git/bin/git--version#timeout=10usingGIT_ASKPASStosetcredentials>/usr/local/git/bin/gitfetch--tags--progresshttp://192.168.20.143:8083/root/maven_demo.git+refs/heads/*:refs/remotes/origin/*>/usr/local/git/bin/gitrev-parserefs/remotes/origin/master^{commit}#timeout=10>/usr/local/git/bin/gitrev-parserefs/remotes/origin/origin/master^{commit}#timeout=10CheckingoutRevisiona26adc740d331eabe5b0fb2a46b372dbf6673d2c(refs/remotes/origin/master)>/usr/local/git/bin/gitconfigcore.sparsecheckout#timeout=10>/usr/local/git/bin/gitcheckout-fa26adc740d331eabe5b0fb2a46b372dbf6673d2cCommitmessage:"Updatepom.xml">/usr/local/git/bin/gitrev-list--no-walka26adc740d331eabe5b0fb2a46b372dbf6673d2c#timeout=10[maven_home]$/project/java/maven/apache-maven-3.6.1/bin/mvn-s/project/java/maven/apache-maven-3.6.1/conf/settings.xml-gs/project/java/maven/apache-maven-3.6.1/conf/settings.xmlcleancompilepackageinstalldeploy-Dmaven.test.skip=true-U[INFO]Scanningforprojects...[INFO][INFO]--------------------<ease:maven_test_demo>---------------------[INFO]Buildingmaven_test_demo1.0.0-SNAPSHOT[INFO]--------------------------------[jar]---------------------------------[INFO][INFO]---maven-clean-plugin:2.5:clean(default-clean)@maven_test_demo---[INFO]Deleting/var/lib/jenkins/workspace/maven_home/target[INFO][INFO]---maven-resources-plugin:2.6:resources(default-resources)@maven_test_demo---[INFO]Using'UTF-8'encodingtocopyfilteredresources.[INFO]skipnonexistingresourceDirectory/var/lib/jenkins/workspace/maven_home/src/main/resources[INFO][INFO]---maven-compiler-plugin:3.6.1:compile(default-compile)@maven_test_demo---[INFO]Changesdetected-recompilingthemodule![INFO]Compiling1sourcefileto/var/lib/jenkins/workspace/maven_home/target/classes[INFO][INFO]---maven-resources-plugin:2.6:resources(default-resources)@maven_test_demo---[INFO]Using'UTF-8'encodingtocopyfilteredresources.[INFO]skipnonexistingresourceDirectory/var/lib/jenkins/workspace/maven_home/src/main/resources[INFO][INFO]---maven-compiler-plugin:3.6.1:compile(default-compile)@maven_test_demo---[INFO]Nothingtocompile-allclassesareuptodate[INFO][INFO]---maven-resources-plugin:2.6:testResources(default-testResources)@maven_test_demo---[INFO]Notcopyingtestresources[INFO][INFO]---maven-compiler-plugin:3.6.1:testCompile(default-testCompile)@maven_test_demo---[INFO]Notcompilingtestsources[INFO][INFO]---maven-surefire-plugin:2.12.4:test(default-test)@maven_test_demo---[INFO]Testsareskipped.[INFO][INFO]---maven-jar-plugin:2.4:jar(default-jar)@maven_test_demo---[INFO]Buildingjar:/var/lib/jenkins/workspace/maven_home/target/maven_test_demo-1.0.0-SNAPSHOT.jar[INFO][INFO]---maven-resources-plugin:2.6:resources(default-resources)@maven_test_demo---[INFO]Using'UTF-8'encodingtocopyfilteredresources.[INFO]skipnonexistingresourceDirectory/var/lib/jenkins/workspace/maven_home/src/main/resources[INFO][INFO]---maven-compiler-plugin:3.6.1:compile(default-compile)@maven_test_demo---[INFO]Nothingtocompile-allclassesareuptodate[INFO][INFO]---maven-resources-plugin:2.6:testResources(default-testResources)@maven_test_demo---[INFO]Notcopyingtestresources[INFO][INFO]---maven-compiler-plugin:3.6.1:testCompile(default-testCompile)@maven_test_demo---[INFO]Notcompilingtestsources[INFO][INFO]---maven-surefire-plugin:2.12.4:test(default-test)@maven_test_demo---[INFO]Testsareskipped.[INFO][INFO]---maven-jar-plugin:2.4:jar(default-jar)@maven_test_demo---[INFO][INFO]---maven-install-plugin:2.4:install(default-install)@maven_test_demo---[INFO]Installing/var/lib/jenkins/workspace/maven_home/target/maven_test_demo-1.0.0-SNAPSHOT.jarto/var/lib/jenkins/.m2/repository/com/netease/maven_test_demo/1.0.0-SNAPSHOT/maven_test_demo-1.0.0-SNAPSHOT.jar[INFO]Installing/var/lib/jenkins/workspace/maven_home/pom.xmlto/var/lib/jenkins/.m2/repository/com/netease/maven_test_demo/1.0.0-SNAPSHOT/maven_test_demo-1.0.0-SNAPSHOT.pom[INFO][INFO]---maven-resources-plugin:2.6:resources(default-resources)@maven_test_demo---[INFO]Using'UTF-8'encodingtocopyfilteredresources.[INFO]skipnonexistingresourceDirectory/var/lib/jenkins/workspace/maven_home/src/main/resources[INFO][INFO]---maven-compiler-plugin:3.6.1:compile(default-compile)@maven_test_demo---[INFO]Nothingtocompile-allclassesareuptodate[INFO][INFO]---maven-resources-plugin:2.6:testResources(default-testResources)@maven_test_demo---[INFO]Notcopyingtestresources[INFO][INFO]---maven-compiler-plugin:3.6.1:testCompile(default-testCompile)@maven_test_demo---[INFO]Notcompilingtestsources[INFO][INFO]---maven-surefire-plugin:2.12.4:test(default-test)@maven_test_demo---[INFO]Testsareskipped.[INFO][INFO]---maven-jar-plugin:2.4:jar(default-jar)@maven_test_demo---[INFO][INFO]---maven-install-plugin:2.4:install(default-install)@maven_test_demo---[INFO]Installing/var/lib/jenkins/workspace/maven_home/target/maven_test_demo-1.0.0-SNAPSHOT.jarto/var/lib/jenkins/.m2/repository/com/netease/maven_test_demo/1.0.0-SNAPSHOT/maven_test_demo-1.0.0-SNAPSHOT.jar[INFO]Installing/var/lib/jenkins/workspace/maven_home/pom.xmlto/var/lib/jenkins/.m2/repository/com/netease/maven_test_demo/1.0.0-SNAPSHOT/maven_test_demo-1.0.0-SNAPSHOT.pom[INFO][INFO]---maven-deploy-plugin:2.7:deploy(default-deploy)@maven_test_demo---Downloadingfromnexus-snapshots:http://192.168.20.143:8081/repository/maven-snapshots/com/netease/maven_test_demo/1.0.0-SNAPSHOT/maven-metadata.xmlProgress(1):776BDownloadedfromnexus-snapshots:http://192.168.20.143:8081/repository/maven-snapshots/com/netease/maven_test_demo/1.0.0-SNAPSHOT/maven-metadata.xml(776Bat6.5kB/s)Uploadingtonexus-snapshots:http://192.168.20.143:8081/repository/maven-snapshots/com/netease/maven_test_demo/1.0.0-SNAPSHOT/maven_test_demo-1.0.0-0827.062446-3.jarProgress(1):2.6kBUploadedtonexus-snapshots:http://192.168.20.143:8081/repository/maven-snapshots/com/netease/maven_test_demo/1.0.0-SNAPSHOT/maven_test_demo-1.0.0-0827.062446-3.jar(2.6kBat13kB/s)Uploadingtonexus-snapshots:http://192.168.20.143:8081/repository/maven-snapshots/com/netease/maven_test_demo/1.0.0-SNAPSHOT/maven_test_demo-1.0.0-0827.062446-3.pomProgress(1):2.1kBUploadedtonexus-snapshots:http://192.168.20.143:8081/repository/maven-snapshots/com/netease/maven_test_demo/1.0.0-SNAPSHOT/maven_test_demo-1.0.0-0827.062446-3.pom(2.1kBat19kB/s)Downloadingfromnexus-snapshots:http://192.168.20.143:8081/repository/maven-snapshots/com/netease/maven_test_demo/maven-metadata.xmlProgress(1):286BDownloadedfromnexus-snapshots:http://192.168.20.143:8081/repository/maven-snapshots/com/netease/maven_test_demo/maven-metadata.xml(286Bat11kB/s)Uploadingtonexus-snapshots:http://192.168.20.143:8081/repository/maven-snapshots/com/netease/maven_test_demo/1.0.0-SNAPSHOT/maven-metadata.xmlProgress(1):776BUploadedtonexus-snapshots:http://192.168.20.143:8081/repository/maven-snapshots/com/netease/maven_test_demo/1.0.0-SNAPSHOT/maven-metadata.xml(776Bat4.6kB/s)Uploadingtonexus-snapshots:http://192.168.20.143:8081/repository/maven-snapshots/com/netease/maven_test_demo/maven-metadata.xmlProgress(1):286BUploadedtonexus-snapshots:http://192.168.20.143:8081/repository/maven-snapshots/com/netease/maven_test_demo/maven-metadata.xml(286Bat2.5kB/s)[INFO]------------------------------------------------------------------------[INFO]BUILDSUCCESS[INFO]------------------------------------------------------------------------[INFO]Totaltime:3.640s[INFO]Finishedat:-08-27T14:24:47+08:00[INFO]------------------------------------------------------------------------Finished:SUCCESS
2.将运行的jar发布到指定的机器
确保jenkins安装了Publish Over SSH插件 Manage Jenkins -> Manage Plugins -> 搜索ssh
然后配置ssh
配置后点击Test Configuration 出现success
配置完成后新建Item(项目)只是多加了一个构建后(注意前面的配置要想要的改 :项目的git地址
)
#最后一个执行的脚本放到的位置是/projects/scriptsmkdirscriptsvimrun.sh#按i将下面内容复制进去Project_name=$1Port_no=$2#echo$Project_name#echo$Port_no./etc/profile#进入到项目cd/projects/$Project_name#找到原进程,killpid=$(ps-ef|grepjava|grep$Project_name|awk-F'[]+''{print$2}')kill-9$pid#启动jarnohupjava-jar$Project_name-1.0-SNAPSHOT.jar--server.port=$Port_no-server-Xmx1000m-Xms1000m-Xmn700m-XX:+UseParallelGC&echo"startingservice..."sleep20#根据重启后是否有当前应用判断启动是否成功pid=$(ps-ef|grepjava|grep$Project_name|awk-F'[]+''{print$2}')#echo$pidif[-z$pid];thenecho"启动失败"exit1elseecho$Project_name:$pid"SUCCESS"fi
现在立即构建 查看控制台输出
StartedbyuserrootRunningasSYSTEMBuildinginworkspace/var/lib/jenkins/workspace/maven_demo_implusingcredentialfad2813a-c894-4386-ae16-11d6e6d349d4>/usr/local/git/bin/gitrev-parse--is-inside-work-tree#timeout=10FetchingchangesfromtheremoteGitrepository>/usr/local/git/bin/gitconfigremote.origin.urlhttp://192.168.20.143:8083/root/maven_demo_impl.git#timeout=10Fetchingupstreamchangesfromhttp://192.168.20.143:8083/root/maven_demo_impl.git>/usr/local/git/bin/git--version#timeout=10usingGIT_ASKPASStosetcredentials>/usr/local/git/bin/gitfetch--tags--progresshttp://192.168.20.143:8083/root/maven_demo_impl.git+refs/heads/*:refs/remotes/origin/*Seenbranchinrepositoryorigin/masterSeen1remotebranch>/usr/local/git/bin/gitshow-ref--tags-d#timeout=10CheckingoutRevisionbf0f9bd981c053359167a0e46e517f4f936c8c98(origin/master)>/usr/local/git/bin/gitconfigcore.sparsecheckout#timeout=10>/usr/local/git/bin/gitcheckout-fbf0f9bd981c053359167a0e46e517f4f936c8c98Commitmessage:"UpdateTestDemoImpl.java">/usr/local/git/bin/gitrev-list--no-walkbf0f9bd981c053359167a0e46e517f4f936c8c98#timeout=10[maven_demo_impl]$/project/java/maven/apache-maven-3.6.1/bin/mvn-s/project/java/maven/apache-maven-3.6.1/conf/settings.xml-gs/project/java/maven/apache-maven-3.6.1/conf/settings.xmlcleancompilepackage-Dmaven.test.skip=true-U[INFO]Scanningforprojects...[INFO][INFO]--------------------<ease:maven_demo_impl>---------------------[INFO]Buildingmaven_demo_impl1.0-SNAPSHOT[INFO]--------------------------------[jar]---------------------------------Downloadingfromnexus-aliyun-repo:/nexus/content/groups/public/com/netease/maven_test_demo/1.0.0-SNAPSHOT/maven-metadata.xmlDownloadingfrommaven-public:http://192.168.20.143:8081/repository/maven-public/com/netease/maven_test_demo/1.0.0-SNAPSHOT/maven-metadata.xmlProgress(1):776BDownloadedfrommaven-public:http://192.168.20.143:8081/repository/maven-public/com/netease/maven_test_demo/1.0.0-SNAPSHOT/maven-metadata.xml(776Bat4.2kB/s)Downloadingfromnexus-aliyun-repo:/nexus/content/groups/public/com/netease/maven_test_demo/1.0.0-SNAPSHOT/maven_test_demo-1.0.0-0827.062446-3.pomDownloadingfrommaven-public:http://192.168.20.143:8081/repository/maven-public/com/netease/maven_test_demo/1.0.0-SNAPSHOT/maven_test_demo-1.0.0-0827.062446-3.pomProgress(1):2.1kBDownloadedfrommaven-public:http://192.168.20.143:8081/repository/maven-public/com/netease/maven_test_demo/1.0.0-SNAPSHOT/maven_test_demo-1.0.0-0827.062446-3.pom(2.1kBat47kB/s)Downloadingfrommaven-public:http://192.168.20.143:8081/repository/maven-public/com/netease/maven_test_demo/1.0.0-SNAPSHOT/maven_test_demo-1.0.0-0827.062446-3.jarProgress(1):2.6kBDownloadedfrommaven-public:http://192.168.20.143:8081/repository/maven-public/com/netease/maven_test_demo/1.0.0-SNAPSHOT/maven_test_demo-1.0.0-0827.062446-3.jar(2.6kBat67kB/s)[INFO][INFO]---maven-clean-plugin:3.0.0:clean(default-clean)@maven_demo_impl---[INFO]Deleting/var/lib/jenkins/workspace/maven_demo_impl/target[INFO][INFO]---maven-resources-plugin:3.0.2:resources(default-resources)@maven_demo_impl---[INFO]Using'UTF-8'encodingtocopyfilteredresources.[INFO]Copying1resource[INFO]Copying0resource[INFO][INFO]---maven-compiler-plugin:3.6.1:compile(default-compile)@maven_demo_impl---[INFO]Changesdetected-recompilingthemodule![INFO]Compiling2sourcefilesto/var/lib/jenkins/workspace/maven_demo_impl/target/classes[INFO][INFO]---maven-resources-plugin:3.0.2:resources(default-resources)@maven_demo_impl---[INFO]Using'UTF-8'encodingtocopyfilteredresources.[INFO]Copying1resource[INFO]Copying0resource[INFO][INFO]---maven-compiler-plugin:3.6.1:compile(default-compile)@maven_demo_impl---[INFO]Nothingtocompile-allclassesareuptodate[INFO][INFO]---maven-resources-plugin:3.0.2:testResources(default-testResources)@maven_demo_impl---[INFO]Notcopyingtestresources[INFO][INFO]---maven-compiler-plugin:3.6.1:testCompile(default-testCompile)@maven_demo_impl---[INFO]Notcompilingtestsources[INFO][INFO]---maven-surefire-plugin:2.21.0:test(default-test)@maven_demo_impl---[INFO]Testsareskipped.[INFO][INFO]---maven-jar-plugin:3.0.2:jar(default-jar)@maven_demo_impl---[INFO]Buildingjar:/var/lib/jenkins/workspace/maven_demo_impl/target/maven_demo_impl-1.0-SNAPSHOT.jar[INFO][INFO]---spring-boot-maven-plugin:2.0.5.RELEASE:repackage(default)@maven_demo_impl---[INFO]------------------------------------------------------------------------[INFO]BUILDSUCCESS[INFO]------------------------------------------------------------------------[INFO]Totaltime:11.163s[INFO]Finishedat:-08-27T15:00:40+08:00[INFO]------------------------------------------------------------------------SSH:Connectingfromhost[localhost.localdomain]SSH:Connectingwithconfiguration[192.168.20.143]...SSH:EXEC:STDOUT/STDERRfromcommand[sh/projects/scripts/run.shmaven_demo_impl10010]...startingservice...nohup:把输出追加到"nohup.out"maven_demo_impl:4406SUCCESSSSH:EXEC:completedafter20,262msSSH:Disconnectingconfiguration[192.168.20.143]...SSH:Transferred1file(s)Finished:SUCCESS
可以看到ssh已经有jar 并运行了。
1.SpringBoot内容聚合
2.面试题内容聚合
3.设计模式内容聚合
4.Mybatis内容聚合
5.多线程内容聚合
最后,推荐一个专注于Java学习的公众号,Java知音。分享java基础、原理性知识、JavaWeb实战、spring全家桶、设计模式及面试资料、开源项目,助力开发者成长!