Jenkins installation of Linux system

Keywords: jenkins Java CentOS Session

1, background

Why Jenkins?

  1. It's more convenient than writing your own scripts. You don't need to care about the corners. You just need to add core compiled scripts to save developers' attention and energy
  2. You can let the test or project manager who does not understand the relevant development generate the version to ensure the integrity of the source code.
    For example: due to the needs of the project, the outsourcers are found. After the source code is negotiated and handed over, the usual software version is generated and tested by the outsourcers. When the source code is finally handed over after the acceptance, the outsourcers may feel that you don't have the relevant technical personnel and delete some core codes at will. Or the departing programmers can run without submitting the code (your way of leading the team needs to be changed more than version management). After using Jenkins, the version is pulled from the code warehouse git or svn, and the software version is generated from the source code, at least ensuring the integrity of the source code. Serious statement: this does not prevent programmers from leaving back doors or holes
  3. Support the packaging of android, ios and server applications (including but not limited to war of javaweb) (it is confirmed that xcode is required for ios packaging, and xcode cannot be installed except for mac system, so the packaging process of ios will not be introduced.)

2, installation

Download the latest centos installation package, Download address ,Installation document.
Note: you need to rely on jdk1.8, which will not be covered here.

[root@centos]# rpm -ih jenkins-2.150.3-1.1.noarch.rpm

 

Warning: jenkins-2.150.3-1.1.noarch.rpm: head V4 DSA/SHA1 Signature, key ID d50582e6: NOKEY
################################# [100%]
Upgrading / installing
################################# [100%]

After the installation is successful, some main file directories are:
/usr/lib/jenkins/jenkins.war
/etc/sysconfig/jenkins configuration file
/var/log/jenkins/jenkins.log log file

Modify profile
[root@centos]# vim /etc/sysconfig/jenkins

 

#Modify port, default 8080
JENKINS_PORT="8088"

start-up
[root@centos]# systemctl restart jenkins

 

Job for jenkins.service failed because the control process exited
 with error code. See "systemctl status jenkins.service" and 
"journalctl -xe" for details.

Start failed, view reason
[root@centos]# systemctl status -l jenkins.service

 

● jenkins.service - LSB: Jenkins Automation Server
   Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled)
   Active: failed (Result: exit-code) since One 2019-02-18 16:06:22 CST; 1min 4s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 8477 ExecStart=/etc/rc.d/init.d/jenkins start (code=exited, status=1/FAILURE)

2 Month 1816:06:22 localhost.localdomain systemd[1]: Starting LSB: Jenkins Automation Server...
2 Month 1816:06:22 localhost.localdomain runuser[8482]: pam_unix(runuser:session): session opened for user root by (uid=0)
2 Month 1816:06:22 localhost.localdomain jenkins[8477]: Starting Jenkins bash: /usr/bin/java: There is no file or directory
2 Month 1816:06:22 localhost.localdomain runuser[8482]: pam_unix(runuser:session): session closed for user root
2 Month 1816:06:22 localhost.localdomain jenkins[8477]: [fail]
2 Month 1816:06:22 localhost.localdomain systemd[1]: jenkins.service: control process exited, code=exited status=1
2 Month 1816:06:22 localhost.localdomain systemd[1]: Failed to start LSB: Jenkins Automation Server.
2 Month 1816:06:22 localhost.localdomain systemd[1]: Unit jenkins.service entered failed state.
2 Month 1816:06:22 localhost.localdomain systemd[1]: jenkins.service failed.

Jenkins bash: /usr/bin/java: no file or directory
Because the directory where I install jdk is not the default directory, I need to modify the configuration file.

Find the java installation directory
[root@centos]# whereis java

 

java: 
/usr/lib/java 
/etc/java 
/usr/share/java 
/usr/java/jdk1.8.0_161/bin/java
/usr/java/jdk1.8.0_161/jre/bin/java

