(1)Jenkins Linux环境下的简单搭建
Jenkins是一个开源软件项目,旨在提供一个开放易用的软件平台,使软件的持续集成变成可能。
----百度百科
这是一款基于Java开发的工具。种种原因,最近刚开始接触,决定研究一下。Jenkins的搭建方法不止一种,一下就是个人总结的其中一种,文章内容比较浅显,不足之处,欢迎指正。
首先,所需要准备的工具JDK、Maven。资料上显示JDK版本最好高于1.7,并没有研究1.7以下版本,所谓“没有实际调研,就没有发言权”,在此就不做过多赘述了。
JDK下载地址应该不用说了,相信你肯定能搜到。
Maven下载地址 http://maven.apache.org/download.cgi
我的工具:
jdk-8u131-linux-x64.tar.gz
apache-maven-3.5.0-bin.tar.gz
环境:
[root@node02 ]# uname -a
Linux node02.cn 2.6.32-642.el6.x86_64 #1 SMP Tue May 10 17:27:01 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
[root@node02 jdk]# free -m
total used free shared buffers cached
Mem: 1861 511 1350 0 10 356
-/+ buffers/cache: 143 1717
Swap: 1023 0 1023
[root@node02 ]#
[root@node02 ~]# service iptables stop
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
[root@node02 ~]# setenforce 0
[root@node02 ~]#
一、配置JDK
[root@node02 jdk]# pwd /data/jdk [root@node02 jdk]# ls jdk-8u131-linux-x64.tar.gz
解压JDK安装包:
[root@node02 jdk]# tar zxvf jdk-8u131-linux-x64.tar.gz
[root@node02 jdk]# ls
jdk1.8.0_131 jdk-8u131-linux-x64.tar.gz
[root@node02 jdk]# cd jdk1.8.0_131/
[root@node02 jdk1.8.0_131]# pwd
/data/jdk/jdk1.8.0_131
[root@node02 jdk1.8.0_131]# ls
bin db javafx-src.zip lib man release THIRDPARTYLICENSEREADME-JAVAFX.txt
COPYRIGHT include jre LICENSE README.html src.zip THIRDPARTYLICENSEREADME.txt
[root@node02 jdk1.8.0_131]#
创建环境变量文件:(为了方便维护,在下创建某个应用的环境变量文件)
[root@node02 jdk1.8.0_131]# vim /etc/profile.d/java-jdk.sh
[root@node02 jdk1.8.0_131]# cat !$
cat /etc/profile.d/java-jdk.sh
export JAVA_HOME=/data/jdk/jdk1.8.0_131
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
保存退出后,用source生效一下:
[root@node02 jdk1.8.0_131]# source !$ source /etc/profile.d/java-jdk.sh
测试JAVA环境:
[root@node02 jdk1.8.0_131]# java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
[root@node02 jdk1.8.0_131]#
二、配置Maven
[root@node02 maven]# pwd /data/maven [root@node02 maven]# ls apache-maven-3.5.0-bin.tar.gz
解压:
[root@node02 maven]# tar zxvf apache-maven-3.5.0-bin.tar.gz ^C
[root@node02 maven]# ls
apache-maven-3.5.0 apache-maven-3.5.0-bin.tar.gz
[root@node02 maven]# cd apache-maven-3.5.0
[root@node02 apache-maven-3.5.0]# ls
bin boot conf lib LICENSE NOTICE README.txt
配置并生效环境变量:
[root@node02 apache-maven-3.5.0]# vim /etc/profile.d/maven.sh
[root@node02 apache-maven-3.5.0]# source !$
source /etc/profile.d/maven.sh
[root@node02 apache-maven-3.5.0]# cat /etc/profile.d/maven.sh
export MAVEN_HOME=/data/maven/apache-maven-3.5.0
export PATH=$MAVEN_HOME/bin:$PATH
[root@node02 apache-maven-3.5.0]#
测试:
[root@node02 apache-maven-3.5.0]# mvn -v
Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-04T03:39:06+08:00)
Maven home: /data/maven/apache-maven-3.5.0
Java version: 1.8.0_131, vendor: Oracle Corporation
Java home: /data/jdk/jdk1.8.0_131/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "2.6.32-642.el6.x86_64", arch: "amd64", family: "unix"
[root@node02 apache-maven-3.5.0]#
配置成功!
三、安装Jenkins:
[root@node02 ~]# wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
[root@node02 ~]# rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
[root@node02 ~]# yum clean all
[root@node02 ~]# yum install jenkins
[root@node02 ~]#
配置Jenkins:
修改Jenkins的配置文件
[root@node02 ~]# vim /etc/sysconfig/jenkins #默认端口是8080
53 # Port Jenkins is listening on.
54 # Set to -1 to disable
55 #
56 JENKINS_PORT="8080"
57
58 ## Type: string
59 ## Default: ""
60 ## ServiceRestart: jenkins
61 #
62 # IP address Jenkins listens on for HTTP requests.
63 # Default is all interfaces (0.0.0.0).
64 #
65 JENKINS_LISTEN_ADDRESS=""
.
修改Jenkins的服务脚本
[root@node02 ~]# vim /etc/init.d/jenkins
.
64 # Search usable Java as /usr/bin/java might not point to minimal version required by Jenkins.
65 # see http://www.nabble.com/guinea-pigs-wanted-----Hudson-RPM-for-RedHat-Linux-td25673707.html
66 candidates="
67 /etc/alternatives/java
68 /usr/lib/jvm/java-1.8.0/bin/java
69 /usr/lib/jvm/jre-1.8.0/bin/java
70 /usr/lib/jvm/java-1.7.0/bin/java
71 /usr/lib/jvm/jre-1.7.0/bin/java
72 /usr/bin/java
73 /data/jdk/jdk1.8.0_131/bin/java #添加内容--指定你的JAVA所在路径
74 "
75 for candidate in $candidates
76 do
77 [ -x "$JENKINS_JAVA_CMD" ] && break
78 JENKINS_JAVA_CMD="$candidate"
.
启动Jenkins服务:
[root@node02 ~]# service jenkins start Starting Jenkins [ OK ] [root@node02 ~]#
访问测试一下吧:
开始界面提示密码生成位置:
[root@node02 ~]# cat /var/lib/jenkins/secrets/initialAdminPassword
粘贴到输入框内即可
接下来,选择建议插件安装:
开始安装插件:
安装完成后,会提示创建用户:
欢迎界面:
接下来就可以创建任务了:
转载于:https://blog.51cto.com/zqsbg/1934314