Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Deploying Jenkins on Linux with Systemd

Tech May 9 3

Environment Preparation

Jenkins requires a Java Development Kit (JDK) and a build tool like Maven to function correctly. The following steps outline the installation of these dependencies on a Linux system.

Installing OpenJDK 11

Modern versions of Jenkins require Java 11 or later. It is recommended to set up a dedicated directory for the Java installation.

mkdir -p /usr/lib/jvm
cd /usr/lib/jvm
wget https://repo.huaweicloud.com/openjdk/11.0.1/openjdk-11.0.1_linux-x64_bin.tar.gz
tar -xzf openjdk-11.0.1_linux-x64_bin.tar.gz
mv jdk-11.0.1 java-11
rm openjdk-11.0.1_linux-x64_bin.tar.gz

Configure the system environment variables by creating a profile script.

cat <<EOF > /etc/profile.d/jdk.sh
export JAVA_HOME=/usr/lib/jvm/java-11
export PATH=\$PATH:\$JAVA_HOME/bin
EOF

source /etc/profile.d/jdk.sh
java -version

Installing Apache Maven

Install Maven using the package manager and configure the mirror repository for faster dependency resolution.

yum install -y maven

Edit the Maven settings file located at /etc/maven/settings.xml to include the Aliyun mirror within the <mirrors> section.

<mirror>
  <id>aliyun-maven</id>
  <mirrorOf>central</mirrorOf>
  <name>Aliyun Maven Mirror</name>
  <url>https://maven.aliyun.com/repository/public</url>
</mirror>

Jenkins Server Installation

Add the official Jenkins repository to the system's package manager list.

wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo --no-check-certificate
rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key
yum install -y jenkins

Service Configuration

Rather than using a manual startup script, managing Jenkins via systemd is recommended for stability and automatic startup capabilities. Locate the jenkins.war file to verify its path.

find / -name "jenkins.war"
# Typically located at /usr/share/java/jenkins.war

Create a systemd service unit file at /etc/systemd/system/jenkins.service. This configuration utilizes the installed JDK 11 and sets a custom HTTP port.

[Unit]
Description=Jenkins Continuous Integration Server
After=network.target

[Service]
Type=simple
User=root
Environment="JENKINS_HOME=/var/lib/jenkins"
WorkingDirectory=/var/lib/jenkins
ExecStart=/usr/lib/jvm/java-11/bin/java -jar /usr/share/java/jenkins.war --httpPort=8091
Restart=always

[Install]
WantedBy=multi-user.target

Reload the systemd daemon, enable the service to start on boot, and start the service.

systemctl daemon-reload
systemctl enable jenkins
systemctl start jenkins

Verify the service status and access the web interface at http://<server-ip>:8091.

Troubleshooting Plugin Installation

During the initial setup, the plugin installation wizard may encounter SSL certificate validation errors (PKIX path building failed). To resolve this, manually install the skip-certificate-check plugin.

Navigate to the Jenkins plugins directory and download the plugin manually.

mkdir -p /root/.jenkins/plugins
cd /root/.jenkins/plugins
wget https://mirrors.tuna.tsinghua.edu.cn/jenkins/plugins/skip-certificate-check/latest/skip-certificate-check.hpi

Restart the Jenkins service to load the plugin. After the restart, allow a few minutes for the initialization process to complete before attempting to install other plugins such as Git.

systemctl restart jenkins

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.