Jenkins持续集成-安装
文章目录
Jenkins持续集成-安装
1.Jenkins简介
Jenkins是一个开源的软件项目,是基于java开发的一种持续集成工具,用于监控持续重复的工作,旨在提供一个开放易用的软件平台,使软件的持续集成变成可能。
- 持续的软件版本发布/测试项目
- 监控外部调用执行的工作
2.环境准备
2.1.Java安装
安装jenkins前确保您的电脑已经配置好JDK
JDK下载地址:https://www.oracle.com/technetwork/java/javase/downloads/jdk11-downloads-5066655.html
安装包文件上传到服务器解压 编辑/etc/profile文件添加Java环境。 配置内容参下面示例内容。
2.2.maven安装
安装包文件上传到服务器解压 编辑/etc/profile文件添加maven环境。
修改 /etc/profile 文件,文件末尾添加如下配置,根据个人软件包安装位置调整
# java
#export JAVA_HOME=/usr/local/java/jdk1.8.0_221
export JAVA_HOME=/usr/local/java/jdk-11.0.8
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
#maven
export MAVEN_HOME=/usr/local/java/apache-maven-3.6.1
export PATH=${MAVEN_HOME}/bin:${PATH}
保存后 source /etc/profile 使环境变量生效
2.3.git安装
# 安装
yum install -y git
# 查看版本
git version
# git version 1.8.3.1
2.4.环境验证
验证Java和maven是否安装成功
[root@VM-12-5-centos ~]# java -version
java version "11.0.8" 2020-07-14 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.8+10-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.8+10-LTS, mixed mode)
[root@VM-12-5-centos ~]# mvn -version
Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-05T03:00:29+08:00)
Maven home: /usr/local/java/apache-maven-3.6.1
Java version: 11.0.8, vendor: Oracle Corporation, runtime: /usr/local/java/jdk-11.0.8
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-1160.11.1.el7.x86_64", arch: "amd64", family: "unix"
[root@VM-12-5-centos ~]# git version
git version 2.31.1
3.Jenkins安装
下载好jenkins安装包
jenkins下载地:https://jenkins.io/
3.1.war包方式运行jenkins
Jenkins官网:https://jenkins.io/download/
3.2.yum方式安装
- 下载依赖
wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
- 导入秘钥
rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
- 安装
yum install jenkins
- 查看安装目录信息
rpm -ql jenkins
- jenkins相关目录释义:
/usr/lib/jenkins/ jenkins安装目录,war包会放在这里。
/etc/sysconfig/jenkins jenkins配置文件,“端口”,“JENKINS_HOME”等都可以在这里配置。
/var/lib/jenkins/ 默认的JENKINS_HOME。
/var/log/jenkins/jenkins.log jenkins日志文件。
- 修改jenkins端口,默认使用8080可能被占用
vi /etc/sysconfig/jenkins
JENKINS_PORT=”9080”
- 设置开机自启动
chkconfig jenkins on
- 启动Jenkins
service jenkins start
- 启动报错,如果启动成功忽略测问题。
查看错误日志:
journalctl -xe
关键错误信息提示为Java路径不对,不是我们安装的路径
-- Unit jenkins.service has begun starting up.
May 31 10:20:25 VM-12-5-centos runuser[25055]: pam_unix(runuser:session): session opened for user jenkins by (uid=0)
May 31 10:20:25 VM-12-5-centos jenkins[25050]: Starting Jenkins bash: /usr/bin/java: No such file or directory
May 31 10:20:25 VM-12-5-centos runuser[25055]: pam_unix(runuser:session): session closed for user jenkins
May 31 10:20:25 VM-12-5-centos systemd[1]: jenkins.service: control process exited, code=exited status=1
May 31 10:20:25 VM-12-5-centos jenkins[25050]: [FAILED]
May 31 10:20:25 VM-12-5-centos systemd[1]: Failed to start LSB: Jenkins Automation Server.
查看我们系统安装的Java环境路径:
[root@VM-12-5-centos ~]# which java
/usr/local/java/jdk-11.0.8/bin/java
- 修改Jenkins启动配置文件,指定java安装路径
vi /etc/init.d/jenkins
找到 candidates=”
在下面添加我们的Java环境路径,添加后效果
# Search usable Java as /usr/bin/java might not point to minimal version required by Jenkins.
# see http://www.nabble.com/guinea-pigs-wanted-----Hudson-RPM-for-RedHat-Linux-td25673707.html
candidates="
/usr/local/java/jdk-11.0.8/bin/java
/etc/alternatives/java
/usr/lib/jvm/java-1.8.0/bin/java
/usr/lib/jvm/jre-1.8.0/bin/java
/usr/lib/jvm/java-11.0/bin/java
/usr/lib/jvm/jre-11.0/bin/java
/usr/lib/jvm/java-11-openjdk-amd64
/usr/bin/java
/usr/local/java/jdk-11.0.8/bin/java 这一行是我们添加的内容
- 再次启动Jenkins
[root@VM-12-5-centos ~]# systemctl start jenkins
Warning: jenkins.service changed on disk. Run 'systemctl daemon-reload' to reload units.
上面启动有一个warning
- 执行去除warning命令
systemctl daemon-reload
- 查看jenkins运行状态
[root@VM-12-5-centos ~]# systemctl status jenkins
● jenkins.service - LSB: Jenkins Automation Server
Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled)
Active: active (running) since Mon 2021-05-31 10:22:49 CST; 10min ago
Docs: man:systemd-sysv-generator(8)
CGroup: /system.slice/jenkins.service
└─25596 /usr/local/java/jdk-11.0.8/bin/java -Dcom.sun.akuma.Daemon=daemonized -Djava.awt.headless=true -DJENKINS_HOME=/var/lib/jenkins -jar /usr/lib/jenkins/jenkins.war --logf...
May 31 10:22:48 VM-12-5-centos systemd[1]: Starting LSB: Jenkins Automation Server...
May 31 10:22:48 VM-12-5-centos runuser[25575]: pam_unix(runuser:session): session opened for user jenkins by (uid=0)
May 31 10:22:49 VM-12-5-centos systemd[1]: Started LSB: Jenkins Automation Server.
May 31 10:22:49 VM-12-5-centos jenkins[25570]: Starting Jenkins [ OK ]
- 浏览器访问安装界面
浏览器输入服务器IP:8080,如果有修改端口则是修改后的端口
查看管理员密码:
[root@VM-12-5-centos ~]# cat /var/lib/jenkins/secrets/initialAdminPassword
cb54efc98a0a41bb8ec751da31465730
安装推荐的插件配置即可 install suggested plugins. 插件安装过程可能比较缓慢
保存示例 默认即可 安装成功
评论