Operate running Systems Flashcards
multiple ways to reboot a system
# reboot # shutdown -r now # sudo init 6 # telinit 6 # shutdown -r +3 reboot after 3 minutes # shutdown -r 10:35 reboot at 10:35
Multiple ways to shutdown a system
# shutdown -h now # sudo init 0 # sudo telinit 0 # poweroff
Boot Process
- Bios initializes
- Bootloader is then called by the Bios
- Bootloader loads the first kernel image
- Kernel then mounts file systems and starts the appropriate system services.
- The system services finish starting up, and a login screen is presented
BIOS
- Basic Input Output System
- installed on a small chip on the motherboard
- initializes basic peripherals on the system, sets the system clock, and searches for the boot device
- once boot device is detected, the program installed(known as bootloader) is executed
BootLoader(GRUB)
- Default RHEL bootLoader is GRUB
- GRUB loads the first kernel image listed in its configuration file
- Then hands control of the rest of the boot process to the Linux kernel
Kernel boot process
- Kernel detects hardware on the system
- Kernel loads device drivers from its initial RAM file system initramfs-.img
- Mounts the root file system in read only mode
- init is then loaded(starts the init process)
Last stages of startup
- init runs the necessary scripts in /etc/init
- /etc/inittab is read for the default runlevel
- runlevel scripts for the appropriate runlevel are started
- user is presented with a login screen
Runlevels
0, shutdown
1, single: Maintenance level
2. level without some network resources(for example lack of NFS)
3. Multi-user level without graphical interface
4. None
5. Multi-user level with graphical interface
6. reboot
to check current run level
runlevel
to change current run level
# init x # telinit x
Boot into different run level at boot time
Press the letter i when you see the bootloader. At the grub menu press the a key to append an argument to the kernel boot line. Enter argument at the end of the parameter, then press enter.
upstart
- Originally developed for Ubuntu
- replaced the old system V init System
- SysV init started services Sequentially
- Upstart starts services in parallel
- Provides a much faster boot experience
- Review man 5 and man 8 for upstart
init
- init is the first process (PID 1)
- All other processes are child process from init
- /sbin/init
- configuration files for init|upstart are in /etc/init
rcs.conf
- /etc/init/rcs.conf
- Primary script that gets called from Upstart
- first it executes /etc/rc.d/rc.sysinit script
- reads /etc/inittab for default run level
- finally it switches to default runlevel
rc.sysinit
- /etc/rc.d/rc.sysinit
- sets system hostname
- starts networking
- Mounts and checks file Systems
- runs plymouth
- sets SELinux state
- send messages to /var/log/dmesg
Plymouth
provides the progress bar that we see during system bootup
inittab
- /etc/inittab
- Used to be the main script file that init uses during system startup
- it has been demoted with RHEL6 with upstar
- sets the default system runlevel
rc.conf
- /etc/rc.conf
- called by the /etc/init/rcs.conf file, uses default runlevel as set in /etc/inittab
- fires up the scripts located in /etc/rc.d/rcx.d/ (where x is the default runlevel)
some important startup scripts
- /etc/sysconfig/init
- – sets colors for plymouth, determines if single user mode will need a password or not etc.
- /etc/init/tty.conf
- –creates terminals accessed through ctrl + alt + F1 - F6
/etc/rc.d/rcx.d
check which scripts are run in different run level. Replace x for 0 - 6
K vs S before service startup scripts
K is for kill and the S is for start
chkconfig
use chkconfig to start or kill services at startup # chkconfig servicename on # chkconfig servicename off # chkconfig --list servicename check if service name is on or off # chkconfig --level 35 atd on allow a service to start at specific runlevel(3,5)
Cancel schedule shutdown
shutdown -c
top command
display an instantaneous image of a server’s activity
to get details about process
ps -edf
to start a process with a low priority
nice - n 10 ./script.sh
To change the priority of an already running process
Get the process's PID (example using PID 789( then type): # renice +5 789 Alternative way # renice +5 `pgrep script.sh`
Killing processes
# kill -9 789 PID 789 # pkill script.sh #killall httpd
display details about IO activities
iostat
display network card activities
netstat -a
get details about virtual memory activities
# vmstat 5 the virtual memory activities include: memory, swap, run queue, cpu, usage, etc). This example runs it every 5 seconds
get a full report of a server activity
sar -A
ps
Report a snapshot of the current processes. It helps you see what processes are being run, what files & commands they are being run with, who they are being run by, as well as their process ID
To see every process on the system using standard syntax
# ps -e # ps -eF # ps -ef # ps -ely
to see every process on the system using BSD syntax
# ps ax # ps aux
to print a process tree
# ps -ejh # ps axjf
to get info about threads
# ps -elf # ps axms
to get security info
# ps -eo euser,ruser,suser,fuser,f,comm,label # ps axz # ps -em
to see every process running as root (real & effective ID) in user format
ps -U root -u root u
pstree
shows which processes are running, but also the parent processes that started each one. It displays a snapshot of that informatin in a tree like diagram
pstree command examples
# pstree # pstree -p shows also the PID for each individual process that are running) # pstree -a shows us any command line options that will run with a particular process)
other ps command examples
# ps -u username # ps -u shows your own processes
top command options
use the h key while in top to see all the commands that you can use with it. The q key will quit top. To change the nice value while in top, press the r key, to renice a process, then enter the pid of a process, then the renice value we want the process to have
system monitor
to access from the GUI, click applications -> system tools -> system Monitor
nice value
Nice values range from negative 20 to 19 (-20,19) with negative 20 being the highest nice value and 19 being the lowest nice value. The nigher the number the less cpu time a process gets. The default value that a process get when it starts is zero
System logs
All system logs are located under /var/log.
/var/log/messages
- standard system logs
- include messages from all system software, boot issues, not related to the kernel
/var/log/dmesg
- messages are added to this log during boot time
- includes messages from the kernel during the boot process
- also includes info about hardware devices that are connected
/var/log/secure
- messages from anything security related, including tcp-wrappers(a security measure for network services), logins, etc
/var/log/audit/audit.log
- messages from selinux subsystems
- contains AVC(Access Vector Cache) messages
/var/log/boot.log
system boot up messages
/var/log/httpd
contains logs from configured web sites
utilities to use with system logs
# tail -f # dmesg monitor kernel boot messages # sealert for selinux messages # aurepart -> for selinux messages
syslog
is the core service that records & monitors system logs on a system. in RHEL6 the original syslog daemon has been replaced with the rsyslog daemon. vi /etc/rsyslog.conf to check out the rules section. After making changes there, you can reload the service instead of restarting it: # service rsyslog reload by default syslog uses port 514
To access virtual console
virt-manager
Connect to a virtual machine
virsh console vm.example.com
KVM
- Kernel-based Virtual Machine
- each virtual machine is viewed as a single process
- Multiple tools that are available to manage machine guests
- – virsh - command line tools for guest management
- – virt-manager - graphical front end for libvirt
To check if your machine qualifies for virtualization
cat /proc/cpuinfo | grep “vmx|svm”
To install virtualization
# yum groupinstall virtualization # chkconfig libvirtd on # service libvirtd start
KVM guests consists of two main components
- Guess XML file = contains details on Ram assigned, cpu amount, location of hard disk image files
- guess hard disk file - either in Raw(pre-allocated) or qemu file formats, ending in .img extension
XML configured files for KVM are stored in
/etc/libvirt/qemu/name-of-guest.xml
hard disk files for KVM are stored in
/var/lib/libvirt/images
Virsh command examples:
virsh
virsh# nodeinfo view guest status
virsh# list –all view a listing of guests on the hypervisor
virsh# shutdown guestname shutting down a guest
virsh# start guestname start guest
virsh# destroy guestname similar to pulling the plug
virsh# dominfo guestname info on guest
virsh# undefine guestname to delete a virtual machine
virsh# autostart guestname enabled autostart
virsh# autostart guestname –disable disabled autostart
virsh# help
virsh# exit
view virtual guests processes
ps -aux | grep qemu
To access virt-manager from the GUI
click Applications -> System Tools -> virtual machine Manager
the ntsysv command
ntsysv
Allows you to configure services to start on bootup
You’ll get a text base gui you can check or uncheck services. Only modify the service in the current run level
System-config-services
- A gui service configuration tool. It's not installed by default # yum install system-config-services # system-config-services or access through the gui System - Administration - Service