更新软件包
yum update
安装 java
yum install java
安装jenkins
# 下载
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
# 引入证书
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
# 安装jenkins
yum install jenkins
# 启动jenkins
service jenkins start
这时在浏览器输入
[服务器ip]:8080
可以进入jenkins初始化界面,但是安装插件时有可能不成功,需要使用梯子翻墙,才能安装初步插件。往下有使用国内镜像教程。
jenkins 基本操作
# 查看jenkins状态
service jenkins status
# 启动jenkins
service jenkins start
# 重启jenkins
service jenkins restart
#停止jenkins
service jenkins stop
jenkins 配置文件/etc/sysconfig/jenkins
- JENKINS_PORT:默认8080
- JENKINS_HOME:默认/var/lib/jenkins
- JENKINS_USER:默认jenkins,linux下jenkins默认使用jenkins用户进行脚本和文件的操作,遇到权限不足问题,可以改此配置,或者手动chown对应目录为该配置所属用户。
- JENKINS_JAVA_OPTIONS:可以设置JVM参数
使用国内镜像
上传自定义证书
# 检测 /var/lib/jenkins/update-center-rootCAs 是否存在,没有就创建
[ ! -d /var/lib/jenkins/update-center-rootCAs ] && mkdir /var/lib/jenkins/update-center-rootCAs
# 证书
wget https://cdn.jsdelivr.net/gh/lework/jenkins-update-center/rootCA/update-center.crt -O /var/lib/jenkins/update-center-rootCAs/update-center.crt
chown jenkins.jenkins -R /var/lib/jenkins/update-center-rootCAs
改变镜像
sed -i 's#https://updates.jenkins.io/update-center.json#https://cdn.jsdelivr.net/gh/lework/jenkins-update-center/updates/huawei/update-center.json#' /var/lib/jenkins/hudson.model.UpdateCenter.xml
打开浏览器 输入[服务器ip]:8080
就可以初始化jenkins
也可以在初始化jenkins后改变镜像
网页上找到jenkins
→ manage jenkins
→ manage plugins(插件管理)
→ advanced(高级)
→ 站点
改成
https://cdn.jsdelivr.net/gh/lework/jenkins-update-center/updates/huawei/update-center.json
还有以下镜像提供选择
site | source | CDN |
---|---|---|
tencent | https://raw.githubusercontent.com/lework/jenkins-update-center/master/updates/tencent/update-center.json | center/master/updates/tencent/update-center.json https://cdn.jsdelivr.net/gh/lework/jenkins-update-center/updates/tencent/update-center.json |
huawei | https://raw.githubusercontent.com/lework/jenkins-update-center/master/updates/huawei/update-center.json | https://cdn.jsdelivr.net/gh/lework/jenkins-update-center/updates/huawei/update-center.json |
tsinghua | https://raw.githubusercontent.com/lework/jenkins-update-center/master/updates/tsinghua/update-center.json | https://cdn.jsdelivr.net/gh/lework/jenkins-update-center/updates/tsinghua/update-center.json |
ustc | https://raw.githubusercontent.com/lework/jenkins-update-center/master/updates/ustc/update-center.json | https://cdn.jsdelivr.net/gh/lework/jenkins-update-center/updates/ustc/update-center.json |
bit | https://raw.githubusercontent.com/lework/jenkins-update-center/master/updates/bit/update-center.json | https://cdn.jsdelivr.net/gh/lework/jenkins-update-center/updates/bit/update-center.json |
解决403问题
jenkins 默认开启了csrf,即跨站请求伪造(英语:Cross-site request forgery)
并且低版本支持在系统管理-全局安全配置关闭该功能,但是新版本不支持页面修改,故需要修改jenkins配置文件
打开jenkins 配置文件
vim /etc/sysconfig/jenkins
修改JENKINS_JAVA_OPTIONS
JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -Dhudson.security.csrf.GlobalCrumbIssuerConfiguration.DISABLE_CSRF_PROTECTION=true"
重启jenkins
service jenkins restart