This is an old revision of the document!
Table of Contents
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
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
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
SLES12:~ # resize2fs /dev/vg02/lv201 resize2fs 1.42.11 (09-Jul-2014) Filesystem at /dev/vg02/lv201 is mounted on /mnt; on-line resizing required old_desc_blocks = 1, new_desc_blocks = 2 The filesystem on /dev/vg02/lv201 is now 360448 blocks long.
xfs:
xfs_growfs device
LVM
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 and look for free PE
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:~ #
Fragmentierung einer Datei
SLES12:/mnt # filefrag -v services Filesystem type is: ef53 Filesystem cylinder groups approximately 16 File size of services is 1263621 (309 blocks of 4096 bytes) ext: logical_offset: physical_offset: length: expected: flags:
0: 0.. 15: 1024.. 1039: 16: merged 1: 16.. 63: 688.. 735: 48: 1040: merged 2: 64.. 127: 768.. 831: 64: 736: merged 3: 128.. 255: 896.. 1023: 128: 832: merged 4: 256.. 308: 1664.. 1716: 53: 1024: last,merged,eof
services: 5 extents found
BTRFS
SLES12:/ # mkfs.btrfs -f /dev/sdc1 /dev/sdc8 btrfs-progs v4.1.2+20151002 See http://btrfs.wiki.kernel.org for more information.
Label: (null) UUID: ac33d521-eec2-4ab5-b3c9-59d661d5e2e8 Node size: 16384 Sector size: 4096 Filesystem size: 3.00GiB Block group profiles:
Data: RAID0 315.12MiB Metadata: RAID1 161.56MiB System: RAID1 12.00MiB
SSD detected: no Incompat features: extref, skinny-metadata Number of devices: 2 Devices:
ID SIZE PATH 1 2.00GiB /dev/sdc1 2 1.00GiB /dev/sdc8
Mounten des Filesystems via uuid
SLES12:/mnt # mount /dev/disk/by-uuid/da8e5d24-9f2a-431e-a3e5-b3288ba7d0dc /mnt/NEU/ SLES12:/mnt # SLES12:/mnt/NEU # btrfs filesystem show /mnt/NEU/ Label: 'btfilesys' uuid: da8e5d24-9f2a-431e-a3e5-b3288ba7d0dc
Total devices 2 FS bytes used 256.00KiB
devid 1 size 2.00GiB used 327.12MiB path /dev/sdc1
devid 2 size 1.00GiB used 315.12MiB path /dev/sdc8
btrfs-progs v4.1.2+20151002
SLES12:/mnt/NEU # btrfs device add -f /dev/sdc2 /mnt/NEU SLES12:/mnt/NEU # SLES12:/mnt/NEU # SLES12:/mnt/NEU # btrfs filesystem show /mnt/NEU/ Label: 'btfilesys' uuid: da8e5d24-9f2a-431e-a3e5-b3288ba7d0dc
Total devices 3 FS bytes used 256.00KiB
devid 1 size 2.00GiB used 327.12MiB path /dev/sdc1
devid 2 size 1.00GiB used 315.12MiB path /dev/sdc8
devid 3 size 2.00GiB used 0.00B path /dev/sdc2
SLES12:/mnt/NEU # btrfs filesystem show /mnt/NEU Label: 'btfilesys' uuid: da8e5d24-9f2a-431e-a3e5-b3288ba7d0dc
Total devices 3 FS bytes used 256.00KiB
devid 1 size 2.00GiB used 327.12MiB path /dev/sdc1
devid 2 size 1.00GiB used 315.12MiB path /dev/sdc8
devid 3 size 2.00GiB used 0.00B path /dev/sdc2
btrfs-progs v4.1.2+20151002
Testdaten auf das Filesystem kopieren
SLES12:/mnt/NEU # cp -R /usr/lib/* . SLES12:/mnt/NEU # SLES12:/mnt/NEU # SLES12:/mnt/NEU # btrfs filesystem show /mnt/NEU Label: 'btfilesys' uuid: da8e5d24-9f2a-431e-a3e5-b3288ba7d0dc
Total devices 3 FS bytes used 86.88MiB
devid 1 size 2.00GiB used 503.12MiB path /dev/sdc1
devid 2 size 1.00GiB used 491.12MiB path /dev/sdc8
devid 3 size 2.00GiB used 176.00MiB path /dev/sdc2
btrfs-progs v4.1.2+20151002
Ein Volume aus dem btrfs Filesystem löschen
SLES12:/mnt/NEU # btrfs device delete /dev/sdc2 /mnt/NEU/ SLES12:/mnt/NEU # SLES12:/mnt/NEU # SLES12:/mnt/NEU # btrfs filesystem show /mnt/NEU Label: 'btfilesys' uuid: da8e5d24-9f2a-431e-a3e5-b3288ba7d0dc
Total devices 2 FS bytes used 792.45MiB
devid 1 size 2.00GiB used 647.12MiB path /dev/sdc1
devid 2 size 1.00GiB used 635.12MiB path /dev/sdc8
Reduzieren des Filesystems um 500M
SLES12:/mnt/NEU # btrfs filesystem resize -500M /mnt/NEU/ Resize '/mnt/NEU/' of '-500M' SLES12:/mnt/NEU # SLES12:/mnt/NEU # SLES12:/mnt/NEU # btrfs filesystem show /mnt/NEU Label: 'btfilesys' uuid: da8e5d24-9f2a-431e-a3e5-b3288ba7d0dc
Total devices 2 FS bytes used 792.33MiB
devid 1 size 1.51GiB used 647.12MiB path /dev/sdc1
devid 2 size 1.00GiB used 635.12MiB path /dev/sdc8
Informationen über die Belegung ausgeben
SLES12:/mnt/NEU # btrfs filesystem df /mnt/NEU/ Data, RAID0: total=947.12MiB, used=778.25MiB System, RAID1: total=8.00MiB, used=16.00KiB System, single: total=4.00MiB, used=0.00B Metadata, RAID1: total=153.56MiB, used=14.06MiB Metadata, single: total=8.00MiB, used=0.00B GlobalReserve, single: total=16.00MiB, used=0.00B
Filesystem ausbalancieren
btrfs balance start /mnt btrfs balance status /mnt btrfs balance cancel /mnt btrfs balance pause /mnt btrfs balance resume /mnt
Snapshots
Subvolume2 unterhalb Subvolume1, wird beim snap von Subvolume1 _nicht_ mitgesnapped
