In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this article, the editor introduces in detail "how to build a CICD environment based on Jenkins+Maven+Gitea+Nexus". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to build a CICD environment based on Jenkins+Maven+Gitea+Nexus" can help you solve your doubts.
In the traditional single software architecture, software development, testing, operation and maintenance are all based on a single process.
When split into micro-services, a single application can be divided into multiple micro-services, such as user systems, and can be divided into basic information management, integral management, order management, user information management, contract management and other micro-service modules.
At this time, the workload of testing and operation and maintenance will be greatly increased if each module is packaged, released, run, developed, tested, and maintained separately.
In this process, if there is a lack of automated testing, automated integration / deployment, automatic operation and maintenance capabilities, the impact is
Increased software delivery cycle
In the case of multi-environment deployment, the problems caused by the differences in each environment.
Manual operation and maintenance is easy to bring some unrepeatable effects to the environment, and once an operation and maintenance error occurs, it is more difficult to recover immediately, resulting in a long fault processing time. And the requirements for the ability of operation and maintenance personnel are high.
All these problems will lead to longer software delivery time, increased risk, and increased operation and maintenance costs. Therefore, we need an automated deployment system to build a CICD model.
The operation of ordinary Jar packages
1. Use maven packagenohup java-jar ${APP_NAME} > goods-service.log 2 > & 1 &
2.nohup purpose: run commands without hanging up
& purpose, running in the background
2 > & 1: in bash:
0 represents STDIN_FILENO standard input (usually keyboard)
1 represents STDOUT_FILENO standard output (usually the display screen, to be exact, the user terminal console)
2 three stands for STDERR_FILENO (standard error (error message output).
2 > & 1 is used to redirect standard error 2 to standard output 1. The thing that precedes 1 here & is for bash to interpret 1 as standard output instead of file 1. As for the last &, let bash execute in the background.
Generate the content directly to the specified file
Set up a Nexus private server environment
Nexus is a powerful Maven warehouse manager that greatly simplifies local internal warehouse maintenance and external warehouse access. Nexus is a "out-of-the-box" system that does not need a database. It uses a file system plus Lucene to organize data.
Sonatype nexus is required for Maven private server environment. Let's analyze the installation and configuration in detail.
Deployment server: 192.168.8.138
Download and install
Visit: https://sonatype-download.global.ssl.fastly.net/repository/downloads-prod-group/3/nexus-3.37.0-01-unix.tar.gz address, download Sonatype Nexus.
Extract to / data/program directory
[root@localhost program] # tar-zxvf nexus-3.37.0-01-unix.tar.gz
Go to the ${NEXUS_HOME}\ bin directory and execute the following command to start Nexus
. / nexus start install Maven
1. Download Maven: https://dlcdn.apache.org/maven/maven-3/3.8.4/binaries/apache-maven-3.8.4-bin.tar.gz
two。 Configure the Maven and JDK environment variables.
Export JAVA_HOME=/data/program/jdk1.8.0_241export MAVEN_HOME=/data/program/apache-maven-3.8.4export PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATHexport CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
3. Go to the ${NEXUS_HOME}\ bin directory and execute the following command to start Nexus
Start with. / nexus start, start in the background, and can be accessed after successful startup.
Start with. / nexus run, start at the foreground, display the log, and access it after startup.
. / nexus start
At startup, there will be the following prompt, which suggests that we use a non-root account to access it.
WARNING: *
WARNING: Detected execution as "root" user. This is NOT recommended!
WARNING: *
4. Visit: http://localhost:8081 accesses Nexus repository
If you want to configure the JVM parameters that the nexus application starts locally, you can use nexus.vmoptions
If you want to change the port number of nexus, you can go to nexus-default.properties
Log in to the console
1. The default login account is admin, and the password will prompt you in the: / data/program/sonatype-work/nexus3/admin.password file.
two。 The content is as follows, copy the content directly and log in.
090849ac-cea7-4353-b2c8-59b2bceadb50
Nexus console description
Enter the Browse menu of the Nexus console and you can see four types of repositories:
1) maven-central: maven central library, which pulls jar from https://repo1.maven.org/maven2/ by default
2) maven-releases: private library distribution jar
3) maven-snapshots: private library snapshot (debug version) jar
4) maven-pubpc: the above three repositories are grouped together to provide services, which are used in the local maven basic configuration settings.xml.
There are four default warehouse types for Nexus: (the above name can be chosen freely, and the key is what warehouse type it corresponds to)
1) group (warehouse group type): also known as group warehouse, which is used to facilitate developers to set up their own warehouse.
2) hosted (host type): release repository for internal projects (internal developers, repositories for release)
3) proxy (agent type): the warehouse that looks for data from the remote central warehouse (you can click on the Configuration page of the corresponding warehouse to sign the value of the Remote Storage Location attribute, that is, the path of the remote warehouse being proxied)
4) virtual (virtual type): virtual warehouse (this is basically useless, focus on the use of the above three warehouses)
Nuget is the package manager for the Microsoft .NET development platform, similar to Maven.
Catalog description
Nexus-3.34.0-01 directory
Bin contains startup scripts and related configurations for nexus
Configuration files such as etc jetty, karaf, etc.
Jre jre environment
Lib java rack package library
Public about the resources needed for nexus applications to run locally
System applies all plug-ins and components
Copyright notice and legal rules of LICENSE.txt and NOTICE.txt
Sonatype-work\ nexus3 directory
Blobs/ creates the default path for blob. Of course, you can also reassign it.
Information about cache/ 's currently cached karaf package
Data from the db/ OrientDB database, the database used to store the metadata of nexus
Elasticsearch status of the current configuration of elasticsearch/
Etc/ is probably something related to the runtime configuration status and customization of the repository
Health-check/, take a look at the directory, the storage directory of health check-related reports.
Keystores/ automatically generated ID primary key about the resource library
Log/ runs log files generated by instances, and there is also a compressed package of log files. Log files seem to be generated every day. You can delete old log files regularly.
The directory where tmp/ stores temporary files
Nexus is set up as a system service
Follow these steps
1. Modify the script ${NEXUS_HOME}\ bin\ nexus to add the following configuration
INSTALL4J_JAVA_HOME_OVERRIDE=/data/program/jdk1.8.0_241
two。 Set up soft links
[root@localhost bin] # ln-s / data/program/nexus-3.37.0-01/bin/nex
3. Configure system services through chkconfig
Cd / etc/init.dsudo chkconfig-- add nexus # add nexus service sudo chkconfig-- levels 345 nexus on # Settings enable self-startup
4. Start and stop services
Sudo service nexus start # enable the service
Service nexus status # View service status
Build Gitea environment
Reference document: https://docs.gitea.io/zh-cn/install-from-binary/
1. Install the git environment: yum-y install git.
two。 Download the installation package from pnux to the / data/program/gitea directory with the following command.
Wget-O gitea https://dl.gitea.io/gitea/1.15.7/gitea-1.15.7-linux-amd64
3. Execute the chmod + x gitea command to grant execution permission
4. Execute the following command to run gitea
. / gitea web
Install as a system service (important)
1. Create a Git user
Sudo useradd\-system\-shell / bin/bash\-comment 'Git Version Control'\-create-home\-home/ home/git\ git
two。 Download binaries
Wget-O gitea https://dl.gitea.io/gitea/1.15.7/gitea-1.15.7-linux-amd64
3. According to the official recommendation of gitea, configure the installation directory of gitea as follows
Move the downloaded files to the / usr/local/bin directory
Sudo mv / data/program/gitea / usr/local/bin
Make the binary executable:
Chmod + x / usr/local/bin/gitea
Follow the command to create the necessary directory and set permissions
Sudo mkdir-p / var/lib/gitea/ {custom,data,indexers,public,log} sudo mkdir-p / var/lib/gitea/ {custom,data,indexers,public,log} sudo chown git: / var/lib/gitea/ {data,indexers,custom,public,log} sudo chmod 750 / var/lib/gitea/ {data,indexers,log} sudo mkdir / etc/giteasudo chown root:git / etc/giteasudo chmod 770 / etc/gitea
Configure the system service according to the official Systemd Unit file provided by Gitea.
Sudo wget https://raw.githubusercontent.com/go-gitea/gitea/master/contrib/systemd/gitea.service-P / etc/systemd/system/
Note that gitea.service cannot be downloaded through wget. You need to copy it on github.
After completing the above process, turn on the automatic startup with the following command
Systemctl enable giteasystemctl start gitea
4. After the installation and startup is complete, visit: http://192.168.8.136:3000 to configure the database-related properties.
Build Jenkins environment
Jenkins is an open source continuous integration tool written in JAVA that runs in a servlet container, supports software configuration management (SCM) tools, and can execute APACHE ANT and APACHE MAVEN-based projects, as well as arbitrary Shell scripts and Windows batch commands
Jenkins provides automatic build and deployment, which is installed as follows:
Wget-O / etc/yum.repos.d/jenkins.repo\ https://pkg.jenkins.io/redhat-stable/jenkins.reporpm-- import https://pkg.jenkins.io/redhat-stable/jenkins.io.keyyum upgradeyum install epel-release java-11-openjdk-develyum install jenkinssystemctl daemon-reload
Start or stop jenkins with the following command
Systemctl start jenkinssystemctl stop jenkins
Access: http://192.168.8.136:8080 access jenkins
Follow the steps prompted by the console step by step.
Note: JENKINS user is used by default for Jenkins installation, so if you are using root permission, you need to modify the account.
[root@localhost bin] # vim / etc/sysconfig/jenkinsJENKINS_USER= "root" project transformation project configuration local private server
Modify setting.xml file to add mirror configuration
Nexus maven-public http://192.168.8.136:8081/repository/maven-public/
Mirror is equivalent to an interceptor. It will intercept maven's requests for remote repository, and use this image to obtain jar packets.
Add the following configuration to the project, that is, to specify the release repository of the jar package for different distributions of snapshots and releases
Snapshots Nexus Snapshot Repository http://192.168.8.136:8081/repository/maven-snapshots/ releases Nexus Release Repository http://192.168.8.136:8081/repository/huhy-nexus/ modifies the settings.xml file of the publisher
The purpose of modifying the settings.xml file of the publisher is because the Jenkins server needs to download the jar package through maven for continuous integration, and this download needs to be obtained from our local private server.
Nexus maven-public http://192.168.8.136:8081/repository/maven-public/ nexusRep nexus http://192.168.8.136:8181/repository/maven-public/ default true always Nexus http://192.168.8.136:8181/repository/maven-public/ true true nexusRep configuration automatic integration and release configuration Jenkins environment variables
Go to the following page, the configuration of the red mark.
Configure the environment for Maven and specify the Maven directory installed on the publisher.
Install the Jenkins plug-in
Gitea, integrate Gitea. After installation, add Gitea Server information to the global configuration of Jenkins.
Git Parameter, configuring Git publishing properties
Pubpsh Over SSH, execute the script on the remote machine, this step requires that the remote machine be configured to ssh
Maven Integration to support the integration of Maven projects
Configure publishing target server information
We think of the following two servers as web nodes
192.168.8.134192.168.8.135
In the global configuration of Jenkins, the information of these two servers is configured for the subsequent implementation of remote transmission of jar packets. The working directory of the Remote Directory target server, where the jar package will be remotely transferred
Add a project release mechanism
The task of creating a Maven project.
Configure the source code, here use the source code address of the project in Gitea, and configure the login account password information.
Configure the execution command for Maven, where root POM, if you are in a multi-module project, needs to specify the pom.xml of the module you are currently building.
Add the execution logic after a successful build, that is, publish the jar package to the remote target server, and then execute the relevant shell script to start the service
Write a release script
Write a shell script and execute the following script after the jar package is sent to the target server.
Do historical jar backup and cleanup
Execute the shell script to start the service
#! Bin/sh-eexport JAVA_HOME=/data/program/jdk1.8.0_241export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jarexport PATH=$ {PATH}: $JAVA_HOME/binsource / etc/profile # define propertyJAR_PATH='/app/service/goods-service'TEMP_PATH='/app/service/temp'BACKUP_PATH='/app/service/backup'JAR_NAME=goods-service.jarFILE_NAME=goods-service# stop target servicecd ${JAR_PATH} sh run-goods-service.sh stopsleep 2rm-rf $FILE_NAME.log# backup old jarBACKUP_DATE=$ (date +% Y%m%d_%H%M) if [!-d $JAR_PATH/backup/$FILE_NAME] Then mkdir-p $JAR_PATH/backup/$FILE_NAMEficd ${JAR_PATH} pwdif [- f $JAR_NAME] Then mv-f. / $JAR_NAME. / backup/$FILE_NAME/$JAR_NAME$BACKUP_DATE sleep 1fi# start jarBUILD_ID=dontKillMecd ${TEMP_PATH} mv-f $JAR_NAME$ JAR_PATHcd ${JAR_PATH} sh run-goods-service.sh restart# clear old backupcd ${JAR_PATH} / backup/$FILE_NAMEls-lt | awk'NR > 5 {print $NF}'| xargs rm-rfps-ef | grep javaecho "= deploy success=" to write and run the script run-goods-service.sh# indicates that the current script adopts / bash program in the / bin path to explain the execution of the jarpackage app _ NAME=goods-service.jarusage () {echo "execute the operation command [start | stop | restart | status]" exit 1} if_exist () {pid= `ps-ef | grep $APP_NAME | grep-v grep | awk'{print $2} '`if [- z "$pid}"] Then return 1 else return 0 fi} start () {if_exist if [$?-eq 0]; then echo "${APP_NAME} already running. Pid=$ {pid} "else nohup java-jar ${APP_NAME} > goods-service.log 2 > & 1 & npid= `ps-ef | grep $APP_NAME | grep-v grep | awk'{print $2} '`echo" start ${APP_NAME} success, pid=$ {npid} "fi} stop () {if_exist if [$?-eq 0]; then kill-9$ pid echo" stop $pid success ". Else echo "${APP_NAME} is not running" fi} status () {if_exist if [$?-eq 0]; then echo "${APP_NAME} is running. Pid is ${pid} "else echo" ${APP_NAME} is not running "fi} restart () {stop sleep 5 start} case" $1 "in" start ") start;;" stop ") stop;;" status ") status;;" restart ") restart;; *) usage;; esac configuration code is dynamically built after submission
What if we want the code to be submitted and merged into a branch and automatically built for release?
Install the Webhook plug-in
Install the Generic Webhook Trigger plug-in in Jenkins, and after the installation is successful, one of the options shown below will be added to the built configuration page.
Configure Generiac Webhook Trigger and add a token as authentication.
Note this address: http://JENKINS_URL/generic-webhook-trigger/invoke, which needs to be configured in webhook as a trigger call.
Gitea add webhook hook
In gitea's project, find the Web hook and add the Web hook. Select gitea.
Add webhook
Verify the behavior that triggers automatically
Modify any code of the gpmall-pc project and submit it to gitea.
Looking at Jenkin's project build directory adds an automatic build task, as shown in the following figure.
And in gitea's webhook, you can see the most recent push record.
After reading this, the article "how to build a CICD environment based on Jenkins+Maven+Gitea+Nexus" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.