Welcome back to the 90DaysOfDevOps Challenge! On Day 7, we delve into the essential components of Linux systems - Package Managers and systemctl
. Let's explore these crucial tools and, as part of our challenge, install Docker and Jenkins using package managers on Ubuntu and CentOS.
Understanding Package Managers:
What is a Package Manager?
In the Linux ecosystem, a Package Manager is a command-line or graphical tool that simplifies the installation, removal, and management of software packages on an operating system. It's the Swiss Army knife for handling software components.
What is a Package?
A package can be an application, a command-line tool, or a library required by other software. It's essentially an archive file containing the binary executable, configuration files, and sometimes information about dependencies.
Different Kinds of Package Managers:
Different Linux distributions have different packaging systems. For instance, RPM-based systems like CentOS use Yum and DNF, while Debian-based systems like Ubuntu have apt-get
and aptitude
.
Installing Docker and Jenkins:
Installing Docker on Ubuntu:
sudo apt-get update
sudo apt-get install docker-ce
Installing Docker on CentOS:
sudo yum install docker-ce
Installing Jenkins on Ubuntu:
sudo apt-get install openjdk-11-jdk # Install Java
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install jenkins
Installing Jenkins on CentOS:
sudo yum install java-11-openjdk # Install Java
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key
sudo yum install jenkins
Understanding systemctl and systemd:
What is systemctl?
systemctl
is a command-line utility and the principal tool to examine and control the "systemd" system and service manager. systemd
is a system and service manager for Unix-like operating systems. It plays a crucial role in managing the startup and control of various system processes, services, and other units in modern Linux distributions.
Here are some key functionalities and use cases of systemctl
:
Service Management:
Start a service:
sudo systemctl start <service-name>
Stop a service:
sudo systemctl stop <service-name>
Restart a service:
sudo systemctl restart <service-name>
Check the status of a service:
systemctl status <service-name>
Enable a service to start on boot:
sudo systemctl enable <service-name>
Disable a service from starting on boot:
sudo systemctl disable <service-name>
Unit Management:
systemctl
can handle various types of units, including services, sockets, devices, targets, and more.
Logging and Journal Management:
View system logs:
journalctl
Filter logs for a specific service:
journalctl -u <service-name>
Power Management:
systemctl
can be used to handle power-related tasks, such as suspending or rebooting the system.
Target Management:
systemctl
can switch between system states or targets. For example, switching to multi-user.target for a text-based interface or graphical.target for a graphical interface.
systemctl
provides a centralized and unified interface for managing various aspects of the system, making it easier to handle processes, services, and system states. It has become the standard for system and service management in many modern Linux distributions, replacing older init systems.
Tasks:
- Check Docker Service Status:
To check the status of the Docker service using systemctl
, you can use the following command:
systemctl status docker
Running this command will provide detailed information about the current status of the Docker service, including whether it is active, any recent logs, and more. If Docker is installed and running, you should see an output indicating that the service is active and running.
Make sure to run this command with administrative privileges, so you might need to use sudo
:
sudo systemctl status docker
This command will help you ensure that the Docker service is up and running on your system. If there are any issues, the output will provide information that can be useful for troubleshooting.
- Stop Jenkins Service:
Task 2 involves stopping the Jenkins service and capturing screenshots before and after the service is stopped. Here's the command:
sudo systemctl stop jenkins
Stop Jenkins Service: bash Copy code sudo systemctl stop jenkins This command will stop the Jenkins service on your system.
Compare
systemctl
andservice
Commands:Using
systemctl
:Check the status of the Docker service using
systemctl
:systemctl status docker
Using
service
:Check the status of the Docker service using the older
service
command:service docker status
Explanation:
systemctl
Command:systemctl
is the modern and more powerful command for managing services in systems using thesystemd
init system.It provides detailed information about the service status, logs, and more.
service
Command:service
is the older command used with traditional init systems like SysV.It is still supported on many systems for compatibility with scripts and commands written for older init systems.
Example Output:
systemctl status docker
:
โ docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2024-02-01 12:00:00 UTC; 1 day 1h ago
...
service docker status
:
โ docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2024-02-01 12:00:00 UTC; 1 day 1h ago
...
Explanation of the Comparison:
Both commands are used to check the status of a service.
systemctl
provides more detailed information, including additional features provided bysystemd
.service
is a simpler and older command, often used in scripts and commands designed for traditional init systems.
Congratulations! You've successfully installed Docker and Jenkins using package managers on both Ubuntu and CentOS. Understanding these tools is pivotal in mastering DevOps, and the exploration of systemctl
and systemd
adds another layer of expertise.
Continue your journey with the 90DaysOfDevOps Challenge, and feel free to experiment with these tools. Stay tuned for Day 8 as we dive deeper into the world of DevOps.
Happy coding! ๐