Jenkins 及插件安装配置
Jenkins 是一个开源软件项目,旨在提供一个开放易用的软件平台,使持续集成变成可能。
Jenkins是基于Java开发的一种持续集成工具,用于监控持续重复的工作,功能包括:
1、持续的软件版本发布/测试项目。
2、监控外部调用执行的工作。
Jenkins 安装
下载war包: download jenkins.war
官方安装教程: Installing Jenkins (推荐)
官方安装步骤(系统级安装,不推荐)
Installation
Add the Jenkins repository to the yum repos, and install Jenkins from here.
- sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
- sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key
- sudo yum install jenkins
Installation of a stable version(稳定版)
There is also a LTS YUM repository for LTS Release Line
- sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo
- sudo rpm --import http://pkg.jenkins-ci.org/redhat-stable/jenkins-ci.org.key
- sudo yum install jenkins
Installation of Java
Jenkins requires Java in order to run, yet certain Fedora-based distros don't include this by default. To install the Open Java Development Kit (OpenJDK) run the following:
sudo yum install java
ln -s /etc/alternatives/java /usr/bin/java # 自定义软链接java路径
必须安装 openJDK
首先保证系统中已经安装了jdk,最好是jdk1.5以上,java必须是openJDK
安装 openJDK
sudo yum -y install java 或者 sudo yum install -y java-1.8.0-openjdk*
安装的openJDK默认的java路径:
# ll /etc/alternatives/java
lrwxrwxrwx 1 root root 46 May 7 21:05 /etc/alternatives/java -> /usr/lib/jvm/jre-1.8.0-openjdk.x86_64/bin/java
# /etc/alternatives/java -version openjdk version "1.8.0_131" OpenJDK Runtime Environment (build 1.8.0_131-b11) OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)
建立 java 软连接(必须建立):
ln -s /etc/alternatives/java /usr/bin/java
Start/Stop
- sudo service jenkins start/stop/restart
- sudo chkconfig jenkins on
Note: if you get the following error message, ensure that Java has been installed:
Starting jenkins (via systemctl): Job for jenkins.service failed. See 'systemctl status jenkins.service' and 'journalctl -xn' for details. [FAILED]
jenkins 启动运行后:
# ps -ef | grep jenkins
jenkins 13549 1 4 17:45 ? 00:00:06 /usr/bin/java -Dcom.sun.akuma.Daemon=daemonized -Djava.awt.headless=true -DJENKINS_HOME=/var/lib/jenkins -jar /usr/lib/jenkins/jenkins.war --logfile=/var/log/jenkins/jenkins.log --webroot=/var/cache/jenkins/war --daemon --httpPort=8080 --debug=5 --handlerCountMax=100 --handlerCountMaxIdle=20
Jenkins 用 Apache 运行
Running Jenkins behind Apache (强烈推荐)
# Jenkins Proxy <VirtualHost *:80> ServerName jenkins.mimvp.com ProxyRequests Off ProxyPreserveHost On AllowEncodedSlashes NoDecode <Proxy http://localhost:8080/jenkins> Order deny,allow Allow from all </Proxy> # ProxyPass /jenkins http://localhost:8080/jenkins/ nocanon # ProxyPassReverse /jenkins http://localhost:8080/jenkins/ ProxyPass / http://localhost:8080/ nocanon ProxyPassReverse / http://localhost:8080/ ErrorLog /var/log/jenkins.mimvp.com-error_log CustomLog /var/log/jenkins.mimvp.com-access_log common </VirtualHost>
上面配置的两种ProxyPass方式都是正确的,使用反向代理用Apache作为Web服务器。
安装小结(重要)
jenkins 版本: 2.58
java 版本: openjdk version "1.8.0_131"
Apache 访问域名: jenkins.mimvp.com
Apache 日志: /var/log/jenkins.mimvp.com-error_log
Jenkins 日志: /var/log/jenkins/jenkins.log
Jenkins 启动: service jenkins start/stop/restart 或 /etc/init.d/start / stop / restart
Jenkins 开机启动: chkconfig jenkins on
安装好 jenkins + openJDK + Apache反向代理后
访问jenkins网页:http://jenkins.mimvp.com
上图中,初次访问jenkins需要读取日志里的密码并验证,读取并输入以下文件中的密码:
# cat /var/lib/jenkins/secrets/initialAdminPassword // 存储密码的日志
33b2f61235fd49a8aafa21e7c5ca2e7a // 密码
输入验证密码后,继续配置:
配置完后,第一次登陆会提示错误:
这里,仍然要用日志中的密码进行登陆才行:
# cat /var/lib/jenkins/secrets/initialAdminPassword // 存储密码的日志
33b2f61235fd49a8aafa21e7c5ca2e7a // 密码
然后,正常登陆后,可以修改超级管理员的密码,添加新用户等
全部设置完毕后,正常的jenkins界面如下:
Jenkis 手动启动方法
启动Jenkins方法如下:
第一种方法
切换到jenkins.war存放的目录,输入如下命令:
$ java -jar jenkins.war // 默认端口为 8080
或者指定端口,如下:
$ java -jar jenkins.war --httpPort=80 // 指定端口为 80
然后在浏览器中(推荐用火狐)输入:http://localhost:8080
localhost可以是本机的ip,也可以是计算机名,就可以打开jenkins
第二种方法(推荐)
将jenkins.war文件放入tomcat下的webapps目录下
启动tomcat,启动命令: /opt/apache-tomcat-7.0.54/bin/startup.sh
启动tomcat服务后,jenkins.war包会自动解压在webapps目录下建立jenkins目录
在浏览器输入: http://115.129.235.128:8080/jenkins/
即可访问,安装成功!
Jenkins 安装后的目录
Jenkins安装后的目录,默认在用户的 ~/.jenkins/ 根目录下
ll ~/.jenkins/
[root@ithomer ~]# ll ~/.jenkins/ total 60 -rw-r--r-- 1 root root 1423 Jan 22 01:10 config.xml -rw-r--r-- 1 root root 21 Jan 22 00:58 Fingerprint cleanup.log -rw-r--r-- 1 root root 159 Jan 22 00:58 hudson.model.UpdateCenter.xml -rw------- 1 root root 1680 Jan 21 23:46 identity.key.enc -rw-r--r-- 1 root root 169 Jan 22 01:10 jenkins.security.QueueItemAuthenticatorConfiguration.xml drwxr-xr-x 3 root root 4096 Jan 21 23:51 jobs -rw-r--r-- 1 root root 907 Jan 22 00:58 nodeMonitors.xml drwxr-xr-x 20 root root 4096 Jan 21 23:46 plugins -rw-r--r-- 1 root root 46 Jan 22 00:57 queue.xml.bak -rw-r--r-- 1 root root 64 Jan 21 23:46 secret.key -rw-r--r-- 1 root root 0 Jan 21 23:46 secret.key.not-so-secret drwxr-xr-x 4 root root 4096 Jan 22 00:07 secrets drwxr-xr-x 2 root root 4096 Jan 21 23:50 updates drwxr-xr-x 2 root root 4096 Jan 21 23:46 userContent drwxr-xr-x 3 root root 4096 Jan 22 00:05 users -rw-r--r-- 1 root root 21 Jan 22 09:28 Workspace clean-up.log
问题与解决
问题1: 无权限访问,错误信息如下:
Access Denied
mimvp is missing the Overall/Read permission
解决:
删除 ~/.jenkins/config.xml 和 ~/.jenkins/user
[root@ithomer jenkins]# rm -rf ~/.jenkins/config.xml
[root@ithomer jenkins]# rm -rf ~/.jenkins/user
然后,重启jenkins 或 tomcat,命令如下:
/opt/apache-tomcat-7.0.54/bin/shutdown.sh
/opt/apache-tomcat-7.0.54/bin/startup.sh
问题2: 修改 server : Apache-Coyote/1.1
解决: 修改 conf/server.xml,添加下面红色部分
vim /opt/apache-tomcat-7.0.54/conf/server.xml
<Connector port="8280" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
server="MIServer" />
问题3: 配置 tomcat 域名
解决: 添加如下配置项
<Host name="jenkins.mimvp.com" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false" >
<Context docBase="jenkins" path="" debug="0" reloadable="true" />
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
说明:
name="jenkins.mimvp.com" // 为域名
appBase="webapps" // 为 war 放置的目录下
docBase="jenkins" // 为 war 解压后的文件夹
如果需要直接用域名(jenkins.mimvp.com)访问,还需要修改端口号 8080 为 80,修改如下:
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
server="MIServer" />
参考推荐:
持续集成环境maven+nexus+jenkins+svn搭建
版权所有: 本文系米扑博客原创、转载、摘录,或修订后发表,最后更新于 2024-08-08 16:19:28
侵权处理: 本个人博客,不盈利,若侵犯了您的作品权,请联系博主删除,莫恶意,索钱财,感谢!
转载注明: Jenkins 及插件安装配置 (米扑博客)