ssh-keygen- generate ssh keyssh-copy-id web_user@monolith- copy ssh key on remote hostssh web_user@monolith cat /etc/redhat-release- get release info via sshscp web_user@monolith:/home/web_user/*.gz .- copy any tar files from remote machine on your working directorysftp db_user@monolith- access remote host via secure FTP protocolmget *.gz- grab all files via sftp with .gz extension
man httpdorman mariadb- search for manualsinfo httpdorinfo mariadb- search for documentation in infols -la /usr/share/doc | egrep -i "httpd|mariadb|mysql"- search for httpd|mariadb|mysql documentation in directory with case sensitivesudo dnf -y install httpd mariadb- install httpd and mariadb packagesmariadb --help | more- get help about mariadb packagemariadb -? | more- same as --helpwhatis httpd mariadb httpd mysql- get man page numberapropos httpd- get information about commands and function about the commandman 8 httpd.socket- get manual for httpd with page 8more /usr/share/doc/httpd/LICENSE- get information about Apache License
sudo tree /var/log | more- get tree of directory by one pagesudo grep httpd /var/log/* > raw_logs/master.log- forward all found entries with httpd to master.log filesudo grep httpd /var/log/* > raw_logs/master.log 2> /dev/null- draw away all errorswc -l raw_logs/master.log- count number of lines in master.log filejournalctl --unit=httpd --no-pager >> raw_logs/master.log- append found entries related to httpd unit with no-pager key to master.log filegrep systemd raw_logs/master.log > httpd_logs/systemd.log- look for systemd entry in master.log file and move them to the new file systemd.logegrep -v "dnf|secure" raw_logs/master.log > httpd_logs/no_dnf_secure.log- exclude entries with dnf|secure and forward output to the no_dnf_secure.log file
- vi commands
i- insertu- undo3x- delete 3 chars after pointerdd- completely remove linep- pastew hosts2- write and save file as a hosts2 file
chmod 755 script.sh- rwx for user, read and execute for group and other worldchmod -R 777 my_dir- full permission for directory recursivelychmod ugo+x script.sh- give execution permission for user, group and otherschmod -R go-wx my_dir- remove write and execute permissions for group and otherchmod u=rw, go=r file.txt- read and write permission for the user, and read-only permission for group and otherchown -R web_user:web_group /web/_data- change user and group ownew of the directorychmod -R g+w /web_data/- give write permission for group of directoryln -s /web_data/* /var/www- create soft link in /var/www directoryls -li /var/www- get inode numbers of soft linksecho 'umask 0027' >> ~/.bashrc- make newly created files not readable by other users.umaskworks in opposite way - subtractive. Default permissions for file 666 and for directories 777.- if
umask 0022- that means newly created file will have permissions 744.
tar cvf /home/archives/user1.tar user1- create, verbose and put into file user1.tar content of user1 directorystar -cv file=/home/archives/user1.star user1- same command as above, but withstarcommandtar tvf archives/user1.tar- list content of archivestar -tv file=archives/user1.star- get content ofstararchivegzip archives/user1.tarorbzip2 archives/user1.star- compress archivestar cvfz /home/archives/user2.tar.gz user2- create archive, compress files with gzip of user2 directorystar -cv -bz /home/archives/user2.star.bz2 user2- create archive, compress files with bzip2 of user2 directoryrm -rf user{1..5}- remove directory with name user1 to user5 namestar cvfz archives/project_archive.tar.gz project{1..5}- create archive and compress with gzip directories with names project1 to project5tar xvfj archives/user1.star.bz2- unarchive and decompress bzip2 archivebzip2 -d archives/CentOS-7.bz2- decompress archive.
-
Add the cloud_user identity to the agent and to reload the agent:
eval $(ssh-agent -s)
-
Add your cloud_user identity to the agent, which can now act on your behalf:
ssh-add
-
Execute a backup command on a remote system:
ssh cloud_user@<SECOND_PUBLIC_IP_ADDRESS> tar -czvf wget-server2.tar.gz wget-1*.rpm
-
Hit the Up arrow and perform an scp:
scp cloud_user@<SECOND_PUBLIC_IP_ADDRESS>:~/wget-server2*.* .
-
ls -d *[0-9]*- list directories, but not their's content.
find / -name "hosts"- find file by namefind /etc -type f -size +100M- find regular file with size more than 100Mfind / -user student- find files related to the userfind /etc -exec grep -l student {} \; 2> dev/null- find any files in /etc that contains student word insidefind /etc -size +100c -exec grep -l student {} \;- search for files with size more than 100 bytes and with word student in itfind /etc -size +100c -exec grep -l student {} \; -exec cp {} /tmp \; 2>/dev/null- same as command above and copy content to /tmp folder
ln /etc/hosts /root/hardhosts - create hard link for /etc/hosts
ln -s /etc/hosts symhosts - create symbolic link
cp /etc/[a-c]* /tmp/files - copy files starting from abc to /tmp/files
cut -f 3 -d : /etc/passwd- filter 3rd field with delimeter : in /etc/passwdcut -f 1 -d : /etc/passwd | sort -n- numeric sortcut -f 1 -d : /etc/passwd | sort | tr [a-z] [A-Z- sort output and translate lowercase to uppercase
ps aux | grep sshgrep linda *grep -i linda *- case insensitivegrep -A5 linda /etc/passwd- show 5 lines aftergrep -B5 linda /etc/passwd- show 5 lines beforegrep -R root /etc- recursive search
grep 'b.t' fileegrep 'b.?t' filegrep 'b.*t' file
awk -F : '/linda/ { print $4}' /etc/passwd
sed -n 4p sedfile- print 4th line in the filesed -i s/four/FOUR/g sedfile- replace four with FOUR in the filesed -i -e '2d' sedfile- edit file and remove line 2
grep '\<root\>' * 2>/dev/null- look for root wordps aux | awk '{ print $NF}- print the last column
useradd- create userusermod- modify properties of useruserdel- delete user accountspasswd- set user passwords
useradd -D- specify default settings/etc/default/useradd- default settings for useradd/etc/login.defs- default settings of user/etc/skel- files in this directory will be created during user creation
/etc/shadow- password properties stored in this filetcpdump:!!:18847::::::- exclamation mark in /etc/shadow file means that password is currently disabled/etc/group- list of existing groups
groupadd- add groupsgroupdel- delete groupsgroupmod- modify groupslid -g wheel- list users of wheel group
chageorpasswd- change password settingschage student- modify password's aging for user student
chown user[:group] file- set user-ownershipchgrop group file- set group-ownership
chmod 750 myfile- changing permission in absolute modechmod +x myscript- changing permission in relative mode
666- default umask for file777- default umask for directoryumask 027- set default umask to 027/etc/profile- umask is coming from this file/home/user/.bash_profile- if you want to setup umask for specific user
- SUID - special user ID
chmod 4770 myfile- set special user permissionchmod u+s myfile- set special user permission
- GUID - special group ID
chmod 2770 mydir- set special group permissionchmod g+s mydir- set special group permission
- Sticky bit
chmod 1770 mydir- set sticky bit permissionchmod +t mydir- set sticky bit permission
getfacl- shows current settingssetfacl -R -m g:somegroup:rx /data/groups- set read and execute permissions for /data/groups directory recursivelysetfacl -m d:g:somegroup:rx /data/groups- set default permission for newly created files
ip addr- manage address propertiesip link- show link propertiesip route- manage route propertiesip -s link show- show statisticsip addr show- show ip address propertiesip addr add dev ens33 10.0.0.10/24- add secondary ip addressip addr add dev ens33 10.0.0.10/24- add secondary ip address in runtime configurationifconfig- is obsolete and shouldn't be used anymore. Useip addrorip linkinsteadip route show- get information about network routesip route add default via 192.168.4.2- add default routeip route del default via 192.168.4.2- delete default routecat /ets/resolv.conf- dns file generated by NetworkManager
systemctl status NetworkManager- check that network manager service is runningman nmcli-examples- get examples related to nmclisudo nmcli connection add con-name secondary-ip ifname eth0 ipv4.addresses 192.168.0.125 ipv4.gateway 192.168.0.1 ipv4.dns 8.8.8.8 type ethernet- add secondary ip address for interface eth0nmtui- network manager in graphical interface
/etc/sysconfig/network-scripts- directory of network configuration filesnmcli connection up eth0- to apply new network configuration
ping- test connectivityip addr show- show current configurationip route show- show current routing tabledig- test DNS nameserver working
-
command &- start job in the background -
To move a job to the background
- First stop it using Ctrl+Z
- Type bg to move it to the background
-
jobs- complete overview of running jobs -
fg [n]- move the last job back to the foreground -
Ctrl + C- to completeley cancel the job
ps- overview of current processesps aux- overview of all processesps -fax- show hierarchical relations between processesps -fU linda- show all processes owned by lindaps -f --forest -C sshd- shows a process tree for a specific processps L- shows format specifiersps -eo pid,ppid,user,cmd- uses some of these specifiers to show a list of processes
lscpu - get information about CPU
top- dashboard that allow you to monitor current system activityf- show and select from available display fieldsM- filter on memory usageW- save new display settings1- show single CPU loadk- kill processr- renice process
-
man 7 signals- manual for signals -
kill PID- to kill process with specific PID -
pkillandkillall- similar to kill command -
signals
15/sigterm- termination of signal9/sigkill- kill signalkill -s 15 13210- terminate signal with pid 13210kill -s 9 13210- kill signal with pid 13210killall dd- kill all processes with name dd
-
Nice values range: -20 up to 19
- Negative nice value indicates an increased priority, a positive nice value indicates decreased priority
- Users can set their processes to a lower priority, to increase priorities you need root access
-
Execute
topandr- to renice processnice -n -1 dd if=/dev/zero of=/dev/null &- start a process with nice value -1renice -n 10 -p 4886- renice value to 10 for process with PID 4886
tuned- service that allows for performance optimization in an easy waytuned-adm list- will show a list of profilestuned-adm profile <name>- will set a profiletuned-adm active- will show the current profile
-
dd if=/dev/sr0 of=/rhel8.iso bs=1M- create an ISO image -
mkdir /repo- create a directory /repo -
/rhel8.iso /repo iso9660 defaults 0 0- edit fstab and add the following line to the end -
systemctl datemon-reload- to update fstab configuration -
mount -a- mount iso -
RHEL 8 needs two repositories - one is upstream and second one baseos
Create the file /etc/yum.repos.d/appstream.repo with following contents.
[appstream]
name = appstream
baseurl = file:///repo/AppStream
gpgcheck = 0
Create the file /etc/yum.repos.d/base.repo
[BaseOs]
name = BaseOs
baseurl = file:///repo/BaseOs
gpgcheck = 0
yum repolist- list repositories
yum search nmap- search for nmap packageyum install nmap-ncat- install package. Dependencies will be solved automaticallyyum remove- remove packageyum update- will compare all packages' version with repository versions and update them if necessaryyum update nmap- update specific packageyum provides- similar toyum search, but search is looking for package name and description, while provides is looking for files to find name that you're looking foryum search sepolicy- no packages will be foundyum provides */sepolicy- will find necessary packages for us
Last metadata expiration check: 2:49:02 ago on Sat 14 Aug 2021 12:50:54 PM CEST.
policycoreutils-devel-2.8-16.1.el8.i686 : SELinux policy core policy devel utilities
Repo : rhel-8-for-x86_64-baseos-rpms
Matched from:
Filename : /usr/bin/sepolicy
yum info nmap- get information about packageyum list all- list all packagesyum list installedlist all installed packages
yum module- used to manage module propertiesyum module list- list available list of modulesyum module provides httpd- search for a module that provides specific package
Updating Subscription Management repositories.
Last metadata expiration check: 3:01:17 ago on Sat 14 Aug 2021 12:50:54 PM CEST.
httpd-2.4.37-10.module+el8+2764+7127e69e.x86_64
Module : httpd:2.4:820190206142837:9edba152:x86_64
Profiles : common devel minimal
Repo : rhel-8-for-x86_64-appstream-rpms
Summary : Apache HTTP Server
yum module info php- get information about packageyum module info --profile php- shows profilesyum module install php:7.1oryum install @php:7.1- install module php with specific versionyum module install php:7.1- installs a specific profileyum install httpd- will have yum automatically enable the module stream this package is in before installing this package.yum module enable php:7.1- enables the module, but doesn't install anything yetyum module install php:7.1- will install a specific PHP module stream.yum module install php:7.2- will update to the newer version and disable 7.1 streamyum distro-sync- to update or downgrade packages from a previous module stream that are not listed in profiles that are installed with the module update
- yum groups are provided to give access to specific catergories of software
yum groups list- gives a list of most common yum groupsyum groups list hidded- show all yum groupsyum groups info <groupname>- shows which packages are in a groupyum groups install <groupname>- install groupyum groups install --with-optional "Directory Client"- install Directory Client group with Optional packages included
yum history- gives a list of recently issued commandsyum history undo- allow you to undo a specific command, based on the history informationyum update- will update all packages on your systemyum update <packagename>- update specific package
-
rpm- queries by default are against the database of installed packages, add -p to query package filesrpm -qf /any/file- will give you a package name where file is coming fromrpm -ql mypackage- will show you a files that are in the packagerpm -qc mypackage- will show you configuration files of the packagerpm -qp --scripts mypackage-file.rpm- if there are any scripts inside of .rpm packagerpm -qd httpd- check which documentation is available for specific package
-
yumdownloader httpd- download, but don't install a package -
rpm -qp --scripts httpd-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64.rpm- check which scripts will be executed during package installation.
systemctl list-unit-files- list current state of unit filessystemctl -t help- get list of different unit typessystemctl list-units- get status of running unit filessystemctl status vsftpd- get status about vsftpd servicesystemctl start vsftpd- start servicesystemctl enable vsftpd- enable (start on boot) service
/usr/lib/systemd/system- default system-provided systemd unit files/etc/systemd/system/- custom unit files located here. Custom files should be created here no in/usr/lib/systemd/systemsystem-provided directory/run/systemd- run-time automatically generated unit filessystemctl cat unit.service- configuration of unit.filesystemctl edit unit.service- to edit unitfilessystemctl show- get list of available parameterssystemctl daemon-reload- to apply your changes if you modified unit files
crontab -e- create user-specific cron job/etc/cron.d- generic time-specific Cron jobs
[root@localhost ~]# ls -l /etc/cron.*
-rw-r--r--. 1 root root 0 Jun 12 2019 /etc/cron.deny
/etc/cron.d:
total 8
-rw-r--r--. 1 root root 128 Jun 12 2019 0hourly
-rw-r--r--. 1 root root 108 Jan 11 2021 raid-check
/etc/cron.daily:
total 4
-rwxr-xr-x. 1 root root 189 Jan 4 2018 logrotate
/etc/cron.hourly:
total 4
-rwxr-xr-x. 1 root root 575 Jun 12 2019 0anacron
/etc/cron.monthly:
total 0
/etc/cron.weekly:
total 0
/etc/crontab- deprecated way of scheduling tasks
[root@localhost etc]# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
- Anacron is a service behind cron that takes care jobs are executed on a regular basis, but not at a specific time
- It takes care of the jobs in
/etc/cron.{hourly,daily,weekly,monthly} /etc/anacrontab- configuration of anacron
crontab -e- as a specific user/etc/cron.d- create a file in this directory20 16 * * * logger hello- write hello message in/var/log/messagesat 16:20 every day of month, each month and each day of week.
man 7 systemd-timer- more information about systemd timersman 7 systemd-time- specification of the time format to be usedls -l /usr/lib/systemd/system/*timer- get list of existing systemd timers
atd- the service which should run to schedule a task with atat <time>to schedule a jobatq- list of jobs currently scheduledatrm- remove scheduled job
systemd-tmpfilesor/usr/lib/tmpfiles.d- manges settings for creating, deleting and cleaning up of temporary filessystemd-tmpfiles-clean.timer- unit which can be configured to automatically clean up temporary files- It triggers the
systemd.tmpfiles-clean.service - This service runs
systemd-tmpfiles --clean
- It triggers the
/usr/lib/tmpfiles.d/tmp.conf- file that contains settings for the automatic tmp file cleanup- Copy
/usr/lib/tmpfiles.d/tmp.confto/etc/tmpfiles.d/- for defining custom configuration file of tmpfiles systemctl daemon-reloadand thensystemd-tmpfiles --clean /etc/tmpfiles.d/tmp.confto ensure that there are no errors in tmp.conf file
systemd-journald- heart of all logging on the systemdjournalctl- logging can be accessed by this command/var/log/journal- by default systemd-journal keeps logs in memory, to write them in a persistent way you should create this directory.
rsyslogd- service should be started/etc/rsyslog.conf- main configuration file/etc/rsyslog.d- snap-in files can be placed here- Each logger line contains three items
- facility: the specific facility that the log is created for
- severity: the severity from which should be logged (ex: debug or emergency)
- destination: the file or other destination the log should be written to
logger- command to write messages to rsyslog manually
systemd-journald- log service that is a part of systemdsystemctl status <unit>- in integrates well with status outputjournalctl- to read log entries in the journalgorG- navigate from top to bottom<=or=>- arrow key to move left and rightjournalctl UNIT=sshd- search logs for specific unit
mkdir /var/log/journal- to make journal persistent create this directoryvim /etc/systemd/journald.conf- to configure your journald use this configuration file
/run/log/journal- by default journal is written in this directory, which is automatically cleared on system reboot/etc/systemd/journal.conf- edit this file to make the journal persistend across reboots- Set the Storage parameter in this file to the appropriate value
- persistent - will store the journal in the
/var/log/journaldirectory. This directory will be created if it doesn't exist - volatile - stores the journal only in
/run/log/journal - auto - will store the journal in
/var/log/journalif that exists, and in/run/log/journalif no/var/log/journalexists
- persistent - will store the journal in the
/etc/logrotate.conf- main configuration file/etc/logrotate.d- snap-in files can be provided here
lsblk- list block devicescat /proc/partitions- list of partitions from the kernel point of view- Storage options:
- Partitions - use to allocate dedicated storage to specific types of data
- LVM Logical Volumes - adds flexibility to storage (resize, snapshots and more)
- Stratis - next generation Volume Managing Filesystem that uses thin provisioning by default. Implemented in user space, which makes API access possible.
- Virtual Data Optimizer - focused on storing files in the most efficient way. Manages deduplicated and compressed storage pools.
- MBR - Master Boot Record
- 4 partitions only with a max. size of 2TiB
- To use more partitions, extended and logical partitions must be used
- GPT - GUID Partition Table
- 128 partitions max
- More space to store partitions
- Used to overcome MBR limitations
parted- default disk utility in RHEL 8fdiskorgdiskcan be used alternativelyparted /dev/sdb- create a partitionprint- will show if there is a current partition tablemklabel msdos|gpt- create a partition typemkpart part-type name fs-type start end- part-type - applies to MBR only and sets primary, logical, or extended partition
- name - arbitrary name, required for GPT
- fs-type - does NOT modify the filesystem, but sets some irrelevant file system dependent metadata
- start end - specify start and end, counting from the beginning of the disk
mkpart primary 1024MiB 2048MiBudevadm settle- ensure that the new partition device is created
fdisk /dev/nvme0n3- access disk with fdisk utilityn- new partitionm- for helpp- print the partition tablew- write table to disk and exit
Filesystems
- xfs
- Fast and scalable
- Uses Copy on Write tu guarantee data integrity
- Size can be increased, not decreased
- ext4
- Backward compatible to ext2
- Uses journal to guarantee data integrity
- Size can be increased and decreased
mkfs.xsf- creates an xfs file systemmkfs.ext4- creates and Ext4 file systemmount- mount file system after creationumount- unmount before disconnecting devicelsof /mnt- list of open files in /mnt directory
/etc/fstab- main configuration file to persistently mount partitions/etc/fstab- used to generate systemd mounts by the systemd-fstab-generator utilitysystemctl daemon-reload- to update systemd after editing /etc/fstabmount -a- mount file systems that in fstab file, but which are not mounted yet
blkid- get UUID of the devicetune2fs- set label to ext4 file systemxfs_admin- set label to xfs file systemls -l /dev/disk- possibilites for providing unique device names
drwxr-xr-x. 2 root root 480 Aug 16 14:33 by-id
drwxr-xr-x. 2 root root 120 Aug 16 14:33 by-partuuid
drwxr-xr-x. 2 root root 180 Aug 16 14:33 by-path
drwxr-xr-x. 2 root root 120 Aug 16 19:12 by-uuid
systemctl cat tmp.mount- example of .mount file\etc\systemd\system\tmp_ext4.mount- name of moutn should be the same as mount point- Mount file content:
[Unit]
Description=Tmp Ext4
Conflicts=umount.target
Before=local-fs.target umount.target
After=swap.target
[Mount]
What=LABEL=tmp_ext4
Where=/tmp_ext4
Type=ext4
Options=defaults
systemctl daemon-reload- update your systemd configurationsystemctl status tmp_ext4.mount- get status of newly created .mount
● tmp_ext4.mount - Tmp Ext4
Loaded: loaded (/etc/systemd/system/tmp_ext4.mount; static; vendor preset: disabled)
Active: active (mounted) since Mon 2021-08-16 20:00:02 CEST; 50s ago
Where: /tmp_ext4
What: /dev/sdb1
Tasks: 0 (limit: 10841)
Memory: 4.0K
CGroup: /system.slice/tmp_ext4.mount
- xfsdump - utility can be used for creating backups of XFS formatted devices
- works only on a complete XFS device
- can make full backups or different levels of incremental backups
xfsdump -l 0 -f /backupfiles/data.xfsdump /data- creates a full backup of the contents of the /data directory
- xfsretosre - restore backup that was made with xfsdump
xfsrestore -f /backupfiles/data.xfsdump /data
- xfsrepair - command can be manually started to repair broken XFS file systems
partedmkpart primary linux-swap 1MiB 2048MiB- create swap partition
mkswap- create swap filesystemswapon- activate swap
- LVM
- Used during defualt installation of RHEL
- Add flexibility to storage
- Stratis
- Next generation Volume Managing Filesystem that uses thin provisioning by default
- Implemented in user space, which makes API access possible
- Virtual Data Optimizer (VDO)
- Focused on storing files in the most efficient way
- Manages deduplicated and compressed storage pools
- Create a partition
- from parted use
set n lvm on - from fdisk select code 8e
- from parted use
pvcreate /dev/sdb1- create physical volumevgcreate vgdata /dev/sdb1- create volume grouplvcreate -n lvdata -L 1G vgdata- create logical volume with name lvdatafindmnt- shows you existing mounts in perspective of linux file system
lvextend -r -L +1G /dev/vgdata/lvdata1- extend logical volume by 1Gb and do resize2fs for file systemlvreduce -r -L 250M /dev/vgdata/lvdata1- reduce size of logical volume to 250M and do resize2fslvresize -r -l +-20 /dev/vgdata/lvdata1- increase or reduce size of logical volume by 20 extents and do resize2fs- In case you forgot
-roptione2resize- Resize for Ext file systemxfs_growfs- for XFS file system. Shrinking is not possible on XFS volumes
- On top of Stratis a regular file system is needed: XFS
- It's built on top of any block device, including LVM devices
- It offers advanced features
- Thin provisioning
- Snapshots
- Cache tier
- Programmatic API
- Monitoring and Repair
yum install -y stratis-cli stratisdsystemctl enable --now stratisd- enable and start stratis daemonstratis pool create mypool /dev/nvme0n2- create poolstratis fs create mypool myfs1- create filesystem on top of poolstratis pool list- list existing poolsstratis fs list- list existing filesystems in stratis poolstratis blockdev list stratispool- show info about clock devices used in pool
stratis pool add-data mypool /dev/nvme0n3- to add another block device- Standard Linux toold don't give accurate sizes as Stratis volumes are thin provisioned
stratis blockdev- get information about all block devices used for Stratisstratis pool- get information about all poolsstratis filesystem- monitor individual filesystems
stratis fs snapshot mypool myfs1 myfs1-snapshot- Changes to the original FS will not be reflected in the snapshot
- Use
mount /stratis/mypool/my-fs-snapshot /mnt- to mount it
- Revert the original volume to the state in the snapshot
umount /myfs1stratis fs destroy mypool myfs1stratis fs snapshot mypool myfs1-snap myfs1
stratis filesystem destroy mypool mysnapshot- will delete a snapshotstratis filesystem destroy mypool myfs- similar procedure is used for destroying file systemsstratis pool destroy mypool- when there are no more file systems in a pool you can delete a pool
- VDO (Virtual Data Optimizer) - used to optimize how data is stored on disk
- It is used as a separate volume manager on top of which file systems will be created
- Provides thin-provisioned storage
- Use a logical size 10 times the physical size for VMs and containers
- Use a logical size 30 times the physical size for object storage
- Used in Cloud/Container environments
- Ensure that underlying block devices are > 4GiB
yum install vdo kmod-kvdovdo create --name=vdo1 --device=/dev/nvme0np2 --vdoLogicalSize=1Tmkfs.xfs -K /dev/mapper/vdo1udevadm settle- will wait for the system to register the new device name- In /etc/fstab, include the
x-systemd.requires=vdo.servicemount option vdostats --human-readable- monitor state
- Use
partedto create a partition cryptsetup luksFormat /dev/sdd1- will format the LUKS devicecryptsetup luksOpen /dev/sdd1 secret- will open it and create a device mapper namemkfs.xfs /dev/mapper/secret- create file system and map your device- To automate the
cryptsetup luksOpenuse /etc/crypttab - To automate mounting the volume use /etc/fstab
- Kernel
- initramfs
- systemd-udevd
- modprobe
modprobe <module_name- manually load kernel modulemodprobe -r <module_name- manually unload kernel modulelsmod- list currently loaded kernel modules
modinfo- get module parameters/etc/modprobe.confor/etc/modprobe.d- to load specify kernel module parametersmodprobe <module_name>- to apply changes made for the module in configuration file
/proc- is a fily system that provides access to kernel information- PID directories
- Status files
- Tunables in
/proc/sys
- Use echo to write a value to any file in
/proc/systo change kernel performance parameters - Write the parameters to
/etc/sysctl.confto make them persistentnet.ipv4.ip_forward = 1- add line in/etc/sysctl.conf. Where dots mean slashes /proc/sys/net/ipv4/ip_forward
- Use
sysctl -ato show a list of all current settings
yum update kernel or yum install kernel - to update the kernel
- Boot Procedure
- POST
- BIOS\UEFI
- GRUB
- Kernel
- Systemd
- Services
- Press keys during boot:
e- to edit runtime boot optionsc- for command promptesc- go back to menu
/etc/default/grub- To make grup changes persistent edit this configuration file.- Once you done compile changes to
grub.cfggrub2-mkconfig -o /boot/grub2/grub.cfggrub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
- A systemd target is a group of unit files
- Some targets are isolatable, which means that the define the final state a system is starting in
- emergency.target
- rescue.target
- multi-user.target
- graphical.target
systemctl get-default- get info about default targetsystemctl set-default multi-user.target- set multi-user targetsystemctl set-default graphical.target- set graphical target
systemctl.unit=xxx.target- On the grub2 prompt use this value to boot into a specific targetsystemctl isolate xxx.target- to change between targets on a running system
- Enter Grub menu while booting
- Find the line that loads the Linux kernel and add rd.break to the end of the line
mount -o remount,rw /sysroot- remount sysroot in read-write modechroot /sysroot- change root directorypasswd root- change root passwordtouch /.autorelabel- apply SELinux policyCtrl-DCtrl-D
- Problems occur when making typo's in /etc/fstab
- To fix: if necessary, remount filesystem in read/write stat and edit /etc/fstab
- Fragmentation can be an issue, different tools exist to fix
xfs_fsr- is the XFS file system reorganizer, it optimizes XFS file systemse4defrag- can be used to defragment Ext4
-
Common network issues
- Wrong Subnet Mask
- Wrong router
- DNS not working
-
ip a d 192.168.4.235/32 dev ens33- remove IP address with incorrect subnet mask -
ip a a dev ens33 192.168.4.235/24- assign proper IP address to device ens33 -
ip route add default via 192.168.1.1 dev eth0- add default gateway to eth0 device -
dhclient- renew your request to dhcp server
-
Focus on the four key area's of performance
- memory
- cpu load
- disk load
- network
-
main tool for troubleshooting is
top
ldconfig- update the library cache
chmod +x myscript.sh- make it executableecho- prints the textread DIR- waiting for user input and write it to DIR variablecd $DIR- change directory to $DIR variable- By default scripts are being run in a subshell. If you want to run it in a current shell use following commands:
. myscript.shsource myscript.sh
-
if ... then .. fi -
while ... do ... done -
until ... do ... done -
case ... in ... esac -
for ... in ... do ... done -
man test- to see existing test conditions -
exit- special exit codes can be usedexit 0- code run successfullyexit 1- code run with errorsecho $?- to see exit code
#!/bin/bash
if [ -z $1 ]
then
echo you have to provide an argument
exit 6
else
echo the argument is $1
echo $(( 2 + 2))- do some calculations
#!/bin/bash
COUNTER=$1
COUNTER=$(( COUNTER * 60))
minusone(){
COUNTER=$(( COUNTER - 1 ))
sleep 1
}
while [ $COUNTER -gt 0 ]
do
echo you have $COUNTER seconds left
minusone
done
[ $COUNTER = 0 ] && echo time is up && minusone
[ $COUNTER = "-1"] && echo you are one second late && minusone
while true
do
echo you are now ${COUNTER#-} seconds late
minusone
done
/etc/ssh/sshd_config- servers options are set here/etc/ssh/ssh_config- client options are set herePort 22PermitRootLoginPubkeyAuthenticationPasswordAuthenticationX11Forwarding
scp- can be used to securely copy files over the network using sshd processscp file1 file2 student@remoteserver:/home/studentscp -r root@remoteserver:/tmp/files .
sftp- FTP client interface to securely transfer files using SSHput /my/file- to upload a fileget /your/file- to download a file to the current directorylpwd- print local working directorypwd- print remote working directorylcd- change local directorycd- change remote directoryexit- stop an sftp session
rsync- is using SSH to syncronize files- If source and target file already exists, rsync will only synchronize their differences
rsynccan be used with many options-r- recursively syncronize the entire directory tree-l- synchronizes symbolic links-p- preserver symbolic links-n- will do a dry run before actually synchronizing-a- uses archive mode-A- uses archive mode and also synchronizes ACLs-X- will synchronize SELinux context as well
/var/www/html- directory where your webserver contents stored/etc/httpd/conf/httpd.conf- configuration where DocumentRoot directory can be changed
- Modes of SELinux
enabled- Enforcing - fully operational. Will block and log everything
- Permissive - do logging, but don't block anything
disabled- to switching between enabled and disabled modes reboot is required. This mode can be set only from/etc/sysconfig/selinux
setenforce [ Enforcing | Permissive | 1 | 0 ]- to switch between enforcing and permissive mode. Reboot is not requiredgetenforce- get currently applied SELinux policy/etc/sysconfig/selinux- manage the default state of SELinux
- Every object is labeled with a context label
- user: user specific context
- role: role specific context
- type: flags which type of operation is allowed on this object
- Many commands support a -Z option to show current context information
ps auxZ | grep sshd- get information about context label for sshd servicesystem_u- user contextsystem_r- role contextsystem_t- context type
system_u:system_r:sshd_t:s0-s0:c0.c1023 root 20246 0.0 0.2 92320 7920 ?
ps auxZ | grep httpd- another example with httpd servicehttpd_t- context type allows followinghttpd_sys_script_exec_t- execute scripts in cgi-binhttpd_sys_content_t- read context in /var/www/html/ directory
system_u:system_r:httpd_t:s0
getsebool -a- get SELinux boolean value(s)getsebool -a | grep httpdhttpd_enable_homedirs- enable home directories for the users
setsebool -P httpd_enable_homedirs on- allow permanently httpd server to access users' home directories
semanage fcontext- set the file context label- This will write the context to the SELinux Policy
restorecon- enforce the policy setting on the file systemtouch /.autorelabel- alternative way. Will relabel all files to the context that is specified in the policyman semanage fcontext- get information about fcontext
Add file-context for everything under /web
# semanage fcontext -a -t httpd_sys_content_t "/web(/.*)?"
# restorecon -R -v /web
- Selinux uses auditd to write log messages to the audit log
sealert- it interprets messages from the audit log and writes meaningful messages to /var/log/messagesgrep AVC /var/log/audit/audit.log- get SELinux related messages. AVC stands for - Access Vector Cash.
type=AVC msg=audit(1630010413.373:849): avc: denied { getattr } for pid=29763 comm="httpd" path="/web/index.html" dev="sda2" ino=10618022 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:default_t:s0 tclass=file permissive=0
journalctl | grep sealert- look for alerts in journalctl. To get more information we should run suggested command below
Aug 26 22:40:20 localhost.localdomain setroubleshoot[30064]: SELinux is preventing /usr/sbin/httpd from getattr access on the file /web/index.html. For complete SELinux messages run: sealert -l 51056217-76c4-4d51-ab2d-ec19143cdff1
sealert -l 51056217-76c4-4d51-ab2d-ec19143cdff1- get more information about this error
load_policy -i- load SELinux for troubleshooting while you're in initramfs stagerestorecon -v /etc/shadow- relabel shadow with with necessary context typetouch /.autorelabel- ensure that rest of the file relabeled
- Firewalld - using different components to make firewalling easier
- Service: - main component, contains one or more ports as well as optional kernel modules that should be loaded
- Zone: a default configuration to which network cards can be assigned to apply specific settings
- Ports: optional elements to allow access to specific ports
firewall-cmd --list-all- list current configuration
firewall-cmd- command is used to write firewall configuration--permanent- write rule to persistent configuration (but not to runtime)- Without
--permanent- write rule to rutime (but not to persistent)
firewall-cmd --get-services- list servicesfirewall-cmd --add-service ftp- allow ftp servicefirewall-cmd --add-service ftp --permanent- allow ftp service permanentlyfirewall-cmd --reload- reload firewalldyum search firewall-config- search for graphical firewall utility. Not necessary at all.
- 2 files exists in user homer directory after installations
anaconda-ks.cfginitial-setup-ks.cfg
- Use
ks=http://somwhere/ks.cfg- before installation client indicates where to get the Kickstart file from
hwclock- set hardware clock and synchroniza with system timedate- set current time and display formattzselect- allows to select the current time zonetimedatectl- new utility to manage all aspects of timetimedatectl list-timezonestimedatectl set-timezone
Procedure is following
- Run the nfs-server service
- Create a directory you want to share: /data
/data *(rw,no_root_squash)- edit /etc/exports to containt the following line- Configure firewalld to allow connection
firewall-cmd --add-service nfsfirewall-cmd --add-service mountdfirewall-cmd --add-service rpc-bind
showmount -e nfs-server- show exportsmount nfsserver:/share /mnt- mount shared directory_netdev- use this mount option while mounting through /etc/fstab
- Install the Samba server package
- Create a directory to share
- Create a local linux user
- Set Linux Permissions
smbpasswd -a- add a Samba user account/etc/samba/smb.conf- enable the sharesystemctl start smb- start the servicefirewall-cmd --add-service samba --permanentfirewall-cmd --reload
- Install
cifs-utilsandsamba-clientRPM packages yum groupinstall 'Network File System Client'- install necessary packages for connectionsmbclient -L //sambahost- discover sharesmount -o username=sambauser //sambaserver/share /somewhere- mount a share- Make mount persistent through
/etc/fstab, using the_netdev, username= password=mount options
/etc/auto.master- here you define the directory that automount should manage/etc/auto.data- here you define subdirectory on which to mount, and what to mount exactly- `files -rw nfsserver:/data/files
systemctl enable --now autofs- ensure the autofs service is started
yum install autofs- install autofs package- autofs configuration files:
/etc/auto.master/etc/auto.misc
/etc/auto.files- if you're planning to create automount. You should createauto*file in etc and name it the same as directory
-
yum module install container-tools- install container management tools -
podman pull- pre-pull the image from registry to the local system -
podman run- pull the container (if necessary) and run itpodman run -d- run in detached modepodman run -it- run in interactive tty mode--rm- remove the container after using itctrl-p, ctrl-q- detach from a container tty
-
podman run -d nginx- you can immediately start running containers from the Docker Registry -
podman login- to access Red Hat registry you should authenticate. -
podman pull registry.access.redhat.com/ubi8/ubi:latest- to get a specific container, use a complete name reference
/etc/containers/registries.conf- images are obtained from registries, which are specified in this configuration fie.[reggistries.search]- additional registries can be added in this section- `[reggistries.insecure] - insecure registries without TLS encryption must be listed there
podman info- to see which registries are currently usedpodman search- search all registriespodman search --no-trunc registry.redhat.io/rhel8- search specific registry on the rhel8 string- Use filters:
--limit 5- shows a maximum of 5 images per registry--filter start=5- shows images with 5 stars or more
skopeo- inspect images before pulling themskopeo inspect docker://registry.redhat.io/ubi8/ubipodman inspect registry.redhat.io/ubi8/ubipodman rmi- remove images
podman run -d -p 8000:80 nginx- will map host port 8000 to container port 80podman port -a- will show all current container port mappingsfirewall-cmd -add-port=8000/tcp [permanent]- do not forget to open ports in the host firewallpodmam logs containername- get logs of container-e VAR=value- while starting the container to pass variable valuespodman run -d --name mydb -e MYSQL_ROOT_PASSWORD=password -p 3306:3306 mariadb
podman stop mycontainerpodman kill mycontainerpodman rm mycontainerpodman restart mycontainerpodman exec mycontainer uname -r- runs an additional process inside a running containerpodman exec -it mycontainer /bin/bash- access an interactive shellpodman exec -l cat /etc/redhat-release- runs the command on the last container that was used in any command
podman run -d -v /webfiles:/webfiles:Z nginx- if the container user is owner of the host directory, the :Z option can be used.sudo chmod o+w /webfilessudo chown student:student /webfilessudo run -d --name mynewdb -v /dbfiles:/var/lib/mysql:Z -e MYSQL_ROOT_PASSWORD=password mariadb- create container with attached storage
-
loginctl enable-linger- start user services for a specific userloginctl enable-linger lindaloginctl show-user lindaloginctl disable-linger linda
-
podman generate systemd --name myweb --files- generate systemd unit for existing container--files- Generate files instead of printing to stdout. The generated files are named {container,pod}-{ID,name}.service and will be placed in the current working directory.
-
podman generate systemd --name ephemeral_ellie --files --new- you can't keep persistent data in this container.--new- Using this flag will yield unit files that do not expect containers and pods to exist.
-
/etc/systemd/system- to generate a service file for a root container, do it from this directory, because--fileskey will create unit file in the current working directory -
Creating User Unit files
- Create user specific unit files in
~/.config/systemd/user - Manage them using
systemctl --usersystemctl --user daemon-reloadsystemctl --user enable myapp.service(requires linger)systemctl --user start myapp.service
systemctl --user- commands work only when logging in on console or SSH and do not work in sudo su sessions
- Create user specific unit files in