Installation and configuration of Tomcat + Jenkins (window11)



Preface

During the development process, software is basically integrated once a day, which means that the software is changing all the time. If every integration can be verified through automated builds (including compilation, release, and automated testing), Integration errors can be caught early, allowing teams to develop cohesive software faster. Using Jenkins for continuous integration of software can achieve the above requirements to a certain extent. The following is a brief introduction to the installation and configuration issues encountered when deploying Jenkins through Tomcat under the window11 system.


1. Analysis of the idea of ​​deploying Jenkins in the window11 system based on Tomcat

The content of this article is mainly divided into the following parts
1. Install JDK (Java17)
2. Install Tomcat (apache-tomcat- 9.0.79 -windows-x64.zip) - The version of tomcat10 was originally used here. Due to the 404 problem, it was changed to this version
3. Install Jenkins (Jenkins 2.346.3 LTS ), here you can install through msi file, war file installation
4. Analysis of problems encountered during the installation and configuration process
5. Tomcat starts Jenkins and builds it simply Task

2. Installation and environment configuration of JDK, Tomcat, and Jenkins

1. Download and install JDK 17

(1) JDK download link: https://www.oracle.com/java/technologies/downloads/#jdk17-windows. Enter the above URL and choose to download the window version of JDK 17, as shown in the figure below. Just download the compressed package of x64 Compressed Archive
Insert image description here
(2) After downloading, unzip jdk-17_windows-x64_bin.zip to E:\JDK\jdk-17.0.8_windows-x64_bin (according to your actual situation Just arrange the storage path according to the situation)
Insert image description here
(3) After decompressing to the local folder, the window search box directly searches for the environment variables, calls up the system properties menu, and configures the JDK environment variables: Create a new JAVA_HOME environment variable: E:\JDK\jdk-17.0.8_windows-x64_bin and configure it on Path: %java_home%bin (it needs to be configured in the bin directory here)
Insert image description here
(4) After configuring the environment variables, Win + R Enter cmd to enter the window terminal and enter: java -version. If the prompt JDK version information is consistent with the installed version information (as shown below), the JDK environment is configured successfully

C:\Users\12345>java -version
java version "17.0.8" 2023-07-18 LTS
Java(TM) SE Runtime Environment (build 17.0.8+9-LTS-211)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.8+9-LTS-211, mixed mode, sharing)

2. Download and install TomCat

(1) Tomcat download link: https://tomcat.apache.org/, enter the above URL, check the version information of Tomcat, and download the corresponding Tomcat version according to the jdk version you actually use, which is selected here It is the Tomcat version of apache-tomcat-9.0.79 (originally I chose the 10.1.12 version, but later encountered a 404 problem when starting Jenkins, so I changed it to the 9.0.79 version)
Insert image description here
(2) Click to enter the download page and download the corresponding package. The configuration used here is window11, so the 64-bit zip compressed package apache-tomcat-9.0.79-windows-x64.zip is downloaded (4) After creating the new environment variable, configure it on the Path: %CATALINA_HOME%bin
Insert image description here
(3) After downloading, unzip it to a local folder, change the name of the tomcat compressed package to tomcat9, search the environment variables directly in the window search box, call up the system properties menu, and configure Tomcat into the environment variables go. Create a new environment variable. The variable name is CATALINA_HOME and the variable value is E:\jenkins\tomcat9
Insert image description here

Insert image description here

Insert image description here

E:\jenkins\tomcat9\bin>service.bat install

(6) Find the startup.bat file in the E:\jenkins\tomcat9\bin directory. After double-clicking, the final result will appear as shown below. You may encounter garbled characters. When garbled characters appear, you can solve the problem by modifying the corresponding file. , will be discussed in detail later

