Explain in detail how to deploy spring boot project with Jenkins

Jenkins is a Devops artifact. This article describes how to install and use Jenkins to deploy the spring boot project

Jenkins construction and deployment is divided into three steps;

The first step is Jenkins installation

Preparation environment:

JDK is installed by default

Configure maven

Version requirements Maven 3 five

Software download

install

Modify the environment variable and add the following lines in / etc / profile

Remember to execute source / etc / profile to make the environment variable take effect.

Finally, run MVN - V to verify whether Maven is installed successfully

Configure protective wall

Close the protective wall

Run the two commands at the same time. After running, check the firewall shutdown status

Jenkins installation

download

Start service

Jenkins started successfully! Its war package comes with a jetty server

When Jenkins is started for the first time, for security reasons, Jenkins will automatically generate a random password. Note the password output from the console, copy it, and then enter the password in the browser:

Access the browser: http://localhost:8080/

Input: 0cca37389e6540c08ce6e4c96f46da0f

In the user-defined plug-in interface, it is recommended to install the official recommended plug-in, because you have to install it yourself after installation:

Next, enter the plug-in installation progress interface:

The plug-in may not be completely installed at one time. You can click Retry to install it again. Until all are installed successfully

After waiting for a period of time, the plug-in installation is completed, and the user name and password are configured:

Input: admin / Admin

System management - global tool configuration JDK path,

The second step is plug-in installation and configuration

Many plug-ins are installed by default, so we don't need to install many plug-ins now. Git plugin, Maven integration plugin, publish over SSH and CVs plug-ins manage SSH.

Plug in installation: System Management > plug-in management > optional plug-ins, check the plug-ins to be installed, click direct installation or download and restart to install

Configure global variables

System Management > global tool configuration

JDK

Configure the path of the local JDK and remove the check box for automatic installation

Maven

Configure the path of the local Maven and remove the check box for automatic installation

Other contents can be installed according to your own situation.

Configure SSH login free

SSH can be configured with a key or a password. Here we use the key to configure. Before configuration, configure the keys of the Jenkins server and the application server, authenticate the Jenkins server, generate a key pair, and use the SSH keygen - t RSA command

Enter the following command and press enter until a rectangular figure appears, indicating success. In ~ / There will be a private key ID under SSH /_ RSA and public key ID_ rsa. pub

The public key ID of the Jenkins server_ rsa. Copy the contents in pub to ~ /. Of the application server Authorized under SSH /_ Keys file

Restart the SSH service on the application server. Service sshd restart now the Jenkins server can log in directly to the application server without password

After that, try whether you can log in to the B server without password with SSH B. If you still need to enter a password, there are the following reasons

a. The non root account may not support SSH public key authentication (depending on whether the server has restrictions) B. the public key file passed over does not have sufficient permissions. You can authorize Chmod 644 authorized_keys to this file C. when using the root account to execute the SSH copy ID - I ~ /. SSH / id_rsa.pub command, if you need to enter a password, configure sshd_config

Restart the sshd service after modification

Finally, if SSH IP password free login is successful, SSH public key authentication is successful.

Step 3: push SSH

System Management > system settings

Select publish over SSH

Passphrase write the generated SSH path without setting path to key: / root / ssh/id_ rsa

The following SSH servers are the key points

Name is optional to represent this service. It will be selected according to it later. Then hostname configures the address of the application server username configures the login user name of Linux remote directory, which is not filled in

Click add below to add addresses of multiple application servers

Step 4: deploy the project

Click new on the home page: enter the project name

Select to build a maven project below and click OK.

Check discard old builds and choose whether to back up the replaced old packages. I choose to back up the last 10 here

Source code management, select SVN, configure SVN related information, and click Add to enter the account and password of SVN

Svn address: http://192.168.0.xx/svn/xxx @Head, @ head means the latest version

Check "add timestamps to the console output" in the build environment, and the log will be printed during code building

Enter the MVN command before packaging in build, such as:

It means: exclude the package content of the test and use the configuration file with the suffix test.

Post steps select run only if build successes

Click add post build step and select send files or execute commands over SSH

Name select the push SSH configured above

Source files configuration: target / xxx-0.0 1-SNAPSHOT. Jar project jar package name remove prefix: target / remote directory: Jenkins in / code directory address of application server, exec command: Jenkins in / xxx SH script corresponding to the application server.

You need to create a folder in the application server: Jenkins in. Copy the script content in the folder: XXX sh

The meaning of this script is to kill the old project, delete the old project, start a new project and back up the old project.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>