Sunday, 13 July 2014


RHCSA 7 Exam Notes #2: Operate running systems

 
Word Version available here:
https://drive.google.com/file/d/0B9WPh0iDN4KwekpZekF6TmZXQ0k/edit?usp=sharing

Boot, reboot, and shut down a system normally
systemctl halt              systemctl reboot            systemctl --nowall poweroff (no broadcast)
shuttdown -[h/r] [now/20]      (halt/reboot, now/20 minutes)

Boot systems into different targets manually

Runlevels have been replaced with system targets controlled by the systemctl command.
Runlevel
Target Units
Description
0
runlevel0.target, poweroff.target
Shut down and power off the system.
1
runlevel1.target, rescue.target
Set up a rescue shell.
2
runlevel2.target, multi-user.target
Set up a non-graphical multi-user system.
3
runlevel3.target, multi-user.target
Set up a non-graphical multi-user system.
4
runlevel4.target, multi-user.target
Set up a non-graphical multi-user system.
5
runlevel5.target, graphical.target
Set up a graphical multi-user system.
6
runlevel6.target, reboot.target
Shut down and reboot the system.

systemctl set-default multi-user.target          (Sets default to non-graphical multi-user system, set it back with graphical.target, watch for proper placement of – and . symbols!)
systemctl isolate multi-user.target    (switches to non-graphical multi-user system immediately)systemctl rescue/emergency                         (switches to rescue/emergency shell immediately)systemctl can also be used against remote systems:
systemctl -H root@server-01.example.com status crond.service
 
Interrupt the boot process in order to gain access to a system

Note: this broke the root password for me. Ensure you use visudo to give another account full access to avoid being locked out! I was able to recover by using sudo passwd root in the graphical session later. All attempts to use the method below to set the root password failed!

To reset root account as an example:
Press any key at the Grub boot loader and then e to edit the default option
Scroll down to the line starting with initrd16 and press the left arrow once until you get to the end of the line ending in LANG=en_IE.UTF-8 and append as follows:
LANG=en_IE.UTF-8 init=/bin/sh
Press CTRL-X to boot and you’ll get to a sh-4.2# prompt

/usr/sbin/load_policy -I
mount -o remount,rw /
passwd root
mount -o remount,ro /
Now reboot the system. Note: commands entered in the bash prompt are not echoed to screen. I got palindrome errors when attempting to change the root password but the default password policies may need to be relaxed a bit for this to work.

Identify CPU/memory intensive processes, adjust process priority with renice, and kill
Processes

TOP is your buddy!
Load average: last minute, 5 minutes, 15 minutes     (Anchor value = 1 per Cpu Core)
Press 1 to show all Cores in a multi CPU system
CPU: us=user space apps not run with root priority, sy=system space used by kernel, id=idle time, wa=waiting on I/O if over 30% issues, st=Virtualization stealing cpu from host, move those pesky VMs somewhere else!
Memory: watch out for used Swap, is normal for Oracle/SAP though

Processes: USER is who started process, PRiority rt=realtime, VIRT=memory claimed when process first started, RES=resident memory is how much process is using now, SHR=memory shared with other process

Press f and scroll down to highlight & select P = Last Used Cpu (SMP) to see context switches by a process in action
vmstat                         vmstat –s                    (good sampling utility –s is since boot, use -d for disk activity of iostat, netstat for network)

free –m           (free memory)            slabtop             (kernel memory usage, yes that’s spelled “s-l-a-b….”!!)
ps -efl to show processes and niceness (NI column: valued from -20 critical, 0 default to +19 don’t care)
pidof crond      (shows process ID of crond process)
ps -U root        (shows all processes owned by root)
nice --2 tail -f /var/log/messages       (use to launch new process with specified niceness, notice -2 would mean +2 but --2 means -2 !)
ps -efl | grep tail         (let’s see in another terminal what the niceness of the tail process is)
renice -4 3057             (this change niceness to -4, to set +4 drop the -)
ps -p 3057 -fl               (let’s see the niceness of process 3057)
pgrep tail / kill 3057               (find tail’s process id / kill process 3057, use –p if process stuck waiting on input)
pkill tail                       (kill process tail, use –p if process stuck waiting on input)
 
Locate and interpret system log files and journals

Most log files are in /var/log
cat /var/log/boot.log              (checks for service startup on boot)
tail -f /var/log/messages                    dmesg             (check messages file,useful for USB info)
/etc/logrotate.conf     /etc/logrotate.d/<subfolder>             (controls log rotation, specific service amendments in subfolders)
journalctl -n 20                       (shows last 20 log entries generated with their entry point, -f for realtime, -p and either word or number: debug (0), info (1), notice(2), warning (3), err (4), crit (5), alert (6), and emerg (7))
 
Access a virtual machine's console
 Click Applications, System Tools, Virtual Machine Manager and double click on the VM to open the console. CTRL+ALT to release the cursor.
virt-manager   (Main Virtual Machine Manager program – same as above)
virt-viewer myvm (opens VMs console)
virsh is the command line utility. Some useful commands are:
virsh list  (list VMs, called domains here)
virsh -v (get kvm version info)
virsh autostart myvm (starts VM on host bootup)
virsh dominfo myvm (get vm info)
virt-top  (yes, you guessed it, TOP for VMs!)

Start and stop virtual machines

Invoke virt-manager or use virsh commands below:
virsh [reboot/reset/screenshot/shutdown/start] myvm

Start, stop, and check the status of network services
systemctl [start/stop/status] vsftpd.service   (replace vsftpd with service name)
systemctl list-units –type service        (displays the status of all services)
systemctl [enable/disable/is-enabled] vsftpd.service (sets vsftpd service to start / stop on system startup, is-enabled checks status)

Securely transfer files between systems
Default install of RHEL7 should have the following line in /etc/ssh/sshd_config:
Subsystem   sftp   /usr/libexec/openssh/sftp-server

Test remote SSH connection first to cache client certificate:
ssh student@192.168.31.52
Now choose one of the following:
SFTP:
sftp student@192.168.31.52               (Setup secure sftp connection)
ls                                                          (check remote directory listing)
cd Desktop                                          (Let’s drop the file into the Desktop folder)lls                                                         (Checks LOCAL directory for file to transfer)
put iometer.iso                                   (Transfers File iometer.iso)
ls                                                          (Check remote directory that file now exists)quit                                                      (Closes connection)
So the basic commands (Remote vs Local) are cd/lcd, ls/lls. You can use Put/Get to transfer files in either direction. Also mkdir/rmdir work on REMOTE system.

SCP:
Enter command below to transfer iso file from one Desktop to the other remote system:
scp ~/Desktop/iometer.iso student@192.168.31.52:~/Desktop
You will be prompted for student’s password where if accepted the file will be transferred.