CentOS 安装 Jenkins 及 国内下载加速

Scroll Down

yum 下离线安装 Jenkins

cd /tmp
wget https://pkg.jenkins.io/redhat-stable/jenkins-2.222.1-1.1.noarch.rpm
yum localinstall jenkins-2.222.1-1.1.noarch.rpm

## 启动jenkins(默认端口8080)
systemctl start jenkins

## 查看日志
tail -f /var/log/jenkins/jenkins.log

如果启动失败,请看这里:

Jenkins 默认会在以下目录按顺序搜寻 JDK,一旦找到一个可用的即返回。

/etc/alternatives/java
/usr/lib/jvm/java-1.8.0/bin/java
/usr/lib/jvm/jre-1.8.0/bin/java
/usr/lib/jvm/java-1.7.0/bin/java
/usr/lib/jvm/jre-1.7.0/bin/java
/usr/lib/jvm/java-11.0/bin/java
/usr/lib/jvm/jre-11.0/bin/java
/usr/lib/jvm/java-11-openjdk-amd64
/usr/bin/java

如果系统的以上位置都未安装 JDK,启动时就会报错,这是可以考虑建立软连接:

ln -s /opt/java/jdk1.8.0_231/bin/java /usr/bin/java

yum 在线安装 Jenkins

wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
yum install jenkins

还可以实现在线更新

yum update jenkins
## 安装后需要重启jenkins
systemctl restart jenkins

Jenkins 国内环境 插件下载加速

  • 1.第一步 修改配置
    打开地址:http://xxx/pluginManager/advanced
    修改原升级站点:https://updates.jenkins.io/update-center.json
    改为:https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json
  • 2.第二步 修改默认配置json文件 /var/lib/jenkins/updates/default.json
    替换所有插件下载的url
cd /var/lib/jenkins/updates
sed -i 's/http:\/\/updates.jenkins-ci.org\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g' default.json

替换连接测试url

sed -i 's/http:\/\/www.google.com/https:\/\/www.baidu.com/g' default.json
  • 3.重启jenkins
http://xxx/restart

jenkins占用内存较大问题

为了解决此问题,打开/etc/init.d/jenkins找到JENKINS_JAVA_OPTIONS

修改成或新增:

JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -Xms256m -Xmx512m -XX:MaxNewSize=256m -XX:MaxPermSize=256m"