linux deploy jenkins

Install Jenkins

Use the wget command to download Jenkins

First install wget yum install wget , if it has already been installed, ignore it and go directly to the next step;

  • If your java environment is 11~17, you can execute: wget http://mirrors.jenkins.io/war-stable/latest/jenkins.war

  • If your java environment is 8, you can execute: wget https://mirrors.jenkins.io/war-stable/2.346.1/jenkins.war

  • Or through the jenkins war package list According to the released and long-term supported version, according to your jdk version environment, download the jekins version you need

  • Or through the jenkins war package list According to the released and long-term supported version, according to your jdk version environment, download the jekins version you need

  • Note: The jenkins operation is based on the java environment
    Through the following command, first check whether java is installed successfully java -version
    If the java version is output, it means that the java installation is successful, otherwise you need to install java online, yum install java-1.8.0-openjdk
    After the installation is complete, configure the environment variables at the same time, (environment variable configuration can be checked online) and then enter the command java -version to check

1. JDK1.8 official website download

Download address: Java Downloads | Oracle

Two, decompression

3. After decompression, you will see a folder jdk1.8.0_371 named after the specific version number of jdk in the current directory

3. Configure environment variables

1. Edit the profile file

vim /etc/profile

2. In edit mode (press i key or insert key to enter edit mode), add the following configuration at the end of the profile file:

export JAVA_HOME=/usr/local/java/jdk1.8.0_321

export PATH=$JAVA_HOME/bin:$PATH

export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

3. Save and exit

Press Esc to exit edit mode, then press Shift + : enter wq to save and exit

4. Recompile the profile file

source /etc/profile

Then check the jdk version java -version If the jdk version is displayed, it means the configuration is successful

Create a Jenkins log directory and run jekins

Create Jenkins log directory mkdir /var/log/jenkins
Run jenkins [Start a daemon process of jenkins, specify the port and log name]
java -jar jenkins.war --httpPort=8080 --logfile=/var/log/jenkins/8080.log --daemon

Check whether jenkins runs successfully
ps -aux |grep jenkins or pe -ef|grep jenkins

Access jenkins and unlock jenkins, install plugins and create administrator users

The browser accesses the address of the server started by jenkins, eg: 127.0.0.1:8081, the screenshot below the password prompts to find in this file tail -f /root/.jenkins/secrets/initialAdminPassword< /strong>

Select recommended plugins to install

After setting the information, it will prompt:

enkins URL is used to provide the root address of absolute path links to various Jenkins resources. This means that many Jenkins features need to be set up correctly, such as: email notifications, PR status updates, and the BUILD_URL environment variable provided to the build step.
Recommended defaults are shown in Not yet saved, which are generated from the current request if possible. Best practice is to set this value, users may need to use it. This will avoid confusion when sharing or viewing links.

final tip

This is it, it’s done

Let’s take a look at the jenkins interface

Finish, problems encountered in the above steps

1. Jenkins cannot start

Question: The problem when running above is also moved down
Note: If an error is reported during startup: Address already in use , it can be solved by adjusting the port

error message
java.net.BindException: Address already in use
        at sun.nio.ch.Net.bind0(Native Method)
    .....
Caused: java.io.IOException: Failed to bind to 0.0.0.0/0.0.0.0:8080
        at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:349)
      .....

Solution: The error prompt is occupied, the solution is of course to change the port, haha, please execute the following command:
java -jar jenkins.war --httpPort=8081 --logfile=/var/log/jenkins/8081.log --daemon
After successful execution, there will be a prompt similar to the following:

2. Jenkins cannot access

When you find that you can’t access it, first check the status of jenins: systemctl status jenkins
Check jenkins status There are 2 situations:
If case 1 returns: Unit jenkins.service could not be found.

Analysis: If your server is an Alibaba Cloud server, you need to set a security policy on the Alibaba Cloud management platform. Only after the port is opened can the external network access the corresponding port

Solution: Find Network and Security→Security Group in your console, click Manage Rules

Manually add a security group policy configuration
It can be understood as opening a port to provide access, my current port 8081. The configuration is as follows:

Case 2
The running status of jenkins is normal, indicating that the website cannot be accessed. The next step is to check the firewall
The corresponding rules can be added:
firewall-cmd --add-port=8080/tcp --permanent --zone=public
Or close the Linux firewall directly: systemctl stop firewalld

syntaxbug.com © 2021 All Rights Reserved.