离线安装jenkins

最近搭建jenkins集成环境,发现服务器不能连接外网,只能通过离线来安装。那么怎么安装才能“多、快、好、省”呢?
根据官网(https://wiki.jenkins.io/display/JENKINS/Installing+Jenkins+on+Red+Hat+distributions )推荐的centos安装方法是:
1、 设置yum源

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

2、执行yum安装命令

yum install jenkins

3、启动关闭

sudo service jenkins start/stop/restart

4、设置开机自启动

sudo chkconfig jenkins on

那么配置文件在哪里呢?

1、Jenkins will be launched as a daemon on startup. See /etc/init.d/jenkins for more details.
jenkins会以守护进程的方式启动,更多信息,查看文件/etc/init.d/jenkins。
2、The 'jenkins' user is created to run this service. If you change this to a different user via the config file, 
you must change the owner of /var/log/jenkins, /var/lib/jenkins, and /var/cache/jenkins.
用户`jenkins`会被创建,并用此用户来启动服务。如果你想换一个用户启动,需修改/var/log/jenkins, /var/lib/jenkins, 和 /var/cache/jenkins.的权限。
3、Log file will be placed in /var/log/jenkins/jenkins.log. Check this file if you are troubleshooting Jenkins.
如果遇到问题,通过/var/log/jenkins/jenkins.log 文件查阅日志。
4、/etc/sysconfig/jenkins will capture configuration parameters for the launch.
/etc/sysconfig/jenkins是jenkins的配置文件,启动时会被加载、读取。
5、By default, Jenkins listen on port 8080. Access this port with your browser to start configuration.  
Note that the built-in firewall may have to be opened to access this port from other computers. 
 (See http://www.cyberciti.biz/faq/disable-linux-firewall-under-centos-rhel-fedora/ for instructions how to disable the firewall permanently)
 默认情况下,jenkins占用端口是8080,通过访问这个端口,设置你的jenkins配置。注意:从别的电脑访问这个端口时,可能需要开启防火墙权限。
6、A Jenkins RPM repository is added in /etc/yum.repos.d/jenkins.repo
会在 /etc/yum.repos.d/jenkins.repo  添加jenkins RPM仓库。

当然上述安装方法是要服务器支持外网的情况下;如果服务器不支持外网的情况该如何处理呢?

方法一

通过一台能访问外网的服务器,通过上述方法安装配置。毕竟顺利的话,执行三条命令的就能安装完毕,不算麻烦。然后下载对应版本的rpm版本(需与yum安装的版本一致,防止后面插件安装版本不对应)。官方下载地址为:https://pkg.jenkins.io/redhat/
执行命令:

rpm -ivh jenkins.noarch.rpm
方法二

先下载tomcat包,而后下载 jenkins.war包,war包放在tomcat的 webapp 目录下即可。

离线安装插件

以上述第一种yum安装的方法为例:
1、通过浏览器访问能连接外网的jenkins服务,点击安装自己所需要的jenkins插件,在线安装。安装完毕后,在/var/lib/jenkins/plugins目录下会生成安装的插件目录,以及插件安装文件(.jpi 格式)。
2、通过浏览器访问不能连接外网的jenkins服务,点击jenkins --> 系统管理 --> 插件管理 --> 高级 --> 上传插件上传实际所需要的插件。插件文件为jenkins主目录下的plugins目录中(.jpi格式的文件)。安装的时候,如果报错,一般就是缺少依赖插件。此时先安装依赖,再安装目标插件。根据提示,可完成插件的安装。

当然你也可以根据自己的需要直接从官网下载插件离线安装。地址为:http://updates.jenkins-ci.org/download/plugins/ 但是,并不太推荐这种方法,一是下载包麻;二是下载的包版本高了低了可能会引起更大的困扰。