Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Jenkins to realize automatic deployment in Linux

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Linux how to use Jenkins to achieve automatic deployment, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

Install Java

Jenkins is a Java application that requires Java 8 or later to be installed on the system. We will install OpenJDK 11, the open source implementation of the Java platform.

Run the following command as root user or user with sudo privileges or root user to install OpenJDK 11:

Linuxmi@linuxmi:~/www.linuxmi.com$ sudo apt update linuxmi@linuxmi:~/www.linuxmi.com$ sudo apt install openjdk-11-jdk

After the installation is complete, check the Java version:

Linuxmi@linuxmi:~/www.linuxmi.com$ java-version

The output should look like this:

Openjdk version "11.0.8" 2020-07-14 OpenJDK Runtime Environment (build 11.0.8+10-post-Ubuntu-0ubuntu120.04) OpenJDK 64-Bit Server VM (build 11.0.8+10-post-Ubuntu-0ubuntu120.04, mixed mode, sharing)

Install Jenkins

It is relatively easy to install Jenkins on Ubuntu. We will enable the Jenkins APT repository, import the repository GPG key, and install the Jenkins package.

Use the following wget command to import the GPG key for the Jenkins repository:

Linuxmi@linuxmi:~/www.linuxmi.com$ wget-Q-O-https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add-

Next, add the Jenkins repository to the system using the following command:

Linuxmi@linuxmi:~/www.linuxmi.com$ sudo sh-c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > / etc/apt/sources.list.d/jenkins.list'

After enabling the Jenkins repository, update the list of apt packages and install the latest version of Jenkins by entering the following command:

Linuxmi@linuxmi:~/www.linuxmi.com$ sudo apt update linuxmi@linuxmi:~/www.linuxmi.com$ sudo apt install jenkins

If you get an error message that says:

W: GPG error: https://pkg.jenkins.io/debian-stable binary/ Release: the following signature cannot be verified because there is no public key: NO_PUBKEY 9B7D32F2D50582E6

E: the warehouse "http://pkg.jenkins.io/debian-stable binary/ Release" does not have a digital signature.

Solution method

Import key:

Linuxmi@linuxmi:~/www.linuxmi.com$ sudo apt-key adv-keyserver keyserver.ubuntu.com-recv-keys 9B7D32F2D50582E6

Then run it again:

Linuxmi@linuxmi:~/www.linuxmi.com$ sudo apt update linuxmi@linuxmi:~/www.linuxmi.com$ sudo apt install jenkins

The Jenkins service will start automatically after the installation process is complete. You can verify it with the following command:

Linuxmi@linuxmi:~/www.linuxmi.com$ systemctl status jenkins

You should see something like this:

● jenkins.service-LSB: Start Jenkins at boot time

Loaded: loaded (/ etc/init.d/jenkins; generated) Active: active (exited) since Fri 2020-07-24 16:47:34 CST; 1min 27s ago Docs: man:systemd-sysv-generator (8) Tasks: 0 (limit: 4624) Memory: 0B CGroup: / system.slice/ jenkins.serviceJuly 24 16:47:32 linuxmi systemd [1]: Starting LSB: Start Jenkins at boot time... July 24 16:47:32 linuxmi jenkins [33922]: Correct java version found July 24 16:47:32 linuxmi jenkins [33922]: * Starting Jenkins Automation Server j > July 24 16:47:33 linuxmi su [33976]: (to jenkins) root on none July 24 16:47:33 linuxmi su [33976]: pam_unix (su-l:session): session opened for u > July 24 16:47:33 linuxmi su [33976]: pam_unix (su-l:session): session closed for u > 7 The 24th 16:47:34 linuxmi jenkins [33922]:... done. July 24 16:47:34 linuxmi systemd [1]: Started LSB: Start Jenkins at boot time.

You can also view process information.

Linuxmi@linuxmi:~/www.linuxmi.com$ ps-ef | grep jenkins

Adjust the firewall

If you install Jenkins on a remote Ubuntu server protected by a firewall, you need to open port 8080.

The Jenkins default port is 8080, which is defined in the configuration file / etc/default/jenkins.

HTTP_PORT=8080

This article is revised to 9090

Typically, you want to allow access to the Jenkins server only from a specific IP address or IP range. For example, to allow only connections from the "192.168.135.0 Universe 24" subnet, run the following command:

Sudo ufw allow proto tcp from 192.168.135.0/24 to any port 9090

If you need to allow access to run from anywhere:

Sudo ufw allow 9090

Set up Jenkins

To install a new Jenkins installation, open a browser, enter a domain or IP address, and then enter port 9090, http://192.168.150.135:9090

The following page prompts you for the administrator password created during installation:

Unlock Jenkins

To ensure that the administrator installs Jenkins safely, the password has been written to the log (I don't know where? ) the file is on the server:

/ var/lib/jenkins/secrets/initialAdminPassword

Please copy the password locally and paste it below.

Use cat to display the password on the terminal:

Sudo cat / var/lib/jenkins/secrets/initialAdminPassword

You should see a 32-character alphanumeric password, as follows:

B55aa5df790f41688125c182193aecfe

Copy the password from the terminal, paste it into the Administrator password field, and click continue.

On the next screen, the installation wizard will ask you if you want to install the recommended plug-in or select a specific plug-in.

Click the "install recommended plug-ins" box, and the installation process will begin immediately.

Once the plug-in is installed, you will be prompted to set up the first administrator user. Fill in all the required information, and then click "Save and finish".

The next page will ask you to set up URL for the Jenkins instance. This field will be populated with an automatically generated URL.

Confirm URL by clicking the Save and finish button, and the setup process will be completed.

Click the restart button to start using Jenkins, and you will be redirected to the Jenkins dashboard logged in as the admin user you created in one of the previous steps.

At this point, you have successfully installed Jenkins on the server.

After reading the above, have you mastered how to use Jenkins to achieve automatic deployment in Linux? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report