[E:\jenkins\tomcat9\webapps\ROOT]的部署已在[31]毫秒内完成
21-Aug-2023 23:46:48.074 信息 [main] org.apache.coyote.AbstractProtocol.start 开始协议处理句柄["http-nio-8080"]
21-Aug-2023 23:46:48.090 信息 [main] org.apache.catalina.startup.Catalina.start [6803]毫秒后服务器启动
21-Aug-2023 23:46:54.967 信息 [pool-6-thread-23] jenkins.InitReactorRunner$1.onAttained Prepared all plugins
21-Aug-2023 23:46:55.010 信息 [pool-6-thread-19] jenkins.InitReactorRunner$1.onAttained Started all plugins
21-Aug-2023 23:46:55.012 信息 [pool-6-thread-19] jenkins.InitReactorRunner$1.onAttained Augmented all extensions
21-Aug-2023 23:46:55.380 信息 [GitSCM.onLoaded] hudson.plugins.build_timeout.global.GlobalTimeOutConfiguration.load global timeout not set
21-Aug-2023 23:46:55.882 信息 [pool-6-thread-20] jenkins.InitReactorRunner$1.onAttained System config loaded
21-Aug-2023 23:46:55.882 信息 [pool-6-thread-20] jenkins.InitReactorRunner$1.onAttained System config adapted
21-Aug-2023 23:46:55.914 信息 [pool-6-thread-18] jenkins.InitReactorRunner$1.onAttained Loaded all jobs
21-Aug-2023 23:46:55.927 信息 [pool-6-thread-8] jenkins.InitReactorRunner$1.onAttained Configuration for all jobs updated
21-Aug-2023 23:46:55.984 信息 [pool-6-thread-24] jenkins.InitReactorRunner$1.onAttained Completed initialization
21-Aug-2023 23:46:56.018 信息 [Jenkins initialization thread] hudson.lifecycle.Lifecycle.onReady Jenkins is fully up and running

(7) Open the browser and enter 127.0.0.1:8080 to display the Tom Cat web page, which means the installation is successful. (8080 is the default port number. If it conflicts with other software ports, you can modify the port number in server.xml in the configuration file)
Insert image description here

3. Download and install Jenkins

To deploy Jenkins to tomcat, here are the following two methods: 1. The first method is to directly download the installation file (jenkins.msi) file under the window , double-click to install to the directory of the previous Tomcat installation path E:\jenkins\tomcat9\webapps. The specific installation steps are as follows. (1) Jenkins download link: https://www.jenkins.io/download/, enter the above URL, select the stable version of the window system package, and click to download (2) After the download is completed, you will get a jenkins.msi installation package. Double-click to open it and install it in the E:\jenkins\tomcat10\webapps directory of Tomcat (3) When installing Jenkins, it is recommended Install and run Jenkins as a standalone, using LocalSystem (Windows equivalent of root), which will grant Jenkins full access to your machines and services; running Jenkins as a Windows service as a local or domain user is much safer. To run the Jenkins service using a local or domain user, specify the domain username and password you want to use to run Jenkins, click Test Credentials to test your domain credentials, and then click Next. The account used here is a window account re-established under the window11 system. For specific reasons, please refer to question 1 below. (4) After the account domain credentials are successfully verified, the next step will be to enter the port settings. The default port number used here is 8080 (but since Tomcat’s default port number is also 8080, so here In order to avoid conflicts, it was changed to another unoccupied port number: 8868). After setting the port number, click Next to enter the JDK path setting page, where you can select the path of the JDK you installed (note here, The JDK versions supported by Jenkins are only Java11 and Java17) (5) After selecting the JDK path, click Next directly to reach the installation page and click Install ( 6) After the installation is completed, click Finish (7) After the installation is completed, you can access http://127.0.0.1:8868 directly through the browser (in addition to accessing directly through the browser, there are also You can start it through the startup.bat file in the following tomcat installation path E:\jenkins\tomcat9\bin, double-click to open it, and access http://127.0.0.1:8080/Jenkins/ through the browser to start Jenkins). After the access is successful, , you will enter the Unlock Jenkins page, open the file with the above path, copy the contents of the file to the administrator password box, click Continue, and enter the installation plug-in page. Here, novices can just choose to install the recommended plug-in. (8) After clicking to install the recommended plug-in, enter the plug-in installation page. After the installation is completed, you will enter the creation page for creating an administrator account in Jenkins. Here you can create a Jenkins account according to your personal preferences. Yes, you can log in to Jenkins through this account in the future. After the creation is successful, click Save and complete to proceed to the next step (9) After creating the account, you will enter the Jenkins URL setting interface. Here you can adjust it according to your actual situation. Usage setting, here we directly use the simplest http://127.0.0.1:8868 to implement basic Jenkins operation. After setting, save, enter the installation completion interface, click to start using Jenkins 2. The second method is to directly download the jenkins.war file of Jenkins, cut and copy it to the webapps file directory of tomcat (E:\jenkins\tomcat9\webapps). The specific installation steps are as follows. (1) Visit https://www.jenkins.io/download/, choose to download the war file, and copy the jenkins.war file to the E:\jenkins\tomcat9\webapps directory a> (2) Enter the E:\jenkins\tomcat9\bin folder, double-click startup.bat to start tomcat, and Jenkins will start together with the server and will be in the E:\jenkins\tomcat9\webapps directory Automatically create the Jenkins directory under (3) After starting tomcat, use the browser to access http://127.0.0.1:8080/ to enter the tomcat page and access http://127.0.0.1: 8080/Jenkins/ can enter the Jenkins page, and you can deploy and configure Jenkins after logging in (4) Contents that may be set during use: 1. Modify the port number of Jenkins. Due to the differences between tomcat and Jenkins The default port numbers are all 8080, so you can change the port number of Jenkins or tomcat here to avoid conflicts; 2. Set the permission account and password required for tomcat login; 3. When tomcat runs, the information displayed is garbled; I will not introduce it here, but it will be discussed later. We will do further analysis when explaining the problems encountered during the installation; 4. Change the jenkins storage path, etc.


