Building a production CICD environment based on Jenkins ------- Day 84 of learning operation and maintenance on the road from novice to master

Stage 4

Time: August 21, 2023

Participants: All members of the class

Contents:

Build a production CICD environment based on Jenkins

Table of contents

1. Environment Overview

2. Introduction to Jenkins

(1) Jenkins includes the following features:

(2) Continuous integration

1. Benefits of continuous integration

2. The role of continuous integration

3. Characteristics of continuous integration

(3) Continuous delivery

(4) Continuous deployment

(5) Introduction to Maven

3. Install and configure Jenkins

Jenkins installation method 1: war package

Jenkins installation method 2: rpm method (recommended)

Start jenkins

Contents of RPM package installation

Configuration file description

web operations


1. Environment Overview

        As the requirements and complexity of software development continue to increase, how to better collaborate among team development members to ensure the quality of software development has gradually become an unavoidable issue in the development process.

        Jenkins automated deployment can solve repetitive tasks such as integration, testing, and deployment. The efficiency of tool integration is significantly higher than manual operation; and continuous integration can obtain code change information earlier, thereby entering the testing phase earlier, and Discover problems, so that the cost of solving them will drop significantly; continuous integration shortens the time in all aspects of development, integration, testing, and deployment, thereby shortening the waiting time in the middle; continuous integration also means development, integration , testing, and deployment can be sustained.

        Therefore, after configuring the Jenkins continuous integration and continuous delivery environment, you can hand over the publishing tasks to the integration server. Use Maven (Ant), etc. to implement automated build, release and deployment of Java projects.

        These tools can help automate releases, rollbacks and other actions during the build process.

2. Introduction to Jenkins

 

        Jenkins is an open source continuous integration tool written in Java. After a dispute with Oracle, the project became independent from the Hudson Project.

Official website: https://jenkins.io/.

        Jenkins provides continuous integration services for software development. It runs in a Servlet container (Tomcat). It supports software configuration management (SCM) tools (including AccuRev SCM, CVS, Subversion, Git, Perforce, Clearcase, and RTC) and can execute projects based on Apache Ant and Apache Maven, as well as arbitrary Shell scripts and Windows batch commands. The main developer of Jenkins is Kosuke Kawaguchi. Jenkins is free software released under the MIT license.

        Jenkins can monitor problems in the continuous integration process in real time, provide detailed log files and reminder functions, and can also use charts to vividly display the trend and stability of project construction.

(1) Jenkins includes the following features:

Easy to install: There is only one jenkins.war. After downloading the file from the official website, you can run it directly without additional installation or database installation;

Easy to configure: Provides a friendly GUI configuration interface;

Change support: Jenkins can obtain and generate a code update list from the code repository (SVN/Git), and output it to the compilation output information;

Supports permanent links: Users access Jenkins through the Web, and the link addresses of these Web pages are permanent link addresses, which can be used directly in various documents;

Integrated Email/RSS/IM: When an integration is completed, the integration results can be collected in real time through these tools (it takes a certain amount of time to build an integration. With this function, you can do other things while waiting for the results) ;

JUnit/TestNG test report: It is used to provide detailed test report function in the form of charts and other forms;

Support distributed build: Jenkins can distribute integrated build and other work to multiple computers for completion;

File fingerprint information: Jenkins will save the jars files generated by building the integration and which version was used for the integration build;

Support third-party plug-ins: Jenkins supports third-party plug-ins, which makes Jenkins more and more powerful.

(2) Continuous integration

        Continuous integration (English: Continuous integration, abbreviated as CI ) is a software engineering process that integrates all engineers' working copies of the software onto a common mainline (mainline) several times a day.

        This name was first proposed by Grady Booch in his district method, but he did not mention integrating several times a day. Later it became part of extreme programming (XP). Test-driven development (TDD) is often paired with automated unit testing.

        Continuous integration was proposed mainly to solve various problems faced by software when integrating systems. Extreme Programming calls these problems integration hell.

 

        Continuous integration mainly emphasizes that developers should build and (unit) test immediately after submitting new code. Based on the test results, we can determine whether the new code and the original code integrate correctly. To put it simply: frequently (multiple times a day) integrate code into the trunk.

1. Benefits of continuous integration

·Integration errors are caught early and are easy to track because revisions are small, which saves project time and cost.

· Avoid chaos in the minute before the release date, when everyone is trying to check for the little incompatible version they have made.

·When a unit test fails or an error occurs, if the developer needs to restore the code base to a problem-free state without debugging, only a small part of the changes need to be discarded (because integrations are frequent).

·Keep the "latest" programs available for testing, demonstration, or release.

· Frequent code commits encourage developers to create modular, low-complexity code.

·Prevent branches from deviating significantly from the trunk. If integration is not frequent and the backbone is constantly being updated, it will become more difficult or even difficult to integrate in the future.

2. The role of continuous integration

·Ensure the quality of code submitted by team developers and reduce the pressure during software release;

·Every link in continuous integration is completed automatically without much manual intervention, which helps reduce repetitive processes to save time, cost and workload.

3. Characteristics of continuous integration

·It is an automated and periodic integration testing process, from checking out code, compiling and building, running tests, result recording, test statistics, etc., all are completed automatically without manual intervention;

·A dedicated integration server is required to perform integration builds;

·Requires code hosting tool support;

(3) Continuous delivery

        Continuous delivery (English: Continuous delivery, abbreviated as CD ) is a software engineering technique that allows the production process of software products to be completed in a short cycle to ensure that the software can be stably and continuously maintained in a state that can be released at any time. .

        Its goal is to make software build, test, and release faster and more frequent. This method can reduce the cost and time of software development and reduce risks.

        Continuous delivery is based on continuous integration and deploys the integrated code to "production-like environments" that are closer to the real operating environment. For example, after we complete unit testing, we can deploy the code to the Staging environment connected to the database for more tests. If there are no problems with the code, you can continue to manually deploy it to the production environment.

