Day 7- #90DaysOfDevOps Challenge

Package Management in Linux

⚡What is Package Manager in Linux?

A package manager is a tool that is used to download, install, update, configure, and remove software applications on a computer operating system. It can be a command line tool like apt(Advanced package tool), yum(Yellowdog update modified), rpm(RedHat package manager), etc., or a GUI application.

An experienced Linux user will rarely use any websites to download software because of ease of use, security, and the fact that most Linux distributions have a list of sources which are called Repositories, from where users can download free open-source software packages.

A package is a compressed software archive file that has all the files related to that software application to deliver its functionality. It may consist of binary executables, configuration files, and other software dependencies. Some common types of Linux packages are .deb, .rpm, and .tgz.


🌟Tasks:

Task 1- Steps to Install Docker and Jenkins using package managers on Ubuntu and CentOS.

Install Docker On Ubuntu:

We can install Docker Engine in different ways, depending on our needs:

Install using apt Repository

Before installing the Docker engine for the first time on a new machine, we need to set up the docker repository, and then we can install and update the docker from this repository.

  1. Update apt package index and install packages to allow apt to use a repository over HTTPS-
$ sudo apt-get update
$ sudo apt-get install ca-certificates curl gnupg

2. Add docker's official GPG key-

$ sudo install -m 0755 -d /etc/apt/keyrings
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
$ sudo chmod a+r /etc/apt/keyrings/docker.gpg

3. Now set up the repository-

$ echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Install Docker Engine:

  1. Update apt package index-
$ sudo apt-get update

2. Install the docker engine, containerd, and docker-compose-

$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

3. Docker should now be installed, the daemon started, and the process enabled to start on boot. Check that it’s running-

$ sudo systemctl status docker

The output should be similar to the following, showing that the service is active and running-

Output

● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2020-05-19 17:00:41 UTC; 17s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 24321 (dockerd)
      Tasks: 8
     Memory: 46.4M
     CGroup: /system.slice/docker.service
             └─24321 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Install Docker on CentOS:

Set up the repository

Install the yum-utils package (which provides the yum-config-manager utility) and set up the repository.

$ sudo yum install -y yum-utils
$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

Install Docker Engine

  1. Install Docker Engine, containerd, and Docker Compose-
$ sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

If prompted to accept the GPG key, verify that the fingerprint matches 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35, and if so, accept it.

This command installs Docker, but it doesn’t start Docker. It also creates a docker group, however, it doesn’t add any users to the group by default.

2. Start Docker-

$ sudo systemctl start docker

3. Docker should now be installed, the daemon started, and the process enabled to start on boot. Check that it’s running-

$ sudo systemctl status docker

4. To make sure it starts at every server reboot-

$ sudo systemctl enable docker

Install Jenkins on Ubuntu:

  1. Jenkins is a JAVA-based open-source tool. So we need to install JAVA to use Jenkins on our system-
$ sudo apt update
$ sudo apt install openjdk-11-jdk -y

2. Add Jenkins repository

It is recommended to install Jenkins using the project-maintained repository, rather than from the default Ubuntu repository. The reason for that is the Jenkins version in the default Ubuntu repository might not be the latest available version, which means it could lack the latest features and bug fixes.

Follow the steps below to add the Jenkins repository to your Ubuntu system.

a. Start by importing the GPG key. The GPG key verifies package integrity but there is no output. Run-

$ curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \
  /usr/share/keyrings/jenkins-keyring.asc > /dev/null

b. Add the Jenkins software repository to the source list and provide the authentication 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

The command adds the Long Term Support (LTS) stable release to the sources list, but there is no output.

3. Install Jenkins

a. Update the system repository one more time. Updating refreshes the cache and makes the system aware of the new Jenkins repository.

$ sudo apt update

b. Install Jenkins by running-

$ sudo apt install jenkins -y

Wait for the download and installation to complete.

c. To check if Jenkins is installed and running, run the following command-

$ sudo systemctl status jenkins

A bright green entry labeled active (running) should appear in the output, indicating that the service is running.

If the Jenkins service is not running or active, run the following command to start it-

$ sudo systemctl enable --now jenkins

Install Jenkins on CentOS:

  1. Install JAVA-
$ sudo yum update -y
$ sudo yum install java-1.8.0-openjdk-devel -y
$ sudo java -version

2. Add the Jenkins repository-

$ wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo

3. Verify Security Key-

$ rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key

4. Update the package again so that the new repository is recognized and available.

$ sudo yum update -y

5. Now install Jenkins-

$ sudo yum install jenkins -y

6. Jenkins has been installed. Let’s start the service and configure it to run automatically when the system is rebooted.

$ sudo systemctl start jenkins
$ sudo systemctl enable jenkins
$ sudo systemctl status jenkins

Task 2- Install docker and Jenkins in Ubuntu and check the status.

Install docker- I created a script using the commands mentioned in Task 1.

No alt text provided for this image

Docker is installed and running-

No alt text provided for this image

Install Jenkins- I created a script using the commands mentioned in Task 1.

No alt text provided for this image

No alt text provided for this image

Task 3 - systemctl vs service command.

These 2 different commands are for 2 different init systems in Linux.

  1. SysVInit - Classic initialization process in Linux.

    • The initialization process relies on the individual service to install relevant scripts on the /etc/init.d directory.

    • Additionally, the scripts must support standard commands such as start, stop, and status.

    • One of the main characteristics of this init system is that it is a start-once process and does not track the individual services afterward.

    • The service command is used for running these init scripts from the terminal.

2. SystemD - A recent initialization system that aims to replace SysVInit.

  • Most Linux distributions such as Debian and Red Hat are already using SystemD as their init system.

  • SystemD continues to run as a daemon process after the initialization is completed.

  • They are also actively tracking the services through their cgroups.

  • The systemctl command is the entry point for users to interact and configures the SystemD.


Thank you for reading! 📘