Insert image description here

Insert image description here

Insert image description here

Insert image description here

Insert image description here

Insert image description here

Insert image description here

Insert image description here

Insert image description here


Insert image description here

Insert image description here

Insert image description here

3. Create a simple Jenkins task

(1) After configuring Jenkins, open the browser, enter the following link http://127.0.0.1:8868, and log in to Jenkins using the administrator account (Similarly, in addition to accessing directly through the browser, you can also access it here Start through the startup.bat file in the following tomcat installation path E:\jenkins\tomcat9\bin, double-click to open it, and access http://127.0.0.1:8080/Jenkins/ through the browser to start Jenkins. It is recommended to use this Method to perform the following operations)
Insert image description here
(2) Create a build task
As shown in the figure below, build a simple Jenkins task, click Create task, and a pop-up will appear Select Build a free-style software project on the task type selection interface and enter the project name; enter the build project menu, switch directly to the Build option, choose to execute the window batch command, enter python -h in the input box, and click Save. Go to the next step and click Build Now. The first build will generate a link to #1. Click to enter the link and click on the console output to view the build log
Insert image description here
(3) Run python test< /span>
Create the test file test_sample.py, enter the following code for practice, save it and store it in the directory where the Sample task is located (the specific path of this directory can be viewed through the console output of Jenkins)
Insert image description here

# test_sample.py的代码内容如下
# add()函数
def add(a, b):
	return a + b

# 测试add()函数
def test_add():
	assert add(2, 4) == 5

Enter the E:\jenkins\tomcat9\bin directory, double-click the startup.bat file to run Tomcat, visit http://127.0.0.1:8080/jenkins/ with the browser, enter the Jenkins home page, and enter the Jenkins Simple task home page , click the Configure build option, change the execution window batch command to pytest test_sample.py, save, click build new to build #13 immediately, click #13 to enter the build version information page, click on the console output, you can view the pytest running test The results generated by the use case are shown in the figure below.
Insert image description here
(4) Jenkins plug-in installation
During the installation of Jenkins, you choose to install the default plug-in. If you need to use the functions of certain plug-ins later, this Then you need to install the plug-in. As shown below, enter the Jenkins home page, click Manage Jenkins in the upper right corner -> Plug-in Management -> You can see the plug-in management page, where we can install, update or uninstall plug-ins.
Insert image description here

4. Problems encountered during installation and configuration of Jenkins

Issue 1: Exception in verifying Jenkins account credentials

(1) When using the computer's default account to verify the Jenkins account credentials, an exception pops up, "0x8007052e - Error logging on username/username OA...", and the verification has not been successful.
Insert image description here
Analysis and processing: Looking at the tutorial on Jenkins installation and configuration, we found that it is most likely because the domain user cannot obtain valid service login credentials. Therefore, we first try to add a login account to the user rights allocation, and then restart Jenkins attempts to log in with a domain account. Step 1: The system used here is a Windows 11 system, and the local security policy cannot be found. You need to download the corresponding local security policy first. First, create the gpedit-enabler.bat file, enter the following content and save it:

@echo off 
pushd "%~dp0" 

dir /b %SystemRoot%\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientExtensions-Package~3*.mum >List.txt 
dir /b %SystemRoot%\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientTools-Package~3*.mum >>List.txt 

for /f %%i in ('findstr /i . List.txt 2^>nul') do dism /online /norestart /add-package:"%SystemRoot%\servicing\Packages\%%i" 
pause

