Chapter 7. Class #7 - System Administration & System Logging Configuration

Table of Contents

Intro to System Administration
System Administration Configuration
System Administration Commands
Additional Notes & Considerations for System Administration
New in RHEL 7: systemd
Intro to rsyslog
Installing rsyslog
rsyslog Configuration
rsyslog as a Service
Commands to Manipulate rsyslog
Securing rsyslog
Additional Notes & Considerations for rsyslog
Reference Material for this Chapter

Crucial information for System Administration. While much of this information is not part of the RHCE exam, it will be very difficult to engage the exam without this knowledge.

Intro to System Administration

The material below on System Administration is a collection of tidbits that will generate discussion and digression in class. The items outlined are starting points for the discussion that will take place.

System Administration Configuration

Take an exploratory tour through the following virtual directories.

  1. '/proc' - a "holding area" for information from the kernel.
  2. '/dev' - a container for listing the devices on the system that also makes possible interection with those devices.

Also look at the file '/etc/sysctl.conf' for a way to change kernel runtime parameters such that they'll persist after a reboot.

System Administration Commands

The table below lists several commands that are used regularly for System Administration. We'll talk about these in class.

Table 7.1. Common System Administration Commands

Command[a][b]. Description
`cat` Concatenates files. When used with only one file, it simply echoes the file to STDOUT.
`cut` Print selected sections of input lines. Use the '-d' flag to change the field deliminator. The default delimiter is the TAB.
`sort` Sort input lines (based on "keys" & collation order).
`uniq` Similar to `sort -u` but with more options.
`wc` The Word Count command. Count lines, words, & characters of the input to the command. '-l' = count lines; '-w' = count words; '-c' = count characters; no options = display the count of all three.
`tee` Send the output of a command to two (or more) places.
`sed` Stream EDitor. Gives the ability to edit a file in place without opening the file.[c]
`awk` A serious utility that is a programming language all to itself. Extremely useful for manipulating well formatted files. The cut command will work as a substitute for simple application.[d]
`grep` Search for specific content within a file.[e]
`head` By default, prints the first 10 lines of a file. -n <num> changes the number of lines. Lots of options available.
`tail` By default, prints the last 10 lines of a file. -n <num> changes the number of lines. Lots of options available.
'>'; '>>'; '|' Redirection operators and the pipe. Note the important distinction between > & >>.
STDOUT; STDIN; STDERR Everything is going somewhere. Redirecting the output creates options. [f]
`file` Returns crucial information about a file.[g]
`touch` Update the modification time of a file. Create the file if it does not exist.
`ln` Create a link to said file. There is a very important distinction between hard and soft links. Soft links are obvious. Hard links are somewhat obscured.[h].
`shred` Securely erase a file.
`md5sum` & `sha1sum` Generate (or verify) hash signatures of files.
`dd` disk dump utilty. Very helpful command that dates to antiquity. Reads and outputs (to wherever you send it) the input, which can be a device - such as a disk, or a pseudo-device (such as /dev/{zero,random,null, etc}). Note the strange sequence for using the command: `dd if=<input-file> of=<output-file> <options>`. See Examples of `dd` Command for examples.
`rsync` Remote synchronization tool. Extremely useful.
`ip` Networking command.
`ethtool` Networking command.
`dhclient` Networking command.
`ifup` & `ifdown` Networking command.
`ifconfig` Networking command.
`system-config-network` Networking command. See also `system-config-network-tui` & `system-config-network-cmd`.
`netstat -[n r a t]` Networking command. The flags are thus: (n=numeric ip, r=routing table, a=all, t=tcp).
`arp` Networking command. Address Resolution Pprotocol. Shows mappings of ip numbers to MAC addresses.
`route` Networking command.
`top` System analysis tool. Note the use of a .toprc file.
`ps` Process analysis tool.
`service <what-to-do-with-it> [--status-all]` See Figure 7.2, "Service Usage Options" for the details.
`cron` The system's "chronic" scheduler for tasks. See Figure 7.1, "Crontab Config File" for details.
`at` A "queue" type system for one-time tasks.

[a] The coreutils package provides a set of basic GNU tools commonly used in shell scripts. The package is a combination of the old GNU fileutils, sh-utils, and textutils packages.

[b] Remember the three key helpful elements to search for information on commands or config files: `man -k <what-to-search-for>`; `<command> --help`; and `man <command>`

[c] See sed One Liners for several working examples of the `sed` command.

[d] See awk One Liners for several working examples of the `awk` command.

[e] Note the following (simplified) regex operators available: '?' = zero or one; '*' = zero or more; '+' = one or more; '(/.*)?' = matches file path, any subsequent character.

[f] See the Standard Streams Wikipedia Article for in depth information.

[g] Note that Linux file systems do not depend on a file's extension to determine the type of file it is. The system reads the metadata about the file and returns a best guess about the file.

[h] Watch the context sensitive column of the `ls -al` command.


Listed below is a screenshot of the main configuration file for cron that is located at /etc/cron.

Figure 7.1. Crontab Config File

Crontab Config File

Figure 7.2. Service Usage Options

Service Usage Options

Additional Notes & Considerations for System Administration

Listed below are examples of looping at the command prompt.

    `for x in {1..9}; do <x,y,z<; done`
    `for user in /home/students/*; do passwd -S `basename $user` | awk '{print $3}'; done`

Listed below are examples of the `sed` command.

    --> sed edit a file in place - note the empty option after the -i, and empty extension; 
        if a backup is desired, enter the extension instead of the empty string
    `sed -e 's/<text-to-replace>/<text-to-replace-it-with>/' -i '' <file-to-work-on>`
    
    `sed -i 7d <file>` // deletes line 7 of specified file

    `for user in /home/students/*; do passwd -S `basename $user` | sed -e '/2003/b' -e '/2004/b' -e '/2005/b' -e '/2006/b' -e '/2007/b' -e d  | awk '{print $1}'; done`                 */
        `for user in { jbosshart mcidon searley cgadilhe mmorgan gormsby rpinon apitts jrangel lwatts tzunker nstein }; do "usermod -e 2010-06-01 $user"; done`

Listed below are examples of the `dd` command.

    `dd if=/dev/sda of=/dev/sdb`                                            // back up an entire disk
    `dd if=/dev/sda1 of=/dev/sdb1 conf=notrunc,noerror`                     // copy an entire partition
    `dd if=/dev/sda`                                                        // wipe a partition (note no output file)
    `dd if=/dev/zero of=/dev/sda bs=1M`                                     // overwrite a disk with zeros
    `dd if=/dev/urandom of=existing-file bs=3769 count=1 conv=notrunc`      // overwrite an existing file with zeros
    `dd of=source.iso of=/dev/sdb`                                          // put a disk image to a flash drive to make it bootable
    `dd if=/dev/hda of=~/hdadisk.img`                                       // create a disk image backup at specified location
    `dd if=hdadisk.img of=/dev/hdb`                                         //S restore a disk image to another partition

New in RHEL 7: systemd

One of the new features that will be available in RHEL 7 is systemd, which is a complete rewrite of the familiar and long-standing sysvinit scripts. There's more information at systemd on Fedora Project , systemd details , systemd Tutorial , and SysVinit to systemd cheatsheet .[15]



[15] Please note that systemd is a complete rewrite and diversion from the "old way of doing things". In many instances, it's made to work with the old commands, but there is a learning curve. Plan to spend some time with this new utility when preparing for the RHCSA/RHCE exams.