【jenkins系列】centos7下yum安装jenkins

安装

规划目录

jdk版本:oracle jdk8
jenkins目录: /home/jenkins

前置条件

已经安装好jdk版本。

安装jenkins

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

编辑配置文件

vim /etc/sysconfig/jenkins

## Path:        Development/Jenkins
## Description: Jenkins Automation Server
## Type: string
## Default: "/var/lib/jenkins"
## ServiceRestart: jenkins
#
# Directory where Jenkins store its configuration and working
# files (checkouts, build reports, artifacts, ...).
#
JENKINS_HOME="/home/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: "false"
## ServiceRestart: jenkins
#
# Whether to skip potentially long-running chown at the
# $JENKINS_HOME location. Do not enable this, "true", unless
# you know what you're doing. See JENKINS-23273.
#
#JENKINS_INSTALL_SKIP_CHOWN="false"

## 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="48080"

编辑启动文件

vim /etc/rc.d/init.d/jenkins

···

# 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
# 修改java路径
candidates="/data/jdk1.8.0_161/bin/java"

···

# 根据磁盘的情况,修改安装路径
JAVA_CMD="$JENKINS_JAVA_CMD $JENKINS_JAVA_OPTIONS -DJENKINS_HOME=/home/jenkins -jar $JENKINS_WAR"
PARAMS="--logfile=/home/jenkins/log/jenkins.log --webroot=/home/jenkins/war --daemon"

···

重新加载

systemctl daemon-reload

创建目录和授权

cd home/
mkdir jenkins
chown -R jenkins:jenkins jenkins/
ll
cd jenkins/
mv /data/jenkins/jenkins.war .
mkdir log
mkdir war
chown -R jenkins:jenkins jenkins/
cd jenkins/

启动jenkins

不同于传统的systemctl,这里用

service  start jenkins