Centos quickly installs Jenkins and accesses it through the nginx agent

Posted by xterra on Tue, 01 Feb 2022 16:13:58 +0100

Here are some points to note during installation

Install according to the official website documents

Remember! First, the documents are official documents. Please don't read Baidu articles at will. For those that are well written and poorly written, it's best to look at the official website:

Jenkins official website:
https://www.jenkins.io/

Centos installation documentation

https://www.jenkins.io/doc/book/installing/linux/#red-hat-centos

I usually choose the latest and most stable version in the Long Term Support release

# Get image source from yum
sudo wget -O /etc/yum.repos.d/jenkins.repo \
    https://pkg.jenkins.io/redhat-stable/jenkins.repo
# Import yum image source    
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key

# Update yum or up2date
sudo yum upgrade

# Install jenkins using yum. You need to install jdk11 related components here
sudo yum install jenkins java-11-openjdk-devel

# Register to update systemctl 
sudo systemctl daemon-reload

# Start Jenkins
sudo systemctl start jenkins

Attention

  1. The default port is 880. If you have firewall restrictions, please open port 8080

    The virtual machine is usually set in the security group. You can add port 8080. If yes
    Local host, using firewall management command:

    	YOURPORT=8080
    	PERM="--permanent"
    	SERV="$PERM --service=jenkins"
    	
    	firewall-cmd $PERM --new-service=jenkins
    	firewall-cmd $SERV --set-short="Jenkins ports"
    	firewall-cmd $SERV --set-description="Jenkins port exceptions"
    	firewall-cmd $SERV --add-port=$YOURPORT/tcp
    	firewall-cmd $PERM --add-service=jenkins
    	firewall-cmd --zone=public --add-service=http --permanent
    	firewall-cmd --reload
    
  2. Startup management file location: / etc / RC d/init. d/jenkins
    According to the sudo systemctl status jenkins command, you can view the output information, including the location of the startup management file

  3. From / etc / RC d/init. The address of the loaded configuration file can be seen in D / Jenkins:
    /In / etc/sysconfig/jenkins, you can modify the properties here. Of course, you need to restart jenk to take effect

  4. The configuration file includes which user uses jenk. The default is "Jenkins". If you don't want to add a new user, you can directly use root. You need to modify the following properties


	## Type:        string
	## Default:     "jenkins"
	## ServiceRestart: jenkins
	#
	# Unix user account that runs the Jenkins daemon
	# Be careful when you change this, as you need to update
	# permissions of $JENKINS_HOME and /var/log/jenkins.
	#
	JENKINS_USER="root"


  1. Port information is included in the configuration file
 	## Type:        integer(0:65535)
 	## Default:     8080
 	## ServiceRestart: jenkins
 	#
 	# Port Jenkins is listening on.
 	# Set to -1 to disable
 	#
 	JENKINS_PORT="8080"

  1. The prefix of Jenkins web access can be set in the configuration file. It is none by default and can be accessed directly http://localhost:8080 , if the prefix "/ jenkins" is set below, the final access address is
    http://localhost:8080/jenkins
  
	## Type:        string
	## Default:     ""
	## ServiceRestart: jenkins
	#
	# Pass arbitrary arguments to Jenkins.
	# Full option list: java -jar jenkins.war --help
	#
	JENKINS_ARGS="--prefix=/jenkins"

  1. Using nginx agent, the nginx configuration is as follows:
location /jenkins/
{
	proxy_redirect off;
	# proxy_set_header Host $host;
	proxy_set_header Host $host:$server_port; #$server_port
	proxy_set_header X-Real-IP $remote_addr;
	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	proxy_set_header X-Forwarded-Proto $scheme;
	proxy_set_header X-Nginx-Proxy true;
	proxy_pass http://172.17.0.1:8080/jenkins/;
}

The above configuration environment is that nginx is started by the docker container in the physical host. Jenkins is directly followed by the physical host, so the ip address is changed to 172.17.0.1. If nginx is also directly followed by the physical host, directly l change the ip address to localhost.

Access and install plug-ins

According to the prefix configuration above, access http://172.17.0.1:8080/jenkins/

Generally, you need to enter token for Unlocking Jenkins for the first time

Command view token

sudo cat /var/lib/jenkins/secrets/initialAdminPassword

Then enter the plug-in selection and installation interface Customizing Jenkins with plugins

It is recommended to choose Custom installation plug-ins, otherwise the recommended installation is slow and time-consuming.

over thanks !

Topics: Linux Operation & Maintenance CentOS Docker jenkins