(4) Continuous deployment

        Continuous Deployment (English: Continuous Deployment, abbreviated as CD ) is the next step in continuous delivery. It refers to the automatic deployment to the production environment after the code passes the review.

        Sometimes, continuous deployment is also confused with continuous delivery. Continuous deployment means that all changes are automatically deployed to the production environment. Continuous delivery means that all changes can be deployed to the production environment, but due to business considerations, you can choose not to deploy. If you want to implement continuous deployment, you must first implement continuous delivery.

 

Continuous deployment is to automate the process of deploying to the production environment based on continuous delivery.

Keywords: CI/CD continuous integration/continuous delivery/continuous deployment

(5) Introduction to Maven

        The Maven Project Object Model (POM) is a software project management tool that can manage the construction, reporting and documentation of the project through a small piece of description information.

        In addition to featuring program building capabilities, Maven also provides advanced project management tools. Since Maven's default build rules are highly reusable, simple projects can often be built with two or three lines of Maven build scripts.

        Due to Maven's project-oriented approach, many Apache Jakarta projects use Maven when publishing documents, and the proportion of company projects using Maven continues to grow.

        The word Maven comes from Yiddish (Jewish), meaning the accumulation of knowledge, and was originally used in the Jakata Turbine project to simplify the build process. At that time, there were some projects (with their own Ant build files) that were only slightly different, and the JAR files were maintained by CVS. So I hope there is a standardized way to build projects, a clear way to define the composition of the project, an easy way to publish project information, and an easy way to share JARs among multiple projects.

3. Install and configure Jenkins

1. Host initialization

[root@localhost ~]# hostname jenkins

[root@localhost ~]# bash

[root@jenkins ~]# systemctl stop firewalld

[root@jenkins ~]# iptables -F

[root@jenkins ~]# setenforce 0

 

2. Software requirements

Java 8 Either Java Runtime Environment (JRE) or Java Development Kit (JDK) will work.

1) The first way:

[root@jenkins ~]# yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel

[root@jenkins ~]# java -version

openjdk version "1.8.0_161"

OpenJDK Runtime Environment (build 1.8.0_161-b14)

OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)

2) The second way :

[root@jenkins ~]#rm -rf /usr/bin/java

[root@jenkins ~]#rz

[root@jenkins ~]#tar xf jdk-17_linux-x64_bin.tar.gz

[root@jenkins ~]#mv jdk-17.0.8 /usr/local/java

[root@jenkins ~]#vim /etc/profile

[root@jenkins ~]#source /etc/profile

[root@jenkins ~]#java -version

 

Jenkins installation method 1: war package

First install tomcat and place jenkins.war directly in the webapps directory

Run directly through the java -jar jenkins.war --httpPort=8080 command

Official repository: https://pkg.jenkins.io/redhat-stable/

Tsinghua University open source software mirror site:

Index of /jenkins/redhat/ | Tsinghua University Open Source Software Mirror Station | Tsinghua Open Source Mirror

Just download the corresponding data package. I am using jenkins-2.401-1.1.noarch.rpm here.

Jenkins installation method 2: rpm method (recommended)

[root@jenkins ~]# rpm -ivh jenkins-2.181-1.1.noarch.rpm

 

Start jenkins

[root@jenkins ~]# jenkins start (keep it open)

[root@jenkins ~]# netstat -lnpt | grep :8080

 

Contents of RPM package installation

[root@jenkins ~]# rpm -ql jenkins

/etc/init.d/jenkins #Startup file

/etc/logrotate.d/jenkins # Log splitting configuration file

/etc/sysconfig/jenkins # jenkins main configuration file

/usr/lib/jenkins # Store the war package directory

/usr/lib/jenkins/jenkins.war # war package

/usr/sbin/rcjenkins # Command

/var/cache/jenkins # war package decompression directory jenkins web code directory

/var/lib/jenkins # jenkins working directory

/var/log/jenkins # Log

Configuration file description

[root@jenkins ~]# grep "^[a-Z]" /etc/sysconfig/jenkins

JENKINS_HOME="/var/lib/jenkins" #jenkins working directory

JENKINS_JAVA_CMD=""

JENKINS_USER="jenkins" # jenkinx start user

JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true"

JENKINS_PORT="8080" # Port

JENKINS_LISTEN_ADDRESS=""

JENKINS_HTTPS_PORT=""

JENKINS_HTTPS_KEYSTORE=""

JENKINS_HTTPS_KEYSTORE_PASSWORD=""

JENKINS_HTTPS_LISTEN_ADDRESS=""

JENKINS_DEBUG_LEVEL="5"

JENKINS_ENABLE_ACCESS_LOG="no"

JENKINS_HANDLER_MAX="100" # Maximum connection

JENKINS_HANDLER_IDLE="20"

JENKINS_ARGS=""

web operations

Browser access test: http://192.168. 1 00.1 3 1:8080

 

Enter the secret key:

 

Unlock Jenkins, password obtained from command line

 

 Enter the authorization password and click Next

 

Choose to install recommended plug-ins

 

Automatically download plug-ins (status is all green, next step)

 

The status is red, please restart and install again.

 

The status is red, and you can enter after restarting. However, there are plug-in installation errors, which will affect

 

After turning green, do the following:

Create an administrator user and choose to use the admin account to continue!

 

Instance configuration, save and done!

 

Click to get started

Ready to use!

Guess you like

Origin blog.csdn.net/2302_77582029/article/details/132409041