Jenkins离线部署
Jenkins离线部署
安装jdk
# 查询是否安装过JDK
rpm -qa|grep jdk
# 如已安装且版本不合适,根据查询结果进行卸载
yum -y remove xxx
# 安装jdk
rpm -ivh jdk-8u281-linux-x64.rpm
安装git
离线安装git比较复杂,需要进行源码编译,编译过程中有其他依赖,如果不存在会编译失败,因此需要事先将git的依赖包安装之后再进行源码编译,操作步骤如下:
-
先在一台有网络的服务器上将git依赖包全部下载下来然后传到离线环境
yumdownloader zlib-devel openssl-devel perl cpio expat-devel gettext-devel openssl zlib curl autoconf tk perl-ExtUtils-MakeMaker --resolve
-
在离线环境执行以下命令强制安装所有rpm包
rpm -ivh *.rpm --force --nodeps
-
从git下载源码包,地址:https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.8.4.tar.gz ,然后编译
tar -zvxf git-2.8.4.tar.gz cd git-2.8.4 ./configure --prefix=/usr/local/git make && make install
-
配置环境变量
vim /etc/profile # 下面这句加入文件中 export PATH=$PATH:/usr/local/git/bin # 环境变量立即生效 source /etc/profile # 查询git版本进行测试 git --version
安装maven
从官网下载压缩包apache-maven-3.8.1-bin.tar.gz
# 解压至/usr/local/下
tar -zvxf apache-maven-3.8.1-bin.tar.gz -C /usr/local/maven/
# 配置环境变量
vim /etc/profile
# 在文件最下方加入以下内容
export MAVEN_HOME=/usr/local/maven
export PATH=$PATH:$MAVEN_HOME/bin
# 让修改立即生效
source /etc/profile
安装jenkins
-
rpm安装
rpm -ivh jenkins-2.277.1-1.1.noarch.rpm
安装后默认Jenkins主目录为
/var/lib/jenkins
,可在/etc/sysconfig/jenkins
中修改 -
查询Jenkins安装的文件
rpm -ql jenkins
输出结果如下:
/etc/init.d/jenkins
/etc/logrotate.d/jenkins
/etc/sysconfig/jenkins
/usr/lib/jenkins
/usr/lib/jenkins/jenkins.war
/usr/sbin/rcjenkins
/var/cache/jenkins
/var/lib/jenkins
/var/log/jenkins -
修改配置文件
配置文件路径
/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="/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: "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 # web端口,根据需要修改 JENKINS_PORT="8001" ## Type: string ## Default: "" ## ServiceRestart: jenkins # # IP address Jenkins listens on for HTTP requests. # Default is all interfaces (0.0.0.0). # JENKINS_LISTEN_ADDRESS="" ## Type: integer(0:65535) ## Default: "" ## ServiceRestart: jenkins # # HTTPS port Jenkins is listening on. # Default is disabled. # JENKINS_HTTPS_PORT="" ## Type: string ## Default: "" ## ServiceRestart: jenkins # # Path to the keystore in JKS format (as created by the JDK 'keytool'). # Default is disabled. # JENKINS_HTTPS_KEYSTORE="" ## Type: string ## Default: "" ## ServiceRestart: jenkins # # Password to access the keystore defined in JENKINS_HTTPS_KEYSTORE. # Default is disabled. # JENKINS_HTTPS_KEYSTORE_PASSWORD="" ## Type: string ## Default: "" ## ServiceRestart: jenkins # # IP address Jenkins listens on for HTTPS requests. # Default is disabled. # JENKINS_HTTPS_LISTEN_ADDRESS="" ## Type: integer(0:65535) ## Default: "" ## ServiceRestart: jenkins # # HTTP2 port Jenkins is listening on. # Default is disabled. # # Notice: HTTP2 support may require additional configuration, see Winstone # documentation for more information. # JENKINS_HTTP2_PORT="" ## Type: string ## Default: "" ## ServiceRestart: jenkins # # IP address Jenkins listens on for HTTP2 requests. # Default is disabled. # # Notice: HTTP2 support may require additional configuration, see Winstone # documentation for more information. # JENKINS_HTTP2_LISTEN_ADDRESS="" ## 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 # # Folder for additional jar files to add to the Jetty class loader. # See Winstone documentation for more information. # Default is disabled. # JENKINS_EXTRA_LIB_FOLDER="" ## Type: string ## Default: "" ## ServiceRestart: jenkins # # Pass arbitrary arguments to Jenkins. # Full option list: java -jar jenkins.war --help # JENKINS_ARGS="--prefix=/jenkins"
-
配置jdk
如果是安装的编译好的jdk,jenkins会找不到jdk,需要手动指定,修改配置文件:
/etc/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 candidates=" /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 # 在此处指定安装的jdk路径,指定到java命令处eg:/usr/local/jdk1.8/bin/java "
-
开启Jenkins服务
systemctl start jenkins
-
浏览器中输入ip和port打开jenkins界面
出于安全考虑,首次启动Jenkins需要进行解锁,解锁密码在/var/lib/jenkins/secrets/initialAdminPassword中
选择插件步骤直接跳过,因为是离线环境,无法直接下载插件,后续插件需要手动安装
环境配置
-
配置JDK
管理Jenkins->Global Tool Configuration->JDK
-
配置MAVEN
管理Jenkins->Global Tool Configuration->Maven配置
管理Jenkins->Global Tool Configuration->Maven
-
配置Git
管理Jenkins->Global Tool Configuration->Git