jenkins rpm包安装

itwxming 2020-05-04

一、环境说明

jenkins依赖java环境,启动jenkins要安装jdk
1.此次安装采用rpm包方式安装,版本为jenkins-2.234-1.1
2.jdk版本为: jdk-8u51-linux-x64.tar.gz
3.jenkins要结合mvn用,版本为:apache-maven-3.6.3-bin.tar.gz
4.jenkins安装完成后以root方式启动
5.服务器系统为centos7.6 X86_64位,关闭selinx ,开启iptables

二、jenkins具体安装过程

2.1安装jdk

[ soft]# tar xf /data/soft/jdk-8u51-linux-x64.tar.gz -C /usr/local/
[ soft]# cd /usr/local/
[ local]# ln -sv jdk1.8.0_51 jdk
"jdk" -> "jdk1.8.0_51"

2.2安装maven

[ ~]# tar xf /data/soft/apache-maven-3.6.3-bin.tar.gz -C /usr/local/
[ ~]# ln -sv /usr/local/apache-maven-3.6.3 /usr/local/maven
"/usr/local/maven" -> "/usr/local/apache-maven-3.6.3"

2.3添加环境变量:

[ ~]# tail -7 /etc/profile
export MAVEN_HOME=/usr/local/maven
export JAVA_HOME=/usr/local/jdk
export JRE_HOME=/usr/local/jdk/jre
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH
[ ~]# source /etc/profile
[ ~]# which java
/usr/local/jdk/bin/java
[ ~]# which mvn
/usr/local/maven/bin/mvn
[ ~]# mvn -v
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/maven
Java version: 1.8.0_51, vendor: Oracle Corporation, runtime: /usr/local/jdk1.8.0_51/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-957.el7.x86_64", arch: "amd64", family: "unix"

[ ~]# java -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)

2.4 jenkins rpm包安装

rpm包下载地址:
https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/
插件下载地址如下:
http://mirror.serverion.com/jenkins/plugins/

[ soft]# wget -P /data/soft/  https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/jenkins-2.222.3-1.1.noarch.rpm

[ soft]# rpm -ivh /data/soft/jenkins-2.234-1.1.noarch.rpm 
警告:/data/soft/jenkins-2.234-1.1.noarch.rpm: 头V4 RSA/SHA512 Signature, 密钥 ID 45f2c3d5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:jenkins-2.234-1.1                ################################# [100%]

2.5准备jenkins配置文件

cp /etc/sysconfig/jenkins /etc/sysconfig/jenkins.ori
[ data]# cat /etc/sysconfig/jenkins
JENKINS_HOME="/data/jenkins"
JENKINS_JAVA_CMD="/usr/local/jdk/bin/java"
JENKINS_USER="root"
JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -Duser.timezone=Asia/Shanghai -Djava.util.logging.config.file=/etc/sysconfig/jenkins.logging.properties"
JENKINS_PORT="55266"

2.6启动jenkins服务并让jenkins开机自启动:

[ ~]# /etc/init.d/jenkins start
Starting jenkins (via systemctl):                          [  确定  ]
[ ~]# chkconfig jenkins on
或者:
[ soft]# systemctl enable jenkins.service 
jenkins.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig jenkins on

[ ~]# chkconfig --list|grep jenkins

注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。 

      要列出 systemd 服务,请执行 ‘systemctl list-unit-files‘。
      查看在具体 target 启用的服务请执行
      ‘systemctl list-dependencies [target]‘。

jenkins         0:关 1:关 2:开 3:开 4:开 5:开 6:关

jenkins服务已经启动:

[ ~]# ss -lntup|grep java
tcp    LISTEN     0      50       :::55266                :::*                   users:(("java",pid=24246,fd=161))
[ ~]# ps -ef|grep jenkins
root     24246     1 24 19:07 ?        00:00:26 /usr/local/jdk/bin/java -Dcom.sun.akuma.Daemon=daemonized -Djava.awt.headless=true -Duser.timezone=Asia/Shanghai -Djava.util.logging.config.file=/etc/sysconfig/jenkins.logging.properties -DJENKINS_HOME=/data/jenkins -jar /usr/lib/jenkins/jenkins.war --logfile=/var/log/jenkins/jenkins.log --webroot=/var/cache/jenkins/war --daemon --httpPort=55266
root     24931 11970  0 19:09 pts/2    00:00:00 grep --color jenkins
[ ~]#

