jinkens官网:Jenkins download and deployment
下载稳定版最新版本2.361.1系列版,尽量安装高版本的稳定版,低版本后面安装插件很麻烦,各种不兼容问题一大堆。
一、下载jinkens:
wget https://get.jenkins.io/war-stable/2.361.4/jenkins.war
下载失败,报证书已经过期:
[root@master1 local]# wget https://get.jenkins.io/war-stable/2.361.4/jenkins.war
--2023-12-28 16:12:00-- https://get.jenkins.io/war-stable/2.361.4/jenkins.war
正在解析主机 get.jenkins.io (get.jenkins.io)... 20.7.178.24, 2603:1030:408:5::15a
正在连接 get.jenkins.io (get.jenkins.io)|20.7.178.24|:443... 已连接。
错误: 无法验证 get.jenkins.io 的由 “/C=US/O=Let's Encrypt/CN=R3” 颁发的证书:
颁发的证书已经过期。
要以不安全的方式连接至 get.jenkins.io,使用“--no-check-certificate”。
解决:
方法一:在浏览器上下载之后,上传到服务器。#注意下载jinkens包的格式是jinkens.war
方法二:wget https://get.jenkins.io/war-stable/2.361.4/jenkins.war --no-check-certificate #以不信任的方式下载
方法三: yum install -y ca-certificates #安装证书,这个和虚拟机配置的yum源地址有关
二、安装jinkens:
方法一:将jenkins.war放在tommcat的webapp中,启动tomcat
方法二:jenkins.war包中也包含了tomcat,可以使用jar包的方式启动
方法一:
下载tomcat:Apache Tomcat® - Welcome!
我们安装的jenkins需要的jdk本的11的,所以tomcat也要选择支撑jdk11版本:https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.18/bin/apache-tomcat-10.1.18.tar.gz
我下载的是tar.gz(积分下载)格式的包,下载zip(积分下载)格式的也行,jdk需要自己下载,注意:jdk11不要设置环境变量
如果原来安装了jdk8的话,就不需要在/etc/profile中添加环境变量了,添加了也只会显示一个版本,如果想jdk11在当前环境生效的话,重启或者重新连接之后失效,(临时生效:只对当前环境有效)只需要输入下面的命令:
export PATH=/usr/local/jdk-11.0.15.1/bin:$PATH
然后再启动tomcat10:
[root@master1 local]# tar -zxvf apache-tomcat-10.1.17.tar.gz
...
[root@master1 local]# mv apache-tomcat-10.1.17 tomcat
[root@master1 local]# cd tomcat
[root@master1 tomcat]# ls
bin BUILDING.txt conf CONTRIBUTING.md lib LICENSE logs NOTICE README.md RELEASE-NOTES RUNNING.txt temp webapps work
[root@master1 tomcat]# cd conf/
[root@master1 conf]# ls
Catalina catalina.policy catalina.properties context.xml jaspic-providers.xml jaspic-providers.xsd logging.properties server.xml tomcat-users.xml tomcat-users.xsd web.xml
[root@master1 conf]# vim server.xml
<Connector port="8888" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
启动:
[root@master1 tomcat]# ls
bin BUILDING.txt conf CONTRIBUTING.md lib LICENSE logs NOTICE README.md RELEASE-NOTES RUNNING.txt temp webapps work
[root@master1 tomcat]# cd bin/
[root@master1 bin]# ls
bootstrap.jar ciphers.sh daemon.sh migrate.bat shutdown.sh tool-wrapper.bat
catalina.bat commons-daemon.jar digest.bat migrate.sh startup.bat tool-wrapper.sh
catalina.sh commons-daemon-native.tar.gz digest.sh setclasspath.bat startup.sh version.bat
catalina-tasks.xml configtest.bat makebase.bat setclasspath.sh tomcat-juli.jar version.sh
ciphers.bat configtest.sh makebase.sh shutdown.bat tomcat-native.tar.gz
[root@master1 bin]# sh startup.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/local/jdk-11.0.15.1
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
[root@master1 bin]# ps -ef |grep tomcat
root 32372 1 49 10:41 pts/1 00:00:05 /usr/local/jdk-11.0.15.1/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
root 32436 24806 0 10:41 pts/1 00:00:00 grep --color=auto tomcat
验证:
访问方式:http://ip:8888/jenkins
安装页面提示查看管理员密码:
[root@master1 tomcat]# cat /root/.jenkins/secrets/initialAdminPassword
0979d5e4e9f0401a92f22e41de887fb6
选择第一个默认安装或者自定插件都行:
安装失败的插件后面手动下载安装,插件下载地址:Jenkins Plugins
设置完成的页面:
设置中文:
在搜索框输入:Localization: Chinese ,选择安装后重启就是中文的了
重启jenkins:
http://ip:8800/restart
方法二:
需要自己去安装jdk(注意下载jdk11)
[root@master1 local]# ls jenkins.war
jenkins.war
[root@master1 local]# mkdir jenkins
[root@master1 local]# mv jenkins.war jenkins
[root@master1 local]# cd jenkins/
[root@master1 jenkins]# ls
jenkins.war
[root@master1 jenkins]# vim start.sh
nohup /usr/local/jdk-11.0.15.1/bin/java -jar /usr/local/jenkins/jenkins.war --httpPort=8800 >/usr/local/jenkins/nohup.out &
[root@master1 jenkins]# ls
jenkins.war start.sh
[root@master1 jenkins]# export PATH=/usr/local/jdk-11.0.15.1/bin:$PATH
[root@master1 jenkins]# sh start.sh
[root@master1 jenkins]# nohup: 重定向标准错误到标准输出
[root@master1 jenkins]# ps -ef |grep jenkins
root 35295 1 40 11:00 pts/1 00:00:53 /usr/local/jdk-11.0.15.1/bin/java -jar /usr/local/jenkins/jenkins.war --httpPort=8800
root 35705 34059 0 11:02 pts/1 00:00:00 grep --color=auto jenkins
[root@master1 jenkins]# tail -f nohup.out
2024-01-04 03:00:56.415+0000 [id=33] INFO jenkins.InitReactorRunner$1#onAttained: System config adapted
2024-01-04 03:00:56.447+0000 [id=32] INFO jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
2024-01-04 03:00:56.449+0000 [id=29] INFO jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs updated
2024-01-04 03:00:56.511+0000 [id=49] INFO hudson.model.AsyncPeriodicWork#lambda$doRun$1: Started Download metadata
2024-01-04 03:00:56.686+0000 [id=34] INFO j.install.InstallState$Upgrade#applyForcedChanges: New API token system configured with insecure options to keep legacy behavior
2024-01-04 03:00:56.908+0000 [id=31] INFO jenkins.InitReactorRunner$1#onAttained: Completed initialization
2024-01-04 03:00:56.970+0000 [id=23] INFO hudson.lifecycle.Lifecycle#onReady: Jenkins is fully up and running
2024-01-04 03:01:04.639+0000 [id=49] INFO h.m.DownloadService$Downloadable#load: Obtained the updated data file for hudson.tasks.Ant.AntInstaller
2024-01-04 03:01:09.308+0000 [id=49] INFO h.m.DownloadService$Downloadable#load: Obtained the updated data file for hudson.tools.JDKInstaller
2024-01-04 03:01:09.309+0000 [id=49] INFO hudson.model.AsyncPeriodicWork#lambda$doRun$1: Finished Download metadata. 12,796 ms
验证:
访问方式:http://ip:8800
插件安装:
在使用jenkins编译发布的时候需要安装git,ssh,subversion,nodejs,maven插件,插件安装时默认是国外的源地址,可以修改为国内源地址:
war安装:
[root@VM-0-15-centos .jenkins]# cd /root/.jenkins
[root@VM-0-15-centos .jenkins]# ls
config.xml jenkins.install.InstallUtil.installingPlugins jobs nodes queue.xml.bak secret.key.not-so-secret updates users
hudson.model.UpdateCenter.xml jenkins.telemetry.Correlator.xml nodeMonitors.xml plugins secret.key secrets userContent war
[root@VM-0-15-centos .jenkins]# vim hudson.model.UpdateCenter.xml
<?xml version='1.1' encoding='UTF-8'?>
<sites>
<site>
<id>default</id>
<url>http://mirror.xmission.com/jenkins/updates/update-center.json</url>
</site>
</sites>
yum安装:
vim /var/lib/jenkins/hudson.model.UpdateCenter.xml
其他安装方式可以全局搜索文件:hudson.model.UpdateCenter.xml
find /* -name hudson.model.UpdateCenter.xml
1.安装git插件:
2.安装ssh插件:
3.安装subversion插件:
maven,nodejs插件自己按照上面的安装,如果不能安装自己手动去下载插件安装。
安装完成后需要重启一下jenkins: http://ip:8800/restart
二,前端发布
需要自己在jenkins服务器上安装nodejs
执行命令参考:
#编译配置:
#npm config set registry https://registry.npmmirror.com #清华源地址
npm config set registry https://registry.npm.taobao.org #淘宝源地址
#npm install && npm run build
#rm -rf node_modules && npm install && npm run build
#rm -rf node_modules && npm run build
npm run build
#编译后配置:
Time=$(date "+%Y%m%d%H%M")
mv /data/erp/web/dist /data/erp/web/dist.$Time
mv /root/.jenkins/workspace/test-前端/dist /data/erp/web/dist
发布到远程机器上:
1.现在系统配置里面配置远程地址
三,后端发布
需要自己在jenkins服务器上安装maven
配置jdk:
配置maven:
构建代码源配置:
代码在git上和svn上的配置都差不多:
如果maven插件没有安装,这个"构建一个maven项目" 是没有的。
git就选git,svn就选 Subversion
配置maven:
clean package -Dmaven.test.skip=true
构建后操作:
Time=$(date "+%Y%m%d%H%M")
mv /data/app/app-1.0.0.jar /data/app/app-1.0.0.jar.$Time
mv /root/.jenkins/workspace/test-后端/sysman/target/app-1.0.0.jar /data/app/
sh /data/app/stop.sh
BUILD_ID=dontKillMe #阻止jenkins杀掉后端进程,需要在启动前加入,如果不行的话用下面注释的
#export BUILD_ID=dontKillMe
#source /etc/profile
sh /data/app/start.sh
发布到远程的方法和前端差不多。