How To Install Jenkins on CentOS Stream 10
In this tutorial, we will show you how to install Jenkins on CentOS Stream 10. Jenkins is a powerful tool for automating software development processes, offering a robust platform for Continuous Integration (CI) and Continuous Deployment (CD). It is widely used in the software industry due to its flexibility, scalability, and extensive plugin ecosystem. In this article, we will guide you through the process of installing Jenkins on CentOS Stream 10, a stable and reliable Linux distribution that provides a solid foundation for running Jenkins.
Introduction to Jenkins and CentOS Stream 10
Jenkins is a Java-based application, which means it requires a Java Development Kit (JDK) to be installed on your system. CentOS Stream 10, with its stable and rolling updates, is an excellent choice for hosting Jenkins, as it ensures that your system remains up-to-date with the latest security patches and software versions.
Why Choose CentOS Stream 10 for Jenkins?
- Stability and Support: CentOS Stream 10 offers a balance between stability and the latest software updates, making it ideal for production environments.
- Community Support: It benefits from a large community of users and developers, ensuring there are plenty of resources available for troubleshooting and optimization.
- Compatibility: CentOS Stream 10 is compatible with a wide range of software applications, including Jenkins, due to its adherence to Red Hat Enterprise Linux (RHEL) standards.
Prerequisites for Installing Jenkins
Before you begin the installation process, ensure your system meets the necessary prerequisites.
Hardware Requirements
Jenkins requires at least 256 MB of RAM and 1 GB of disk space for basic operations. However, for a more robust setup, especially if you plan to run multiple jobs or use Docker containers, consider the following:
- Recommended RAM: 4 GB or more.
- Recommended Disk Space: 50 GB or more.
Software Requirements
- Java: Jenkins requires Java to run. You can install OpenJDK, which is a popular choice for Jenkins installations.
- Internet Connection: Ensure you have an active internet connection to download the necessary packages.
Step-by-Step Installation Guide
Step 1: Update CentOS Stream 10
To ensure your system is up-to-date, run the following command in your terminal:
sudo dnf update
This command updates all packages to their latest versions, which is crucial for maintaining system stability and security.
Step 2: Install Java
Jenkins requires Java to function. Install OpenJDK using the following command:
sudo dnf install java-17-openjdk
Verify that Java has been installed correctly by checking its version:
java --version
Step 3: Add Jenkins Repository
Jenkins is not included in the default CentOS repositories. You need to add the Jenkins repository manually:
sudo curl -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
Step 4: Import GPG Key
To ensure the authenticity of the Jenkins package, import the GPG key:
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
Step 5: Install Jenkins
Now, you can install Jenkins using the following command:
sudo dnf install jenkins
Step 6: Configure Jenkins Service
To ensure Jenkins listens on all interfaces, you may need to edit its configuration. However, for most setups, the default configuration is sufficient. If you need to make changes, you can edit the service file:
sudo systemctl edit jenkins
Add the following lines to the [Service]
section to set the Java command and listening address:
[Service]
Environment="JENKINS_JAVA_CMD=/etc/alternatives/java"
Environment="JENKINS_LISTEN_ADDRESS=0.0.0.0"
Save and exit the editor.
Step 7: Start and Enable Jenkins Service
Start the Jenkins service and enable it to run on boot:
sudo systemctl start jenkins
sudo systemctl enable jenkins
Step 8: Verify Jenkins Service Status
Check if the Jenkins service is running correctly:
sudo systemctl status jenkins
Step 9: Configure Firewall Rules
If your server uses a firewall, you need to allow Jenkins traffic. Open port 8080 (the default Jenkins port):
sudo firewall-cmd --add-port=8080/tcp --permanent
sudo firewall-cmd --reload
Step 10: Retrieve Initial Admin Password
To access Jenkins for the first time, retrieve the initial admin password:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Step 11: Access and Set Up Jenkins
- Access Jenkins: Open a web browser and navigate to
http://your-server-ip:8080
. - Unlock Jenkins: Enter the initial admin password.
- Install Suggested Plugins: Choose to install the recommended plugins for a basic setup.
- Create Admin User: Set up your admin user account.
- Set Jenkins URL: Optionally, configure the Jenkins URL to match your server’s domain or IP.
- Start Using Jenkins: Click “Start using Jenkins” to complete the setup.
Advanced Configuration Options
Customizing Jenkins URL
If you want to change the default Jenkins URL, you can do so during the initial setup or later by editing the Jenkins configuration file:
- Access Jenkins and go to Manage Jenkins > Configure System.
- Find the Jenkins URL field and update it with your desired URL.
- Save and restart the Jenkins service if necessary.
Using Different Ports
To use a different port (e.g., 9090), edit the Jenkins service configuration:
- Edit the Jenkins service file:
sudo systemctl edit jenkins
- Add or modify the
JENKINS_PORT
environment variable:
[Service]
Environment="JENKINS_PORT=9090"
- Reload systemd and restart the Jenkins service:
sudo systemctl daemon-reload
sudo systemctl restart jenkins
- Update firewall rules if necessary:
sudo firewall-cmd --add-port=9090/tcp --permanent
sudo firewall-cmd --reload
Securing Jenkins with SSL/TLS
To secure your Jenkins instance with HTTPS, you can use a reverse proxy server like NGINX:
- Install NGINX:
sudo dnf install nginx
- Generate SSL Certificates (e.g., using Let’s Encrypt):
sudo dnf install certbot python3-certbot-nginx sudo certbot --nginx -d yourdomain.com
- Configure NGINX as a Reverse Proxy: Edit the NGINX configuration file (
/etc/nginx/nginx.conf
or a site-specific file in/etc/nginx/conf.d/
) to include:server { listen 443 ssl; server_name yourdomain.com; ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem; location / { proxy_pass http://localhost:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } }
- Restart NGINX:
sudo systemctl restart nginx
Troubleshooting Common Issues
Jenkins Service Not Starting
- Check Service Status: Use
sudo systemctl status jenkins
to identify any errors. - Journalctl Logs: Inspect detailed logs with
sudo journalctl -u jenkins
. - Java Version Compatibility: Ensure you are using a compatible Java version.
Firewall Issues
- Check Firewall Rules: Verify that Jenkins’ port is open using
sudo firewall-cmd --list-all
. - Temporary Allowance: Temporarily disable the firewall to test if it’s blocking Jenkins.
Java Version Compatibility
- Check Java Version: Run
java --version
to ensure you are using a supported version. - Update Java: If necessary, update Java to a compatible version.
Congratulations! You have successfully installed Jenkins. Thanks for using this tutorial for installing Jenkins on your CentOS Stream 10 system. For additional help or useful information, we recommend you check the official Jenkins website.