2.7解锁Jenkins

浏览器访问:http://21.110.16.39:55266/
jenkins rpm包安装

提示:到这里,先不急着去输入密码,我们可以在这里先把插件源换掉,这样可以加快后续安装插件的速度,失败的机率大大降低,也不会再初始化部分卡好久 我曾经卡过1个多小时

2.8替换jenkins插件源地址

修改hudson.model.UpdateCenter.xml 文件中https为http:

[ updates]# cat /data/jenkins/hudson.model.UpdateCenter.xml 
<?xml version=‘1.1‘ encoding=‘UTF-8‘?>
<sites>
  <site>
    <id>default</id>
    <url>http://updates.jenkins.io/update-center.json</url>
  </site>

重启jenkins服务:

systemctl stop jenkins
systemctl start jenkins

/data/jenkins下面会生成updates文件:

[ jenkins]# ll /data/jenkins/updates/
总用量 1900
-rw-r--r-- 1 root root 1936882 5月   4 08:33 default.json
-rw-r--r-- 1 root root    5350 5月   4 08:33 hudson.tasks.Maven.MavenInstaller

要是没有生成updates文件夹的话,修改/data/jenkins/hudson.model.UpdateCenter.xml 也就是 修改默认Jenkins插件源与连接检测位置:

sed -i "s/http:\/\/updates.jenkins.io\/update-center.json/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins\/updates\/update-center.json/g" /data/jenkins/hudson.model.UpdateCenter.xml

要是修改完地址还没生成updates目录的话,可以尝试重启下jenkins服务试下:
systemctl restart jenkins

如果提示/data/jenkins/updates/default.json不存在,那么可能是你的网络连不到Jenkins官方仓库上,是不会生成updates目录的,解决方式也简单
执行如下命令,重启Jenkins,再查看updates文件夹是否生成

sed -i "s/http:\/\/updates.jenkins.io\/update-center.json/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins\/updates\/update-center.json/g" /data/jenkins/hudson.model.UpdateCenter.xml

重启jenkins服务,经测试,updates目录没有生成的话,主要还是你的网络连不到Jenkins官方仓库上。需要多次尝试重启下jenkins服务

如果/data/jenkins/updates/default.json文件生成了,则执行下面的命令替换掉默认的下载源:

sed -i ‘s/http:\/\/updates.jenkins-ci.org\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g‘ /data/jenkins/updates/default.json
sed -i ‘s/http:\/\/www.google.com/http:\/\/www.baidu.com/g‘ /data/jenkins/updates/default.json
systemctl stop jenkins
systemctl start jenkins

2.9正常替换掉下载源地址注册jenkins服务

jenkins rpm包安装
从服务器找到密码文件输入密码
jenkins rpm包安装
jenkins rpm包安装
jenkins rpm包安装
jenkins rpm包安装

输入管理员账户和密码登录
jenkins rpm包安装

提示:要是/data/jenkins/updates/default.json文件一直没生成的话,浏览器访问链接进行注册jenkins服务时会一直提示离线安装的
截图如下:

三、安装注册总结

Jenkins所谓的update site换源没什么用,每次在初次安装jenkins以及在jenkins安装完成后安装所需插件时,都要等好久,或者经常安装失败。
最终的解决办法如下:
换成清华源的同时,也要同时把下载插件包的地址也要换成清华的下载源,具体需要修改的配置文件:

[ ~]# cat /data/jenkins/hudson.model.UpdateCenter.xml 
<?xml version=‘1.1‘ encoding=‘UTF-8‘?>
<sites>
  <site>
    <id>default</id>
    <url>https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json</url>
  </site>

sed -i ‘s/http:\/\/updates.jenkins-ci.org\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g‘ /data/jenkins/updates/default.json
sed -i ‘s/http:\/\/www.google.com/http:\/\/www.baidu.com/g‘ /data/jenkins/updates/default.json
systemctl restart jenkins

采用如上方式,比原先安装要快好多。

相关推荐