Tuesday, May 2, 2023

Deploy, Configure, and Maintain Systems(Part-6)

 In Part 5 of the Learning Linux blog series, we learned how to create and configure Linux file systems like ext4, vfat, xfs, etc. 

In part 6, We will learn and try to understand and construct the required commands to Configure, Manage and maintain the Linux systems. 


- Schedule tasks to run at a set date and time

    Cron Utility: For scheduling repetitive jobs that run every minute, hour, day, etc.

    Scheduling job with cron: Always advise not to put the cron job at the global cron table instead try user-level cron jobs(command - crontab -e)

    # Example of job definition:

# .---------------- minute (0 - 59)

# |  .------------- hour (0 - 23)

# |  |  .---------- day of month (1 - 31)

# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr

# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat

# |  |  |  |  |

# *  *  *  *  * user-name  command to be executed

        crontab -l(list the cronjobs for logged-in user), 

        sudo crontab -e -u aaron(modify crontab for aaron user), 

        sudo crontab -r(remove crontab), 

        By placing the script file(without an extension like .sh) in the below directories:

        cron.daily/

cron.hourly/

cron.monthly/

cron.weekly/

    Scheduling job with anacron: Small unit anacron work with is day so it can run tasks for every days, weeks, months, etc. Cron can miss the job if system is offline but anacron can resume post power-on of the system.

        sudo vim /etc/anacrontab, 

anacron -T (test the anacron file), 

sudo anacron -n -f(force anacron to re-run the jobs again)

    Scheduling job with at: For onetime task.

at 15:00 --> return --> type command --> ctrl + d , 

atq(list the jobs), 

at -c <job id> (view the job detail including the command),

atrm <job id>(remove job), 

Example: 

at 'august 20 2022', 

at '2:30 august 20 2022', 

at 'now + 30 minutes', 

at 'now + 3 hours/days/weeks/months'


- Verify completion of scheduled jobs

    cat /var/log/cron(read the cron log), 

    sudo anacron -n(run the schedule job for today now), 

    sudo grep 'anacron' /var/log/cron(search for anacron in the cron log, you may also search for job name), 

    sudo grep atd /var/log/cron 

    Job command | systemd-cat --identifier=job1 (Record the logs about job in journalcrl), journalctl  | grep 'job1'( look for logs in journalctl for job1), 


- Manage the startup process and services

    Startup processes and services: systemctl cat sshd.service(looking at sshd service unit file), 

    sudo systemctl is-enabled sshd.service(Check the enablement status of service), 

    sudo systemctl enable/disable --now sshd.service(enable and start the service, disable and stop service), 

    sudo systemctl mask atd.service(This command will disable the service and other user/process/service cannot start the service), sudo systemcltl unmask atd.service(disable the masking), 

    sudo systemctl list-units --type service --all (List all service units), 


- Install and update software packages from Red Hat Network, a remote repository, or from the local file system

   Subscription Manager: rhel activating and attaching subscription.

    sudo subscription-manager register --username your-rh-developer-username 

   Repositories: Repository can be local or hosted in internet for all the packages

    sudo yum repolist (show the repository list), 

    sudo yum repolist -v (show the repo with urls, folder, etc), 

    sudo yum repolist all(list all repos optional or disabled ones), 

    sudo subscription-manager repos --enable/disable repo id or sudo yum-config-manager --enable/disable repo id, 

    Add Repos: sudo yum-config-manager --add-repo repo id

     Add repo by adding repo files: 

sudo vi /etc/yum.repos.d/docker-ce.repo 

<

[short name]

name=My repo full name name with desc

baseurl=http://server1.example.com/stable

enabled=1

>

    Managing Package with Yum: 

sudo yum seach 'short desc',  

sudo yum info package name(for more detail about the package), 

sudo yum install httpd, sudo yum reinstall httpd(Reinstall),

 sudo yum remove httpd(remove packages).

Package Groups: 

sudo yum group list(show the package groups), 

sudo yum group install 'Server with GUI', 

sudo yum group remove 'Server with GUI'

Install RPM file: sudo yum install ./package.rpm(install app using yum with rpm package), 

Updating and upgrading with yum: sudo yum check-upgrade, sudo yum update

Work with package module streams:

sudo yum module list, (list all modules)

sudo yum module list nodejs (list nodejs module)

sudo yum module install nodejs:14/development, (Installing nodejs version 14 with development profile)

sudo yum module list --installed nodejs, 


--> echo "Thank you :)"