Run the gpedit-enabler.bat file, use win + R to call up the running terminal and enter secpol.msc -> Call up the local security policy, and configure the account used to log in to Jenkins. The configuration steps are as shown in the figure below. After the configuration is completed, restart the computer and try to re-verify the domain user. If the verification still fails, you need to proceed to the next step.
Insert image description here
Step 2: Generally speaking, the problem is solved after completing the first step. However, when I log in again after configuring the user rights allocation, the same error is still prompted, and the computer has its own The accounts have been configured all over and cannot be verified. I checked online later and found that after Windows 11, accounts are all bound to Microsoft accounts. I suspected that the computer's default account did not meet the standards of domain users, so I re-created a local account (as shown in the figure below, add a no. Microsoft account user), and configure this account according to the first step, log in as a service, restart Jenkins, enter the newly created account for verification, and the verification is successful.
Insert image description here
The tutorial link for the official Jenkins installation and configuration is as follows: https://www.jenkins.io/doc/book/installing/windows/#invalid-service-logon-credentials

Problem 2: Tomcat fails to start and keeps crashing when clicking

(2) Tomcat fails to start and keeps crashing when clicking. After installing Jenkins according to the first method above, double-click E:\jenkins\tomcat9\bin\startup.bat to start Tomcat. It keeps crashing. By changing startup After dragging the .bat file to the window running terminal and running it, you can see the following exception message prompt

The CATALINA_HOME environment variable is not defined correctly
This environment variable is needed to run this program

Analysis and processing: After checking that there are no abnormalities in the environment variable configuration of Tomcat, JDK and Jenkins, we found that we can try to name the folder where Tomcat
is located apache-tomcat-10.1.11 Change the long name of -windows-x64 to a short name like tomcat10 to solve this problem. After changing the tomcat folder naming, reconfigure the environment variable CATALINA_HOME to E:\jenkins\tomcat9 to solve this problem, but here is When re-running, I encountered another crash problem, which will be analyzed and dealt with in Problem 4.

Problem 3: Changing the name of the tomcat folder encounters program occupation

(3) When encountering problem 2, you can solve the crash problem by changing the tomcat file name. Since Jenkins has been deployed to tomcat here, when changing the name of the tomcat folder, you will encounter the problem of program occupation. Unable to change file name.
Insert image description here
Analysis and processing: Because Jenkins is always running, the name cannot be changed. So we need to enter the service and pause the Jenkins service. After pausing the Jenkins service, we can change the tomcat folder name.
Insert image description here

Problem 4: CATALINA_HOME environment crashes abnormally

(4) After changing the name of the tomcat folder, although the "CATALINA_HOME environment" problem is no longer reported, there is still a crash problem when double-clicking startup.bat to run. Drag the startup.bat file to the window terminal to run. Obtained the following error message.

java.lang.ClassNotFoundException: org.apache.catalina.startup.Catalina

Analysis and processing: After confirming that there are no abnormalities in the versions of jdk, tomcat, Jenkins, etc., it is found that the permissions are not given in the folder. Click on the tomcat folders and a pop-up window for permissions will pop up. Click to confirm, and then restart again. crashed
Insert image description here

Question 5: Change Jenkins execution path

(5) When encountering problem 2, in order to solve the problem of crashing when running tomcat, the name of the folder was changed. However, after changing the name of the tomcat folder, there was a problem that the Jenkins service could not be opened again.
Analysis and processing: The analysis found that an error occurred when running Jenkins because the execution path initially configured in Jenkins changed. When the file name of tomcat is changed, the execution path of Jenkins originally configured to tomcat also changes, so here we need to change the execution path of Jenkins.
Step 1: Find the Jenkins configuration file jenkins.xml in E:\jenkins\tomcat9\webapps, open it into edit mode, and change the execution path to "E:\jenkins\tomcat9\webapps \jenkins.war”

  <executable>E:\JDK\jdk-17.0.8_windows-x64_bin\bin\java.exe</executable>
  <arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "E:\jenkins\tomcat9\webapps\jenkins.war" --httpPort=6688 --webroot="%LocalAppData%\Jenkins\war"</arguments>
  <!--

Step 2: After changing the execution path, you also need to change the path information of Jenkins in the registry. Win + R and enter regedit to bring up the registry and modify the path information in Jenkins in the registry
Insert image description here
After changing the path information in the above two places, restart the computer, restart Jenkins, and Jenkins can open normally.

Question 6: Modify Tomcat and Jenkins port numbers

