Linux(centos6.5)下安装jenkins
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux(centos6.5)下安装jenkins相关的知识,希望对你有一定的参考价值。
Jenkins 的前身是 Hudson 是一个可扩展的持续集成引擎。
通俗的来讲,jenkins就是一个可以实现自动化部署的一个插件,
对于我来说,也是应用在系统部署上。
废话不多说,直接进入我们的安装步骤吧
1.安装JDK,maven环境搭建
因为考虑到jenkins的实际应用场景,我们需要把这些基础环境先安装完成。
jdk安装比较简单不做赘述,maven环境借用了osc其他大侠的博客内容,
试了下安装成功。
maven官网下载安装包:http://maven.apache.org/download.cgi
自己根据需求下载版本,这里作者选择的是3.1.1版本。
1.把apache-maven-3.1.1-bin.tar.gz传到服务器上,
解压:
tar -zvxf apache-maven-3.1.1-bin.tar.gz
移至/usr/local下:
1
|
mv apache-maven-3.1.1 /usr/local |
配置环境变量
1
|
vi /etc/profile |
在文件中加入
1
2
|
export MAVEN_HOME= /usr/local/apache-maven-3 .1.1 export PATH=$PATH:$MAVEN_HOME /bin |
重新编译文件
1
|
source /etc/profile |
验证maven是否安装成功
1
|
mvn --version |
控制台显示如下:
Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 23:22:22+0800)
Maven home: /usr/local/apache-maven-3.1.1
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home: /usr/java/jdk1.7.0_25/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "2.6.32-358.6.2.el6.x86_64", arch: "amd64", family: "unix"
表示安装成功。
2.安装jenkins
1
2
3
|
wget -O /etc/yum .repos.d /jenkins .repo http: //pkg .jenkins-ci.org /redhat/jenkins .repo rpm -- import http: //pkg .jenkins-ci.org /redhat/jenkins-ci .org.key yum install jenkins |
一条一条命令执行完成后,jenkins就安装完成了,非常简单吧。
然后需要配置下jenkins的端口,避免冲突。
1
|
vi /etc/sysconfig/jenkins |
进入该文件,这个是jenkins的系统配置文件,
找到2处修改端口号:
JENKINS_PORT="8080"
JENKINS_AJP_PORT="8009"
默认是这样的,我们可以随意修改成自己需要的端口号,避免冲突(tomcat默认端口也是这样的)
这里作者修改成了:
JENKINS_PORT="8888"
JENKINS_AJP_PORT="8889"
接下来我们就可以尝试启动jenkins服务了。
1
|
service jenkins start |
如果提示:Starting Jenkins [确定]
则表示jenkins服务成功启动,你可以通过http://ip:端口号的方式直接访问jenkins了。
但是一般情况下会报错:
1
2
|
Starting Jenkins bash : /usr/bin/java : 没有那个文件或目录 [失败] |
如果出现该错误也不需要慌张,报这个错的原因是因为你的jdk配置错误,
执行命令:
1
|
java -version |
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
我们可以看到jdk版本为1.7.0_25,复制该名称
1
|
vi /etc/init .d /jenkins |
找到这段代码
1
2
3
4
5
6
7
8
9
|
candidates=" /etc/alternatives/java /usr/lib/jvm/java-1 .6.0 /bin/java /usr/lib/jvm/jre-1 .6.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-1 .8.0 /bin/java /usr/lib/jvm/jre-1 .8.0 /bin/java /usr/bin/java |
我们会发现这里面没有叫1.7.0_25的文件目录
我们在这段代码后面加上
1
|
/usr/java/jdk1 .7.0_25 /bin/java |
效果如下:
1
2
3
4
5
6
7
8
9
10
11
|
candidates=" /etc/alternatives/java /usr/lib/jvm/java-1 .6.0 /bin/java /usr/lib/jvm/jre-1 .6.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-1 .8.0 /bin/java /usr/lib/jvm/jre-1 .8.0 /bin/java /usr/bin/java /usr/java/jdk1 .7.0_25 /bin/java " |
保存退出。重新执行启动命令:
1
|
service jenkins start |
是不是成功了呢?
停止命令:
1
|
service jenkins stop |
重启命令:
1
|
service jenkins restart |
成功启动后,我们就可以通过http://ip:端口号访问了。
到此,jenkins安装就OK了。呵呵
CentOS 上 Jenkins 安装
文章来源:http://www.cnblogs.com/zhangqingsh/archive/2013/03/19/2968998.html
1. 添加Jenkins的源(repository):
$ sudo wget -O /etc/yum.repos.d/jenkins.repo http://jenkins-ci.org/redhat/jenkins.repo
$ sudo rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
2. 安装/检查JDK:
$ java --version
$ sudo yum install java-1.6.0-openjdk
3. 安装Jenkins:
$ sudo yum install jenkins
安装完成后,有如下相关目录:
(3.1)/usr/lib/jenkins/:jenkins安装目录,WAR包会放在这里。
$ cd /usr/lib/jenkins
$ ll
-rw-r--r-- 1 root root 52891723 Feb 27 00:13 jenkins.war
(3.2) /etc/sysconfig/jenkins:jenkins配置文件,“端口”,“JENKINS_HOME”等都可以在这里配置。内容如下:
## Path: Development/Jenkins
## Description: Configuration for the Jenkins continuous build server
## Type: string
## Default: "/var/lib/jenkins"
## ServiceRestart: jenkins
#
# Directory where Jenkins store its configuration and working
# files (checkouts, build reports, artifacts, ...).
#
JENKINS_HOME="/var/lib/jenkins"
## Type: string
## Default: ""
## ServiceRestart: jenkins
#
# Java executable to run Jenkins
# When left empty, we‘ll try to find the suitable Java.
#
JENKINS_JAVA_CMD=""
## Type: string
## Default: "jenkins"
## ServiceRestart: jenkins
#
# Unix user account that runs the Jenkins daemon
# Be careful when you change this, as you need to update
# permissions of $JENKINS_HOME and /var/log/jenkins.
#
JENKINS_USER="jenkins"
## Type: string
## Default: "-Djava.awt.headless=true"
## ServiceRestart: jenkins
#
# Options to pass to java when running Jenkins.
#
JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true"
## Type: integer(0:65535)
## Default: 8080
## ServiceRestart: jenkins
#
# Port Jenkins is listening on.
# Set to -1 to disable
#
JENKINS_PORT="8080"
## Type: integer(0:65535)
## Default: 8009
## ServiceRestart: jenkins
#
# Ajp13 Port Jenkins is listening on.
# Set to -1 to disable
#
JENKINS_AJP_PORT="8009"
## Type: integer(1:9)
## Default: 5
## ServiceRestart: jenkins
#
# Debug level for logs -- the higher the value, the more verbose.
# 5 is INFO.
#
JENKINS_DEBUG_LEVEL="5"
## Type: yesno
## Default: no
## ServiceRestart: jenkins
#
# Whether to enable access logging or not.
#
JENKINS_ENABLE_ACCESS_LOG="no"
## Type: integer
## Default: 100
## ServiceRestart: jenkins
#
# Maximum number of HTTP worker threads.
#
JENKINS_HANDLER_MAX="100"
## Type: integer
## Default: 20
## ServiceRestart: jenkins
#
# Maximum number of idle HTTP worker threads.
#
JENKINS_HANDLER_IDLE="20"
## Type: string
## Default: ""
## ServiceRestart: jenkins
#
# Pass arbitrary arguments to Jenkins.
# Full option list: java -jar jenkins.war --help
#
JENKINS_ARGS=""
(3.3)/var/lib/jenkins/:默认的JENKINS_HOME。目录结构如下:
$ cd /var/lib/jenkins/
$ ls -lst
total 216
4 -rw-r--r-- 1 jenkins jenkins 0 Mar 18 23:59 Fingerprint cleanup.log
4 -rw-r--r-- 1 jenkins jenkins 0 Mar 18 18:54 Workspace clean-up.log
8 drwxr-xr-x 180 jenkins jenkins 4096 Mar 18 17:04 fingerprints
8 -rw-r--r-- 1 jenkins jenkins 1636 Mar 18 16:41 config.xml
8 -rw-r--r-- 1 jenkins jenkins 903 Mar 18 16:41 hudson.maven.MavenModuleSet.xml
8 -rw-r--r-- 1 jenkins jenkins 1122 Mar 18 16:41 hudson.plugins.sonar.SonarPublisher.xml
8 -rw-r--r-- 1 jenkins jenkins 205 Mar 18 16:41 hudson.plugins.sonar.SonarRunnerInstallation.xml
8 -rw-r--r-- 1 jenkins jenkins 196 Mar 18 16:41 hudson.scm.CVSSCM.xml
8 -rw-r--r-- 1 jenkins jenkins 692 Mar 18 16:41 hudson.scm.SubversionSCM.xml
8 -rw-r--r-- 1 jenkins jenkins 145 Mar 18 16:41 hudson.tasks.Ant.xml
8 -rw-r--r-- 1 jenkins jenkins 187 Mar 18 16:41 hudson.tasks.Mailer.xml
8 -rw-r--r-- 1 jenkins jenkins 330 Mar 18 16:41 hudson.tasks.Maven.xml
8 -rw-r--r-- 1 jenkins jenkins 76 Mar 18 16:41 hudson.tasks.Shell.xml
8 -rw-r--r-- 1 jenkins jenkins 215 Mar 18 16:41 hudson.triggers.SCMTrigger.xml
8 -rw-r--r-- 1 jenkins jenkins 264 Mar 18 16:41 jenkins.model.JenkinsLocationConfiguration.xml
8 -rw-r--r-- 1 jenkins jenkins 907 Mar 18 16:29 nodeMonitors.xml
8 -rw-r--r-- 1 jenkins jenkins 159 Mar 18 16:29 hudson.model.UpdateCenter.xml
8 -rw-r--r-- 1 jenkins jenkins 46 Mar 18 16:29 queue.xml.bak
8 drwxr-xr-x 2 jenkins jenkins 4096 Mar 18 16:24 updates
4 -rw-r--r-- 1 jenkins jenkins 0 Mar 16 10:27 Connection Activity monitoring to slaves.log
8 drwxr-xr-x 6 jenkins jenkins 4096 Mar 13 18:24 workspace
8 drwxr-xr-x 13 jenkins jenkins 4096 Mar 13 17:59 jobs
8 drwx------ 2 jenkins jenkins 4096 Feb 28 11:16 secrets
8 -rw-r--r-- 1 jenkins jenkins 165 Feb 27 13:29 sonar.xml
8 drwxr-xr-x 14 jenkins jenkins 4096 Feb 27 13:29 plugins
8 -rw------- 1 jenkins jenkins 1679 Feb 27 12:12 identity.key
8 drwxr-xr-x 2 jenkins jenkins 4096 Feb 27 12:12 userContent
8 -rw-r--r-- 1 jenkins jenkins 64 Feb 27 12:12 secret.key
4 -rw-r--r-- 1 jenkins jenkins 0 Feb 27 12:12 secret.key.not-so-secret
(3.4)/var/log/jenkins/jenkins.log:Jenkins日志文件。
4. 启动Jenkins
$ sudo service jenkins start
有可能出现错误:“Starting Jenkins -bash: /usr/bin/java: No such file or directory”。表示找不到Jenkins找不到java。
这时就需要“vi /etc/init.d/jenkins”,把java路径加上(如下):
64 # Search usable Java. We do this because various reports indicated
65 # that /usr/bin/java may not always point to Java 1.5
66 # see http://www.nabble.com/guinea-pigs-wanted-----Hudson-RPM-for-RedHat-Linux-td25673707.html
67 for candidate in /etc/alternatives/java
/usr/lib/jvm/java-1.6.0/bin/java /usr/lib/jvm/jre-1.6.0/bin/java
/usr/lib/jvm/java-1 .5.0/bin/java /usr/lib/jvm/jre-1.5.0/bin/java /opt/app/jdk1.7.0_09/bin/java
68 do
69 [ -x "$JENKINS_JAVA_CMD" ] && break
70 JENKINS_JAVA_CMD="$candidate"
71 done
5. 登录Jenkins
如果没有特别配置端口,使用http://<ip address>:8080/登录Jenkins,并进行相关配置(插件安装、权限配置、View/Job创建等等)。