Jenkins is an open source platform that supports tasks such as automated construction and deployment. Basically, it can be said that it is an indispensable tool for continuous integration (CI) and continuous release (CD).
Official website: https://jenkins.io/
Tools/Environment | Version |
---|---|
Linux Server | CentOS 7 |
Jenkins | 2.121.2 |
JDK | 1.8.0_181 |
Nginx | 1.14.0 |
Reference: https://ken.io/note/centos-java-setup
Deploy jdk1.8.0_181 in the directory /usr/java/
After deployment, the root directory of jdk is: /usr/java/jdk1.8.0_181/
Reference: https://ken.io/note/centos-quickstart-nginx-setup
Nginx is deployed to facilitate our access to Jenkins through the domain name. If there is no such requirement, you can ignore this operation
# Add Yum source
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
# Import key
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
sudo yum install -y jenkins
The default listening port of the Jenkins site is 8080
sudo firewall-cmd --add-port=8080/tcp --permanent
sudo firewall-cmd --reload
Because Jenkins default java optional path does not include the jdk path we deployed, so we need to configure it here, otherwise the Jenkins service will fail to start
# Modify the jenkins startup script
sudo vi /etc/init.d/jenkins
# Modify candidates to add java optional path:/usr/java/jdk1.8.0_181/bin/java
candidates="
/etc/alternatives/java
/usr/lib/jvm/java-1.8.0/bin/java
/usr/lib/jvm/jre-1.8.0/bin/java
/usr/lib/jvm/java-1.7.0/bin/java
/usr/lib/jvm/jre-1.7.0/bin/java
/usr/bin/java
/usr/java/jdk1.8.0_181/bin/java
"
# Reload the service (because the Jenkins startup script was modified earlier)
sudo systemctl daemon-reload
# Start the Jenkins service
sudo systemctl start jenkins
# Set the Jenkins service to start on boot
# Since Jenkins is not a Native Service, you need to use the chkconfig command instead of the systemctl command
sudo /sbin/chkconfig jenkins on
Browser enter http://<ip address> :8080
Visit Jenkins
# New Nginx configuration file for Jenkins
sudo vi /etc/nginx/conf.d/jenkins.conf
# Enter the following and save
server {
listen 80; #Listen on port 80
server_name jenkins.ken.io; #Listening domain
access_log /var/log/nginx/jenkins.access.log main;
error_log /var/log/nginx/jenkins.error.log error;
location /{ #Forward or process
proxy_pass http://127.0.0.1:8080;}
error_page 500502503504/50x.html;#Error page
location =/50x.html {
root /usr/share/nginx/html;}}
sudo nginx -s reload
If you do not configure SELinux and access through Nginx reverse proxy, the following errors may occur
# View error message
/var/log/nginx/jenkins.error.log
# Examples of error messages
connect() to 127.0.0.1:8001failed(13: Permission denied)while connecting to upstream, client:127.0.0.1
Method 1: setsebool -P httpd_can_network_connect 1
Method 2:
# Turn off SELinux:
sed -i '/SELINUX/s/enforcing/disabled/'/etc/selinux/config
# Restart:
reboot
Modify the local hosts, point the domain name jenkins.ken.io
to the CentOS IP, and pass the domain name test access
Query the default password of the root account
cat /var/lib/jenkins/secrets/initialAdminPassword
Enter password and unlock
Just select "Install recommended plug-ins" here
After selecting the installed plug-in, you will enter the plug-in installation interface
After the plug-in is installed, it will automatically enter the add administrator interface
The URL here refers to the address where Jenkins is accessed by default.
The default is http://:8080. If you have configured the domain name through Nginx, just fill in the configured domain name.
After configuring the Jenkins URL, the entire Jenkins configuration guide is completed
Click "Start using Jenkins" to enter the Jenkins homepage
Finished~
https://wiki.jenkins.io/display/JENKINS/Installing+Jenkins+on+Red+Hat+distributions
Recommended Posts