This is an old revision of the document!
Table of Contents
Übgungsaufgabe 1 (Startskripte):
SLES11SP4:~ # cat /etc/init.d/meinscript
#!/bin/bash
### BEGIN INIT INFO
# Provides: meinscript
# Required-Start: $network $remote_fs
# Required-Stop: $network $remote_fs
# Default-Start: 3
# Default-Stop:
# Description: tmpfilecreator
### END INIT INFO
case "$1" in
start)
echo "datei anlegen"
touch /tmp/level3_michael
;;
stop)
echo "datei loeschen"
rm /tmp/level3_michael
;;
esac
Übung 2: chkconfig
SLES11SP4:~ # chkconfig atd
atd off SLES11SP4:~ # chkconfig -a atd atd 0:off 1:off 2:on 3:on 4:off 5:on 6:off
rm S und K script
SLES11SP4:/etc/init.d/rc2.d # chkconfig -l | grep atd
atd 0:off 1:off 2:off 3:on 4:off 5:on 6:off
Stoppe cups und ntp:
SLES11SP4:/etc/init.d/rc2.d # /etc/init.d/cups stop Shutting down cupsd done SLES11SP4:/etc/init.d/rc2.d # /etc/init.d/ntp stop Shutting down network time protocol daemon (NTPD) done
Deaktiviere cups und ntp:
SLES11SP4:/etc/init.d/rc2.d # chkconfig -d cups cups 0:off 1:off 2:off 3:off 4:off 5:off 6:off SLES11SP4:/etc/init.d/rc2.d # chkconfig -d ntp ntp 0:off 1:off 2:off 3:off 4:off 5:off 6:off
Aktiviere Cups für aktuellen Runlevel wieder:
SLES11SP4:/etc/init.d/rc2.d # chkconfig -e cups # BESSER NICHT VERWENDEN
Check:
SLES11SP4:/etc/init.d/rc2.d # chkconfig cups cups on
atd dienst wieder in Standard Runlevel starten:
SLES11SP4:/etc/init.d/rc2.d # chkconfig -d atd atd 0:off 1:off 2:off 3:off 4:off 5:off 6:off SLES11SP4:/etc/init.d/rc2.d # chkconfig -a atd atd 0:off 1:off 2:on 3:on 4:off 5:on 6:off
Übung 3 Eigener Runlevel
96 2016-07-14 11:41:38 cp -P ../rc3.d/* . 99 2016-07-14 11:41:52 chkconfig -l
runlevel 4 eintragen und aktivieren
105 2016-07-14 11:42:18 vi smb 106 2016-07-14 11:43:01 chkconfig -d smb 107 2016-07-14 11:43:04 chkconfig -a smb
postfix aus 4 löschen
108 2016-07-14 11:43:19 cd rc4.d/ 110 2016-07-14 11:43:26 rm *postfix
smb und nmb in 4 aktivieren und in 3 deaktivieren
116 2016-07-14 11:44:21 chkconfig -d nmb smb 117 2016-07-14 11:44:23 chkconfig -a nmb smb
atd in 4 aktivieren
118 2016-07-14 11:44:32 vi atd 119 2016-07-14 11:44:42 chkconfig -d atd 120 2016-07-14 11:44:45 chkconfig -a atd
testen
121 2016-07-14 11:44:55 init 4
/etc/nologin anlegen → keine kann sich mehr anmelden. Test in der Datei wird angezeigt shutdown -k tut so, als würde ein Shutdown durchgeführt werden. :)
!!!! halt, reboot, poweroff, swsusp nicht verwenden.
SLES12:/etc/systemd/system # cat default.target
# This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version.
[Unit] Description=Graphical Interface Documentation=man:systemd.special(7) Requires=multi-user.target After=multi-user.target Conflicts=rescue.target Wants=display-manager.service AllowIsolate=yes
Standard Targets:
poweroff.target runlevel0.target rescue.target runlevel1.target runlevel2.target multi-user.target runlevel3.target graphical.target runlevel5.target reboot.target runlevel6.target emergency.target
Config: - individuell : /etc/systemd/system/default.target - standard : /usr/lib/systemd/system/default.target
default.target → graphical.target → multi-user.target → basic.target → sysinit.target → “wants”
Übung fail2ban
[root@h1826968 wiki]# systemctl enable fail2ban Created symlink from /etc/systemd/system/multi-user.target.wants/fail2ban.service to /usr/lib/systemd/system/fail2ban.service.
firewalld default config:
[root@h1826968 zones]# pwd /usr/lib/firewalld/zones [root@h1826968 zones]# ll insgesamt 36 -rw-r----- 1 root root 299 20. Nov 2015 block.xml -rw-r----- 1 root root 293 20. Nov 2015 dmz.xml -rw-r----- 1 root root 291 20. Nov 2015 drop.xml -rw-r----- 1 root root 304 20. Nov 2015 external.xml -rw-r----- 1 root root 400 20. Nov 2015 home.xml -rw-r----- 1 root root 415 20. Nov 2015 internal.xml -rw-r----- 1 root root 315 20. Nov 2015 public.xml -rw-r----- 1 root root 162 20. Nov 2015 trusted.xml -rw-r----- 1 root root 342 20. Nov 2015 work.xml
Targets und Services:
SLES12:/usr/lib/systemd/system # SLES12:/usr/lib/systemd/system # grep -l AllowI *.target ctrl-alt-del.target default.target emergency.target graphical.target halt.target initrd-switch-root.target initrd.target kexec.target multi-user.target poweroff.target reboot.target rescue.target runlevel0.target runlevel1.target runlevel2.target runlevel3.target runlevel4.target runlevel5.target runlevel6.target system-update.target
Übung Systemctl, Targets:
SLES12:/usr/lib/systemd/system # systemctl isolate multi-user SLES12:/usr/lib/systemd/system # SLES12:/usr/lib/systemd/system # SLES12:/usr/lib/systemd/system # runlevel 5 3 SLES12:/usr/lib/systemd/system # systemctl start atd.service SLES12:/usr/lib/systemd/system # SLES12:/usr/lib/systemd/system # systemctl status atd atd.service - Deferred execution scheduler
Loaded: loaded (/usr/lib/systemd/system/atd.service; disabled) Active: active (running) since Thu 2016-07-14 13:01:08 CEST; 12s ago
Main PID: 5140 (atd)
CGroup: /system.slice/atd.service
└─5140 /usr/sbin/atd -f
SLES12:/usr/lib/systemd/system # systemctl isolate graphical SLES12:/usr/lib/systemd/system # SLES12:/usr/lib/systemd/system # systemctl status atd atd.service - Deferred execution scheduler
Loaded: loaded (/usr/lib/systemd/system/atd.service; disabled) Active: inactive (dead)
SLES12:/usr/lib/systemd/system # cd /etc/sys sysconfig/ sysctl.d/ systemd/ SLES12:/usr/lib/systemd/system # cd /etc/systemd/ system/ user/ SLES12:/usr/lib/systemd/system # cd /etc/systemd/system/ SLES12:/etc/systemd/system # ll default.target lrwxrwxrwx 1 root root 40 Mar 15 12:39 default.target → /usr/lib/systemd/system/graphical.target SLES12:/etc/systemd/system # SLES12:/etc/systemd/system # systemctl set-default rescue.target SLES12:/etc/systemd/system # SLES12:/etc/systemd/system # ll default.target lrwxrwxrwx 1 root root 37 Jul 14 13:03 default.target → /usr/lib/systemd/system/rescue.target SLES12:/etc/systemd/system # SLES12:/etc/systemd/system #
Checked ob alle Abhänigen Dienste laufen. systemctl enable xy.service
Startet den Dienst einfach. Kann zu Problemen führen. systemctl start xy.service
Services auflisten:
linux-tmer:/etc/systemd/system # service -s accounts-daemon.service loaded active running Accounts Service after-local.service loaded active exited /etc/init.d/after.local Compatibility apparmor.service loaded active exited LSB: AppArmor initialization atd.service loaded active running Deferred execution scheduler cron.service loaded active running Command Scheduler dbus.service loaded active running D-Bus System Message Bus display-manager.service loaded active running X Display Manager getty@tty1.service loaded active running Getty on tty1
Wichtige Befehle
systemctl status --type=service systemctl enable/disable xy.service systemctl start/stop xy.service systemctl mask xy.service
aktive Dienste
systemctl list-units --type=service
vorhandene Dienste
systemctl list-units-files --type=service
Konfig Datei editieren
systemctl edit nginx.service
Alle aktiven Runlevel anzeigen
systemctl list-units --type=target
Alle vorhandenen
systemctl list-unit-files --type=target
Dienste eines Targets abfrage
systemctl | show -p "Wants" target-name.target | less, oder: systemctl show target-name.target | grep Want
Partitionen von Platte 1 auf Platte 2 klonen:
linux-tmer:~ # sfdisk -d /dev/sdb | sfdisk /dev/sdc sfdisk: Checking that no-one is using this disk right now … sfdisk: OK
Disk /dev/sdc: 1305 cylinders, 255 heads, 63 sectors/track sfdisk: /dev/sdc: unrecognized partition table type Old situation: sfdisk: No partitions found sfdisk: Warning: extended partition does not start at a cylinder boundary. DOS and Linux will interpret the contents differently. New situation: Units: sectors of 512 bytes, counting from 0
Device Boot Start End #sectors Id System
/dev/sdc1 2048 4196351 4194304 83 Linux /dev/sdc2 4196352 8390655 4194304 83 Linux /dev/sdc3 8390656 20971519 12580864 5 Extended /dev/sdc4 0 - 0 0 Empty /dev/sdc5 8392704 10489855 2097152 83 Linux /dev/sdc6 10491904 12589055 2097152 83 Linux /dev/sdc7 12591104 14688255 2097152 83 Linux /dev/sdc8 14690304 16787455 2097152 83 Linux sfdisk: Warning: partition 1 does not end at a cylinder boundary sfdisk: Warning: partition 2 does not start at a cylinder boundary sfdisk: Warning: partition 2 does not end at a cylinder boundary sfdisk: Warning: partition 3 does not start at a cylinder boundary sfdisk: Warning: partition 3 does not end at a cylinder boundary sfdisk: Warning: partition 5 does not end at a cylinder boundary sfdisk: Warning: partition [6] does not start at a cylinder boundary sfdisk: Warning: partition [6] does not end at a cylinder boundary sfdisk: Warning: partition 6 does not end at a cylinder boundary sfdisk: Warning: partition [7] does not start at a cylinder boundary sfdisk: Warning: partition [7] does not end at a cylinder boundary sfdisk: Warning: partition 7 does not end at a cylinder boundary sfdisk: Warning: partition [8] does not start at a cylinder boundary sfdisk: Warning: partition [8] does not end at a cylinder boundary sfdisk: Warning: partition 8 does not end at a cylinder boundary sfdisk: Warning: no primary partition is marked bootable (active) This does not matter for LILO, but the DOS MBR will not boot this disk. Successfully wrote the new partition table
Re-reading the partition table …
sfdisk: If you created or changed a DOS partition, /dev/foo7, say, then use dd(1) to zero the first 512 bytes: dd if=/dev/zero of=/dev/foo7 bs=512 count=1 (See fdisk(8).)
ext3 platte etc: max-mount auf 0 Setzen. sonst kann es zu fsck kommen. -I intervall 0
