2021.03.04 - AlmaLinux Tips
There's deffinitly some differances between CentOS 6 and Red Hat Enterprise Linux 8 / AlmaLinux
- Home
- Intro
- Extra Packages to Install
- Other Random System Tweaks
- Viewing Systemd Journal Log Files
- rsync
Intro
Beyond firewalld there are a bunch of little things I ran into when setting up Red Hat Enterprise Linux 8 / AlmaLinux that I wanted to make notes of. In particular I like to use the minimal installation ISO so there there's some extra packages to install, some alias shortcuts I like to make and just some log weirdness I want to make notes on.
Before starting the installation, as I'll be running this machine on Microsoft Hyper-V I'm going to use a custom command to create the VHDX file, as the default creation apparently doesn't work as well as it could for Linux. This may be a completly outdated step at this point as this is the page I'm getting the information from: Best Practices for running Linux on Hyper-V. The page says its been updated in the last couple of months, but some of the information is outdated (at least for Red Hat Enterprise Linux 8). For example Red Hat Enterprise Linux 8 uses Grub 2 which doesn't seem to have the timeout issues Grub had. Also it uses the mq-deadline scheduler, which is what Red Hat recommends for use when it's a guest OS.
To customize the ext4 formatting options you need to use a KickStart file, which you can find more information about in another post here. To manually create the VHDX file
with a block size of 1MB:
New-VHD -Path C:\MyVHDs\test.vhdx -SizeBytes 127GB -Dynamic -BlockSizeBytes 1MB
You'll also want to assign a static MAC address to the network interface and turn off Secure Boot as it's not (as of this writing) supported in AlmaLinux. Also, don't forget to change the boot order so that Network is at the bottom of the list and your installation media is at the top.
Extra Packages to Install
So in AlmaLinux (I'm just gonna sitck with AlmaLinux but this applies to any Red Hat Enterprise Linux 8 based OS) yum has been replaced (renamed?) with dnf. That said dnf still reponds to yum commands so I'm going to keep using the yum command. So the packages I like to add:
- nano - Easier text editor to use than vim...
- telnet - nice to have handy for testing firewalls
- nmap - nice to have handy for testing firewalls
- mailx - easy email sending from the CLI
- lftp - handy for scripting secure file transfers
- rsync - useful for transfering files from one linux system another
- wget - I suppose you could just pipe curl to a file
- whois - It's annoying when you want to lookup a domain name and grab a random server and whois doesn't work
- logwatch - Handy for getting an email once a day with a snapshot of what showed up in log files that day
- net-tools - Provides ifconfig and some other useful basic tools
- bind-utils - Provides dig and some other useful dns tools
- expect - Handy scripting tool
- ntsysv - Nice GUI for controlling what services start on boot
- rsyslog - Most logging is done through systemd now, but rsyslog is still handy
- mlocate - Gives the locate command to quickly find files on the server
- lsof - Show what proccess is using files or ports on the server
- tar - Extract and Create tar files
- zip - Extract and Create zip files
- glibc.i686 - Adds support for running 32-bit apps, I'm not really sure what files are exactly needed
- libgcc.i686 - Adds support for running 32-bit apps, I'm not really sure what files are exactly needed
yum install epel-release
yum install nano telnet nmap mailx lftp rsync wget whois logwatch expect ntsysv rsyslog net-tools bind-utils mlocate lsof tar zip glibc.i686 libgcc.i686
Other Random System Tweaks
Like anyone else that's used Linux for a while I have some preferances about how I like my termial setup, so here they are. It's completly possible some of these setting changes aren't needed anymore and are the defaults now, but we'll change them anyways. First some aditional to the ~/.bashrc file:
alias f='pinky -l'
#shortcut for the finger command to check to see if a user exists,
#finger doesn't seem to actaully exist anymore
alias eweb='nano /etc/httpd/conf/httpd.conf'
alias pivert='nano /etc/postfix/virtual'
alias ttml='tail -f /var/log/maillog'
alias tthl='tail -f /var/log/httpd/error_log'
alias utar='tar -zxvf'
#I don't use this one much anymore, I can actaully remember how to use tar!
alias fix='echo -ne "\\017"'
#handy for when you cat a binary file and it messes up your terminal
alias pico='nano'
#muscle memory is a thing
In the ~/.bash_profile I like to make the following aditions becuase it's nice to know exactly the path you are in, not just the current folder. Oh, and becuase I'm a psychopath I set nano to the default text editor instead of Vim
export EDITOR=nano
export PS1="[\u@\h \w]# "
I also found some neat things to add to the ~/.bash_profile to make the history command more useful (also fun trick, use !{line-number} at the bash prompt to just run that line from the history):
export HISTIGNORE="ls:ll:ps:history:poweroff:reboot"
#Stops history from recording these commands long term
export HISTCONTROL=ignoredups
#Only records one time if you run a command multiple times
export HISTFILESIZE=10000
#Sets the max size of the history file to 10,000 lines
export HISTTIMEFORMAT="%h %d %H:%M:%S "
#Includes the day and time the command was run
I also prefer to have my log files numbered .1, .2, .3, .4 and so on, so I edit /etc/logrotate.conf and comment out the line dateext. This setting doesn't do as much as it once did though as most system logs run through journal now. With that in mind add this folder to AlmaLinux so that journal logs to an actual file and not just in memory: /var/log/journal/ (more on journal below). Also, SELinux is an awesome tool... That really just gets in my way too much so I turn it off (edit /etc/selinux/config and set to disabled, you will need to reboot your server after making this change).
The last set of changes are a couple to the /etc/profile file. At the end I add stty erase ^H. I think that's to fix the backspace key working in some older programs. Also in the # Path manipulation section I add pathmunge /var/scripts and pathmunge /var/scripts after to the approprate places so I can add the folder /var/scripts to hold any custom scripts I write and make backing them up easier.
Viewing Systemd Journal Log Files
Systemd... well it's here and it's what the world is using now so just accept it. It does weird stuff with log files though, it kinda holds them in one giant file, which you can then query. I haven't totally got the hang of it yet but here's a couple of commands I've found to at least get started. First if you created the /var/log/journal folder and run service systemd-journald restart you should now have a system.journal file inside it. If you ever need to view this file (server is offline for some reason) you can use the command journalctl --file /var/log/journal/{machine-id}/system.journal. This will show you the whole log starting at the beginning. If the system is up and running normally there are better ways to read the log file.
The command journalctl just by itself will give you the same output as specifying the file. Digital Ocean has a handy little guide. Some commands I found useful are listed below:
journalctl -f -n30
# -f follows the log -n show last x number of lines
journalctl -b
# Shows all logs since the most current boot, instead of the complete log file
journalctl --since 09:00 --until "1 hour ago"
# Specify a time range to view, humanlike strings work, like now
journalctl -u dnf-makecache.service -u crond.service
# view logs from a particular "unit"
journalctl -p warning
# view logs at severity level, levels are:
emerg, alert, crit, err, warning, notice, info, debug
journalctl -o verbose
# view logs displayed differant ways, short is the default, verbose is good for finding these things:
journalctl _PID=1579
# view logs from a particular proccess PID
journalctl _UID=$(id -u root)
# view logs generated by user
journalctl _COMM=dnf
# view logs filtered by the command name (probably easier to use than unit
rsync
This isn't particularly an AlamLinux thing, but still a handy command to get a refresher on when moving to a new server. rsync is a great tool to use to copy files from one linux server to another becuase first it works over SSH so normally there are no extra programs to install, second it keeps all the permissions in place (assuming the users have the same user IDs between servers) and third becuase it only copies files that need to be. So if you copy a directory you can copy it again later and it only transfers the files that have changed.
You can use -n as a dry-run flag along with -v to see what would happen if you run a command without actaully doing it. It's useful if you aren't exactly sure if you have all the trailing slashes correct. Or in my case I like to use the --delete flag to clean up files that make have been deleted from the source server between rsync runs, so seeing what files it will delete is nice. Also the -a flag is required if you want to transfer directories as well. The -a flag means archive so it also copies symbolic links and some other special things, so you might just want to use it on all your transfers.
rsync -n -v -a --delete /home/ root@192.168.100.5:/home
# copies the home directory from one server to another
# the -n is a dry-run flag, remove it to actaully make something happen
rsync -n -v -a /var/scripts/ root@192.168.100.5:/var/scripts
# copies every file/folder in the /var/scripts/ folder from one server to another
# the -n is a dry-run flag, remove it to actaully make something happen