Linux环境下Jenkins简单搭建步骤
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux环境下Jenkins简单搭建步骤相关的知识,希望对你有一定的参考价值。
简介
Jenkins是一个开源软件项目,旨在提供一个开放易用的软件平台,使软件的持续集成变成可能。这是一款基于Java开发的工具。
种种原因,最近刚开始接触,决定研究一下。Jenkins的搭建方法不止一种,一下就是个人总结的其中一种,文章内容比较浅显,不足之处,欢迎指正。
JDK下载地址应该不用说了,相信你肯定能搜到。
Maven下载地址 http://maven.apache.org/download.cgi
安装软件如下:
jdk-8u131-linux-x64.tar.gz
apache-maven-3.5.0-bin.tar.gz
环境:
[[email protected] ]# uname -a
Linux node02.cn 2.6.32-642.el6.x86_64 # 17:27:01 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[[email protected] jdk]# free -m
total used free shared buffers cached
Mem: 1861 511 1350 0 10 356
-/+ buffers/cache: 143 1717
Swap: 1023 0 1023
[[email protected] ]#
[[email protected] ~]# service iptables stop 或者 systemctl stop firewalld [ OK ]
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
[[email protected] ~]# setenforce 0
[[email protected] ~]#
一、配置JDK
[[email protected] jdk]# pwd
/data/jdk
[[email protected] jdk]# ls
jdk-8u131-linux-x64.tar.gz
解压JDK安装包:
[[email protected] jdk]# tar zxvf jdk-8u131-linux-x64.tar.gz
[[email protected] jdk]# ls
jdk1.8.0_131 jdk-8u131-linux-x64.tar.gz
[[email protected] jdk]# cd jdk1.8.0_131/
[[email protected] jdk1.8.0_131]# pwd
/data/jdk/jdk1.8.0_131
[[email protected] 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
[[email protected] jdk1.8.0_131]#
创建环境变量文件:(为了方便维护,在下创建某个应用的环境变量文件)
[[email protected] jdk1.8.0_131]# vim /etc/profile.d/java-jdk.sh
[[email protected] 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生效一下:
[[email protected] jdk1.8.0_131]# source !$
source /etc/profile.d/java-jdk.sh
测试JAVA环境:
[[email protected] 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)
[[email protected] jdk1.8.0_131]#
二、配置Maven
[[email protected] maven]# pwd
/data/maven
[[email protected] maven]# ls
apache-maven-3.5.0-bin.tar.gz
解压:
[[email protected] maven]# tar zxvf apache-maven-3.5.0-bin.tar.gz ^C
[[email protected] maven]# ls
apache-maven-3.5.0 apache-maven-3.5.0-bin.tar.gz
[[email protected] maven]# cd apache-maven-3.5.0
[[email protected] apache-maven-3.5.0]# ls
bin boot conf lib LICENSE NOTICE README.txt
配置并生效环境变量:
[[email protected] apache-maven-3.5.0]# vim /etc/profile.d/maven.sh
[[email protected] apache-maven-3.5.0]# source !$
source /etc/profile.d/maven.sh
[[email protected] 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
[[email protected] apache-maven-3.5.0]#
测试:
[[email protected] 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"
[[email protected] apache-maven-3.5.0]#
配置成功!
三、安装Jenkins:
[[email protected] ~]# wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/RedHat/jenkins.repo
[[email protected] ~]# rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
[[email protected] ~]# yum clean all
[[email protected] ~]# yum install jenkins
[[email protected] ~]#
配置Jenkins:
修改Jenkins的配置文件
[[email protected] ~]# 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的服务脚本
[[email protected] ~]# 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服务:
[[email protected] ~]# service jenkins start
Starting Jenkins [ OK ]
[[email protected] ~]#
访问测试一下吧:
开始界面提示密码生成位置:
[[email protected] ~]# cat /var/lib/jenkins/secrets/initialAdminPassword
粘贴到输入框内即可
接下来,选择建议插件安装:
开始安装插件:
安装完成后,会提示创建用户:
欢迎界面:
接下来就可以创建任务了:
以上是关于Linux环境下Jenkins简单搭建步骤的主要内容,如果未能解决你的问题,请参考以下文章