[Server] Install Jenkins+cpolar on Linux to achieve remote access

        Jenkins is an open source continuous integration (CI) and continuous delivery (CD) tool for automating the building, testing, and deployment of software projects. It provides an easy-to-use platform for the process of building, testing, and delivering software.

        The following describes how to install Jenkins in Linux CentOS 7 and combine it with the cpolar intranet penetration tool to achieve remote access to Jenkins.

1. Install Jenkins

According to the official installation document tutorial: Linux , we enter the following instructions to install.

#添加源
sudo wget -O /etc/yum.repos.d/jenkins.repo \
    https://pkg.jenkins.io/redhat-stable/jenkins.repo
    
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key

#更新仓库,遇到提示,输入y即可
sudo yum upgrade
#安装JDK,如已安装,可以直接跳过
sudo yum install java-11-openjdk

#安装Jinkens
sudo yum install jenkins
​
sudo systemctl daemon-reload

If no errors are reported during the installation process, it means success. Next, start Jenkins.

#设置开机启动
sudo systemctl enable jenkins
​
#启动Jenkins
sudo systemctl start jenkins
​
#查看状态
sudo systemctl status jenkins

After the startup is successful, we check the Jenkins status. We can see that the status is running. At the same time, the local port through which we access Jenkins is also shown below. The 8080latest version of Jenkins does not support lower versions of JDK. It is recommended to install a higher JDK version. .

 

image-20230821143328302.png57d7381fe7d140628c5d8fa1ef7d9057.png

2. Access Jenkins via LAN

Above, after running the Jenkins service, we saw that the local port is 8080. In the external browser, enter the Linux LAN IP address + port 8080 to access the Jenkins web interface. If you cannot access it, you can close the firewall and try it.

52b10ddcd29d40fabdaf721e1622eb55.png

Above we can see on the interface that we need to enter a super administrator password. We follow the prompts and view the corresponding configuration file to view the password.

cat /var/lib/jenkins/secrets/initialAdminPassword

After entering, you can see a very long string, which is the login password.

 b369c0ae56c44afab36b5a53fd079b4f.png

         Through the password we viewed, we can log in successfully after entering it on the interface. Next, we can operate and use Jenkins. The current access is through the LAN. Next, we install and configure cpolar to achieve remote access.

824a4a67293f497e9740df2ab0f71dd6.png

3. Install cpolar intranet penetration software

Above we installed and started the Jenkins service in local Linux, and local access was ok. Next we installed the cpolar intranet penetration tool in Linux. Through cpolar's http public network address, we can easily access Jenkins remotely without having to do it ourselves. Register a domain name and purchase a cloud server. The following are the steps to install cpolar

cpolar official website address: https://www.cpolar.com

  • Use one-click script installation command

curl -L https://www.cpolar.com/static/downloads/install-release-cpolar.sh | sudo bash
  • Add services to the system

sudo systemctl enable cpolar
  • Start cpolar service

sudo systemctl start cpolar

After cpolar is successfully installed, access the 9200 port of Linux on the browser: [http://LAN ip:9200], log in with the cpolar account, and after logging in, you can see the cpolar web configuration interface, and configure it in the web interface. Can

3f0048573aa5449fad9916104dc19c41.png

4. Configure Jenkins public network access address

Click Tunnel Management - Create Tunnel on the left dashboard to create an 80 tunnel for our http access method above!

  • Tunnel name: You can customize the name. Be careful not to duplicate the existing tunnel name.

  • Protocol: Select http

  • Local address: 8080

  • Domain name type: Choose a random domain name for free

  • Region: Select China vip

Click创建

22fb49ba949841faba59f3c9908a2661.png

After the tunnel is successfully created, click the status on the left - online tunnel list to view the generated public network address. There are two access methods, one is http and https, both methods can be accessed.

 

image-20230821142729276.png

5. Remote access to Jenkins via public network

We use the http public network address to access, and we can see our Jenkins site. Such a public network address that can be accessed remotely has been created. To access a new address, you may need to log in again. We can re-enter the password viewed above to log in.

2d01b26f463a40058588e287fbb14a32.png

6. Fixed public network address

Since the tunnel created using cpolar above uses a random public network address, it will change randomly within 24 hours, which is not conducive to long-term remote access. Therefore, we can configure a second-level subdomain name for it. This address is a fixed address and will not change randomly [ps: cpolar.cn has been filed]

Note that you need to upgrade the cpolar package to a basic package or above, and the bandwidth corresponding to each package is different. [cpolar.cn has been registered]

Log in to the cpolar official website , click Reserve on the left, select to reserve the second-level subdomain name, set a second-level subdomain name, click Reserve, and copy the reserved second-level subdomain name after the reservation is successful.

cf827ba7a62c4aeda9206ca90df37885.png

After the reservation is successful, copy the name of the reserved second-level subdomain name

        0a78cf5781e9465d90f78c15bd414e01.png

        Log in to the cpolar web UI management interface, click Tunnel Management - Tunnel List on the left dashboard, find the Jenkins tunnel you want to configure, and click Edit on the right

ee1e044a13554210815fbc68f07d61d1.png

Modify the tunnel information and configure the successfully reserved second-level subdomain name into the tunnel.

  • Domain name type: Select a second-level subdomain name

  • Sub Domain: Fill in the successfully reserved second-level subdomain name

Click 更新(note, click once to update, no need to submit again)

 e6d2d51027164a6aa7d99edc67080f0e.png

After the update is completed, open the online tunnel list. At this time, you can see that the public network address has changed and the address name has become a fixed second-level subdomain name.

        3543f55e965940a89f88991bce3fb148.png

         Finally, we use the fixed public network address to access the Jenkins site. We can see that the access is successful. In this way, a fixed and permanent public network address is set.

04b494c807f64a09b25467245e16dfe4.png

Guess you like

Origin blog.csdn.net/m0_73367097/article/details/132436465