jenkins rpm package installation

1, Environmental description

jenkins depends on the java environment. To start jenkins, you need to install jdk
1. This installation adopts rpm package, version is jenkins-2.234-1.1
2.jdk version: jdk-8u51-linux-x64.tar.gz
3.jenkins should be used in combination with mvn, version: apache-maven-3.6.3-bin.tar.gz
4. Start Jenkins in root mode after installation
5. The server system is centos7.6 x86 ﹤ 64 bit. Turn off selinx and turn on iptables

2, jenkins specific installation process

2.1 install jdk

[root@jenkins soft]# tar xf /data/soft/jdk-8u51-linux-x64.tar.gz -C /usr/local/
[root@jenkins soft]# cd /usr/local/
[root@jenkins local]# ln -sv jdk1.8.0_51 jdk
"jdk" -> "jdk1.8.0_51"

2.2 installing maven

[root@jenkins ~]# tar xf /data/soft/apache-maven-3.6.3-bin.tar.gz -C /usr/local/
[root@jenkins ~]# ln -sv /usr/local/apache-maven-3.6.3 /usr/local/maven
"/usr/local/maven" -> "/usr/local/apache-maven-3.6.3"

2.3 add environment variables:

[root@jenkins ~]# tail -7 /etc/profile
export MAVEN_HOME=/usr/local/maven
export JAVA_HOME=/usr/local/jdk
export JRE_HOME=/usr/local/jdk/jre
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH
[root@jenkins ~]# source /etc/profile
[root@jenkins ~]# which java
[root@jenkins ~]# which mvn
[root@jenkins ~]# mvn -v
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/maven
Java version: 1.8.0_51, vendor: Oracle Corporation, runtime: /usr/local/jdk1.8.0_51/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-957.el7.x86_64", arch: "amd64", family: "unix"

[root@jenkins ~]# java -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)

2.4 jenkins rpm package installation

rpm package download address:
The plug-in download address is as follows:

[root@jenkins soft]# wget -P /data/soft/

[root@jenkins soft]# rpm -ivh /data/soft/jenkins-2.234-1.1.noarch.rpm 
//Warning / data/soft/jenkins-2.234-1.1.noarch.rpm: head V4 RSA/SHA512 Signature, key ID 45f2c3d5: NOKEY
//Upgrading / installing
   1:jenkins-2.234-1.1                ################################# [100%]

2.5 preparing jenkins configuration file

 cp /etc/sysconfig/jenkins /etc/sysconfig/jenkins.ori
[root@jenkins data]# cat /etc/sysconfig/jenkins
JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -Duser.timezone=Asia/Shanghai -Djava.util.logging.config.file=/etc/sysconfig/"

2.6 start the jenkins service and let jenkins start automatically:

[root@jenkins ~]# /etc/init.d/jenkins start
 Starting jenkins (via systemctl): [OK]
[root@jenkins ~]# chkconfig jenkins on
[root@jenkins soft]# systemctl enable jenkins.service 
jenkins.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig jenkins on

[root@jenkins ~]# chkconfig --list|grep jenkins

Note: this output only shows SysV service, and does not contain
 Native systemd service. SysV configuration data
 May be overridden by native systemd configuration. 

      To list systemd services, execute 'systemctl list unit files'.
      To view the services enabled in the specific target, please execute the
      'systemctl list-dependencies [target]'. 

Jenkins 0: off 1: off 2: on 3: on 4: on 5: on 6: off

jenkins service started:

[root@jenkins ~]# ss -lntup|grep java
tcp    LISTEN     0      50       :::55266                :::*                   users:(("java",pid=24246,fd=161))
[root@jenkins ~]# ps -ef|grep jenkins
root     24246     1 24 19:07 ?        00:00:26 /usr/local/jdk/bin/java -Dcom.sun.akuma.Daemon=daemonized -Djava.awt.headless=true -Duser.timezone=Asia/Shanghai -Djava.util.logging.config.file=/etc/sysconfig/ -DJENKINS_HOME=/data/jenkins -jar /usr/lib/jenkins/jenkins.war --logfile=/var/log/jenkins/jenkins.log --webroot=/var/cache/jenkins/war --daemon --httpPort=55266
root     24931 11970  0 19:09 pts/2    00:00:00 grep --color jenkins
[root@jenkins ~]# 

