Table of contents
- What is a Package Manager in Linux?
- What is a Package?
- Different types of package managers in Linux?
- Installation of Docker and Jenkins on Ubuntu & CentOS using package managers
- Systemctl and Systemd
- Write a script to automate the starting and stopping of Docker and Jenkins services
- Use systemctl to enable Docker to start on boot and disable Jenkins from starting on boot
- Use journalctl to analyze the logs of the Docker and Jenkins services
What is a Package Manager in Linux?
A package manager on Linux is essentially a software tool that simplifies the installation, removal, updating, and management of software on your system.
Instead of downloading and installing software manually, the package manager does it for you and keeps everything organized and up-to-date.
comes in two main forms
Command-line tools: These are text-based interfaces that allow you to interact with the package manager using commands. Some popular examples include apt (Debian/Ubuntu), yum (RedHat/CentOS), and pacman (Arch Linux).
Graphical user interfaces (GUIs): These are visual interfaces that provide a user-friendly way to manage software. Most Linux distributions come with a built-in GUI software center, such as the Ubuntu Software Center or GNOME Software.
What is a Package?
In Linux, a package is like a self-contained box of software goodness. It typically includes:
Executable files: These are the actual programs you can run on your system.
Libraries: These are reusable code blocks that other programs can rely on to function.
Configuration files: These files define how the software behaves and are often customized during installation.
Documentation: Sometimes, packages include manuals or other helpful information about the software.
Different types of package managers in Linux?
1. DEB (dpkg and APT):
Used in: Debian, Ubuntu, and many Debian-based distributions.
dpkg: The low-level package manager for installing, removing, and providing information on packages. It doesn't handle dependency resolution automatically.
APT (Advanced Package Tool): Builds on top of dpkg, offering a more user-friendly experience with features like automatic dependency resolution, searching for packages, and handling upgrades.
2. RPM (RPM Package Manager):
Used in: Red Hat Enterprise Linux (RHEL), CentOS, Fedora, and many other RPM-based distributions.
RPM: The core package manager for installing, querying, and removing RPM packages.
Yum (Yellowdog Updater, Modified): A higher-level tool built on RPM, providing functionalities similar to APT like dependency management, updates, and easier searching for packages.
DNF (dnf, or dandified yum): The newer package manager replacing yum in Fedora, offering faster performance, improved dependency handling, and better transaction management.
3. Pacman:
Used in: Arch Linux.
Known for its rolling release model, where packages are continuously updated.
Pacman is a lightweight and efficient package manager that handles installation, removal, upgrades, and dependency resolution.
Installation of Docker and Jenkins on Ubuntu & CentOS using package managers
Installation of Docker on Ubuntu
# Docker installation on Ubuntu
$ apt install docker.io -y
$ docker --version
$ docker images
Installation of Docker on CentOS
The first step is to install any necessary dependencies for Docker. To do this, issue the following command,
$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2
Once that command completes, you’ll need to add the docker-ce repository with the command,
$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
With the repository in place, install docker-ce with the command.
$ sudo yum install docker-ce
You will be asked to okay the installation,
When this completes, you’ll need to add your user to the Docker group. If you skip this step, you’ll only be able to run Docker commands using sudo, which is a security risk. To add your user to the Docker group, issue the command,
$ sudo usermod -aG docker $(whoami)
Log out of CentOS 7 and log back in for the change to take effect.
Finally, you need to start the Docker daemon and enable it so that it will start at system boot. This can be done with the following two commands,
$ sudo systemctl enable docker
$ sudo systemctl start docker
To verify Docker installation,
$ docker --version
Installation of Jenkins on Ubuntu
Jenkins requires Java to run, yet not all Linux distributions include Java by default.
Jenkins by default runs on port 8080.
# Installation of Java
$ sudo apt update
$ sudo apt install fontconfig openjdk-17-jre
$ java -version
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc]" \
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins
$ sudo systemctl status jenkins
Installation of Jenkins on CentOS
Install Java
$ sudo apt install fontconfig openjdk-17-jre
Adding Jenkins software repository
$ sudo wget –O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo
Adding the repository manually – In some instances, the repository will not download correctly. To manually add the repository, enter the following,
$ sudo nano /etc/yum.repos.d/jenkins.repo
This will open the jenkins.repo file for editing. Enter the following lines,
[jenkins]
name=Jenkins-stable
baseurl=http://pkg.jenkins.io/redhat
gpgcheck=1
Next, import the GPG key to ensure your software is legitimate,
$ sudo rpm ––import https://pkg.jenkins.io/redhat/jenkins.io.key
If the process is successful, the system returns a new command line without error.
Install Jenkins
$ sudo dnf install jenkins
If you receive an error that mentions “jenkins not found,” go back and add the repository manually as outlined in the previous step. The system will prompt you to confirm the installation. Type y
, press Enter, and let the installation complete.
Start Jenkins service
To start the Jenkins service and enable it at startup, enter the following,
$ sudo systemctl start jenkins
$ sudo systemctl enable jenkins
To display the status of the Jenkins service, enter the following,
$ sudo systemctl status jenkins
Set Firewall to allow Jenkins
$ sudo firewall-cmd ––permanent ––zone=public ––add-port=8080/tcp
$ sudo firewall-cmd ––reload
Run and Setup Jenkins
# Acces through browser
http://localhost:8080
The browser should display an Unlock Jenkins page. It will ask you to enter a temporary password.
This password was created automatically (but not displayed) during setup. To find it, switch to a terminal window and enter the following,
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
The location is displayed on the Getting Started / Unlock Jenkins page.
The system will display an alphanumeric code. Copy this code and paste it into the password field. Then click Continue.
Jenkins will prompt you to install plugins. It is recommended that you Install suggested plugins. You can always change or customize plugins later.
Once plugins are configured, you’ll be prompted to Create First Admin User. Enter the values you want for your Jenkins Administrator, then click Save and Continue.
Systemctl and Systemd
Systemd is a software suite that acts as the init system on most modern Linux distributions. An init system is the first process that starts up during the boot process and is responsible for initializing the system and bringing up other services.
Systemctl is the primary command-line utility for interacting with systemd.
Write a script to automate the starting and stopping of Docker and Jenkins services
#!/bin/bash
start_service(){
echo "Starting Docker service...."
sudo systemctl start docker
echo "Docker started"
}
stop_service(){
echo "Stoping Docker service...."
sudo systemctl stop docker
echo "Docker stopped"
}
restart_service(){
echo "Restarting Docker service...."
sudo systemctl restart docker
echo "Docker restarted"
}
status_service(){
echo "Checking status of Docker...."
sudo systemctl status docker
}
case "$1" in
start)
start_service
;;
stop)
stop_service
;;
restart)
restart_service
;;
status)
status_service
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0
Use systemctl to enable Docker to start on boot and disable Jenkins from starting on boot
#!/bin/bash
# Function to enable Docker to start on boot
enable_docker_on_boot() {
echo "Enabling Docker to start on boot..."
sudo systemctl enable docker
echo "Docker is enabled to start on boot."
}
# Function to disable Jenkins from starting on boot
disable_jenkins_on_boot() {
echo "Disabling Jenkins from starting on boot..."
sudo systemctl disable jenkins
echo "Jenkins is disabled from starting on boot."
}
# Main script execution
enable_docker_on_boot
disable_jenkins_on_boot
echo "Operation completed."
Use journalctl to analyze the logs of the Docker and Jenkins services
$ sudo journalctl -u docker
$ sudo journalctl -u jenkins
I hope you will enjoy my blog. For more blogs like this, please follow :)
Many thanks for reading! Cheers to learning!!