Complete the installation of Jenkins in the Linux environment in 5 minutes

Install Jenkins

step1: Use wget command to download Jenkins

Install wget first yum install wget. If it has already been installed, you can ignore it and go 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 download the jenkins version you need according to your jdk version environment according to the released and long-term supported version through the jenkins war package list.

Note: Jenkins runs based on the java environment
. Use the following command to first check whether the java is installed successfully. java -version
If the java version is output, it means the java installation is successful. Otherwise, you need to install java online. yum install java-1.8.0-openjdk
After the installation is completed, configure the environment variables at the same time. (Environment variables You can check the configuration online) You can enter the command again java -versionto check.
The expected return result is:Insert image description here

step2, create the Jenkins log directory and run jekins

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

Check whether jenkins is running successfully
ps -aux |grep jenkinsor pe -ef|grep jenkins

step3, access jenkins and unlock jenkins, install plug-ins and create administrator users

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

Insert image description here
I have chosen the recommended plug-ins to install.
Insert image description here
After clicking on the recommended plug-ins and
Insert image description here
Insert image description here
setting the information, I will be prompted:

Jenkins URL is the root address used to provide 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 if they have not yet been saved and are generated based on the current request if possible. Best practice is to set this value if the user may need it. This will avoid confusion when sharing or viewing links.
Insert image description here
It will prompt at the end
Insert image description here

step4. At this point, it is completed.

Let’s take a look at the interface of jenkins
Insert image description here

Finish, problems encountered in the above steps

1. Jenkins cannot start

Problem: The above running problem has also been removed.
Note: If an error is reported during the startup process: Address already in use, it can be solved by adjusting the port.

报错信息
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 message 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:
Insert image description here

2. Jenkins cannot be accessed

When you find that you cannot access it, first check the status of jenkins: systemctl status jenkins
There are two situations for checking the status of jenkins:
If case 1 returns:Unit jenkins.service could not be found.

Analysis: If yours is an Alibaba Cloud server, you need to set the security policy to open the port in the Alibaba Cloud management platform before the external network can access the corresponding port.

Solution: Find Network and Security → Security Group in your console, click Manage Rules and
Insert image description here
manually add a security group policy configuration
. This can be understood as opening a port to provide access, my current port is 8081. The configuration is as shown below:
Insert image description hereCase 2
Jenkins is running normally, but it prompts that the website cannot be accessed. The next step is to check the firewall. You
can add corresponding rules:
firewall-cmd --add-port=8080/tcp --permanent --zone=public
or directly turn off the Linux firewall:systemctl stop firewalld

Guess you like

Origin blog.csdn.net/qq_17033579/article/details/129007689