Jenkins2.4 is installed in Linux environment

1. Introduction to Jenkins

  Jenkins is a self-contained open source automation server that can be used to automate various tasks related to building, testing, delivering or deploying software. Jenkins can be installed via native system packages, Docker, or even run independently from any machine with a Java Runtime Environment (JRE) installed. Jenkins 2.4 introduces many new features and improvements compared to previous versions to improve the efficiency and productivity of development teams. Key features of Jenkins 2.4 include:

  • Pipeline as Code: Jenkins 2.4 introduces the Pipeline plugin, which allows users to define the build process as maintainable code for better management and version control. This makes the build process more flexible and repeatable, and can be integrated with other tools and services.
  • Enhanced user interface: Jenkins 2.4 improves the user interface, making it more intuitive and easier to use. The new interface provides more visual tools and reports to help developers better understand and analyze problems during the build process.
  • Distributed build: Jenkins 2.4 supports distributed build, allowing build tasks to be distributed to multiple agent nodes for parallel execution. This improves the speed and scalability of builds and reduces build queue wait times.
  • Security enhancements: Jenkins 2.4 introduces more security features such as role-based access control and single sign-on integration. These capabilities can help protect sensitive build and deployment processes from unauthorized access and manipulation.

  Overall, Jenkins 2.4 is a powerful and easy-to-use continuous integration and continuous delivery tool that can help development teams better manage and automate the software development process and improve the quality and efficiency of software delivery.

2. Environmental description

  Since Jenkins version 2.357, it is required to install java11 or java17. The current latest version of Jenkins is 2.414, which requires java11 or above. In addition, Jenkins will stop supporting centos7 after November 16, 2023. The blogger is only conducting Jenkins experiments. If it is a production environment, it is recommended to use centos8 or above. The blog experimental environment is as follows:

  • Operating system: centos7.9
  • JAVA version: 17.0.8
  • Jenkins version: 2.414

3. Installation steps

1. Download java17

[root@s209 opt]# cd /usr/local/
[root@s209 local]# wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz

2. Unzip the software package

[root@s209 local]# tar -zxvf jdk-17_linux-x64_bin.tar.gz

3. Create soft links

[root@s209 local]# ln -s jdk-17.0.8 java

4. Configure java environment variables

  Configure the environment variables of java17. Java17 does not have a jre environment. We only need to configure java_home. After the configuration is completed, remember to use the source command to make the environment variable configuration take effect.

[root@s209 local]# cat /etc/profile

export JAVA_HOME=/usr/local/java
export CLASSPATH=$JAVA_HOME/lib:$CLASSPATH
export PATH=${JAVA_HOME}/bin:$PATH
[root@s209 local]# source /etc/profile

5. Download the Jenkins image source file

[root@s209 yum.repos.d]# wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat/jenkins.repo
[root@s209 yum.repos.d]# rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key

6. Update system

[root@s209 yum.repos.d]# yum upgrade

7. Install Jenkins with yum

[root@s209 /]# yum install -y jenkins

Installed:
jenkins.noarch 0:2.414.1-1.1

Complete!

8. Custom service port

  Modify the JENKINS_PORT service port to a custom port. In the new version, the JENKINS_PORT parameter in this file is modified in /usr/lib/systemd/system/jenkins.service. In historical versions before Jenkins2.3, the JENKINS_PORT parameter in /etc/sysconfig/jenkins is modified. Most of the parameters found on the Internet are modified here. After the blogger's experimental test, modifying the /etc/sysconfig/jenkins file is invalid, but this file will indeed be generated during installation. If any bloggers who know the reason are welcome to leave a reply.

[root@s209 /]# [root@s209 /]# vim /usr/lib/systemd/system/jenkins.service
#Modify the default 8080 in the following line It is a customized 8888 port, save it after modification
[root@s209 /]# cat /usr/lib/systemd/system/jenkins.service |grep Environment |grep -v "#"
Environment=“JENKINS_HOME=/var/lib/jenkins”
Environment=“JENKINS_WEBROOT=%C/jenkins/war”
Environment=“JAVA_OPTS=-Djava.awt.headless=true”
Environment=“JENKINS_PORT=8888”

9. Reload system configuration

[root@s209 /]# systemctl daemon-reload

10. Modify the java environment variable soft link

  It is recommended to modify the /etc/alternatives/java soft link to update the system java version, otherwise the error java environment mismatch will always be reported when starting Jenkins. Of course, in addition to modifying the soft link method, you can also specify it through environment variable parameters, modify the /usr/lib/systemd/system/jenkins.service file, and add a line Environment="JENKINS_JAVA_CMD=/usr/local/java17/bin/java", followed by The detailed path is the java17 environment installation path of the host. It is recommended to use method 2, which does not affect other services of the existing host.

[root@s209 /]# rm -rf /etc/alternatives/java
[root@s209 /]# ln -s /usr/local/java/bin/java /etc/alternatives/java
[root@s209 /]# /etc/alternatives/java -version
java version “17.0.8” 2023-07-18 LTS
Java™ SE Runtime Environment (build 17.0.8+9-LTS-211)
Java HotSpot™ 64-Bit Server VM (build 17.0.8+9-LTS-211, mixed mode, sharing)

11. Start Jenkins

[root@s209 /]# systemctl start jenkins

12. Log in to the system

  You need to enter a password when logging in to the system for the first time. The initial password file can be found as follows.

[root@s209 local]# cat /var/lib/jenkins/secrets/initialAdminPassword
cf659af39e414ac9919292e9c24f50cb

13. Initialize plug-in installation

  The first time you log in, you will be prompted to install the plug-in. After the blogger chooses the recommended installation, the installation content is as follows.
Insert image description here

14. Create an administrator user

  Jenkins2.4 supports role management, and multiple administrator users can be created. Of course, we can also choose to skip and continue using the admin account.
Insert image description here

15. Instance configuration

  Instance configuration is actually to configure the access URL of Jenkins, just select the default one.
Insert image description here

16. Jenkins is ready

  See the following prompt to indicate that the initial installation of Jenkins is complete. Click Start to use and we can officially use the Jenkins service.
Insert image description here

17. Login interface

  The following is the interface after logging in for the first time.
Insert image description here

18. Official login

  Log out and log in to Jenkins again. The login interface is as follows. At this time we need to enter the username and password to log in. The default username is only admin and the password is initial.
Insert image description here

4. QA

1. Start the java environment that reports an invalid error

  • Error message: jenkins: invalid Java version: openjdk version “1.8.0_181”
  • Reason for the error: The Java environment version does not match the current Jenkins version
  • Solution: Modify the candidates parameters in /etc/rc.d/init.d/jenkins and add the java17 path, but it also has no effect. Delete the /etc/alternatives/java soft link and point the soft link to the java17 installation path. For details, please refer to step 10 of the installation steps chapter.

2. Unable to start Jenkins

  • Error message: jenkins.service: main process exited, code=exited, status=1/FAILURE
    Insert image description here
  • Reason for the error: The service port is occupied. Other services have been opened on port 8080 on the blog's experimental host. The /etc/sysconfig/jenkins file modified by the blogger's custom service port is invalid.
  • Solution: Refer to step 8 of the installation steps chapter to customize the service port.

Guess you like

Origin blog.csdn.net/carefree2005/article/details/132487973