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
linux-tmer:~ # tune2fs -l /dev/sdb7
Dateisysteme vergrößern nach vergrößern der Partition:
ext2/3/4:
resize2fs device
xfs:
xfs_growfs device
LVM Übgung
Create Physical Volume SLES12:~ # pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created
Create Volume Group SLES12:~ # vgcreate vg01 /dev/sdb1
Volume group "vg01" successfully created
SLES12:~ #
Create logical Volumes SLES12:~ # lvcreate -n lv101 -L 400M vg01
Logical volume "lv101" created.
SLES12:~ # lvcreate -n lv102 -L 500M vg01
Logical volume "lv102" created.
SLES12:~ #
Create additional Swap SLES12:~ # SLES12:~ # mkswap /dev/vg01/lv102 Setting up swapspace version 1, size = 511996 KiB no label, UUID=523b3c51-55fa-4361-b5e0-7bfb596dce9e SLES12:~ #
Aktivate Swap SLES12:~ # swapon /dev/vg01/lv102 SLES12:~ # SLES12:~ #
Check if swap is aktivated SLES12:~ # swapon -s Filename Type Size Used Priority /dev/sda1 partition 2103292 0 -1 /dev/dm-1 partition 511996 0 -2 SLES12:~ #
Erstellen eines ext3 Filesystems SLES12:~ # mke2fs -j /dev/vg01/lv101 mke2fs 1.42.11 (09-Jul-2014) Creating filesystem with 409600 1k blocks and 102400 inodes Filesystem UUID: e9ebd313-7641-4a4c-8c45-e71739794b25 Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409
Allocating group tables: done Writing inode tables: done Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done
Mount formatted Filesystem, copy /usr/bin/ and “overmount” /usr/bin“ SLES12:~ # SLES12:~ # mount /dev/vg01/lv101 /mnt/ SLES12:~ # SLES12:~ # cp -R /usr/bin/* /mnt/ SLES12:~ # SLES12:~ # umount /mnt SLES12:~ # SLES12:~ # mount /dev/vg01/lv101 /usr/bin/ SLES12:~ #
List the VG SLES12:~ # vgdisplay -v
Using volume group(s) on command line. --- Volume group --- VG Name vg01 System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 2.00 GiB PE Size 4.00 MiB Total PE 511 Alloc PE / Size 225 / 900.00 MiB Free PE / Size 286 / 1.12 GiB VG UUID 0WVhD5-yVVR-m7SG-uqDR-lp04-5GHl-qLExwD
- – Logical volume —
LV Path /dev/vg01/lv101
LV Name lv101 VG Name vg01 LV UUID yBT0Vq-w2Am-CfnX-cmCo-8n39-GySx-HQgHkT LV Write Access read/write LV Creation host, time SLES12, 2016-07-15 10:05:52 +0200 LV Status available # open 1 LV Size 400.00 MiB Current LE 100 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 1024 Block device 254:0
- – Logical volume —
LV Path /dev/vg01/lv102
LV Name lv102 VG Name vg01 LV UUID zVqjlO-kdfz-xliL-znpJ-Mgb1-4FFi-jUHYoW LV Write Access read/write LV Creation host, time SLES12, 2016-07-15 10:05:59 +0200 LV Status available # open 2 LV Size 500.00 MiB Current LE 125 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 1024 Block device 254:1
- – Physical volumes —
PV Name /dev/sdb1
PV UUID 1OGKSL-xxQk-zGPx-Yf8T-6W3s-yATQ-yplBhx PV Status allocatable Total PE / Free PE 511 / 286
SLES12:~ #