(6) Tomcat and Jenkins port numbers conflict. Enter http://127.0.0.1:8080/ to enter the Jenkins page, not the Tomcat page.
Analysis and processing: When using the default configuration to install tomcat and Jenkins, the default access addresses are http://127.0.0.1:8080/. At this time, due to port number conflicts, browsing The above addresses entered by the server can only access the Jenkins homepage, but not the Tomcat homepage. Therefore, the solution here is to change their port numbers to avoid conflicts. This is why you need to manually change the Jenkins port when initially installing Jenkins. Because of the port number, if the port number conflict is discovered after the installation is completed, it can only be done by modifying the configuration file.
1. Change the Jenkins configuration file: change the port number in the file jenkins.xml, find the Jenkins configuration file jenkins.xml in E:\jenkins\tomcat9\webapps, open it and enter the edit mode , change the port to "6688", save, restart the notebook, use the browser to access the following link http://127.0.0.1:6688/ to enter the Jenkins homepage.

  <executable>E:\JDK\jdk-17.0.8_windows-x64_bin\bin\java.exe</executable>
  <arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "E:\jenkins\tomcat9\webapps\jenkins.war" --httpPort=6688 --webroot="%LocalAppData%\Jenkins\war"</arguments>
  <!--

2. Change the Tomcat configuration file: change the port number in the file server.xml, find the Tomcat configuration file server.xml in E:\jenkins\tomcat9\conf\, open it and enter the edit mode, and change the port to "8800". Save, restart the notebook, and use the browser to access the following link http://127.0.0.1:8800/ to enter the Tomcat homepage.

    <Connector port="8800" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" URIEncodeing="UTF-8"
               maxParameterCount="1000"
               />

Question 7: Clicking startup.bat to run Tomcat displays garbled information.

(7) After installing Tomcat, when you double-click tomcat’s startup.bat to run Tomcat, you find that the information displayed on the terminal is garbled.
Analysis and processing: The main reason is due to different encoding and decoding. First, open E:\jenkins\tomcat9\conf\server.xml of tomcat and add the displayed encoding method to it, as follows Display, add the statement URIEncoding="UTF-8"
Insert image description here
Then modify the encoding format of the log, open tomcat's E:\jenkins\tomcat9\conf\logging.properties, as follows Display, added java.util.logging.ConsoleHandler.encoding = GBK statement
Insert image description here
After the change is completed, restart tomcat to solve the garbled code problem.

Question 8: Because there is still insufficient free space after clearing expired cache entries - consider increasing the maximum size of the cache

(8) When running tomcat, a warning from tomcat indicating insufficient cache space appears.
Analysis and processing: Open E:\jenkins\tomcat9\conf\context.xml of tomcat, add the following statement to it, save and restart tomcat.
Insert image description here

Question 9: When using a browser to access Jenkins, the webpage prompts 404

(9) When I first configured Jenkins to tomcat, a 404 error was prompted when accessing the browser http://127.0.0.1:8080/Jenkins/.
Insert image description here
Analysis and processing: This problem is mainly caused by version incompatibility. The environment version information initially built here is Java17, Tomcat-10.1.7, and Jenkins 2.346.3 LTS. Here, After changing the Tomcat version to Tomcat-9.0.79, reconfiguring Jenkins solved this problem.

Question 10: Create a Tomcat manager account

Visit http://127.0.0.1:8080/ with the browser and click the manager on the Tomcat homepage as shown in the figure. When logging in to the Tomcat manager, a pop-up window prompts you to enter an account.
Insert image description here
Analysis and processing: When the account input interface appears, click Cancel and the following page information will appear. From the prompted information, we can know that when logging in to the tomcat manager for the first time, we need to enter tomcat-users. Add a login account to the xml file.
Insert image description here
Because we follow the prompts to change the tomcat-users.xml file in E:\jenkins\tomcat9\conf and add the following information

<role rolename="manager-gui-123"/>
<user username="tomcat" password="s3c34dt" roles="manager-gui-123"/>

The tomcat-users.xml file after adding the information is as follows
Insert image description here
After saving successfully, refresh the http://127.0.0.1:8080/ page again, and click Login Management again Manager, use the account added above to log in (username: tomcat, password: s3cret), and you can enter the manager page after logging in. Insert image description here


5. Summary

The above is what this article is going to talk about. This article only briefly introduces the basic deployment method and the implementation of simple tasks of tomcat + Jenkins under the window system. The functions provided by Jenkins are far more than this. Through Jenkins combined with the git warehouse, software can be implemented If you are interested in the continuous integration and automated testing of the project, you can study it in depth on your own.

Guess you like

Origin blog.csdn.net/qq_46166916/article/details/132267154