[root@centos]# vim /etc/rc.d/init.d/jenkins
The modification method here is wrong. See the following for the correct modification method

 

#source file
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-1.7.0/bin/java
/usr/lib/jvm/jre-1.7.0/bin/java
/usr/bin/java
"
#After modification
candidates="
/usr/lib/java 
/etc/java 
/usr/share/java 
/usr/java/jdk1.8.0_161/bin/java
/usr/java/jdk1.8.0_161/jre/bin/java
"

[root@centos]# systemctl restart jenkins

 

Warning: jenkins.service changed on disk. Run 'systemctl daemon-reload' to reload units.
Job for jenkins.service failed because the control process exited with error code. See "systemctl status jenkins.service" and "journalctl -xe" for details.

reload as prompted
[root@centos]# systemctl daemon-reload
restart
[root@centos]# systemctl restart jenkins
Failed again, check the reason
[root@centos]# systemctl status -l jenkins.service

 

● jenkins.service - LSB: Jenkins Automation Server
   Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled)
   Active: failed (Result: exit-code) since One 2019-02-18 16:25:58 CST; 1min 53s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 9103 ExecStart=/etc/rc.d/init.d/jenkins start (code=exited, status=1/FAILURE)

2 Month 1816:25:58 localhost.localdomain systemd[1]: Starting LSB: Jenkins Automation Server...
2 Month 1816:25:58 localhost.localdomain runuser[9108]: pam_unix(runuser:session): session opened for user jenkins by (uid=0)
2 Month 1816:25:58 localhost.localdomain jenkins[9103]: Starting Jenkins bash: /usr/lib/java: Is a directory
2 Month 1816:25:58 localhost.localdomain runuser[9108]: pam_unix(runuser:session): session closed for user jenkins
2 Month 1816:25:58 localhost.localdomain jenkins[9103]: [fail]
2 Month 1816:25:58 localhost.localdomain systemd[1]: jenkins.service: control process exited, code=exited status=1
2 Month 1816:25:58 localhost.localdomain systemd[1]: Failed to start LSB: Jenkins Automation Server.
2 Month 1816:25:58 localhost.localdomain systemd[1]: Unit jenkins.service entered failed state.
2 Month 1816:25:58 localhost.localdomain systemd[1]: jenkins.service failed.

Starting Jenkins bash: /usr/lib/java: is a directory
I wasted half an hour in this pit. At the beginning, I thought it was a directory that represented the success of modification, and I cried for it.

After checking / usr/lib/java, I found that it was really an empty directory, and I had to modify the configuration file to delete all non real java path directories, leaving only two real addresses
[root@centos]# vim /etc/rc.d/init.d/jenkins

 

#After the first amendment
candidates="
/usr/lib/java 
/etc/java 
/usr/share/java 
/usr/java/jdk1.8.0_161/bin/java
/usr/java/jdk1.8.0_161/jre/bin/java
"
#After the second amendment
candidates="
/usr/java/jdk1.8.0_161/bin/java
/usr/java/jdk1.8.0_161/jre/bin/java
"

[root@centos]# systemctl daemon-reload
[root@centos]# systemctl restart jenkins
 

Set startup
[root@centos]# systemctl enable jenkins
Open port
[root@centos]# firewall-cmd --permanent --add-port=8088/tcp
[root@centos]# firewall-cmd --reload

Browser access (exchange IP) http://192.168.1.91:8088

 

Copy password to browser box
[root@centos]# cat /var/lib/jenkins/secrets/initialAdminPassword

Default until the administrator account password is set.



Author: I'm not a teenager
Link: https://www.jianshu.com/p/ed73f1f07682
Source: Jianshu
The copyright belongs to the author. For commercial reprint, please contact the author for authorization. For non-commercial reprint, please indicate the source.

104 original articles published, praised 127, visited 350000+
Private letter follow

Posted by aalmos on Tue, 14 Jan 2020 02:34:50 -0800