Linux system builds CICD jenkins environment from scratch

1. Operating system and environment

This article teaches you to build a jenkins environment from scratch and start your CICD journey.

1.1 System and installation environment

The environment of this article is a cloud server environment, and the system is a linux Red-hat system. The version information is as follows:

Linux version 3.10.0-1160.88.1.el7.x86_64 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP

If it is linux other systems, you can also refer to it.
If you don't know the version information of your environment, you can use the following command to check:

cat /proc/verison

1.2 Confirm whether jenkins has been installed

jenkins --versino # 查看jenkins的版本

If jenkins has been installed in the environment, you can see the installed version of jenkins. If it shows that the command does not exist, then it is not installed.

2. Install JDK

Because jenkins needs to rely on the jdk environment, it is necessary to install jdk on the environment first.

2.1 First check whether jdk is installed on the server.

java -version # 检查是否安装jdk

If jdk is installed, the java version information will be displayed. If it prompts that the java command does not exist, it means that it is not installed. You can follow the steps below to install.

2.2 View the java version that can be installed in the environment

yum -y list java*   # 查看可用的java版本

insert image description here

2.3 Select the required java version to install.

I chose java-1.8.0-openjdk-src.x86_64 here. Because the jenkins version needs to match the java version. If the version of java is too high, Jenkins may not support it, so it is not recommended to choose a version that is too high.

 yun install -y java-1.8.0-openjdk-src.x86_64

2.4 Check whether the installation is successful

If the installation is successful, enter the following command to see the installed version. As shown below
insert image description here

3. Download and install jenkins software

3.1 Download jenkins software

I first download the jenkins software through the windows computer, and then upload the software to the linux server through the ssh connection for installation.
First go to the jenkins official website to download the jenkins software, as shown in the figure below:
select the software corresponding to the centos system in the red box
insert image description here
, and then select the specific version to download. I choose version 2.345 here.
If the java version is also 1.8.0, it is recommended to choose a version of 2.345 or below, otherwise it may not match the java version.
insert image description here

3.2 install jenkins

Upload the downloaded jenkins to the linux server. The storage path is not particularly particular, for example, it exists under the opt2/download directory.
Execute the following decompression and install jenkins (jenkins version needs to be based on the version you downloaded)

rpm -ivh jenkins-2.345-1.1.noarch.rpm

Installation is quick to complete.
insert image description here
If the installation is successful, enter: jenkins --version to see the version information of jenkins.

WARNING: You are running Jenkins on Java 1.8, support for which will end on or after September 1, 2022. Please refer to the documentation for details on upgrading to Java 11: https://www.jenkins.io/redirect/upgrading-jenkins-java-version-8-to-11
2.345

4. Modify the jenkins configuration file

Edit the configuration file with the following command:

vim /etc/init.d/jenkins

4.1 Update java path

Update the java installation path to the list below.
(Generally speaking, the default installation path is /usr/bin/java, which is already included and does not need to be updated.)
insert image description here
If you are not sure about the java path, you can enter the following command to view

which java

4.2 Update user and port number

Compile the configuration file by the following command, modify the user and port number

vim /etc/sysconfig/jenkins

The user defaults to jenkins. For subsequent convenience, modify the root
insert image description here
port number to 8080 by default. It can be modified to other port numbers as needed (or not modified). It may
insert image description here
not be useful to modify the above files only, and the following files need to be modified:

vim /usr/lib/systemd/system/jenkins.service

insert image description here
After modification, reload the configuration file:

systemctl daemon-reload # 重新加载一下配置文件

Special attention: the port number must be the port number opened by the cloud server. See Appendix 1 for how to view and set the development port number of Tencent Cloud Server

5 Start the jenkins server

5.1 Start the jenkins service

You can start/shut down jenkins with the following three commands and check the running status of jenkins

systemctl start jenkins # 启动jenkins服务
# 然后开启另外一个窗口,查看jenkins状态
systemctl status jenkins # 查看jenkins状态
systemctl stop jenkins # 关闭jenkins服务

5.2 Start jenkins for the first time

If you have just installed the jenkins software and started it for the first time, you need to refer to the following operations.

After starting jenkins for the first time, you can open another window to view the status of jenkins through the following command.
Generally speaking, if it is the first start, when you check the status, you will be prompted with similar information as follows:

Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:
52b645e6561740d9a084900904cb49c4

As shown in the figure below, you can also see the running port number after startup, and the password for the first startup will be prompted when you run it for the first time: At
insert image description here
this time, we only need to enter: ip:port number on the web page to complete the first startup
and then enter the command line Just copy the prompted password to the input box on the webpage.
insert image description here
Then enter the plug-in installation interface, if you are a novice, just choose to install the recommended plug-in.
insert image description here
After completing the above operations, check the running status of jenkins again, and you can see the following:
Jenkins is already in the activated running state, indicating that jenkins is running~
insert image description here

So far, the jenkins environment has been set up, and other software can be installed later as needed, and the cicd journey can be started~

Appendix 1 View and set the development port number of Tencent Cloud Server

First, log in to the Tencent Cloud website, find the server you bought, and then you can see the list of open ports in the firewall, as follows:
insert image description here
If you want to open a new port, click Add rule, for example, I add a port 8888 to be used by jenkins
insert image description here

Guess you like

Origin blog.csdn.net/weixin_43354152/article/details/130958501