Ticker

6/recent/ticker-posts

Systemctl & journalctl command in Linux






Reference of pic : kodekloud


Systemctl command is a utility in Linux to manage & control systemd.

systemd is like a service manager in Linux.

Let's list some of the frequently used systeamctl commands.

How to get list services on your system.

[satish@host]$ sudo service --status-all

### How to list all active units
[satish@host]$ sudo systemctl list-units --all


######
yum install cronie -y && systemctl start crond.service && systemctl status crond.service

How to Restart systemd.

[satish@host]$ sudo systemctl daemon-reload

### if you don't want to use systemctl daemon-reload command after making some change in service use the following command to edit the service.
[pankaj@host]$ sudo systemctl edit myservices.service --full

Enable mariadb service on reboot.

[satish@host]$ sudo systemctl enable mariadb

Disable mariadb service on reboot.

[satish@host]$ sudo systemctl disable mariadb

Disable & Stop mariadb service.

[satish@host]$ sudo systemctl disable mariadb --now

Mask mariadb service.

Before masking the service it is always recommend to stop and disable service

[satish@host]$ sudo systemctl mask mariadb

UnMask mariadb service.

[satish@host]$ sudo systemctl unmask mariadb

View all the active systemd jobs.

[satish@host]$ sudo systemctl list-jobs

View the list of services that failed to run.

[satish@host]$ sudo systemctl --failed

Remove failed status service from systemctl list:

[satihs@host]$ sudo systemctl reset-failed
[satish@host]$ sudo rm -rf /etc/systemd/system/service_name
[satish@host]$ sudo rm -rf /etc/systemd/system/service_symlink

View Log Messages

journalctl command in Linux:

To see all the log messages at once:

[satish@host]$ sudo journalctl 

To see the log message of particular service

[satish@host]$ sudo journalctl -u service_name

To see the log message as they come in live mode basically:

[satish@host]$ sudo journalctl -f

To highlight the error in log message:

[satish@host]$ sudo journalctl -p error

To make the journalctl log message persistence:

[satish@host]$ sudo mkdir -p /var/log/journal

sometime tail command can be useful in the case if journalctl command is not available:

[satish@host]$ tail -f /var/log/messages
[satish@host]$ tail -f /var/log/secure
-f --> follow

Systemctl command to start multiple services:

[satish@host]$ sudo systemctl start(rpcbind,nfs-server,rpc-statd,nfs-idmapd)

Iptables:

$ sudo su -
$ yum install iptables-services -y
$ systemctl enable iptables
$ iptables -A INPUT -p tcp --destination-port 5004 -s 172.16.238.14 -j ACCEPT
$ iptables -A INPUT -p tcp --destination-port 5004 -j DROP
$ service iptables save
$ systemctl restart iptables


I will keep adding more command to this post!!

Thanks for reading.

Post a Comment

0 Comments