The beginning of a Linux Story
Welcome to the day-5 blog of the Linux workshop Guided by Mr Pranav Jambare .
The following Topics were covered on Day 5 of the workshop.
Logs
Linux logs provide a timeline of events for the Linux operating system, applications, and system and are a valuable troubleshooting tool when you encounter issues.
When issues arise, analyzing log files is the first thing an administrator needs to do.
Linux has a special directory for storing logs called
/var/log
.
This directory contains logs from the OS itself, services, and various applications running on the system.
Here are various logs that can be found
Kernel log -> kernel related
Boot log -> Booting related
Cups log -> Pointer related
dmesg log -> Device related
wtmp log -> Login/Logout related
mail log -> Mail related
fail log -> failed login related
yum log -> package installation related
cron log -> Scheduling related
secure log -> Authentication related
message log -> 85-90% logs are messages
xorg -> graphic related
rsyslog.conf
The rsyslog.conf file is used for configuring rsyslog service in Linux.
It is located in "/etc/rsyslog.conf"
"/etc/rsyslog.d/" for ubuntu
It consist of rules, how log messages are recieved, processed and forwarded.
Facilities and Properties
Facilites:-
Facilities are simply categories.
Supported facilities in Linux are auth, auth-priv, cron, daemon, kern, lpr, mail, mark, news, syslog, user, uucp, and local0 through local7.
some of these are self-explanatory, but the following are of special note:
auth
Used for many security events
auth-priv
Used for access-control-related messages
daemon
Used by system processes and other daemons
kern
Used for kernel messages.
mark
Messages generated by syslogd itself, which contain only a timestamp and the string --MARK--; to specify how many minutes should transpire between marks, invoke syslogd with the -m [minutes] flag.
user
The default facility when none is specified by an application or in a selector.
* Wildcard signifying "any facility."
none
Wildcard signifying "no facility."
Priorities:-
- Possible priorities in Linux are (in increasing order of urgency): debug, info, notice, warning, err, crit, alert, and emerg.
Creating a Custom Log
#move to /var/log/ directory :
[root@localhost ~]# cd /var/log/
#Create a file myLog.log :
[root@localhost log]# touch myLog.log
#Create a facility and priority in rsyslog.conf file :
[root@localhost ~]# vim /etc/rsyslog.conf
#Adding facilities and priorities in the rsyslog.conf file :
*.* /var/log/myLog.log
#Restarting the "rsyslog.service: service :
systemctl restart rsyslog.service
#view the output dynamically using tail command
tail -f <pathToFile>
Log Rotation
Log rotation is the process of managing log files by automatically archiving, compressing, and eventually removing old log files to prevent them from growing too large and consuming excessive disk space.
We configure Log rotate by editing "logrotate.conf" file.
yum ,rpm & apt
yum
"YUM” is an acronym that stands for “Yellowdog Updater, Modified"
yum commands
yum install <packageName> -y
yum remove <packageName> -y
yum update <packageName>
yum list <packageName>
yum search <packageName>
yum info <packageName>
yum update -y
rpm:-
RPM stands for Red Hat Package Manager.
It is a free and open-source package managment system.
rpm comands
rpm -ivh <packagename>
to see show installation on screen
rpm -qpr <packagename>
search package dependencies
rpm -ivh --nodeps <packagename>
download package without dependencies
rpm -q<packagename>
search package
rpm -qa -last<packagename>
Lists all installed packages sorted by their installation timestamp, with the most recently installed package displayed at the top. rpm -qa -last
rpm -qa
List all packages
rpm -uvh <packagename>
update package
rpm -evv <packagename>
remove package
apt
Advanced package tool, or APT, is a free-software user interface that works with core libraries to handle the installation and removal of software on Debian, and Debian-based Linux distributions.
apt commands:
apt -get update -y -> System update
apt -get check <package name>
apt -get upgrade <package name>
apt -get install <package name>=<version no.>
apt -get install <package1><package2>
apt -get install -download-only <package name>
Repositories
A repository is a centralized storage location that contains software packages, metadata, and information about dependencies.
The repo's are stored at "/etc/yum.repos.d/redhat.repo", you can navigate there using the cd command and look up the file.
Journalctl
- Journalctl is a command-line utility in Linux that allows you and is responsible to access, view and collect logs from the systemd journal.
Cron
Cron is a time-based job scheduling utility, in short, it's a scheduler.
It allows users to schedule and automate the execution of commands or scripts at specific intervals, such as daily, weekly, monthly, or at specific times of the day.
Cron commands:
#cronlist crontab -l #cron edit crontab -e #Defining a cron tab <minute> <hours> <date> <month> <day> <command>
Example
```plaintext #Create a file cronTest at /tmp [root@localhost tmp]# touch cronTest
#edit the crontab file : [root@localhost ~]# crontab -e
#Enter the fields according to the sytax above
- echo "This is a cron" >> /tmp/crontest
#use tail command to get dynamic output [root@localhost ~]# tail -f /tmp/cronTest
#output This is a cron This is a cron ```
Subscribe to my newsletter
Read articles from Rihaab Wadekar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by