Services and logs Flashcards

1
Q

Log file locations

A
/var/log/syslog
/var/log/messages
/var/log/auth.log
/var/log/secure
/var/log/
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Location of configs related to log rotation

A

/etc/logrotate.d/file_name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Remote logging

A

Rsyslog is used for forwarding log messages in an IP network.
The main configuration file for rsyslog is /etc/rsyslog.conf. Here, you can specify global directives, modules, and rules that consist of filter and action parts.
__
vim /etc/rsyslog.d/my_file.conf
. @1.2.3.4:514 (send all logs from this pc to 1.2.3.4)
1.2.3.4 should be configured to accept requests on 514
@-udp
@@-tcp

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Report the last login of each user on a system

Report of last log users into a system

A

lastlog, lastlog -u user_name

last
lastb

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Conf file for journald

A

/etc/systemd/journald.conf

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Query to systemd journal

A

journalctl [opt] [match]
journalctl -f -o verbose (o=output: short, verbose,json etc)
journalctl -p err (p=priority: err, crit,alert,emerg, notice,warning)
journalct -u ssh (u=unit)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Legacy: init startup

A

After the Linux kernel loads up
and it brings in the initial RAM disk, then seeks out an initialization system.
Kernel look for /sbin/init, then reads configuration at /etc/inittab at what runlevel system to be boot.
init performs some tasks from /etc/rc.d/rc.sysinit and boots up into runlevel

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Legacy: 1. RH service tools
util that sets and queries rl settings or services
2. Util to manage services
3.Textual util for managing services based on their rl-s

A
  1. chkconfig –list -check all services that enabled or disabled on different rl-s
    chkconfig httpd –level 3 on -sets httpd service to start on boot on rl3
  2. service httpd restart (start/stop/status)
  3. ntsysv
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Legacy: Ubuntu’s upstart

A

/sbin/init=>startup=>in parallel: /etc/init/rc-sysinit.conf and mountall=>tellinit=>runlevel=>/etc/init/rc.conf=>login

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Systemd Unit Files Location

A
1. Provided by package installation (do not edit):
/usr/lib/systemd/system
2. For admins:
/etc/systemd/system
3. Runtime unit files:
/run/systemd/system
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

List all unit files on a system

A

systemctl list-unit-files

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Components of Unit Files in general

A

[Unit]
Description=
Documentation=
Requires=units that will be activated when this unit is activated.
or Wants=similar to Requires but if something listed here fails, this will not prevent the unit from starting
Conflicts=units that should not be running when this unit is running
After=this unit starts after listed here units
Before=opposite of After

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

List contents of a unit file

A

systemctl cat unit_name.unit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

systemctl

A

systemctl- show all units status on a system
systemctl status -complete status report in tree manner
systemctl status httpd
systemctl enable/disable httpd
systemctl start/stop httpd
systemctl restart httpd
systemctl is-active/is-enabled httpd
systemctl -H 1.2.3.4 status httpd.service

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Modifying Unit Files

A
  1. Copy existing unit from /usr/lib64/systemd/system to /etc/systemd/system and edit this file
  2. Create drop-in Unit File
    2.1. Create a dir /etc/systemd/system/httpd.service.d/ and file in this new dir my-httpd.conf
    All changes here will be started first
    2.2. systemctl edit
    systemctl edit –full -this copy will replace the original unit file

Run systemd-delta to view modification

Run daemon-reload after any mod in unit files, this command will re-run dependencies

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Target Unit Files

A

A target unit will sync up other units when computer boots or changes states.
It dictates the type of environment you would work in.
Often used to bring a system into a new state
multi-user.target similar to rl3
graphical.unit similar to rl5
rescue.target similar to rl1
basic.target set during boot before another target takes over
sysinit.target -system init

17
Q

List units of specified unit-types

A

systemctl list-unit-files -t target

18
Q

Get default target

Set default target

A

systemctl get-default

systemctl set-default multi-user.target

19
Q

Change current target to another one

A

systemctl isolate unit-name.target

systemctl isolate multi-user.target

20
Q

Switch to rescue target or default

A

systemctl rescue

systemctl default

21
Q

Reboot/poweroff the system with systemctl

A

systemctl poweroff

systemctl reboot

22
Q

Service Units

A

Along with typical section this will have:
[Service]
Type=simple/oneshot/forking/dbus/notify/idle
ExecStart=full path with args of command to be execute to start the process
TimeoutSec=This configures the amount of time that systemd will wait when stopping or stopping the service before marking it as failed or forcefully killing it.
[Install] -Contains info about service installation
WantedBy=lists units that will want this unit. Creates a symlink of this service to target unit’s *.wants directory

23
Q

Link/unlink the service unit to /dev/null

A

systemctl mask httpd.service

systemctl unmask httpd.service

24
Q

Timer Unit Files

A

[Timer]
Unit= (not necessary, if not present .service will be implied)
1. Monotonic
OnBootSec=, OnActiveSec=
2. Real-time
OnCalendar=--* 21:25:00
year-month-day
3. Transient Timers are setup by systemd-run command and do not require .service file
example: systemd-run –on-active=1m /bin/touch /root/hello
[Install]
WantedBy=timers.target

25
Q

List all timers on the system

A

systemctl list-timers –all