编程知识 cdmana.com

linux 安装 jenkins 2.222.4

环境
操作系统:ubuntu16.04
软件版本:jenkins-2.222.4
 
步骤
 
官网
https://www.jenkins.io/zh/download/
# 使用文档
https://www.jenkins.io/zh/doc/pipeline/tour/getting-started/

下载

# 注:下载war包,是最简单安装方式,war包已内置jetty服务,可直接命令行运行
wget http://mirror.serverion.com/jenkins/war-stable/2.222.4/jenkins.war

依赖

Jdk:1.8

创建目录

cd /opt
mkdir -p jenkins

移动文件

mv jenkins.war /opt/jenkins

执行命令行运行

# 默认运行
/opt/jdk1.8.0_51/bin/java -jar jenkins.war
# 指定运行端口
/opt/jdk1.8.0_51/bin/java -jar jenkins.war --httpPort=8088
# 指定运行端口和URL前缀
/opt/jdk1.8.0_51/bin/java -jar jenkins.war --httpPort=8088 --prefix=/jenkins/
注意:第一次执行命令,会初始化生成目录到默认$user.home/.jenkins ,如果当前是root用户,则:Jenkins home directory: /root/.jenkins,启动日志中会打印
# 后台运行
/opt/jdk1.8.0_51/bin/java -jar jenkins.war --httpPort=8088 --prefix=/jenkins/ > log.out 2>&1 &
# 关闭CSRF保护功运行
/opt/jdk1.8.0_51/bin/java -Dhudson.security.csrf.GlobalCrumbIssuerConfiguration.DISABLE_CSRF_PROTECTION=true -jar jenkins.war --httpPort=8088 --prefix=/jenkins/
# Jenkins版本自2.204.6以来的重大变更有:删除禁用 CSRF 保护的功能。
#不启用CSRF保护功能,一定要加在-jar之前,否则有错
-Dhudson.security.csrf.GlobalCrumbIssuerConfiguration.DISABLE_CSRF_PROTECTION=true

查看运行帮助

java -jar jenkins.war --help

访问

http://192.168.1.3:8088

查看可调用api

http://192.168.1.3/jenkins/api/json

查看crubm data值

http://192.168.1.3/jenkins/crumbIssuer/api/xml?tree=crumb#

curl -s 'http://rise_jenkins_admin:1234567890@192.168.1.3/jenkins/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)'

http://rise_jenkins_admin:123456789@192.168.1.3/jenkins/crumbIssuer/api/json

 

Nginx + Jenkins转发配置
#nginx.conf配置,适用于内部统一反向代理(按需配置)
location ^~/jenkins {
   proxy_pass http://192.168.1.3:8088/jenkins;
   proxy_set_header Host $host;
   proxy_set_header X-Real-IP $remote_addr;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_set_header HTTP_X_FORWARDED_FOR $remote_addr;
   proxy_redirect default;
}
# 指定运行端口和URL前缀
/opt/jdk1.8.0_51/bin/java -jar jenkins.war --httpPort=8088 --prefix=/jenkins/

远程执行构建触发器(需配置“构建触发器”)

curl -X post -v -u rise_jenkins_admin:1234567890 http://192.168.1.3:8088/jenkins/job/test-project/build?token=token_123456

 

注意事项

1. 第一次启动,会初始化安装Jenkins,日志中会打印如下:
*************************************************************
Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:
xx90889ddxxxxxxxxxxxxxxxxxxxxx
This may also be found at: /root/.jenkins/secrets/initialAdminPassword
*************************************************************
会生成管理员鉴权密码,请将该串记录下来,再安装过程中需要填入,安装成功后,后续日志中不会在打印;
 
必装插件:
语言包依赖插件:Locale plugin
中文语言包插件:Localization: Chinese (Simplified)
基于矩阵的安全性插件:Matrix Authorization Strategy
基于矩阵项目安全性插件:Authorize Project
Maven管理插件:Maven Integration
SVN插件:Subversion
自动发布war包插件:Deploy to container
SSH协议执行远程shell:SSH Plugin
权限控制管理插件:Role-based Authorization Strategy
 
问题
错误:
插件管理页面提示:
There were errors checking the update sites:IOException:Unable to tunnel through proxy.Proxy returins "HTTP/1.1 400"

插件管理页面提示:
There were errors checking the update sites: SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed

处理方案:

进入插件管理->Advanced,修改Update Site的URL,路径为“http://updates.jenkins.io/update-center.json”,即把默认https换成http,修改完成,submit,然后checknow,即解决。
 
错误:
org.codehaus.cargo.container.tomcat.internal.TomcatManagerException: The username you provided is not allowed to use the text-based Tomcat Manager (error 403)

处理方案:在/etc/tomcat7/tomcat-users.xml文件中为管理用户添加manager-script角色即可。

 
错误:
org.codehaus.cargo.container.tomcat.internal.TomcatManagerException: The username and password you provided are not correct (error 401)

处理方案:在/etc/tomcat7/tomcat-users.xml文件中为管理用户添加manager-status角色即可。

 
错误:
Caused by: org.codehaus.cargo.container.tomcat.internal.TomcatManagerException: The Tomcat Manager responded "FAIL - Deployed application at context path /CloudPayment but context failed to start " instead of the expected "OK" message

处理方案:项目war包启动错误,需排除war包问题;

 
错误:
HTTP ERROR 403 No valid crumb was included in the request

处理方案:老版本Jenkins的CSRF保护功能只需要在 系统管理 > 全局安全配置 中便可进行打开或者关闭。Jenkins版本自2.204.6以来的重大变更有:删除禁用 CSRF 保护的功能。在tomcat启动配置中或jar包运行前加下以下配置参数,禁用CSRF保护功能;

-Dhudson.security.csrf.GlobalCrumbIssuerConfiguration.DISABLE_CSRF_PROTECTION=true

 

版权声明
本文为[不会飞的小龙人]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/437309/blog/4836741

Scroll to Top