2.7 unlock Jenkins

Browser access:

Tip: don't rush to enter the password here. We can replace the plug-in source here first, which can speed up the subsequent installation of plug-ins, greatly reduce the probability of failure, and won't initialize some cards for a long time. I used to card for more than an hour

2.8 replace the source address of jenkins plug-in

Modify https in hudson.model.UpdateCenter.xml file to http:

[root@jenkins updates]# cat /data/jenkins/hudson.model.UpdateCenter.xml 
<?xml version='1.1' encoding='UTF-8'?>

Restart jenkins service:

systemctl stop jenkins
systemctl start jenkins

/data/jenkins will generate the updates file as follows:

[root@jenkins jenkins]# ll /data/jenkins/updates/
//Total consumption 1900
-rw-r--r-- 1 root root 1936882 5 April 4, 2008:33 default.json
-rw-r--r-- 1 root root    5350 5 April 4, 2008:33 hudson.tasks.Maven.MavenInstaller

If the updates folder is not generated, modify / data/jenkins/hudson.model.UpdateCenter.xml to modify the default Jenkins plug-in source and connection detection location:

sed -i "s/http:\/\/\/update-center.json/https:\/\/\/jenkins\/updates\/update-center.json/g" /data/jenkins/hudson.model.UpdateCenter.xml

If you haven't generated the updates directory after modifying the address, you can restart the jenkins service and try:
systemctl restart jenkins

If the prompt / data/jenkins/updates/default.json does not exist, then your network may not be connected to the official Jenkins warehouse, and the updates directory will not be generated. The solution is simple
Execute the following command, restart Jenkins, and check whether the updates folder is generated

sed -i "s/http:\/\/\/update-center.json/https:\/\/\/jenkins\/updates\/update-center.json/g" /data/jenkins/hudson.model.UpdateCenter.xml

Restart the Jenkins service. After testing, if the updates directory is not generated, it is mainly because your network cannot connect to the official Jenkins warehouse. You need to restart Jenkins service several times

If the / data/jenkins/updates/default.json file is generated, execute the following command to replace the default download source:

sed -i 's/http:\/\/\/download/https:\/\/\/jenkins/g' /data/jenkins/updates/default.json
sed -i 's/http:\/\/\/\/' /data/jenkins/updates/default.json
systemctl stop jenkins
systemctl start jenkins

2.9 replace the download source address to register jenkins service normally

Find password file from server enter password

Enter administrator account and password to log in

Tip: if the / data/jenkins/updates/default.json file has not been generated, the browser will always prompt for offline installation when accessing the link to register jenkins service
The screenshot is as follows:

3, Installation registration summary

Jenkins' so-called update site source change is useless. Every time you install Jenkins for the first time or install the required plug-ins after Jenkins installation, you have to wait a long time, or often the installation fails.
The final solution is as follows:
When you change to Tsinghua source, you also need to change the address of the download plug-in package to Tsinghua download source. The specific configuration file needs to be modified:

[root@jenkins ~]# cat /data/jenkins/hudson.model.UpdateCenter.xml 
<?xml version='1.1' encoding='UTF-8'?>

sed -i 's/http:\/\/\/download/https:\/\/\/jenkins/g' /data/jenkins/updates/default.json
sed -i 's/http:\/\/\/\/' /data/jenkins/updates/default.json
systemctl restart jenkins

In the above way, it is much faster than the original installation.

Tags: Linux jenkins JSON Maven Java

Posted on Mon, 04 May 2020 07:51:53 -0700 by gilijk