Sunday, April 14, 2013

RHCSA Notes


RHCSA

graphic issueBinary translation is incompatible with long mode on this platform.
Disabling long mode. Without long mode support, the virtual machine
will not be able to run 64-bit code.
For more details see
http://vmware.com/info?id=152.


Jang RHCE book is awesome.

find / -iname stuff.tar*

VM X-Window Problem - hang enabling fs qutoa
/var/log/messages
- kernel logs, during boot time, bios, HW, PCI devices, CPU
/var/log/dmesg
- system security, TCP wrappers, system logins
/var/log/secure
/var/log/audit/audit.log
[root@localhost ~]# sealert -a /var/log/audit/audit.log
- otherlogs
/var/log/yum.log
/var/log/boot.log
/var/log/httpd

Problem-1: (Solved) system hang "enabling local filesystem quota"check:
search "enabling local filesystem quota"
/etc/rc.d/rc.sysinit

Solution:rm /.autorelabel solved problem

Problem-2: (Ongoing) black screen during boot Tip:
/etc/rsyslog.conf:

Tip-2. turn off ssh firewall
GdmLocalDisplayFactory: maximum number of X display failures
/var/log/gdm
undefined symbol pci_device_map_legacy

Next Action
----------------
- investigate ...GdmLocalDisplayFactory: maximum number of X display failures
- hang jexec service starting rhsmcertd
- prefdm respawning too fast
- failed to load fbdev modelu does not exist
renaming my /etc/X11/xorg.conf file to /etc/X11/xorg.conf.old

- investigate xorg.conf
-investigate new messages log
- search common x11 does not show issues and solutions
-------------------------------------------------------------------------------------------------------

Hard disks & Partitions
Disk /dev/sda: 21.5 GB

100MB - /dev/sda1 * 1 13 102400 83 Linux
20GB - /dev/sda2 13 2611 20868096 8e Linux LVM

PV
[root@RHSCA-2 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 VolGroup00 lvm2 a-- 19.88g 1.00g


VGVG #PV #LV #SN Attr VSize VFree
VolGroup00 1 2 0 wz--n- 19.88g 0

LVM
LogVol00 VolGroup00 -wi-ao-- 15.88g
LogVol01 VolGroup00 -wi-ao-- 4.00g

FSTAB
/dev/mapper/VolGroup00-LogVol00 / ext3 defaults 1 1
UUID=877ecf22-5362-4101-ae26-b84155d3fdc1 /boot ext3 defaults 1 2
/dev/mapper/VolGroup00-LogVol01 swap swap defaults 0 0,

To-Dos

Important
------------------------------------

-7.4 IP command is the default cmd for netw config

Work-to-be-done
-------------------------------------

+ 5.5 LDAP
- 9.6 groupquota not working
[root@RHSCA-2 ~]# quotacheck -cgmv /research/
quotacheck: Your kernel probably supports journaled quota but you are not using it. Consider switching to journaled quota to avoid running quotacheck after an unclean shutdown.
quotacheck: Scanning /dev/mapper/VolGroup00-LogVol03 [/research] done
quotacheck: Old user file not found. Usage will not be substracted.
quotacheck: Cannot stat old group quota file: No such file or directory
quotacheck: Checked 3 directories and 2 files
quotacheck: Cannot create new quotafile /research/aquota.group.new: Permission denied
quotacheck: Cannot initialize IO on new quotafile: Permission denied

- how to learn FS type
- setup SAMBA CIFS share
- ACL - let other usser to write to other users home dir
- How to setup SFTP server

------------------------------------
To-Dos
- Quota Management pt. 1
- exercise with NANO (3.5)
- vimtutor
- study fdisk
- study parted
- man tune2fs -l /dev/sdb1
- man mkfs -t ext4
- man fsck /dev/sdb1

?? how add perm to owner and gruop users?
- man 1 chattr
- study iptables man pages basic level
- study: man yum
- study
man yum.conf
/repositoryid

- man rpm

info ln
[root@localhost ~]# info coreutils 'ln invocation'

RHCSA Objectives

http://www.redhat.com/training/courses/ex200/examobjective

Understand and use essential tools
Access a shell prompt and issue commands with correct syntax.
Use input-output redirection (>, >>, |, 2>, etc.).
Use grep and regular expressions to analyze text.
Access remote systems using ssh and VNC.
Log in and switch users in multiuser runlevels.
Archive, compress, unpack, and uncompress files using tar, star, gzip, and bzip2.
Create and edit text files.
Create, delete, copy, and move files and directories.
Create hard and soft links.
List, set, and change standard ugo/rwx permissions.
Locate, read, and use system documentation including man, info, and files in /usr/share/doc.

Operate running systems
Boot, reboot, and shut down a system normally.
Boot systems into different runlevels manually.
Use single-user mode to gain access to a system.
Identify CPU/memory intensive processes, adjust process priority with renice, and kill processes.
Locate and interpret system log files.
Access a virtual machine's console.
Start and stop virtual machines.
Start, stop, and check the status of network services.

Configure local storage
List, create, delete, and set partition type for primary, extended, and logical partitions.
Create and remove physical volumes, assign physical volumes to volume groups, and create
and delete logical volumes.
Create and configure LUKS-encrypted partitions and logical volumes to prompt for password
and mount a decrypted file system at boot.
Configure systems to mount file systems at boot by Universally Unique ID (UUID) or label.
Add new partitions and logical volumes, and swap to a system non-destructively.

Create and configure file systems
Create, mount, unmount, and use ext2, ext3, and ext4 file systems.
Mount, unmount, and use LUKS-encrypted file systems.
Mount and unmount CIFS and NFS network file systems.
Configure systems to mount ext4, LUKS-encrypted, and network file systems automatically.
Extend existing unencrypted ext4-formatted logical volumes.
Create and configure set-GID directories for collaboration.
Create and manage Access Control Lists (ACLs).
Diagnose and correct file permission problems.

Deploy, configure, and maintain systems
Configure networking and hostname resolution statically or dynamically.
Schedule tasks using cron.
Configure systems to boot into a specific runlevel automatically.
Install Red Hat Enterprise Linux automatically using Kickstart.
Configure a physical machine to host virtual guests.
Install Red Hat Enterprise Linux systems as virtual guests.
Configure systems to launch virtual machines at boot.
Configure network services to start automatically at boot.
Configure a system to run a default configuration HTTP server.
Configure a system to run a default configuration FTP server.
Install and update software packages from Red Hat Network, a remote repository, or from the local file system.
Update the kernel package appropriately to ensure a bootable system.
Modify the system bootloader.

Manage users and group
s
Create, delete, and modify local user accounts.
Change passwords and adjust password aging for local user accounts.
Create, delete, and modify local groups and group memberships.
Configure a system to use an existing LDAP directory service for user and group information.

Manage securit
y
Configure firewall settings using system-config-firewall or iptables.
Set enforcing and permissive modes for SELinux.
List and identify SELinux file and process context.
Restore default file contexts.
Use boolean settings to modify system SELinux settings.
Diagnose and address routine SELinux policy violations.


1 Kickstart Install

/root/anaconda-ks.cfg

// how to add user in ks file
user --name= --password=Pass123

To-do
- http://fedoraproject.org/wiki/Anaconda/Kickstart
- https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Installation_Guide/s1-kickstart2-options.html
2. Installing RHEL with Kickstart

- boot from DVD
- esc
- boot: linux ks=nfs:192.168.75.132:/srv/nfs/ks.cfg

to-do
? - how to setup nfs filesystem

http://www.vmware.com/support/ws5/doc/ws_running_sharedfolder_adding.html
http://www.vmware.com/support/ws5/doc/ws_running_sharedfolder_viewing.html

To view windows shared files on rhel
/mnt/hgfs

3. Basic Command Line
3.1 Accessing a Terminal

Default shell for RHEL8:
BASH
- virtual terminals
ctrl + alt + F2(to F6)
. navigation in virtual term
shift + pageup(pagedown)
- back to desktop
alt+F7
3.2 n 3.3 Basic Commands pt- 1 and 2

// human readable
ls -lh

cd ~ // root usr home

mkdir -p /test/test1/test1a
rmdir /test/test1/test1a // remove only test1a dir
rmdir -p /test/test1/test1a // removes test and subdirs

// force delete
rm -f gok.txt == 'rm' gok.txt

rm -r gok/test.txt //remove folder and txt file

less
---------------------------------------------

display line numbers in less (gnu)?
-N

With n being the line number:
ng: Jump to line number n. Default is the start of the file.

p go to first line
G go to last line

:-i <enter> // ignore case in search
/ search forw
? search backw
n next search result
N previos search result

3.4 Help at the Command Line
man grep
info grep
apropos grep // print mans including grep
grep --help

3.5 CAT and NANO
// way to take notes via cat
[root@localhost ~]# cat << EOF > test.txt
> this is the way to take notes via cat
> yes
> EOF
[root@localhost ~]# cat test.txt
this is the way to take notes via cat
yes
[root@localhost ~]#

// combine files into single file
cat install.log.syslog test.txt > newfile

nano
ctrl o to save
ctrl x to exit nano
ctrl r to find and replace

3.6 vim

vi node


=======================================================================================
UNIX useful vi commands

File Operations:
Save & Quit ZZ (no colon)
:wq
:x

Quit(no save) :q!

Save only :w
Save to newfile :w filename

Insert file at cursor position :r <filename>

Inserting
a after cursor insert
A at end of line insert
o new line below and insert
O new line above and insert
r replace single char

Cursor Movement
:0 begin of file
:$ end of file
0 beginning of line
H move to top of screen
L move to bottom of screen
nG goto line n

Deleting
x delete character
dd (D) delete line

Copy
yy (Y) copy the line
2Y copy two lines
10Y copy ten lines
yG copy to the eof

Paste
p paste after cursor
P paste before cursor

Find
/ find forward (down)
/\capple #case insensitive search
:set ignorecase #case insensitive search
This command can be abbreviated :set ic
To turn off this feature, use the following:
:set noignorecase

? find backwards
n find next
N find previos

Global search and replace :1,$ s/old/new/g
^ ^ ^ ^ ^
In english, this means: | | | | |
| | | | |
From 1 to $ (end of file) | | | |
| | | |
substitute -----------------/ | | |
| | |
occurrences of "old" ----------/ | |
| |
with occurrences of "new" --------/ |
|
globally (i.e., all instances of "old")

:1,$ s/0212_patch_summary/summary/g


Miscellaneous Commands
. re-do
u un-do
U undo all commands on one line
J join current line with next line

:set number // show line number
Or :set nu
: set nonumber // hide line number

=======================================================================================

3.6.1 LESS

less
---------------------------------------------

display line numbers in less (gnu)?
-N

With n being the line number:
ng: Jump to line number n. Default is the start of the file.

p go to first line
G go to last line

:-i <enter> // ignore case in search
/ search forw
? search backw
n next search result
N previos search result

3.7 File Compression

--- Tar

tar -czvf stuff.tgz gok/ // create a compressed tarball
tar -xzvf stuff.tgz // extract a tarball


tar -tf stuff.tgz // view tgz content
gok/
gok/test1
gok/test2

// list tgz w/ sizes
tar -tvf stuff.tgz 
drwxr-xr-x root/root 0 2013-09-12 01:23 compress/
-rw-r--r-- root/root 17 2013-09-12 01:23 compress/vim-test.txt
-rw-r--r-- root/root 1973 2013-09-12 01:23 compress/lslog.txt
-rw-r--r-- root/root 106 2013-09-12 01:23 compress/test.txt
-rw-r--r-- root/root 63 2013-09-12 01:23 compress/test_nano.txt


// tarball tar file
tar -cvf stuff.tar compress/

// zip
gzip stuff.tar

/ tgz file

--- Bz2

tar -cjvf stuff.tar.bz2 gok/
tar -xjvf stuff.tar.bz2 gok/
3.8 Elevating Privileges

su
// use the following
su - 

// root user path
echo $PATH
/usr/lib/qt-3.3/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin

// giving permission of commands to specific users
visudo
vi /etc/sudoers

## Allow root to run any commands anywhere
root ALL=(ALL) ALL
lucent ALL=(ALL) ALL

sudo cat /etc/shadow


Example:
How to permit lucent root cmds access


[lucent@localhost ~]$ sudo cat /etc/shadow
lucent is not in the sudoers file. This incident will be reported.

1.
visudo
// add, under the line "root ALL=(ALL) ALL"
lucent ALL=(ALL) ALL

2.
[lucent@localhost ~]$ sudo cat /etc/shadow
4. Advanced Command Line
4.1 Input and Output Redirection

spell < spelling.txt > mispelled.txt

Error Redirection (2>)
[root@localhost ~]# ls me.txt 2> err.txt
[root@localhost ~]# cat err.txt
ls: cannot access me.txt: No such file or directory

| (pipe command)

ex: how to find hostname
[root@localhost ~]# cat /etc/sysconfig/network | grep HOST
HOSTNAME=localhost.localdomain

4.2 Regular Expressions

EX.1

// with line numbers
grep root /etc/passwd -n
1:root::0:0:root:/root:/bin/bash
11:operator:x:11:0:operator:/root:/sbin/nologin

// list lines have root only in beginning of line
[root@localhost ~]# grep '^root' /etc/passwd
root::0:0:root:/root:/bin/bash

Ex.2

[root@localhost ~]# grep -n '[Aa]pples' test.txt 
1:apples
4:Apples

[root@localhost ~]# cat test.txt 
apples
APPLES
aPPLES
Apples
AppleS

Ex.3

// contain a regexp end of line 

[root@localhost ~]# grep '/sbin/nologin$' /etc/passwd
...
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin

// NOT contain a regexp end of line
[root@localhost ~]# grep -v '/sbin/nologin$' /etc/passwd
root::0:0:root:/root:/bin/bash
sync:x:5:0:sync:/sbin:/bin/sync

EX.4 - SED
[root@localhost ~]# cat test.txt 
apples
APPLES

// replace by sed
[root@localhost ~]# sed 's/apples/oranges/' test.txt > corrected.txt

[root@localhost ~]# cat corrected.txt 
oranges
APPLES

5. User Accounts
5.1 Adding and Removing Users
// useradd
// creates /home/netas
// creates mailbox for netas user

[root@localhost ~]# ls /home/
lucent
[root@localhost ~]# useradd netas

// how to list users -1
( ?? maybe not a good way cuz it will show userdel'ed users dir)

[root@localhost ~]# ls /home/
lucent netas

// how to list users -2
cat /etc/passwd


// userdel
// DOES NOT delete /home/netas
// DOES NOT delete mailbox for netas
[root@localhost ~]# userdel netas

// userdel -r
// DOES delete /home/netas
// DOES delete mailbox for netas
[root@localhost ~]# userdel -r netas

// -c: comment option
useradd -c "alex de souza" asouza

// change default login shell for a C programmer
useradd -s /bin/tcsh aortega

useradd -c "Barney Oldman" -d /home/accounting/boldman boldman

// change user properties
usermod -c "Kralex" alex
5.2 Password Control

[root@localhost ~]# useradd -p 123456 newuser
[root@localhost ~]# passwd newuser
Changing password for user newuser.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

// lock a user account
passwd -l newuser

// unlock a user account
passwd -u newuser

// max passw change of 90 days
chage -M 90 newuser

[root@localhost ~]# chage -E 2013-6-1 newuser
[root@localhost ~]# chage -l newuser
Last password change : Apr 12, 2013
Password expires : Jul 11, 2013
Password inactive : never
Account expires : Jun 01, 2013
Minimum number of days between password change : 0
Maximum number of days between password change : 90
Number of days of warning before password expires : 7

[root@localhost ~]# chage -W 5 newuser
[root@localhost ~]# chage -l newuser
Last password change : Apr 12, 2013
Password expires : Jul 11, 2013
Password inactive : never
Account expires : Jun 01, 2013
Minimum number of days between password change : 0
Maximum number of days between password change : 90
Number of days of warning before password expires : 5
5.3 Group Administration

[root@localhost ~]# groupadd abc[root@localhost ~]# usermod -G abc newuser
[root@localhost ~]# su - newuser
[newuser@localhost ~]$ groupsnewuser abc

[root@localhost ~]# useradd -G grpabc gsimsek
[root@localhost ~]# su - gsimsek
[gsimsek@localhost ~]$ groups
gsimsek grpabc

// change group name
[root@localhost ~]# groupmod -n gabcde gabc
[root@localhost ~]# id gsimsek
uid=506(gsimsek) gid=507(gsimsek) groups=507(gsimsek),506(gabcde)

// change group id
[root@localhost ~]# groupmod -g 1000 gabcde
[root@localhost ~]# id gsimsek
uid=506(gsimsek) gid=507(gsimsek) groups=507(gsimsek),1000(gabcde)

// set gsimsek as a admin user for group abcde
[root@localhost ~]# gpasswd -A gsimsek gabcde
[root@localhost ~]# su - gsimsek
[gsimsek@localhost ~]$ id
uid=506(gsimsek) gid=507(gsimsek) groups=507(gsimsek),1000(gabcde)

// add aortega to non-admin user for group abcde
[gsimsek@localhost ~]$ gpasswd -a aortega gabcde
Adding user aortega to group abcde

// groupdel abcde
5.4 Account Configuration Files

1.
less /etc/passwd


gsimsek:x:506:507:Gman Stone:/home/gsimsek:/bin/bash
(Uname:Passwd:Uid:Gid:Comment:Defaultdir:Defaultshell)

[root@localhost ~]# id gsimsek
uid=506(gsimsek) gid=507(gsimsek) groups=507(gsimsek)v

2.
less /etc/shadow
Uname:Passwd:Xxxx:Maxdayspasswdchg:Warning:
newuser:$1$9Wc.kjBi$AnOuhPtMOqDM4thzeBwuo0:15807:0:90:5::15857:
// !! means no pw 
alex4:!!:15960:0:99999:7:::

[root@localhost ~]# chage -l newuser
Last password change : Apr 12, 2013
Password expires : Jul 11, 2013
Password inactive : never
Account expires : Jun 01, 2013
Minimum number of days between password change : 0
Maximum number of days between password change : 90
Number of days of warning before password expires : 5

3.
less /etc/group
gsimsek:x:507:aortega,newuser
Gname:Gpasswd:Gid:Gmembers

4.
less /etc/gshadow

gsimsek:!:aortega:aortega,newuser
Gname:Gpasswd:GAdmin:Gmembers

HELP
man 5 shadow
man 5 passwd
5.5 User Accounts with LDAP

5.5 User Accounts with LDAP
-----------------------------------------------------------------------

LDAP - Light Weight Directory Access protocol

- Use GUI eaier to setup LDAP
system -> administration -> authentication

dc=example,dc=com
ldaps://192.168.75.2

NOTE:
LDAP Server information above will be provided in the exam.
.
6. File and Folder Permissions
6.1 Basic Permissions pt- 1

owner grp other
rwx rwx rwx

read 4
write 2
exec 1
no perm: 0

- regular file
d dir
l symb link

owner-group-other user grp
drwxr-xr-x 3 root root 4096 Apr 13 2013 Desktop
6.2 Basic Permissions pt- 2

// add w perm to other users
chmod o+w /home/lucent/alu_files.log
u=owner
g=users in file's group
o=others


[root@localhost ~]# ll file.txt
-rwxr-xr-x 1 root root 0 Apr 13 14:58 file.txt

chmod ugo-x file.txt
[root@localhost ~]# ll file.txt
-rw-r--r-- 1 root root 0 Apr 13 14:58 file.txt

chmod ugo+xw file.txt 
[root@localhost ~]# ll file.txt
-rwxrwxrwx 1 root root 0 Apr 13 14:58 file.txt

// umask
default mask=0022
def perm for a file = 666 - 022 = 644 = rw-r--r--
def perm for a fold = 777 - 022 = 755 = rwxr-xr-x


[root@localhost ~]# touch file.txt
[root@localhost ~]# ll file.txt
-rw-r--r-- 1 root root 0 Apr 13 14:58 file.txt

[root@localhost ~]# mkdir test
[root@localhost ~]# ll -dh test/
drwxr-xr-x 2 root root 4.0K Apr 13 14:58 test/

6.3 Basic Permissions pt- 3

ls /home/lucent/notes -l
-rw-r--r-- 1 root root 0 Apr 13 15:41 fruits.txt

// chown -R usr:grp *
// ch ownership of directory as well as files

chown -R lucent:lucent /home/lucent/notes/
[root@localhost ~]# ls /home/lucent/notes -l
total 0
-rw-r--r-- 1 lucent lucent 0 Apr 13 15:41 fruits.txt

[root@localhost ~]# ls -d /home/lucent/notes -l
drwxr-xr-x 2 lucent lucent 4096 Apr 13 15:41 /home/lucent/notes

// immunable bit
lsattr file.txt 
--------------- file.txt
chattr +i file.txt 
[root@localhost ~]# lsattr file.txt
----i---------- file.txt

[root@localhost ~]# rm file.txt 
rm: remove regular empty file `file.txt'? y
rm: cannot remove `file.txt': Operation not permitted
[root@localhost ~]# rm -rf file.txt 
rm: cannot remove `file.txt': Operation not permitted

[root@localhost ~]# chattr -i file.txt 
[root@localhost ~]# rm file.txt 
rm: remove regular empty file `file.txt'? y
[root@localhost ~]#

to-do: check man 1 chattr

6.4 Group Directories
(Group collaboration direct.)

Ex: Collaborative dir for group users of grp: research
(Grp users will be able to work in 
/home/research/)
-------------------------------------------------------

[root@localhost ~]# ls -dl /home/research/
drwxr-xr-x 2 root root 4096 Apr 13 17:00 /home/research/

[root@localhost ~]# chown nobody:research /home/research/
[root@localhost ~]# ls -dl /home/research/
drwxr-xr-x 2 nobody research 4096 Apr 13 17:00 /home/research/

// SGID bit - giving permissions to group
[root@localhost ~]# chmod 2070 /home/research/
[root@localhost ~]# ls -dl /home/research/
d---rws--- 2 nobody research 4096 Apr 13 17:00 /home/research/

[root@localhost ~]# su - alex
[alex@localhost ~]$ mkdir /home/research/test1
[alex@localhost ~]$ ls -ld /home/research/test1
drwxrwsr-x 2 alex research 4096 Apr 13 17:13 /home/research/test1
[alex@localhost ~]$
[alex@localhost ~]$ vi /home/research/test1/to-lucent.txt
[alex@localhost ~]$
[alex@localhost ~]$ exit
logout
[root@localhost ~]# su - lucent
[lucent@localhost ~]$ vi /home/research/test1/to-lucent.txt
[lucent@loca lhost ~]$
[lucent@localhost ~]$
[lucent@localhost ~]$ cat /home/research/test1/to-lucent.txt
whats up lucent?
I am fine bro

[lucent@localhost ~]$ exit
logout
[root@localhost ~]# su - gsimsek
[gsimsek@localhost ~]$
[gsimsek@localhost ~]$ cat /home/research/
cat: /home/research/: Permission denied
[gsimsek@localhost ~]$ ls /home/research/
ls: cannot open directory /home/research/: Permission denied
7. Network Setup and Troubleshooting
7.1 Network Devices

ifconfig

[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:BA:39:EC
inet addr:172.16.82.132 Bcast:172.16.82.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:feba:39ec/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:41 errors:0 dropped:0 overruns:0 frame:0
TX packets:506 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:7330 (7.1 KiB) TX bytes:22312 (21.7 KiB)
Interrupt:19 Base address:0x2000

eth1 Link encap:Ethernet HWaddr 00:0C:29:BA:39:F6
inet addr:192.168.1.10 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:feba:39f6/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:490 errors:0 dropped:0 overruns:0 frame:0
TX packets:37 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:34103 (33.3 KiB) TX bytes:2586 (2.5 KiB)
Interrupt:19 Base address:0x2080


wlan0 // wireless adapt
vmnet0 // for virtual machines
ppp // point-to-point protocol


cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cat ifcfg-lo 
DEVICE=lo
IPADDR=127.0.0.1
NETMASK=255.0.0.0
NETWORK=127.0.0.0
# If you're having problems with gated making 127.0.0.0/8 a martian,
# you can change this to something else (255.255.255.255, for example)
BROADCAST=127.255.255.255
ONBOOT=yes
NAME=loopback

[root@localhost network-scripts]# cat ifcfg-eth0
DEVICE="eth0"
BOOTPROTO="static"
DNS1="172.16.82.1"
GATEWAY="172.16.82.1"
HWADDR="00:0C:29:BA:39:EC"
IPADDR="172.16.82.132"
IPV6INIT="yes"
NETMASK="255.255.255.0"
# controlled by network management
NM_CONTROLLED="yes"
ONBOOT="yes"




7.2 NetworkManager

service NetworkManager stop
7.3 system-config-network

// in order to use system-config-network
// stop NetworkManager and disable it at startup
system-config-network
service NetworkManager stop
Stopping NetworkManager daemon: [ OK ]

chkconfig NetworkManager off

[root@localhost network-scripts]# system-config-network
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
# accept all packets coming into this system
:INPUT ACCEPT [0:0]
# accept all packets forwarded tru this system
:FORWARD ACCEPT [0:0]
# accept all packets leaving this system
:OUTPUT ACCEPT [0:0]
# any packet has state:EST, REL (connections already up and running) will be accepted
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# any packets of ICMP prot. will be accepted
-A INPUT -p icmp -j ACCEPT
# any packets coming to lo device will be acceped
-A INPUT -i lo -j ACCEPT
# enable ssh connections
# any packet (has state:NEW, matches prot. tcp, destin. tcp:22) will be accepted
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
# any other packets coming will be rejected with msg "icmp-host-prohibited"
-A INPUT -j REJECT --reject-with icmp-host-prohibited
# any other packets forwarded will be rejected with msg "icmp-host-prohibited"
-A FORWARD -j REJECT --reject-with icmp-host-prohibited.


EX: accept web connections
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT



[root@localhost network-scripts]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:http
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
target prot opt source destination


* How to disable all Firewall rules for troubleshooting

// Flush all rules
iptables -F

[root@localhost network-scripts]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination

// after service restart, all rules restored
[root@localhost network-scripts]# service iptables restart
iptables: Flushing firewall rules: [ OK ]
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]
[root@localhost network-scripts]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:http
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
target prot opt source destination


** How to add ftp server firewall

[root@localhost sysconfig]# iptables -I INPUT -p tcp --dport 21 -j ACCEPT
[root@localhost sysconfig]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]

[root@localhost sysconfig]# service iptables restart
iptables: Flushing firewall rules: [ OK ]
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]

[root@localhost sysconfig]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:ftp
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:http
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
target prot opt source destination


** How to remove a iptables rule

[root@localhost sysconfig]# iptables -D INPUT -p tcp --dport 21 -j ACCEPT
[root@localhost sysconfig]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
7.4 Network Commands

// assign IP
// !! temporary change
// !! change network scripts to do permenant changes

ifconfig eth1 172.29.4.160 netmask 255.255.252.0

ifdown eth1
ifup eth1


route add default gw 172.29.4.1 eth1

ip addr shpw
[root@localhost ~]# ip route
192.168.1.0/24 dev eth1 proto kernel scope link src 192.168.1.10
192.168.136.0/24 dev eth0 proto kernel scope link src 192.168.136.3 metric 1
172.29.4.0/22 dev eth1 proto kernel scope link src 172.29.4.165
169.254.0.0/16 dev eth1 scope link metric 1003
default via 172.29.4.1 dev eth1 
default via 192.168.1.1 dev eth1

// check drop packets and networking errors
[root@localhost ~]# ip -s link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
RX: bytes packets errors dropped overrun mcast
7500 108 0 0 0 0
TX: bytes packets errors dropped carrier collsns
7500 108 0 0 0 0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:ba:39:ec brd ff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped overrun mcast
275251 1847 0 0 0 0
TX: bytes packets errors dropped carrier collsns
264864 3754 0 0 0 0 


















7.5 Network Scripts


[root@localhost ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=localhost.localdomain
GATEWAY=172.16.82.1


// IPTABLES - Default config
vim /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

// DNS server config - original location
[root@localhost ~]# cat /etc/resolv.conf
# Generated by NetworkManager
domain localdomain
search localdomain
nameserver 192.168.0.1

// Host file
[root@localhost ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6











7.6 system-config-firewall


7.6 system-config-firewall
------------------------------------------------------------------


How to enable VNC server
------------------------------------
1. Administration --> Firewall
2. Other ports --> Add: tcp: 5951


// 
Command line tool for firewall[root@RHSCA-2 ~]# system-config-firewall-tui 
7.7 iptables pt. 1


7.7 iptables pt-1
---------------------------------

[root@localhost network-scripts]# less /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
# accept all packets coming into this system
:INPUT ACCEPT [0:0]
# accept all packets forwarded tru this system
:FORWARD ACCEPT [0:0]
# accept all packets leaving this system
:OUTPUT ACCEPT [0:0]
# any packet has state:EST, REL (connections already up and running) will be accepted
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# any packets of ICMP prot. will be accepted
-A INPUT -p icmp -j ACCEPT
# any packets coming to lo device will be acceped
-A INPUT -i lo -j ACCEPT
# enable ssh connections
# any packet (has state:NEW, matches prot. tcp, destin. tcp:22) will be accepted

-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
# any other packets coming will be rejected with msg "icmp-host-prohibited"
-A INPUT -j REJECT --reject-with icmp-host-prohibited
# any other packets forwarded will be rejected with msg "icmp-host-prohibited"
-A FORWARD -j REJECT --reject-with icmp-host-prohibited.


NOTE-1- IPtables rules processed From TOP to Buttom

NOTE-2
- If system-config-firewall is opened, any change in iptables file will be lost 

How to Add a rule
---------------------------------------


1. EX: accept web connections
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

2. Restart Firewall
service iptables restart

3. Verify Rules
[root@localhost network-scripts]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:http 
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
target prot opt source destination 
7.8 iptables pt. 2

7.8 iptables pt. 2
----------------------------------------------------------------

* How to disable all Firewall rules for troubleshooting
------------------------------------------------

1. // Flush all rules - disable firewall for testing
iptables -F

[root@localhost network-scripts]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination

2. TO re-enable iptables, restart service 
[root@RHSCA-2 ~]# service iptables restart
iptables: Flushing firewall rules: [ OK ]
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]
iptables: Loading additional modules: nf_conntrack_ftp [ OK ]

// after service restart, all rules restored
[root@localhost network-scripts]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:http
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
target prot opt source destination


** How to add ftp server firewall
----------------------------------------


// -I: insert (not append)
[root@localhost sysconfig]# iptables -I INPUT -p tcp --dport 21 -j ACCEPT 

// To make the change permanent
[root@localhost sysconfig]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]

[root@localhost sysconfig]# service iptables restart
iptables: Flushing firewall rules: [ OK ]
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]

[root@localhost sysconfig]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:ftp 
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:http
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
target prot opt source destination


** How to remove a iptables rule
-----------------------------------------------


[root@localhost sysconfig]# iptables -D INPUT -p tcp --dport 21 -j ACCEPT
[root@localhost sysconfig]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
[root@localhost sysconfig]# service iptables restart







8. Software Management
12. Software Management
8.1 RPM Files

RPM - redhat package manager
rpm - compliled code
srpm - source code

name-version-release.architecture.rpm
yum-5.3p1-53.el6_1.2.x86_64.rpm


i386 : 32 bit
x86_64: 64 bit
noarch: platform independent - can be installed on 32 and 64 bit systems
8.2 Yum Command

[root@localhost ~]# yum search system-config-lvm
Loaded plugins: product-id, refresh-packagekit, subscription-manager
Updating certificate-based repositories.
Unable to read consumer identity

This machine has not been registered and therefore has
no access to security and other critical updates. Please
register using subscription-manager.

================================ N/S Matched: system-config-lvm =================================
system-config-lvm.noarch : A utility for graphically configuring Logical Volumes

Name and summary matches only, use "search all" for everything.


[root@localhost ~]# yum info system-config-lvm
Loaded plugins: product-id, refresh-packagekit, subscription-manager
Updating certificate-based repositories.
Unable to read consumer identity

This machine has not been registered and therefore has
no access to security and other critical updates. Please
register using subscription-manager.

Installed Packages
Name : system-config-lvm
Arch : noarch
Version : 1.1.12
Release : 12.el6
Size : 3.1 M
Repo : installed
From repo : anaconda-RedHatEnterpriseLinux-201105101829.i386
Summary : A utility for graphically configuring Logical Volumes
URL : http://git.fedorahosted.org/git/?p=system-config-lvm.git
License : GPLv2
Description : system-config-lvm is a utility for graphically configuring Logical Volumes


yum remove system-config-lvm

** How to add CD/DVD as a base repository in RHEL 6

vi /etc/yum.repos.d/iso.repo

[root@localhost yum.repos.d]# cat iso.repo
[base]
name=CDROM
baseurl=file:///tmp/cdrom
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

mkdir /tmp/cdrom
mount /dev/cdrom /tmp/cdrom


** how to yum groupinstall and yum groupremove
yum groupinstall "Web Server"
yum groupremove "Web Server"



8.3 Yum Repository

cd /etc/yum.repos.d/
ls

iso.repo
localnet.repo.orig
packagekit-media.repo
rhel-source.repo

Note: All repository file names have to end w/ *.repo

[root@localhost yum.repos.d]# cat localnet.repo 
# repo id, it is unique
[localnet]
# repo name
name=Local Network Yum Repo
baseurl=ftp://192.168.75.132/pub
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release


man yum.conf
/\[repositoryid]

******************************
yum repolist all
yum grouplist

yum groupinfo base
yum groupinfo "Backup Server"

yum clean all
8.4 RPM Command

// rpm install
rpm -i lftp-4.0.9-1.el6.i686.rpm

// query all
rpm -qa | grep lftp

// rpm remove
rpm -e lftp

// rpm Upgrade , verbose, hash
rpm -Uvh lftp-4.0.9-1.el6.i686.rpm
warning: /root/Desktop/wmtools/lftp-4.0.9-1.el6.i686.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing... ########################################### [100%]
1:lftp ########################################### [100%]



** rpm documentation
[root@localhost yum.repos.d]# rpm -qd lftp
/usr/share/doc/lftp-4.0.9/BUGS
/usr/share/doc/lftp-4.0.9/COPYING
/usr/share/doc/lftp-4.0.9/ChangeLog
/usr/share/doc/lftp-4.0.9/FAQ
/usr/share/doc/lftp-4.0.9/FEATURES
/usr/share/doc/lftp-4.0.9/NEWS
/usr/share/doc/lftp-4.0.9/README
/usr/share/doc/lftp-4.0.9/README.debug-levels
/usr/share/doc/lftp-4.0.9/README.dnssec
/usr/share/doc/lftp-4.0.9/README.modules
/usr/share/doc/lftp-4.0.9/THANKS
/usr/share/doc/lftp-4.0.9/TODO
/usr/share/man/man1/lftp.1.gz
/usr/share/man/man1/lftpget.1.gz
/usr/share/man/man5/lftp.conf.5.gz

** to locate rpm config file
[root@localhost yum.repos.d]# rpm -qc lftp
/etc/lftp.conf

** rpm info (same with yum info)
[root@localhost yum.repos.d]# rpm -qi lftp
Name : lftp Relocations: (not relocatable)
Version : 4.0.9 Vendor: Red Hat, Inc.
Release : 1.el6 Build Date: Tue 15 Jun 2010 09:13:20 AM BST
Install Date: Sun 14 Apr 2013 06:54:52 PM BST Build Host: x86-004.build.bos.redhat.com
Group : Applications/Internet Source RPM: lftp-4.0.9-1.el6.src.rpm
Size : 2410348 License: GPLv3+
Signature : RSA/8, Mon 16 Aug 2010 06:40:53 PM BST, Key ID 199e2f91fd431d51
Packager : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
URL : http://lftp.yar.ru/
Summary : A sophisticated file transfer program
Description :
LFTP is a sophisticated ftp/http file transfer program. Like bash, it has job
control and uses the readline library for input. It has bookmarks, built-in
mirroring, and can transfer several files in parallel. It is designed with
reliability in mind.
8.5 PackageKit
8.6 Updating the Kernel


[root@localhost yum.repos.d]# uname -r
2.6.32-279.19.1.el6.i686

// update kernelyum install kernel
9. Basic Filesystems
9.1 Creating Partitions


// list all system devices

ls /dev

sda // 1st hard disk (physical disk)
sda1 // 1st hd - 1st partition
sda2 // 1st hd - 2nd partition

sdb // 2nd hard disk

Other disks:
hd : h disks - regular ide drive
vd : virtual disks

** How to use fdisk to add a partition
Note: !! reboot the system after creation of partition

[root@localhost ~]# fdisk /dev/sdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').

Command (m for help): p

Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x8dcd5ddf

Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ 83 Linux

Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Partition number (1-4): 2
First cylinder (133-261, default 133):
Using default value 133
Last cylinder, +cylinders or +size{K,M,G} (133-261, default 261): +1G
Value out of range.
Last cylinder, +cylinders or +size{K,M,G} (133-261, default 261):
Using default value 261

Command (m for help): p

Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x8dcd5ddf

Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ 83 Linux
/dev/sdb2 133 261 1036192+ 5 Extended

Command (m for help): l

0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx
5 Extended 42 SFS 86 NTFS volume set da Non-FS data
6 FAT16 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility
8 AIX 4f QNX4.x 3rd part 8e Linux LVM df BootIt
9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOS access
a OS/2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 52 CP/M 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 61 SpeedStor a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary
16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT
1e Hidden W95 FAT1

Command (m for help): p

Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x8dcd5ddf

Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ 83 Linux
/dev/sdb2 133 261 1036192+ 5 Extended

// to write the changes
Command (m for help): w

**
83 Linux // generally linux et4

** How to make kernel to scan harddrives

echo "- - -" > /sys/class/scsi_host/host0/scan
fdisk -l

partprobe




9.2 Creating Filesystems


partition --> container which holds data
filesystem --> method OS use to read data

// !! reboot the system after creation of partition

** mkfs - make filesystem
mkfs -t ext4 //ext4 is default fs for RHEL6
mkfs.ext4

mkfs.ext4 /dev/sdc1


[root@localhost ~]# tune2fs -l /dev/sdb1
tune2fs 1.41.12 (17-May-2010)
Filesystem volume name: <none>
Last mounted on: <not available>
Filesystem UUID: 1eb2450a-d139-4132-b066-ce2c4c94d7e1 //Universal Unique ID
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Filesystem flags: signed_directory_hash
Default mount options: (none)
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 66384
Block count: 265064
Reserved block count: 13253
Free blocks: 252369
Free inodes: 66373
First block: 0
Block size: 4096
Fragment size: 4096
Reserved GDT blocks: 64
Blocks per group: 32768
Fragments per group: 32768
Inodes per group: 7376
Inode blocks per group: 461
Flex block group size: 16
Filesystem created: Mon Apr 15 09:34:00 2013
Last mount time: n/a
Last write time: Mon Apr 15 09:34:01 2013
Mount count: 0
Maximum mount count: 20
Last checked: Mon Apr 15 09:34:00 2013
Check interval: 15552000 (6 months)
Next check after: Sat Oct 12 09:34:00 2013
Lifetime writes: 49 MB
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 256
Required extra isize: 28
Desired extra isize: 28
Journal inode: 8
Default directory hash: half_md4
Directory Hash Seed: 880cca4d-1af5-49ca-b685-cd8f845cdb2c
Journal backup: inode blocks


** Filesystem check (!!! never to be run on Mounted FS)
[root@localhost ~]# fsck /dev/sdb1 
fsck from util-linux-ng 2.17.2
e2fsck 1.41.12 (17-May-2010)
/dev/sdb1: clean, 11/66384 files, 12695/265064 blocks


9.3 Mounting Filesystems

mount -t ext4 /dev/sdb1 /test
umount /test


vi /etc/fstab
...
...
/dev/sdb1 /test ext4 defaults 1 2
# filesytem kdump fs.check
9.4 Swap Partition

Ex: SWAP Size4GB of RAM
1.5 or 2 times of installed RAM
so swap partion: 6GB < x < 8GB


# to see RAM and SWAP used or free
free -m


# How to create swap

[root@localhost ~]# fdisk /dev/sdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (66-130, default 66):
Using default value 66
Last cylinder, +cylinders or +size{K,M,G} (66-130, default 130):
Using default value 130

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb2e66c5a

Device Boot Start End Blocks Id System
/dev/sdb1 1 65 522081 83 Linux
/dev/sdb2 66 130 522112+ 83 Linux

Command (m for help): l

0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-

1e Hidden W95 FAT1

Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 82 

Changed system type of partition 2 to 82 (Linux swap / Solaris)

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb2e66c5a

Device Boot Start End Blocks Id System
/dev/sdb1 1 65 522081 83 Linux
/dev/sdb2 66 130 522112+ 82 Linux swap / Solaris

Command (m for help): w
The partition table has been altered!


Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)

**************************************************

mkswap -L NEWSWAP /dev/sdb2

swapon -L NEWSWAP

vi /etc/fstab
...
...
LABEL=NEWSWAP swap swap defaults 0 0







9.5 Quota Management pt. 1

/home dir on a separate disk/partition

30,000 blocks = 30 MB

dd if=/dev/zero of=testfile bs=1024 count=25000

inode: entries in a directory


vim /etc/fstab/dev/mapper/VolGroup00-LogVol00 / ext3 defaults,usrquota 1 1

[root@localhost home]# mount -o remount /
[root@localhost home]# mount
/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw,usrquota)

root@localhost home]# edquota -u alex
[root@localhost home]# setquota -u alex 30000 35000 0 0 /

[root@localhost home]# quotaon /
[root@localhost home]# su - alex
[alex@localhost ~]$ dd if=/dev/zero of=testfile bs=1024 count=25000 
25000+0 records in
25000+0 records out
25600000 bytes (26 MB) copied, 0.275913 s, 92.8 MB/s
[alex@localhost ~]$ pwd
/home/alex

[alex@localhost ~]$ ll -h
total 25M
-rw-rw-r--. 1 alex alex 25M Sep 15 05:01 testfile

[alex@localhost ~]$ edquota -u alex
Disk quotas for user alex (uid 501):
Filesystem blocks soft hard inodes soft hard
/dev/mapper/VolGroup00-LogVol00 0 30000 35000 16 0 0

[alex@localhost ~]$ dd if=/dev/zero of=testfile2 bs=1024 count=10000 
dm-1: warning, user block quota exceeded.
dm-1: write failed, user block limit reached.
dd: writing `testfile2': Disk quota exceeded
9909+0 records in
9908+0 records out
10145792 bytes (10 MB) copied, 0.193571 s, 52.4 MB/s

[alex@localhost ~]$ edquota -u alex
Disk quotas for user alex (uid 501):
Filesystem blocks soft hard inodes soft hard
/dev/mapper/VolGroup00-LogVol00 35000 30000 35000 16 0 0

[alex@localhost ~]$ ll -h
total 35M
-rw-rw-r--. 1 alex alex 25M Sep 15 05:03 testfile
-rw-rw-r--. 1 alex alex 9.7M Sep 15 05:03 testfile2

[alex@localhost ~]$ dd if=/dev/zero of=testfile3 bs=1024 count=10000 
dd: writing `testfile3': Disk quota exceeded
1+0 records in
0+0 records out
0 bytes (0 B) copied, 0.000621584 s, 0.0 kB/s

[alex@localhost ~]$ ll -h
total 35M
-rw-rw-r--. 1 alex alex 25M Sep 15 05:03 testfile
-rw-rw-r--. 1 alex alex 9.7M Sep 15 05:03 testfile2
-rw-rw-r--. 1 alex alex 0 Sep 15 05:03 testfile3


*** How to copy quota settings

[alex@localhost ~]$ edquota -u alex
Disk quotas for user alex (uid 501):
Filesystem blocks soft hard inodes soft hard
/dev/mapper/VolGroup00-LogVol00 35000 30000 35000 16 0 0

[alex@localhost ~]$ edquota -u gsimsek
Disk quotas for user gsimsek (uid 503):
Filesystem blocks soft hard inodes soft hard
/dev/mapper/VolGroup00-LogVol00 40 0 0 11 0 0

// use as prototype
edquota -up alex gsimsek

[alex@localhost ~]$ edquota -u gsimsek
Disk quotas for user gsimsek (uid 503):
Filesystem blocks soft hard inodes soft hard
/dev/mapper/VolGroup00-LogVol00 40 30000 35000 11 0 0





9.6 Quota Management pt. 2
grpqouta

How to set group qouta
------------------------------------------------------


[root@localhost ~]# vim /etc/fstab
......
/dev/sdb2 /sales ext4 defaults,grpquota 0 0

[root@localhost ~]# mount -o remount /sales

[root@localhost ~]# mount
/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw)
.....
/dev/sdb2 on /sales type ext4 (rw,grpquota)
# create quota, group, non-remountable
quotacheck -cgm /sales

setquota -g sales 30000 35000 0 0 /sales
edquota -g sales
Disk quotas for group sales (gid 508):
Filesystem blocks soft hard inodes soft hard
/dev/sdb2 4 30000 35000 1 0 0

quotaon /sales

dd if=/dev/zero of=bigfile2 bs=1024 count=36000

# Group Quota
[root@localhost ~]# repquota -ga
*** Report for group quotas on device /dev/sdb2
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
Group used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 16 0 0 1 0 0
sales -- 4 30000 35000 1 0 0
salesman1 -- 72000 0 0 2 0 0

# User Quota
[root@localhost ~]# repquota -a
9.7 Hard and Soft Links

inode = 
index node reference of a file or a directory

# How to list inode
[root@localhost ~]# ls -il test.txt
985912 -rw-r--r-- 1 root root 54 Apr 12 07:38 test.txt

Hard Link : a ponter to a file's inode

[root@localhost ~]# ln test.txt Desktop/test.txt.link

[root@localhost ~]# ls -il Desktop/test.txt.link 
985912 -rw-r--r-- 2 root root 54 Apr 12 07:38 Desktop/test.txt.link


Soft (Symbolic) Link: a file that points to another file DIRECTORY

[root@localhost ~]# ln -s /root/test.txt /root/Desktop/test.txt.slink
// !!! NOTE: be sure to use absolute path while creating sym link.

[root@localhost ~]# ls -il Desktop/test.txt.slink
983277 lrwxrwxrwx 1 root root 14 Apr 29 09:30 Desktop/test.txt.slink -> /root/test.txt

# Move test file
[root@localhost ~]# cat test.txt
applesapples
AppleS

[root@localhost ~]# cat Desktop/test.txt.link
applesapples
AppleS

[root@localhost ~]# cat Desktop/test.txt.slink
applesapples
AppleS

[root@localhost ~]# mv test.txt Desktop/

[root@localhost ~]# cat Desktop/test.txt.slink
cat: Desktop/test.txt.slink: No such file or directory

[root@localhost ~]# cat Desktop/test.txt.link
applesapples
AppleS

Difference
Hard link Symbolic Link

cannot be accessed can be accessed
from different FS from diff FS

when original file moved, when original file moved,
link still works link does not work anymore

// Hard link CANNOT be accessed from different FS
[root@localhost ~]# ln /root/test.txt /sales/test.txt.link
ln: creating hard link `/sales/test.txt.link' => `/root/test.txt': Invalid cross-device link

// Symbolic link CAN be accessed from different FS
[root@localhost ~]# ln -s /root/test.txt /sales/test.txt.slink
[root@localhost ~]#
[root@localhost ~]# cat /sales/test.txt.slink
applesapples
AppleS

info ln
[root@localhost ~]# info coreutils 'ln invocation'





9.8 File and Folder ACL Management


9.8 File and Folder ACL Management
----------------------------------------------------

How to set and remove ACL permission to read and write
to other user's home dir
-----------------------------------------

ACL - Access Control List


1. Append
vim /etc/fstab
/dev/VolGroup00/LogVol03 /gman ext3 defaults,acl 1 2

2. Remount
[root@RHSCA-2 ~]# mount -o remount /gman

3. Verify
[root@RHSCA-2 ~]# mount | grep acl

/dev/mapper/VolGroup00-LogVol03 on /gman type ext3 (rw,acl)


[root@RHSCA-2 ~]# su alex
[alex@RHSCA-2 root]$ mkdir /home/alex/dummy
[alex@RHSCA-2 root]$ vim /home/alex/dummy/to-lucent.txt

[alex@RHSCA-2 root]$ ll /home/alex/to-lucent.txt
-rw-rw-r--. 1 alex alex 20 Oct 8 06:07 /home/alex/to-lucent.txt

[root@RHSCA-2 ~]# su lucent
[lucent@RHSCA-2 root]$ cat /home/alex/dummy/to-lucent.txt
cat: /home/alex/to-lucent.txt: Permission denied

[root@RHSCA-2 ~]# getfacl /home/alex/
getfacl: Removing leading '/' from absolute path names
# file: home/alex/
# owner: alex
# group: alex
user::rwx
group::---
other::---

[root@RHSCA-2 ~]# getfacl /home/alex/dummy/
getfacl: Removing leading '/' from absolute path names
# file: home/alex/dummy/
# owner: alex
# group: alex
user::rwx
group::rwx
other::r-x


4. Modify ACL

[root@RHSCA-2 ~]# setfacl -m u:lucent:x /home/alex/
[root@RHSCA-2 ~]# getfacl /home/alex/
getfacl: Removing leading '/' from absolute path names
# file: home/alex/
# owner: alex
# group: alex
user::rwx
user:lucent:--x
group::---
mask::--x
other::---


5. Success to READ !!
[root@RHSCA-2 ~]# su lucent
[lucent@RHSCA-2 root]$ cat /home/alex/dummy/to-lucent.txt 
Hi Lucent !!


6. Set write Access
[root@RHSCA-2 ~]# setfacl -m u:lucent:xwr /home/alex/dummy/to-lucent.txt 

7. Success to WRITE !!
[root@RHSCA-2 ~]# getfacl /home/alex/dummy/to-lucent.txt 
getfacl: Removing leading '/' from absolute path names
# file: home/alex/dummy/to-lucent.txt
# owner: alex
# group: alex
user::rw-
user:lucent:rwx
group::rw-
mask::rwx
other::r--

[root@RHSCA-2 ~]# su lucent
[lucent@RHSCA-2 root]$ vim /home/alex/dummy/to-lucent.txt 
Alex - Hi Lucent !!
Lucent - I can write Now


8. How to remove ACL Access
[root@RHSCA-2 ~]# setfacl -x u:lucent: /home/alex/dummy/to-lucent.txt
[root@RHSCA-2 ~]# setfacl -x u:lucent: /home/alex/dummy
[root@RHSCA-2 ~]# setfacl -x u:lucent: /home/alex










10. LVM

Example
-------------------------------------------------------------------------------------------------------

Hard disks & Partitions
Disk /dev/sda: 21.5 GB

100MB - /dev/sda1 * 1 13 102400 83 Linux
20GB - /dev/sda2 13 2611 20868096 8e Linux LVM

PV
[root@RHSCA-2 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 VolGroup00 lvm2 a-- 19.88g 1.00g


VG
VG #PV #LV #SN Attr VSize VFree
VolGroup00 1 2 0 wz--n- 19.88g 0

LVM
LogVol00 VolGroup00 -wi-ao-- 15.88g
LogVol01 VolGroup00 -wi-ao-- 4.00g

FSTAB
/dev/mapper/VolGroup00-LogVol00 / ext3 defaults 1 1
UUID=877ecf22-5362-4101-ae26-b84155d3fdc1 /boot ext3 defaults 1 2
/dev/mapper/VolGroup00-LogVol01 swap swap defaults 0 0
10.1 LVM Overview


10.2 Creating a Logical Volume pt- 1

10.2 Creating a Logical Volume pt- 1
-----------------------------------------------

[root@localhost ~]# fdisk /dev/sdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb2e66c5a

Device Boot Start End Blocks Id System
/dev/sdb1 1 65 522081 83 Linux
/dev/sdb2 66 130 522112+ 82 Linux swap / Solaris

Command (m for help):
Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): L

8e Linux LVM 

Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb2e66c5a

Device Boot Start End Blocks Id System
/dev/sdb1 1 65 522081 8e Linux LVM
/dev/sdb2 66 130 522112+ 82 Linux swap / Solaris

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

[root@localhost ~]# pvcreate /dev/sdb1
Writing physical volume data to disk "/dev/sdb1"
Physical volume "/dev/sdb1" successfully created

[root@localhost ~]# pvcreate /dev/sdc
Writing physical volume data to disk "/dev/sdc"
Physical volume "/dev/sdc" successfully created

[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 VolGroup00 lvm2 a-- 19.88g 0
/dev/sdb1 lvm2 a-- 509.84m 509.84m
/dev/sdc lvm2 a-- 2.00g 2.00g

[root@localhost ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name VolGroup00
PV Size 19.90 GiB / not usable 27.00 MiB
Allocatable yes (but full)
PE Size 32.00 MiB
Total PE 636
Free PE 0
Allocated PE 636
PV UUID IlVbCk-yvQY-NFt8-7PmR-9Ep1-gVGE-H6z1QI

"/dev/sdb1" is a new physical volume of "509.84 MiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 509.84 MiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID wchZ3g-Fb7G-ou2X-CWCz-SCXj-DTFB-v4NvUM

"/dev/sdc" is a new physical volume of "2.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdc
VG Name
PV Size 2.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID dLRclz-C5VB-LggL-D2u5-M3cp-gtDG-Yw46mJ

[root@localhost ~]# vgcreate vg_new /dev/sdb1 /dev/sdc
Volume group "vg_new" successfully created

[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
VolGroup00 1 2 0 wz--n- 19.88g 0
vg_new 2 0 0 wz--n- 2.49g 2.49g

[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 VolGroup00 lvm2 a-- 19.88g 0
/dev/sdb1 vg_new lvm2 a-- 508.00m 508.00m
/dev/sdc vg_new lvm2 a-- 2.00g 2.00g

[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name vg_new
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 2.49 GiB
PE Size 4.00 MiB
Total PE 638
Alloc PE / Size 0 / 0
Free PE / Size 638 / 2.49 GiB
VG UUID ty3XHn-Jk7v-qO6i-7WXA-Cseb-AEDe-L1qdFZ

--- Volume group ---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 19.88 GiB
PE Size 32.00 MiB
Total PE 636
Alloc PE / Size 636 / 19.88 GiB
Free PE / Size 0 / 0
VG UUID iAR1uc-rIs7-qJRu-fGW2-eEA0-Fyri-KV30Cj
10.3 Creating a Logical Volume pt- 2

10.3 Creating a Logical Volume pt- 2
----------------------------------------------


[root@localhost ~]# lvcreate -L 800M -n lv_new vg_new
Logical volume "lv_new" created

[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
LogVol00 VolGroup00 -wi-ao-- 15.88g
LogVol01 VolGroup00 -wi-ao-- 4.00g
lv_new vg_new -wi-a--- 800.00m

[root@localhost ~]# mkfs.ext4 /dev/vg_new/lv_new 
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
51296 inodes, 204800 blocks
10240 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=209715200
7 block groups
32768 blocks per group, 32768 fragments per group
7328 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840

Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

[root@localhost ~]# mkdir /extra

[root@localhost ~]# vim /etc/fstab 
/dev/vg_new/lv_new /extra ext4 defaults 0 0

[root@localhost ~]# mount -t ext4 /dev/vg_new/lv_new /extra/

[root@localhost ~]# mount
/dev/mapper/vg_new-lv_new on /extra type ext4 (rw)

[root@localhost ~]# touch /extra/testing

#### How to extend the lvm

// *** resize of the container
[root@localhost ~]# lvresize -L 900M /dev/vg_new/lv_new 
Extending logical volume lv_new to 900.00 MiB
Logical volume lv_new successfully resized

// *** resize of the FS
[root@localhost ~]# resize2fs /dev/vg_new/lv_new 
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_new/lv_new is mounted on /extra; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/vg_new/lv_new to 230400 (4k) blocks.
The filesystem on /dev/vg_new/lv_new is now 230400 blocks long.

[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
LogVol00 VolGroup00 -wi-ao-- 15.88g
LogVol01 VolGroup00 -wi-ao-- 4.00g
lv_new vg_new -wi-ao-- 900.00m


# How to shrink the lv
[root@localhost ~]# umount /extra/
[root@localhost ~]# fsck -f /dev/vg_new/lv_new 
fsck from util-linux-ng 2.17.2
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/vg_new-lv_new: 12/58624 files (0.0% non-contiguous), 8037/230400 blocks

[root@localhost ~]# resize2fs /dev/vg_new/lv_new 800M
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/vg_new/lv_new to 204800 (4k) blocks.
The filesystem on /dev/vg_new/lv_new is now 204800 blocks long.

[root@localhost ~]# lvresize -L 800M /dev/vg_new/lv_new 

WARNING: Reducing active logical volume to 800.00 MiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_new? [y/n]: y
Reducing logical volume lv_new to 800.00 MiB
Logical volume lv_new successfully resized

[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
LogVol00 VolGroup00 -wi-ao-- 15.88g
LogVol01 VolGroup00 -wi-ao-- 4.00g
lv_new vg_new -wi-a--- 800.00m

[root@localhost ~]# mount -t ext4 /dev/vg_new/lv_new /extra/

[root@localhost ~]# df -h /extra/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_new-lv_new
788M 17M 735M 3% /extra



[root@localhost ~]# rm fruits.txt
rm: remove regular empty file `fruits.txt'? y
[root@localhost ~]# rm /extra/fruits.txt
rm: remove regular empty file `/extra/fruits.txt'? y
[root@localhost ~]#
[root@localhost ~]# mount /dev/sd
sda sda1 sda2 sdb sdb1 sdb2 sdc
[root@localhost ~]# mount /dev/vg_new/lvmsnapshot /mnt/snapshot/
[root@localhost ~]# mount | grep snap
/dev/mapper/vg_new-lvmsnapshot on /mnt/snapshot type ext4 (rw)
[root@localhost ~]# ls /mnt/snapshot/
fruits.txt hosts lost+found services testing
[root@localhost ~]#
[root@localhost ~]# cp /mnt/snapshot/fruits.txt /extra/
[root@localhost ~]# ls /extra/
fruits.txt hosts lost+found services testing

10.4 LVM Snapshots

LVM Snapshots
---------------------------------


# How take a lv snapshot

[root@localhost ~]# mkdir /mnt/snapshot

[root@localhost ~]# mount | grep mnt

// snapshot size suggested to be %15-20 of original lvm size
[root@localhost ~]# lvcreate -L 100M -s -n lvmsnapshot /dev/vg_new/lv_new 
Logical volume "lvmsnapshot" created

[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
LogVol00 VolGroup00 -wi-ao-- 15.88g
LogVol01 VolGroup00 -wi-ao-- 4.00g
lv_new vg_new owi-aos- 800.00m
lvmsnapshot vg_new swi-a-s- 100.00m lv_new 0.01

# How to delete a lv
[root@localhost ~]# umount /mnt/snapshot/


[root@localhost ~]# lvremove /dev/vg_new/lvmsnapshot 
Do you really want to remove active logical volume lvmsnapshot? [y/n]: y
Logical volume "lvmsnapshot" successfully removed

[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
LogVol00 VolGroup00 -wi-ao-- 15.88g
LogVol01 VolGroup00 -wi-ao-- 4.00g
lv_new vg_new -wi-ao-- 800.00m
10.5 GUI LVM Management

GUI LVM Management
---------------------------------
IMPORTANT: LVM GUI will Save time in the exam
How to add fresh physical disk to a VG and a LV using LVM GUI.
11. Service Management
11.1 Service Commands


11.1 Service Commands
---------------------------------


!! Possible Exam Q: enable a service on boot.

** to see all services in system

cd /etc/init.d

less atd
exec=/usr/sbin/atd
prog="atd"
config=/etc/sysconfig/atd


[root@localhost init.d]# /etc/init.d/atd status
atd (pid 1921) is running...

[root@localhost init.d]# service atd status
atd (pid 1921) is running...

for Red Hat:
service = /etc/init.d/


service atd stop
service atd start
service atd restart

After changing atd config file, if we dont want to restart the atd we can reload it.
service atd reload

Note: chckconfig on/off by default enables runlevels 3,4,5

[root@localhost init.d]# chkconfig atd off

[root@localhost init.d]# chkconfig atd on

[root@localhost init.d]# chkconfig --list
8950AAA 0:off 1:off 2:off 3:on 4:on 5:on 6:off
NetworkManager 0:off 1:off 2:on 3:on 4:on 5:on 6:off
abrt-ccpp 0:off 1:off 2:off 3:on 4:off 5:on 6:off

[root@localhost init.d]# chkconfig --level 35 atd on
[root@localhost init.d]# chkconfig --list atd
atd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

[root@localhost init.d]# chkconfig --level 24 atd off
[root@localhost init.d]# chkconfig --list atd
atd 0:off 1:off 2:off 3:on 4:off 5:on 6:off

11.2 Using system-config-services



11.2 Using system-config-services GUI
-----------------------------------------------

system-config-services

system > adminis > services

Green circles:
enable at levels 2-3-4-5



** another way is:
ntsysv

Disadv: Only enable/disable service in the run level currently worked on.

Note: GUI Desktop is running on runlevel 5 
12. SELinux
12.1 SELinux Overview

12.1 SELinux Overview
-----------------------------------------------

!!! Selinux responsibilities on RHCSA exam:
1. having enabled
2. properly configured

SELinux: Security Enhanced Linux
MAC: Mandatory Access Control

3 Modes of SELinux
Enforcing - default, all policies enabled (system default)
Permissive - for troubleshooting, policies not enforced but checked.
Disabled - policies disabled (Do not use in RHCSA exam)
- no policies are checked
- requires FS relabel which can take a long time


> SELinux messages (deny and allow access msgs) are cached
> SELinux msgs aka AVC (Access Vector Cache)

> AVC located in
/var/log/messages
/var/log/audit/audit.log
12.2 SELinux Tools

SELinux Tools
---------------------------------------

policycoreutils-gui.i686
setroubleshoot.i686

IMPORTANT: RHCSA responsibilities:
@SELinux GUI RHCSA scope, only three following:
Status
Boolean
File Labeling

SELinux Status on CLI:
[root@localhost init.d]# getenforce
Disabled

[root@localhost init.d]# setenforce Permissive
# 0 same as Permissive
[root@localhost init.d]# setenforce 0


[root@localhost init.d]# setenforce Enforcing
# 1 same as Enforcing
[root@localhost init.d]# setenforce 1

// Selinux config file
less /etc/selinux/config 

// man page selinux
apropos selinux



12.3 Setting SELinux Contexts pt- 1

12.3 Setting SELinux Contexts pt- 1
-------------------------------------------------------------------------


*** security context for /etc directory
[root@localhost init.d]# ls -Zd /etc/
drwxr-xr-x. root root system_u:object_r:etc_t:s0 /etc/

* sec. context has 3 components

1. <user-component, type of user logged in>
system_u: 

2. 
<role component, purpose of file,user, process etc..>
object_r:

3. 
<type component, most important comp.>
etc_t


[root@localhost init.d]# ls -Z /etc/services
-rw-r--r--. root root system_u:object_r:etc_t:s0 /etc/services

[root@localhost init.d]# ls -Z /etc/shadow
----------. root root system_u:object_r:shadow_t:s0 /etc/shadow


// sec. context for a running process

[root@localhost init.d]# ps auZ 
LABEL USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
system_u:system_r:getty_t:s0 root 2235 0.0 0.0 2004 480 tty2 Ss+ 03:48 0:00 /sbin/mingetty /dev/tty2
system_u:system_r:getty_t:s0 root 2237 0.0 0.0 2004 512 tty3 Ss+ 03:48 0:00 /sbin/mingetty /dev/tty3
system_u:system_r:getty_t:s0 root 2238 0.0 0.0 2016 512 ttyS0 Ss+ 03:48 0:00 /sbin/agetty /dev/ttyS0 9600 vt100-nav
system_u:system_r:getty_t:s0 root 2242 0.0 0.0 2004 476 tty4 Ss+ 03:48 0:00 /sbin/mingetty /dev/tty4
system_u:system_r:getty_t:s0 root 2244 0.0 0.0 2004 476 tty5 Ss+ 03:48 0:00 /sbin/mingetty /dev/tty5
system_u:system_r:getty_t:s0 root 2246 0.0 0.0 2004 480 tty6 Ss+ 03:48 0:00 /sbin/mingetty /dev/tty6
system_u:system_r:xserver_t:s0-s0:c0.c1023 root 2290 0.8 2.3 37696 24704 tty1 Ss+ 03:48 1:20 /usr/bin/Xorg :0 -nr -verbose -audit 4 -auth /var/run/gdm/auth-for-gdm-dIQ0Xe/database -nolisten
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 root 2899 0.0 0.1 5252 1712 pts/0 Ss 03:56 0:00 bash
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 root 4690 14.0 0.1 4928 1084 pts/0 R+ 06:25 0:00 ps auZ


// processes not protected by selinux:
(since there is no policy written for them)

unconfined_u:unconfined_r:unconfined


*** How to break the sshd deamon
-----------------------------------------------------------------


[root@localhost init.d]# service sshd stop
Stopping sshd: [ OK ]

[root@localhost init.d]# ls -Z /etc/ssh/sshd_config 
-rw-------. root root system_u:object_r:etc_t:s0 /etc/ssh/sshd_config

// change the sec. cont. as anaconda*.cfg
[root@localhost init.d]# chcon --reference /root/anaconda-ks.cfg /etc/ssh/sshd_config 

[root@localhost init.d]# ls -Z /etc/ssh/sshd_config 
-rw-------. root root system_u:object_r:admin_home_t:s0 /etc/ssh/sshd_config

[root@localhost init.d]# service sshd start
Starting sshd: /etc/ssh/sshd_config: Permission denied
[FAILED]

red: AVC denial message




















12.4 Setting SELinux Contexts pt- 2


12.4 Setting SELinux Contexts pt- 2
--------------------------------------------------------------------------------

*** How to break the sshd deamon.. cntd....
-----------------------------------------------------------------

[root@localhost ~]# sealert -a /var/log/audit/audit.log 

SELinux is preventing /usr/sbin/sshd from read access on the file /etc/ssh/sshd_config.

***** Plugin restorecon (90.5 confidence) suggests *************************

If you want to fix the label.
/etc/ssh/sshd_config default label should be etc_t.
Then you can run restorecon.
Do
# /sbin/restorecon -v /etc/ssh/sshd_config

***** Plugin sshd_root (9.50 confidence) suggests **************************

If you want to allow sshd to have read access on the sshd_config file
Then you must fix the labels.
Do
/sbin/restorecon -Rv /root/.ssh

***** Plugin catchall (1.40 confidence) suggests ***************************

If you believe that sshd should be allowed read access on the sshd_config file by default.
Then you should report this as a bug.
You can generate a local policy module to allow this access.
Do
allow this access for now by executing:
# grep sshd /var/log/audit/audit.log | audit2allow -M mypol
# semodule -i mypol.pp

// solution-1
[root@localhost ~]# /sbin/restorecon -v /etc/ssh/sshd_config
/sbin/restorecon reset /etc/ssh/sshd_config context system_u:object_r:admin_home_t:s0->system_u:object_r:etc_t:s0

[root@localhost ~]# ls -Z /etc/ssh/sshd_config 
-rw-------. root root system_u:object_r:etc_t:s0 /etc/ssh/sshd_config

[root@localhost ~]# service sshd start
Starting sshd: [ OK ]

// solution-2
[root@localhost ~]# chcon --reference /root/anaconda-ks.cfg /etc/ssh/sshd_config 
[root@localhost ~]#
[root@localhost ~]# ls -Z /etc/ssh/sshd_config 
-rw-------. root root system_u:object_r:admin_home_t:s0 /etc/ssh/sshd_config

// !!! chcon is temp solution
// it will survive reboot but it will not survive after FS relabel.

[root@localhost ~]# chcon -t etc_t /etc/ssh/sshd_config 
[root@localhost ~]# ls -Z /etc/ssh/sshd_config 
-rw-------. root root system_u:object_r:etc_t:s0 /etc/ssh/sshd_config

// to make the sec. context permanent, use semanage cmd
[root@localhost ~]# semanage fcontext -a -t etc_t "/etc/ssh/sshd_config"

// to restore file's default security context
restorecon -R -v /etc/ssh/sshd_config 






12.5 SELinux - mv Versus cp

12.5 SELinux - mv & cp
-------------------------------------------------------

mv

-------------------------
!!! sec. context remains with mv cmd

[root@localhost ~]# ls -i anaconda-ks.cfg 
371422 anaconda-ks.cfg

[root@localhost ~]# ls -Z anaconda-ks.cfg 
-rw-------. root root system_u:object_r:admin_home_t:s0 anaconda-ks.cfg

[root@localhost ~]# mv anaconda-ks.cfg /home/alex/

[root@localhost ~]# ls -i /home/alex/anaconda-ks.cfg 
330029 /home/alex/anaconda-ks.cfg

[root@localhost ~]# ls -Z /home/alex/anaconda-ks.cfg 
-rw-------. root root system_u:object_r:admin_home_t:s0 /home/alex/anaconda-ks.cfg

[root@localhost ~]# ls -Zd /home/alex/ 
drwx------. alex alex unconfined_u:object_r:user_home_dir_t:s0 /home/alex/

[root@localhost ~]# mv /home/alex/anaconda-ks.cfg .

[root@localhost ~]# ls -i anaconda-ks.cfg 
371422 anaconda-ks.cfg


cp
-------------------------------

!!! sec. context Does NOT remain with cp cmd

[root@localhost ~]# ls -i anaconda-ks.cfg 
371422 anaconda-ks.cfg

[root@localhost ~]# ls -Z anaconda-ks.cfg 
-rw-------. root root system_u:object_r:admin_home_t:s0 anaconda-ks.cfg

[root@localhost ~]# cp anaconda-ks.cfg /home/alex/
[root@localhost ~]# ls -i anaconda-ks.cfg 
371422 anaconda-ks.cfg

[root@localhost ~]# ls -i /home/alex/anaconda-ks.cfg 
330029 /home/alex/anaconda-ks.cfg

[root@localhost ~]# ls -Z /home/alex/anaconda-ks.cfg 
-rw-------. root root unconfined_u:object_r:user_home_t:s0 /home/alex/anaconda-ks.cfg










12.6 SELinux Booleans

12.6 SELinux Booleans
--------------------------------------------------

[root@localhost ~]# semanage boolean | less
SELinux boolean State Default Description
ftp_home_dir (off , off) Allow ftp to read and write files in the user home directories
smartmon_3ware (off , off) Enable additional permissions needed to support devices on 3ware controllers.
xdm_sysadm_login (off , off) Allow xdm logins as sysadm
xen_use_nfs (off , off) Allow xen to manage nfs files
mozilla_read_content (off , off) Control mozilla content access
........
........

[root@localhost ~]# getsebool -a | grep ftp
allow_ftpd_anon_write --> off
allow_ftpd_full_access --> off
allow_ftpd_use_cifs --> off
allow_ftpd_use_nfs --> off
ftp_home_dir --> off
ftpd_connect_db --> off
ftpd_use_passive_mode --> off
httpd_enable_ftp_server --> off
tftp_anon_write --> off


*** How to conf. allow a user to ftp to home dir
---------------------------------------------------------
[root@localhost ~]# setsebool ftp_home_dir on
same: 
setsebool ftp_home_dir 1
same: setsebool ftp_home_dir true

// permanent change
[root@localhost ~]# setsebool -P ftp_home_dir on















13. Encrypted Filesystems
13.1 Encrypted Filesystems

13.1 Encrypted Filesystems
--------------------------------------------------

RHCSA exam obj:

to enrypt a partition so that it prompts for pw at boot

(luks): linux unified key setup
- partition encryption system

*** How to encrypt partition
---------------------------------------

IMPORTANT:
sdd1 should be unallocated PV in order to be encrypted

[root@localhost init.d]# cryptsetup --verbose --verify-passphrase luksFormat /dev/sdd1

WARNING!
========
This will overwrite data on /dev/sdd1 irrevocably.

Are you sure? (Type uppercase yes): YES
Enter LUKS passphrase:
Verify passphrase:
Command successful.

// encryted partition named "safe"
[root@localhost init.d]# cryptsetup luksOpen /dev/sdd1 safe
Enter passphrase for /dev/sdd1:

[root@localhost init.d]# mkfs.ext4 /dev/mapper/safe 
[root@localhost init.d]# mkdir /safedir
[root@localhost init.d]# mount /dev/mapper/safe /safedir

// restore relabel selinux security context
restorecon -r /safedir/

vim /etc/crypttab
safe /dev/sdd1 none 


vim /etc/fstab
/dev/mapper/safe /sadedir /ext4 defaults 0 0

reboot

[root@localhost ~]# cryptsetup status /dev/mapper/safe 
/dev/mapper/safe is active and is in use.
type: LUKS1
cipher: aes-cbc-essiv:sha256
keysize: 256 bits
device: /dev/sdb1
offset: 4096 sectors
size: 1040066 sectors
mode: read/write


[root@localhost ~]# cryptsetup status safe
/dev/mapper/safe is inactive.


29.5.3. How to Remove a passphrase or key from a device
cryptsetup luksRemoveKey /dev/sdb1

vim /etc/crypttab
#safe /dev/sdd1 none

vim /etc/fstab
#/dev/mapper/safe /sadedir /ext4 defaults 0 0

mkfs.ext4 /dev/sdd1

Homework
1. put some file on a directory of disk
2. encrypt the disk
3. decrypt, check if file exists?










14. Network Services
14.1 NFS

14.1 NFS
--------------------------------------------------

Network File Services (NFS)

support v2,v3,v4

// need to install NFS


// *: everybody access to this share
// show exported nfs files by 192.*.*.*

[root@localhost ~]# showmount -e 192.168.198.1
/srv/nfs *

[root@localhost ~]# mkdir /mnt/nfsshared

[root@localhost ~]# mount -t nfs 192.168.198.1:/srv/nfs /mnt/nfsshared/

umount /mnt/nfsshared

vim /etc/fstab
....
192.168.198.1:/srv/nfs /mnt/nfsshared/ nfs _netdev 0 0
// _netdev: wait for netw services to mount
14.2 FTP pt- 1


14.2 FTP pt- 1
-------------------------------------------------------------------

*** How to setup FTP server
--------------------------------- 


[root@localhost ~]# yum install vsftpd


chkconfig vsftpd on
chkconfig --list vsftpd


[root@localhost ~]# service vsftpd restart
Shutting down vsftpd: [ OK ]
Starting vsftpd for vsftpd: [ OK ]

// enable FTP on firewall
[root@localhost ~]# system-config-firewall

// to verify ftp port is open
[root@localhost ~]# iptables -vL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
103 57993 ACCEPT all -- any any anywhere anywhere state RELATED,ESTABLISHED
2 108 ACCEPT icmp -- any any anywhere anywhere
9 612 ACCEPT all -- lo any anywhere anywhere
0 0 ACCEPT tcp -- any any anywhere anywhere state NEW tcp dpt:ftp 


[root@localhost ~]# sealert -a /var/log/audit/audit.log 

[root@localhost ~]# setsebool -P ftp_home_dir 1


**********************************************************************************

How to use FTP command Windows
------------------------------------------ 
ftp
open 192.168.136.10

lftp alex@192.168.136.10













14.3 FTP pt- 2


14.3 FTP pt- 2
------------------------------------------------


How to prevent ftp users to access system files?
(aka .. to put chroot jail)
------------------------------

1.

[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf 
// comment out
chroot_list_enable=YES

2. 
[root@localhost ~]# vim /etc/vsftpd/chroot_list
root
alex

3.
[root@localhost ~]# service vsftpd restart
Shutting down vsftpd: [ OK ]
Starting vsftpd for vsftpd: [ OK ]

4.
// now ftp user always see the users home dir.
[root@localhost ~]# lftp alex@192.168.136.10
Password:
lftp alex@192.168.136.10:~> ls 
-rw------- 1 0 0 10742 Sep 22 07:58 anaconda-ks.cfg
-rw-r--r-- 1 501 501 40 Sep 26 08:51 from_clone.txt
-rw-rw-r-- 1 501 501 25600000 Sep 15 04:03 testfile
-rw-rw-r-- 1 501 501 10145792 Sep 15 04:03 testfile2
-rw-rw-r-- 1 501 501 0 Sep 15 04:03 testfile3
lftp alex@192.168.136.10:/> pwd
ftp://alex@192.168.136.10/
lftp alex@192.168.136.10:/> cd ..
lftp alex@192.168.136.10:/> ls
-rw------- 1 0 0 10742 Sep 22 07:58 anaconda-ks.cfg
-rw-r--r-- 1 501 501 40 Sep 26 08:51 from_clone.txt
-rw-rw-r-- 1 501 501 25600000 Sep 15 04:03 testfile
-rw-rw-r-- 1 501 501 10145792 Sep 15 04:03 testfile2
-rw-rw-r-- 1 501 501 0 Sep 15 04:03 testfile3


Anonymous Acces
------------------------------

client
----------

[root@localhost ~]# lftp anonymous@192.168.136.10
Password:
lftp anonymous@192.168.136.10:~> ls
drwxr-xr-x 2 0 0 4096 Mar 02 2012 pub

lftp anonymous@192.168.136.10:/> cd pub/
lftp anonymous@192.168.136.10:/pub> ls
-rw-r--r-- 1 0 0 0 Sep 26 11:05 get-me
lftp anonymous@192.168.136.10:/pub>
lftp anonymous@192.168.136.10:/pub>
lftp anonymous@192.168.136.10:/pub> get get-me 


server
----------
// anon. users ftp directory
[root@localhost ~]# cd /var/ftp/pub/

[root@localhost ftp]# cd pub/
[root@localhost pub]# touch get-me

// Selinux sec. context
[root@localhost pub]# ls -Zd /var/ftp/
drwxr-xr-x. root root system_u:object_r:public_content_t:s0 /var/ftp/






















14.4 CIFS (Samba) Client

14.4 CIFS (Samba) Client
------------------------------------------------------
connecting from
Linux client --> to Windows CIFS share server

CIFS - Common Internet File System

RHCSA Responsibilities:mount and unmount CIFS shares


How to Mount
-------------------------------
// FS type cifs
[root@localhost ~]# mount -t cifs -o user=alex //192.168.136.10/samba /mnt/samba



CIFS share:

remote windows share

SMB client:
program used to access remote CIFS shares

[root@localhost ~]# yum install samba
Installed:
samba.i686 0:3.6.9-151.el6

// to see what shares available in a remote server
[root@localhost ~]# smbclient -U alex -L 192.168.136.10
passwd:
Sharename Type Comment
---------------------------------------------------
samba Disk Samba Test


// to login to remote CIF share (I guess it is windows)
[root@localhost ~]# smbclient -U alex //192.168.136.10/samba
passwd:
smb: \> ls

smb: \> dir
smb: \> lcd /home/lucent

smb: \> get file.txt
smb: \> put up_file.txt

smb: \> quit





























14.5 Autofs


14.5 Autofs
---------------------------------------------------

- another way to mount a remote network file share
- MAIN ADV:
. device unmounted when not used


autofs config files
------------------------------

less /etc/auto.master 
#
# Sample auto.master file
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# For details of the format look at autofs(5).
#
/misc /etc/auto.misc
#
# NOTE: mounts done from a hosts map will be mounted with the


vim /etc/auto.misc
#
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# Details may be found in the autofs(5) manpage
........
........
#jaz -fstype=ext2 :/dev/sdc1
#removable -fstype=ext2 :/dev/hdd
nfs -fstype=nfs,intr 192.168.136.10:/srv/nfs


// after the changes restart
[root@localhost ~]# service autofs restart
Loading autofs4: [ OK ]
Starting automount: [ OK ]

// no nfs share since we did not access it yet[root@localhost ~]# ls /misc/
// when we access nfs, it will auto be mounted
[root@localhost ~]# cd /misc/nfs
[root@localhost ~]# pwd
/misc/nfs

!! Note:after 10 min without used, /misc/nfs dir will be unmounted automatically.


How to create /remote auto-mount point
--------------------------------

[root@localhost ~]# vim /etc/auto.master 
....
....
#add this at the eof
/remote /etc/auto.remote

// create the following
[root@localhost ~]# vim /etc/auto.remote 
nfs -fstype=nfs,intr 192.168.136.10:/srv/nfs

[root@localhost ~]# service autofs restart
Loading autofs4: [ OK ]
Starting automount: [ OK ]

// no nfs share since we did not access it yet
[root@localhost ~]# ls /remote/

// when we access nfs, it will auto be mounted
[root@localhost ~]# cd /remote/nfs
[root@localhost ~]# pwd
/remote/nfs




14.6 HTTP Server pt- 1


14.6 HTTP Server pt- 1
---------------------------------------------------

RHCSA Exam Objective:
Setup and configure default web server
- using Apache web server
- apache deamon is named httpd


1. Install httpd:

[root@localhost ~]# yum install httpd
Installed:
httpd.i686 0:2.2.15-26.el6


2. Config file
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf

292 DocumentRoot "/var/www/html"

315 # This should be changed to whatever you set DocumentRoot to.
316 #
317 <Directory "/var/www/html">



[root@localhost ~]# service httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified
domain name, using localhost.localdomain for ServerName

[root@localhost ~]# chkconfig httpd on

[root@localhost ~]# chkconfig --list httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

// allow HTTP port 80 on firewall
[root@localhost ~]# system-config-firewall-tui

// Test the webserver
vim /var/www/html/index.html
Hellooo world

// test the webserver via elinks
[root@localhost ~]# yum install elinks
[root@localhost ~]# elinks http://localhost




14.7 HTTP Server pt- 2

14.7 HTTP Server pt- 2
---------------------------------------------------------

object: 
to serve multiple websites on one server

Apache web server Virtual Host feauture
----------------------------

- allow more than one website in one server

How to create two website on a single server
----------------------------

1.
[root@localhost ~]# vim /etc/hosts
127.0.0.1 example-1.com example-2.com localhost localhost.localdomain
localhost4 localhost4.localdomain4

2.
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# mkdir example-1.com
[root@localhost html]# mkdir example-2.com
[root@localhost html]# ls -Zd example-1.com/
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 example-1.com/
[root@localhost html]# ls -Zd example-2.com/
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 example-2.com/

3.

[root@localhost html]# vim /etc/httpd/conf/httpd.conf 
1011 NameVirtualHost example-1.com:80
1012 <VirtualHost example-1.com:80>
1013 DocumentRoot /var/www/html/example-1.com
1014 ServerName example-1.com
1015 ErrorLog logs/example-1.com-error_log
1016 CustomLog logs/example-1.com-access_log common
1017 </VirtualHost>
1018
1019 NameVirtualHost example-2.com:80
1020 <VirtualHost example-2.com:80>
1021 DocumentRoot /var/www/html/example-2.com
1022 ServerName example-2.com
1023 ErrorLog logs/example-2.com-error_log
1024 CustomLog logs/example-2.com-access_log common
1025 </VirtualHost>


4. How to verify the syntax of http.conf file

[root@localhost html]# service httpd configtest
httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
[Sun Sep 29 07:08:52 2013] [warn] NameVirtualHost example-2.com:80 has no VirtualHosts
Syntax OK

5.
[root@localhost html]# service httpd reload
Reloading httpd:

6. Create content
[root@localhost html]# vim example-1.com/index.html
Hello from example-1.com

[root@localhost html]# vim example-2.com/index.html
Hello from example-2.com

7. Verify from firefox









14.8 NTP Server

14.8 NTP Server
------------------------------------------------


RHCSA Exam Objective:
Setup an NTP server

NTP: Network Time Protocol

NTP Client:
easy

How to setup NTP Server
-------------------------------

1.
[root@localhost html]# vim /etc/ntp.conf 
# Hosts on local network are less restricted.
restrict 192.168.136.0 mask 255.255.255.0 nomodify notrap

2.
[root@localhost html]# chkconfig --list ntpd 
ntpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

3. Verify tcp port 123 are open




Then Apply changes


How to setup NTP Client
-------------------------------































14.9 Secure Shell (SSH) Commands

14.9 Secure Shell (SSH) Commands
-----------------------------------------------------

Openssh package
- includes both SSH Client and SSH Server

How to setup SSH Server
----------------------------------
1.
[root@localhost ~]# chkconfig --list sshd
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

2. Allow SSH on firewall




[root@RHEL-RHSCA-1 ~]# vim /etc/ssh/sshd_config
PermitRootLogin no


SCP - Secure Copy
-----------------------------------


[root@Clone-of-RHSCA-1 ~]# scp scp-test.txt alex@192.168.136.3:/home/alex
alex@192.168.136.3's password:
scp-test.txt





14.10 VNC

14.10 VNC
-----------------------------------------------------


VNC - Virtual Network Computing

How to setup VNC server-client
-----------------------------------
1. install 
tigervnc-server.i686

2. configure

[alex@RHEL-RHSCA-1 ~]$ vncserver :1

You will require a password to access your desktops.

Password:
Password must be at least 6 characters - try again
Password:
Verify:
xauth: creating new authority file /home/alex/.Xauthority
xauth: (stdin):1: bad display name "RHEL-RHSCA-1:1" in "add" command

WARNING: The first attempt to start Xvnc failed, possibly because the font
catalog is not properly configured. Attempting to determine an appropriate
font path for this system and restart Xvnc using that font path ...
Could not start Xvnc.

[root@RHEL-RHSCA-1 ~]# chkconfig vncserver on
[root@RHEL-RHSCA-1 ~]# chkconfig --list vncserver

vncserver 0:off 1:off 2:on 3:on 4:on 5:on 6:off

VNC font PROBLEM-Solution:
[root@RHEL-RHSCA-1 ~]# yum install pixman pixman-devel libXfont

[root@RHEL-RHSCA-1 ~]# vncserver :1
xauth: (stdin):1: bad display name "RHEL-RHSCA-1:1" in "add" command
New 'RHEL-RHSCA-1:1 (root)' desktop is RHEL-RHSCA-1:1
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/RHEL-RHSCA-1:1.log


[root@RHEL-RHSCA-1 ~]# vim /etc/sysconfig/vncservers
VNCSERVERS="1:root 2:lucent"
VNCSERVERARGS[1]="-geometry 1280x1024 -rfbport 5901"

[root@RHEL-RHSCA-1 ~]# service vncserver restart

Firewall Add 5901 tcp

// VNC port Trobule shooting
[root@RHEL-RHSCA-1 ~]# lsof -i -P | grep vnc
Xvnc 7183 alex 0u IPv6 61413 0t0 TCP *:6001 (LISTEN)
Xvnc 7183 alex 1u IPv4 61414 0t0 TCP *:6001 (LISTEN)
Xvnc 7183 alex 6u IPv4 61420 0t0 TCP *:5901 (LISTEN)



// install on the VNC Client
[root@Clone-of-RHSCA-1 ~]# yum install tigervnc// on the client
vncviewer 192.168.136.10:5901






15. Working with Processes
15.1 View Running Processes

15.1 View Running Processes
--------------------------------------------------------


[root@Clone-of-RHSCA-1 log]# pstree
init─┬─NetworkManager─┬─2*[dhclient]
│ └─{NetworkManager}
├─abrt-dump-oops
├─abrtd
├─acpid
├─agetty
├─atd
├─auditd─┬─audispd─┬─sedispatch
│ │ └─{audispd}
│ └─{auditd}

# list processes with PID(process id)
[root@Clone-of-RHSCA-1 log]# pstree -p

init(1)─┬─NetworkManager(1842)─┬─dhclient(1882)
│ ├─dhclient(1884)
│ └─{NetworkManager}(1883)
├─abrt-dump-oops(2008)
├─abrtd(2000)
├─acpid(1857)
├─agetty(2155)
├─atd(2104)
├─auditd(1746)─┬─audispd(1748)─┬─sedispatch(1749)
│ │ └─{audispd}(1750)
│ └─{auditd}(1747)


[root@localhost ~]# pstree -a
init
├─NetworkManager --pid-file=/var/run/NetworkManager/NetworkManager.pid
│ ├─dhclient -d -4 -sf /usr/libexec/nm-dhcp-client.action -pf ...
│ └─{NetworkManager}
├─abrt-dump-oops -d /var/spool/abrt -rwx /var/log/messages
├─abrtd
├─acpid
├─agetty /dev/ttyS0 9600 vt100-nav
├─atd


# List processes by users
root@localhost ~]# ps -U alex
PID TTY TIME CMD

[root@localhost ~]# ps -U root
PID TTY TIME CMD
1 ? 00:00:02 init
2 ? 00:00:00 kthreadd
3 ? 00:00:00 migration/0
4 ? 00:00:00 ksoftirqd/0
// current account processes
[root@localhost ~]# ps u
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 2016 0.0 0.0 2004 484 tty2 Ss+ 16:22 0:00 /sbin/mingetty /dev/tty2
root 2017 0.0 0.0 2016 516 ttyS0 Ss+ 16:22 0:00 /sbin/agetty /dev/ttyS0 9600 vt1
root 2019 0.0 0.0 2004 476 tty3 Ss+ 16:22 0:00 /sbin/mingetty /dev/tty3
root 2021 0.0 0.0 2004 480 tty4 Ss+ 16:22 0:00 /sbin/mingetty /dev/tty4
root 2025 0.0 0.0 2004 480 tty5 Ss+ 16:22 0:00 /sbin/mingetty /dev/tty5
root 2027 0.0 0.0 2004 476 tty6 Ss+ 16:22 0:00 /sbin/mingetty /dev/tty6
root 2044 1.8 1.4 41556 28212 tty1 Rs+ 16:22 2:12 /usr/bin/Xorg :0 -nr -verbose -a
root 2687 0.0 0.0 5240 1768 pts/0 Ss 16:23 0:00 bash
root 3793 0.0 0.0 5240 1732 pts/2 Ss 17:57 0:00 bash
root 4226 0.0 0.1 7508 2476 pts/0 S+ 18:09 0:00 lftp alex@192.168.136.10
root 4285 3.0 0.0 4936 1040 pts/2 R+ 18:19 0:00 ps u

# List all procceses of all users including system processes
[root@RHEL-6_RHSCA-2 ~]# ps aux | more
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 1.0 0.1 2896 1420 ? Ss 07:24 0:02 /sbin/init
root 2 0.0 0.0 0 0 ? S 07:24 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S 07:24 0:00 [migration/0]
root 4 0.0 0.0 0 0 ? S 07:24 0:00 [ksoftirqd/0]
root 5 0.0 0.0 0 0 ? S 07:24 0:00 [migration/0]
root 6 0.0 0.0 0 0 ? S 07:24 0:00 [watchdog/0]
root 7 0.0 0.0 0 0 ? S 07:24 0:00 [events/0]
rpc 1799 0.0 0.0 2576 620 ? Ss 07:25 0:00 rpcbind
dbus 1809 0.2 0.1 13832 1688 ? Ssl 07:25 0:00 dbus-daemon --system
......

[root@localhost ~]# top
top - 18:24:06 up 2:02, 3 users, load average: 0.10, 0.09, 0.03
Tasks: 152 total, 1 running, 151 sleeping, 0 stopped, 0 zombie
Cpu(s): 5.1%us, 4.4%sy, 0.0%ni, 90.5%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 1938968k total, 460560k used, 1478408k free, 6260k buffers
Swap: 4194296k total, 0k used, 4194296k free, 257724k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2044 root 20 0 74968 26m 8976 S 7.6 1.4 2:34.76 Xorg
2685 root 20 0 51652 12m 9736 S 3.0 0.7 0:22.83 gnome-ter

press "h" for TOP help:
Help for Interactive Commands - procps version 3.2.8
Window 1:Def: Cumulative mode Off. System: Delay 3.0 secs; Secure mode Off.

Z,B Global: 'Z' change color mappings; 'B' disable/enable bold
l,t,m Toggle Summaries: 'l' load avg; 't' task/cpu stats; 'm' mem info
1,I Toggle SMP view: '1' single/separate states; 'I' Irix/Solaris mode

f,o . Fields/Columns: 'f' add or remove; 'o' change display order
F or O . Select sort field
<,> . Move sort field: '<' next col left; '>' next col right
R,H . Toggle: 'R' normal/reverse sort; 'H' show threads
c,i,S . Toggle: 'c' cmd name/line; 'i' idle tasks; 'S' cumulative time
x,y . Toggle highlights: 'x' sort field; 'y' running tasks
z,b . Toggle: 'z' color/mono; 'b' bold/reverse (only if 'x' or 'y')
u . Show specific user only
n or # . Set maximum tasks displayed

k,r Manipulate tasks: 'k' kill; 'r' renice
d or s Set update interval
W Write configuration file
q Quit
( commands shown with '.' require a visible task display window )
Press 'h' or '?' for help with Windows,
any other key to continue 


GUI
applications > system tools > system monitor
















15.2 Changing Process Priorities

15.2 Changing Process Priorities
-------------------------------------------------------------

nice value
between -20 -- 19
-20: highest nice value
19 : lowest nice value
default nice value= 0

Notethe higher nice number = the less CPU time process gets

[root@localhost ~]# nice -n -10 service atd start
Starting atd: [ OK ]

[root@localhost ~]# ps -eo pid,nice,comm | grep atd
4420 -10 atd

[root@localhost ~]# renice -n -5 4420 
4420: old priority -10, new priority -5

[root@localhost ~]# top -p4420
top - 18:33:13 up 2:11, 3 users, load average: 0.00, 0.02, 0.00
Tasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie
Cpu(s): 4.0%us, 2.0%sy, 0.0%ni, 94.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 1938968k total, 462668k used, 1476300k free, 6764k buffers
Swap: 4194296k total, 0k used, 4194296k free, 259580k cached
PID to renice:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
4420 root 20 2916 468 324 S 0.0 0.0 0:00.00 atd
15.3 Stopping Processes

15.3 Stopping Processes
-----------------------------------------------------------
// get the PID
[root@localhost ~]# service atd status
atd (pid 4420) is running...
# (kill = kill -s 15), sending termination signal to process

1. Kill

[root@localhost ~]# kill 4420// equal as above - signal 15 is termination signal
[root@localhost ~]# kill -s 15 4420
[root@localhost ~]# service atd status
atd dead but subsys locked

# force stop: kill -9 $PID 
[root@localhost ~]# kill -9 2869

[root@localhost ~]# service atd start
Starting atd: [ OK ]
# How to get PID grep
[root@localhost ~]# pgrep -u root atd
4533
[root@RHEL-6_ ~]# pgrep atd
2869

#reload config file
[root@localhost ~]# service atd reload
Stopping atd: [ OK ]
Starting atd: [ OK ]

//reload config file- equal as above
[root@localhost ~]# kill -s 1 2689

To-do:
[root@localhost ~]# man 7 signal
search for:
standard signals
or
/SIGINT


[root@localhost ~]# service firefox status
firefox: unrecognized service

[root@localhost ~]# ps -aux | grep fire*
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root 4687 10.3 3.0 286936 59500 ? Sl 20:08 0:02 /usr/lib/firefox/firefox
root 4705 0.2 0.0 0 0 ? Z 20:08 0:00 [firefox] <defunct>
root 4743 0.0 0.0 4352 724 pts/2 S+ 20:09 0:00 grep fire*

[root@localhost ~]# pgrep -u root firefox
4687
4705

[root@localhost ~]# service firefox status
firefox: unrecognized service

2. KILLALL
[root@localhost ~]# killall -9 firefox

[root@RHSCA-2 ~]# killall atd
[root@RHSCA-2 ~]# service atd status
atd dead but subsys locked

3. PKILL
[root@RHSCA-2 ~]# pkill atd
[root@RHSCA-2 ~]# service atd status
atd dead but subsys locked






15.4 Scheduling a Job with cron

15.4 Scheduling a Job with cron
------------------------------------------------------------

cron: 
scheduling recurrent jobs
at:schedule a particular time

crond

[root@localhost ~]# chkconfig --list crond
crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off

[root@localhost ~]# service crond status
crond (pid 1964) is running...
[root@localhost ~]# cat /etc/crontab SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# 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

// show only hour
[root@localhost ~]# date +%R


How to create a task w crond
------------------------------------------


// -e: create a task for current user
// use -u for other users

[root@localhost cron.daily]# crontab -e
# 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
# 21 20 12 * * touch /root/HereWeGo

# create ww-3 and ww-4 at 18:53, 1st day of mnth, any mnth, any day
53 18 01 * * touch /root/ww-3
53 18 01 * * touch /root/ww-4

// default location for cron jobs
[root@RHSCA-2 ~]# cat /var/spool/cron/root 
# 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
# 21 20 12 * * touch /root/HereWeGo

53 18 01 * * touch /root/ww-3
53 18 01 * * touch /root/ww-4

# i.e. drop your script under /etc/cron.monthly to make it run every month
[root@localhost cron.daily]# ls /etc/cron*
/etc/cron.deny /etc/crontab
/etc/cron.d:
0hourly raid-check sysstat

/etc/cron.daily:
0logwatch logrotate mlocate.cron readahead.cron tmpwatch
cups makewhatis.cron prelink rhsmd

/etc/cron.hourly:
0anacron

/etc/cron.monthly:
readahead-monthly.cron

/etc/cron.weekly:

To-Do
man crontab


How to create a cron job for a user
---------------------------------------------------
[root@RHSCA-2 ~]# crontab -u alex -e
no crontab for alex - using an empty one
crontab: installing new crontab

[root@RHSCA-2 ~]# ls /var/spool/cron/
alex root 

[root@RHSCA-2 ~]# cat /var/spool/cron/alex 
# 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
# 21 20 12 * * touch /root/HereWeGo

05 19 01 * * touch /home/alex/qq-1






















15.5 Scheduling a Job with at


15.5 Scheduling a Job with at
-------------------------------------------

at: to schedule one time jobs

[root@localhost ~]# service atd status
atd (pid 4924) is running...

[root@localhost ~]# chkconfig --list atd
atd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

How to create a at job
--------------------------------

Job: install mysql at a certain time

1.

[root@RHSCA-2 ~]# vim mysql-install.sh
[root@RHSCA-2 ~]# ll mysql-install.sh 
-rw-r--r--. 1 root root 21 Oct 1 19:08 mysql-install.sh
[root@RHSCA-2 ~]# chmod +x mysql-install.sh 
[root@RHSCA-2 ~]# ll mysql-install.sh 
-rwxr-xr-x. 1 root root 21 Oct 1 19:08 mysql-install.sh
[root@RHSCA-2 ~]# cat mysql-install.sh 
yum -y install mysql

2.
[root@RHSCA-2 ~]# at -f /root/mysql-install.sh now+1minutes
job 11 at 2013-10-01 19:14
// query the jobs[root@RHSCA-2 ~]# atq12 2013-10-01 19:16 a root


How to remove a job
--------------------------------
[root@RHSCA-2 ~]# atq
12 2013-10-01 19:16 a root

[root@RHSCA-2 ~]# atrm 12
[root@RHSCA-2 ~]# atq
// job removed


How to display a job content
--------------------------------

[root@RHSCA-2 ~]# at -f /root/mysql-install.sh now+5minutes
job 13 at 2013-10-01 19:22

[root@RHSCA-2 ~]# atq
13 2013-10-01 19:22 a root

[root@RHSCA-2 ~]# ls /var/spool/at/
a0000d015f1e2e spool

[root@RHSCA-2 ~]# cat /var/spool/at/a0000d015f1e2e 
........
${SHELL:-/bin/sh} << 'marcinDELIMITER784488c5'
yum -y install mysql
marcinDELIMITER784488c5

// 12 noon tomorrow
[root@localhost ~]# at -f any-job.sh 12pm tomorrow

[root@RHSCA-2 ~]# cat /var/spool/mail/alex 


to-do
man atd, man at







16. System Logs
16.1 System Logs Overview

16.1 System Logs Overview
----------------------------------------------------
- all system logs located in:
/var/log/
anaconda.ifcfg.log cron maillog-20130428 rhsm spooler-20130926
anaconda.log cron-20130428 maillog-20130512 sa spooler-20130929
anaconda.program.log cron-20130512 maillog-20130926 samba tallylog
anaconda.storage.log cron-20130926 maillog-20130929 secure wpa_supplicant.log
anaconda.syslog cron-20130929 messages secure-20130428 wtmp
anaconda.yum.log cups messages-20130428 secure-20130512 xferlog
audit dmesg messages-20130512 secure-20130926 xferlog-20130929
boot.log dmesg.old messages-20130926 secure-20130929 Xorg.0.log
btmp dracut.log messages-20130929 setroubleshoot Xorg.0.log.old
btmp-20130926 gdm ntpstats spice-vdagentd Xorg.1.log
conman lastlog pm-powersave.log spooler Xorg.1.log.old
conman.old mail ppp spooler-20130428 Xorg.2.log
ConsoleKit maillog prelink spooler-20130512 yum.log


- standard system logs, boot issues not related to kernel
/var/log/messages
- kernel logs, during boot time, bios, HW, PCI devices, CPU
/var/log/dmesg
- system security, TCP wrappers, system logins
/var/log/secure
[root@localhost ~]# sealert -a /var/log/audit/audit.log 

SELinux logs
AVC-Access Vector Cache
/var/log/audit/audit.log
- other logs
/var/log/Xorg.* // X window logs
/var/log/yum.log
/var/log/boot.log
/var/log/httpd


tail -f
dmesg

SELinux
sealert
aureport





16.2 Reading Logfiles

16.2 Reading Logfiles
-----------------------------------------------
// by default tail show last 10 lines
tail /var/log/messages
May 12 21:16:03 localhost yum[5393]: Installed: trace-cmd-1.0.5-10.el6.i686
May 12 21:18:07 localhost NetworkManager[1806]: <info> (eth0): carrier now OFF (device state 3)
May 12 21:18:07 localhost NetworkManager[1806]: <info> (eth0): device state change: 3 -> 2 (reaso

// show last 5 lines
[root@RHSCA-2 log]# tail -n 5 /var/log/messages
Oct 4 03:51:36 RHSCA-2 tpvmlpd2[2505]: device read timed out
Oct 4 03:53:26 RHSCA-2 tpvmlpd2[2541]: device read timed out
Oct 4 03:55:13 RHSCA-2 tpvmlpd2[2552]: device read timed out
Oct 4 03:56:59 RHSCA-2 tpvmlpd2[2556]: device read timed out
Oct 4 03:58:45 RHSCA-2 tpvmlpd2[2559]: device read timed out

[root@localhost ~]# tail -f /var/log/secure
May 12 20:51:05 localhost atd[5211]: pam_unix(atd:session): session opened for user root by (uid=0)
May 12 20:51:05 localhost atd[5211]: pam_unix(atd:session): session closed for user root
May 12 20:52:00 localhost atd[5228]: pam_unix(atd:session): session opened for user root by (uid=0)
16.3 Syslog

16.3 Syslog
-----------------------------------------------------

RHCSA:
not advanced syslog
but need to know basic configuration

Example from /etc/rsyslog.conf:
# Log cron stuff
// Facility: cron, Priority: * means any messages, Sent to: /var/log/cron
cron.* /var/log/cron
# Everybody gets emergency messages
// Facility: any, Priority: emergency , Sent to: everybody 
*.emerg


[root@localhost ~]# vim /etc/rsyslog.conf
# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.* /dev/console

#### RULES ####

# Log all kernel messages to the console.
# Logging much else clutters up the screen.
kern.crit /var/log/messages

# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;authpriv.none;cron.none /var/log/messages

# The authpriv file has restricted access.
authpriv.* /var/log/secure

# Log all the mail messages in one place.
mail.* -/var/log/maillog


# Log cron stuff
cron.* /var/log/cron
# Everybody gets emergency messages
*.emerg

How to change facility logging
------------------------------------------
1.
Before
# Log all kernel messages to the console.
# kern.* / dev/console

2.
After
# log critical kernel logs in to /var/log/messages
kern.crit /var/log/messages

3. reload rsyslog

[root@localhost ~]# service rsyslog reload


How to setup to send syslog to remote server
---------------------------------------------

1. Before
[root@localhost ~]# vim /etc/rsyslog.conf
# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional
#*.* @@remote-host:514

2. After
#Send all log messages to remote host 192.168.136.1on TCP port 514
*.* @@192.168.136.1:514

Explanations:
*.* means all facilities, all priorities
@@ means TCP
@ means UDP
make sure 514 port is open on the remote host firewall

3. Reload
[root@localhost ~]# service rsyslog reload






17. The Kernel
17.1 Linux Kernel Overview

17.1 Linux Kernel Overview
---------------------------------------------------
kernel responsibilities:
- system start-up
- processes
- networking
- memory management
- security (SELinux, firewall, permissions)

[root@localhost ~]# uname -r
2. 6. 32 -358 .el6. i686
<major>.<minor>.<patch>-<build>.elx.<architecture>

- never upgrade KERNEL, install a new one
- example kernel: 
/boot/vmlinuz-2.6.32-358.el6.i686

How to see installed kernels
------------------------------------
[root@RHSCA-2 log]# ll /boot/vm*
-rwxr-xr-x. 1 root root 3815616 Nov 24 2012 /boot/vmlinuz-2.6.32-279.19.1.el6.i686
-rwxr-xr-x. 1 root root 3918496 Jan 29 2013 /boot/vmlinuz-2.6.32-358.el6.i686

Kernel creates the followings during boot time
-------------------------------------
- During system runtime
running system processes
kernel parameters

/proc
system devices, drivers
/sys
access points, disks
/dev











17.2 Hardware and the Kernel

17.2 Hardware and the Kernel
------------------------------------------
// details of system HW detected by Kernel
dmesg = cat /var/log/dmesg
// info PCI buss
[root@localhost ~]# lspci
00:00.0 Host bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX Host bridge (rev 01)
00:01.0 PCI bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX AGP bridge (rev 01)
00:07.0 ISA bridge: Intel Corporation 82371AB/EB/MB PIIX4 ISA (rev 08)
00:07.1 IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)
00:07.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 08)
00:07.7 System peripheral: VMware Virtual Machine Communication Interface (rev 10)
00:0f.0 VGA compatible controller: VMware SVGA II Adapter
# To see kernel modules for a particular HW
[root@localhost ~]# lspci -k | less
00:18.7 PCI bridge: VMware PCI Express Root Port (rev 01)
Kernel driver in use: pcieport
02:00.0 USB controller: VMware USB1.1 UHCI Controller
Subsystem: VMware Device 1976
Kernel driver in use: uhci_hcd
// to view all USB info of the system
[root@localhost ~]# lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 002: ID 0e0f:0003 VMware, Inc. Virtual Mouse
Bus 002 Device 003: ID 0e0f:0002 VMware, Inc. Virtual USB Hub
Bus 002 Device 004: ID 0e0f:0008 VMware, Inc. 
# lsusb tree mode
[root@localhost ~]# lsusb -t
Bus# 2
`-Dev# 1 Vendor 0x1d6b Product 0x0001
|-Dev# 2 Vendor 0x0e0f Product 0x0003
`-Dev# 3 Vendor 0x0e0f Product 0x0002
`-Dev# 4 Vendor 0x0e0f Product 0x0008
Bus# 1
`-Dev# 1 Vendor 0x1d6b Product 0x0002
// info about BIOS, RAM, CPU, motherboard
[root@localhost ~]# dmidecode -t processor
Handle 0x0043, DMI type 4, 35 bytes
Processor Information
Socket Designation: CPU socket #63
Type: Central Processor
Family: Unknown
Manufacturer: 000000000000
ID: 00 00 00 00 00 00 00 00
Version: 00000000000000000000000000000000
Voltage: 3.3 V
External Clock: Unknown
Max Speed: 30000 MHz
Current Speed: Unknown
Status: Unpopulated
Upgrade: ZIF Socket
L1 Cache Handle: 0x00D2
L2 Cache Handle: 0x00D3
L3 Cache Handle: Not Provided
Serial Number: Not Specified
Asset Tag: Not Specified
Part Number: Not Specified

# overview of processor
[root@localhost ~]# x86info
x86info v1.25. Dave Jones 2001-2009
Feedback to <davej@redhat.com>.

Found 1 CPU
--------------------------------------------------------------------------
EFamily: 0 EModel: 1 Family: 6 Model: 23 Stepping: 10
CPU Model: Core 2 Duo
Processor name string: Intel(R) Core(TM)2 Duo CPU P8700 @ 2.53GHz
Type: 0 (Original OEM) Brand: 0 (Unsupported)
Number of cores per physical package=1
Number of logical processors per socket=1
Number of logical processors per core=1
APIC ID: 0x0 Package: 0 Core: 0 SMT ID 0












17.3 Kernel Modules

17.3 Kernel Modules
-----------------------------------------------

Kernel Modules: 

drivers that HW need to communicate with system kernel

// to view currently loaded kernel modules
[root@localhost ~]# lsmod | less
Module Size Used by
cdrom 33416 1 sr_mod
mptspi 14535 4
mptscsih 31362 1 mptspi

[root@localhost ~]# modinfo sr_mod
filename: /lib/modules/2.6.32-358.el6.i686/kernel/drivers/scsi/sr_mod.ko
license: GPL
alias: scsi:t-0x04*
alias: scsi:t-0x05*
alias: block-major-11-*
license: GPL
description: SCSI cdrom (sr) driver
srcversion: 4E9BBFEC88A9F4C928EF837
depends: cdrom
vermagic: 2.6.32-358.el6.i686 SMP mod_unload modversions 686
parm: xa_test:int

# remove cd-rom driver to save some memory
[root@localhost ~]# modprobe -r -v sr_mod

# install cd-rom driver
[root@localhost ~]# modprobe sr_mod 

[root@localhost ~]# uname -r
2.6.32-358.el6.i686

// To see all kernel modules you have in your system
[root@localhost ~]# ls /lib/modules/$(uname -r)/kernel
arch crypto drivers fs kernel lib net sound


Tags:
Driver issues
Kernel modules










17.4 Working with proc and sysctl-conf


17.4 Working with proc and sysctl-conf
----------------------------------------------------

-what is proc filesystem? 
. virtual filesystem
. contains extensive, detailed kernel, process, cpu usage, memory

[root@RHSCA-2 /]# ls /proc/
1 1674 1892 2030 2229 2297 25 37 bus kcore sched_debug
10 1685 19 205 2233 23 2504 374 cgroups keys schedstat
11 1695 1902 206 2238 2300 2542 39 cmdline key-users scsi
12 1697 1908 207 2245 2301 2543 4 
cpuinfo kmsg self
13 17 1910 2070 2252 2306 2544 40 crypto kpagecount slabinfo
14 1727 1912 2081 2254 2309 2575 452 devices kpageflags softirqs
1454 1756 1913 2086 2263 2313 26 5 diskstats loadavg stat
15 1766 1917 21 2265 2314 2602 6 dma locks swaps
1522 1770 1918 2118 2267 2316 27 683 driver mdstat sys
1567 1787 1919 2119 2271 2324 28 7 execdomains meminfo sysrq-trigger
1569 1795 1921 2122 2277 2348 29 71 fb misc sysvipc
1577 18 193 2124 2279 2378 3 751 filesystems modules timer_list
1590 1806 1936 2134 2281 24 30 8 fs mounts timer_stats
1597 1832 1938 2144 2282 2449 31 899 interrupts mpt tty
1598 1840 195 2145 2284 2454 338 9 iomem mtd uptime
16 1848 1954 22 2286 2461 340 902 ioports mtrr version
1649 1856 2 2215 2289 2462 342 998 ipmi net vmallocinfo
1659 1867 20 2220 2292 2463 36 acpi irq pagetypeinfo vmstat
1670 1888 2024 2228 2293 2481 365 buddyinfo kallsyms partitions zoneinfo



cat /proc/cpuinfo// processor information
[root@localhost proc]# cat cpuinfo 
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 23
model name : Intel(R) Core(TM)2 Duo CPU P8700 @ 2.53GHz

# memory
cat /proc/meminfo
[root@localhost proc]# cat meminfo
MemTotal: 1938968 kB
MemFree: 1541048 kB
Buffers: 50956 kB
Cached: 175448 kB

# memory and swap usage
free -m
[root@localhost proc]# free -m
total used free shared buffers cached
Mem: 1893 409 1483 0 50 187
-/+ buffers/cache: 172 1721
Swap: 4095 0 4095

# cat /proc/mount & mount comparison
[root@localhost proc]# cat /proc/mounts 
rootfs / rootfs rw 0 0
proc /proc proc rw,relatime 0 0
sysfs /sys sysfs rw,seclabel,relatime 0 0
devtmpfs /dev devtmpfs rw,seclabel,relatime,size=961620k,nr_inodes=183352,mode=755 0 0
devpts /dev/pts devpts rw,seclabel,relatime,gid=5,mode=620,ptmxmode=000 0 0
tmpfs /dev/shm tmpfs rw,seclabel,relatime 0 0
/dev/mapper/VolGroup00-LogVol00 / ext3 rw,seclabel,relatime,errors=continue,user_xattr,acl,barrier=1,data=ordered 0 0

[root@localhost proc]# mount
/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)

How to set Kernel route packes tru it
----------------------------------------------
// IP forwarding is turned off in the kernel 
[root@localhost proc]# cat /proc/sys/net/ipv4/ip_forward 
0
// ** change is not permanent- lost after boot
[root@RHSCA-2 proc]# echo 1 > sys/net/ipv4/ip_forward

// ** permanent kernel settings
[root@localhost ~]# vim /etc/sysctl.conf
# Kernel sysctl configuration file for Red Hat Linux
#
# For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and
# sysctl.conf(5) for more details.

# Controls IP packet forwarding
net.ipv4.ip_forward = 0

[root@localhost ~]# sysctl -a | less
kernel.sched_child_runs_first = 0
kernel.sched_min_granularity_ns = 1000000
kernel.sched_latency_ns = 5000000

// ** add the line into sysctl.cong file to make it permanent

// to do: study 
. sysctl -a
. sysctl.conf












18. The Boot Process
18.1 The Boot Process

18.1 The Boot Process
-------------------------------------------------

1. BIOS inits

2. BIOS calls bootloader
3. bootloader loads first kernel image
4. Kernel 
- mount filesystems
- start system services
5. Sys services started up, login screen appears


Details:
----------------------------------

1... BIOS:
- a small program installed on motherboard
- inits mouse, clock, keyboard,
- detec bootloader

2... Default boot-loader In RHEL is GRUB

3... GRUB loads kernel image

4... Kernel get control of boot process
- detects HW
- load device drivers from initramfs
. initramfs-$kernel-version.img
- mount root FS read-only
- init loaded
- init runs scripts in /etc/init
- /etc/inittab is read for default runlevel
- runlevel scripts started
- login screen appears













18.2 GRUB

18.2 GRUB
------------------------------------------


GRUB has 2 stages


1st Stage (runs in install)
small application witin master boot record
(or boot sector of the hard disk)

2nd Stage
Loaded from boot partition on the FS

[root@RHSCA-2 ~]# cat /boot/grub/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/VolGroup00/LogVol00
# initrd /initrd-version.img
#boot=/dev/sda
serial --unit=0 --speed=9600 --word=8 --parity=no --stop=1
terminal --timeout=10 serial console
default=0
# 5 seconds

timeout=5
#splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux Server (2.6.32-358.el6.i686)
// which harddisk to boot from
root (hd0,0)
kernel /vmlinuz-2.6.32-358.el6.i686 ro root=/dev/mapper/VolGroup00-LogVol00 rhgb
quiet console=tty0 console=ttyS0,9600n8 crashkernel=auto SYSFONT=latarcyrheb-sun16
LANG=en_US.UTF-8 KEYTABLE=trq
// initial ram disk file - to load device drivers and initial scripts
initrd /initramfs-2.6.32-358.el6.i686.img
title Red Hat Enterprise Linux Server (2.6.32-279.19.1.el6.i686)
root (hd0,0)
kernel /vmlinuz-2.6.32-279.19.1.el6.i686 ro root=/dev/VolGroup00/LogVol00 rhgb quiet console=tty0 console=ttyS0,9600n8
initrd /initramfs-2.6.32-279.19.1.el6.i686.img
#title Red Hat Enterprise Linux Server-base (2.6.18-274.17.1.el5)
# root (hd0,0)
# kernel /vmlinuz-2.6.18-274.17.1.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet console=tty0 console=ttyS0,9600n8
# initrd /initrd-2.6.18-274.17.1.el5.img



*How to change grub at startup
-----------------------------------------------

boot
enter grub menu
press a
delete rhgb quiet to see all system message

rhgb (red hat graphical boot) quiet

* How to protect startup-grub-modification
-------------------------------------------------

(keyword: security)

1.
[root@localhost ~]# grub-md5-crypt 
Password:
Retype password:
$1$3BR3I1$SOL9ZtqgvADwGKGgENDpb.

2. Copy the cryted pw in to grub.conf 
[root@localhost ~]# vim /boot/grub/grub.conf
….
password --md5 $1$3BR3I1$SOL9ZtqgvADwGKGgENDpb.
title Red Hat Enterprise Linux Server (2.6.32-358.el6.i686)
….

to-do-list
look at grub info pages







18.3 Upstart

18.3 Upstart
-----------------------------------------------

What is upstart?
Deftault system startup service

- upstart replaces old init system: SysV
- SysV iniy started services sequentially
- Upstart starts services in parallel
- Much faster boot

- init: first process (PID 1)
/sbin/init

[root@localhost ~]# pstree -p
init(1)─┬─NetworkManager(1793)─┬─dhclient(1836)
│ └─{NetworkManager}(1837)
├─abrt-dump-oops(1962)
├─abrtd(1950)
├─acpid(1819)
├─agetty(2055)
├─atd(2013)
├─auditd(1694)─┬─audispd(1696)─┬─sedispatch(1701)
│ │ └─{audispd}(1703)
│ └─{auditd}(1695)
├─bonobo-activati(2373)───{bonobo-activat}(2374)
├─clock-applet(2547)
├─console-kit-dae(2096)─┬─{console-kit-da}(2097)
│ ├─{console-kit-da}(2098)
│ ├─{console-kit-da}(2099)
│ ├─{console-kit-da}(2100)



After INIT Scripts: 
- /etc/init/rcS.conf
- /etc/rc.d/rc.sysinit
- read /etc/inittab for default runlevel

- /etc/rc.d/rc.sysinit
. hostname
. networking
. mount check FS
. run Plymouth // progress bar during boot
. set SELinux state
. msg to /var/log/dmesg

- /etc/inittab
. sets default runlevel

- /etc/init/rc.conf
. fires scripts in /etc/rc.dx.d/
// x: runlevel

// Other startup scripts
- /etc/sysconfig/init
. plymouth

- /etc/init/tty.conf
. creates terminals (ctrl+Alt+F1 to F6)

- /etc/init/
. other startup scripts

to-do-list
. man 5 init
. man 8 init
. read comments in script files




18.4 Runlevels pt- 1

18.4 Runlevels pt- 1
----------------------------------------------------

- there are 8 runlevels

- one level can be active at a time


0- halt (sys shutdown)
1- single user (for root user, rood pw reset, no network)
6 - reboot constantly reboot



[root@localhost ~]# runlevelN 5

* how to change runlevel on live system
--------------------------------------------------
telinit 3
Warn: Data may be lost

* How to change runlevel
--------------------------------------------------

[root@RHSCA-2 ~]# cat /etc/inittab#
# inittab This file describes how the INIT process should set up
# the system in a certain run-level.
#
# Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
# Modified for RHS Linux by Marc Ewing and Donnie Barnes
#

# Default runlevel. The runlevels used by RHS are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#
id:5:initdefault:

Note: telinit 6 can be used to reboot







18.5 Runlevels pt- 2

18.5 Runlevels pt- 2
--------------------------------------------------------------------------

* How to chg runlevel startup-bootloader menu
-----------------------------------------

. reboot
. press any key
. press a
append “1” for runlevel 1 (at the end)
. enter


* you can change root pasw in single user w/o entering old passw
* How to prevent root pw chg in single user mode
-----------------------------------------

(key: security)

1.
vim /etc/sysconfig/init

// change last line
# SINGLE=/sbin/sushell
SINGLE=/sbin/sulogin



[root@RHSCA-2 ~]# cat /etc/init/rc.conf 
# rc - System V runlevel compatibility
#
# This task runs the old sysv-rc runlevel scripts. It
# is usually started by the telinit compatibility wrapper.

start on runlevel [0123456]

stop on runlevel [!$RUNLEVEL]

task

export RUNLEVEL
console output
exec /etc/rc.d/rc $RUNLEVEL

[root@RHSCA-2 ~]# ls /etc/rc.d/
init.d rc rc0.d rc1.d rc2.d rc3.d rc4.d rc5.d rc6.d rc.local rc.sysinit

// K=Kill, S=Start, 01 is the second process to be killed/started on RUNLEVEL 5
// symbolic links

[root@localhost ~]# ls /etc/rc.d/rc5.d -l
total 0
lrwxrwxrwx. 1 root root 17 May 12 15:13 K00ipmievd -> ../init.d/ipmievd
lrwxrwxrwx. 1 root root 16 May 12 15:13 K01smartd -> ../init.d/smartd
….
lrwxrwxrwx. 1 root root 17 May 12 15:13 S01sandbox -> ../init.d/sandbox
lrwxrwxrwx. 1 root root 17 May 12 15:13 S01sysstat -> ../init.d/sysstat


* What happened when smart is enabled?
-------------------------------------------

[root@localhost ~]# ls /etc/rc.d/rc5.d -l | grep smartd
lrwxrwxrwx. 1 root root 16 May 12 15:13 K01smartd -> ../init.d/smartd

[root@localhost ~]# chkconfig --list smartd
smartd 0:off 1:off 2:off 3:off 4:off 5:off 6:off

[root@localhost ~]# chkconfig smartd on
[root@localhost ~]# chkconfig --list smartd
smartd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

[root@localhost ~]# ls /etc/rc.d/rc5.d -l | grep smartd
lrwxrwxrwx. 1 root root 16 Aug 2 14:37 S99smartd -> ../init.d/smartd

// halt level

[root@RHSCA-2 ~]# ll /etc/rc.d/rc0.d/
total 0
lrwxrwxrwx. 1 root root 17 Apr 13 16:48 K00ipmievd -> ../init.d/ipmievd
lrwxrwxrwx. 1 root root 16 Apr 13 16:48 K01smartd -> ../init.d/smartd
lrwxrwxrwx. 1 root root 19 Apr 13 16:44 K02rhsmcertd -> ../init.d/rhsmcertd










18.6 Powering Down the System

18.6 Powering Down the System
------------------------------------------------
// inform other users about reboot
[root@localhost ~]# shutdown -r +5

Broadcast message from root@localhost.localdomain
(/dev/pts/0) at 12:49 ...

The system is going down for reboot in 5 minutes!

// how to cancel a reboot
[root@localhost ~]# shutdown -c
shutdown: Shutdown cancelled


How to schedule a shutdown ?
--------------------------------


// -h: halt
shutdown -h 21:20 "System will be shutdown at 9:20pm this evening..."

Broadcast message from root@localhost.localdomain
(/dev/pts/0) at 12:55 ...

The system is going down for halt in 605 minutes!
System will be shutdown at 11pm...

NOTE: 5 mins prior to shutdown no user login will be permitted


How to schedule a reboot ?
--------------------------------
[root@RHSCA-2 ~]# shutdown -r 09:20

Broadcast message from root@RHSCA-2
(/dev/pts/0) at 9:13 ...

The system is going down for reboot in 7 minutes!
^Cshutdown: Shutdown cancelled


// shutdown immidiately
[root@localhost ~]# shutdown -h now











19. System Recovery
19.1 Basic Troubleshooting


19.1 Basic Troubleshooting
-------------------------------------------------------

System Logs:
--------------------------------

1st
/var/log/messages

2nd
// parse the log
// sealert -a /var/log/audit/audit.log 

/var/log/audit/audit.log

3rd
/var/log/secure

4th
service logs files – http, ftp etc..


Slow system
--------------------------------


// CPU, memort problems:
gnome-system-monitor
top
ps
renice // chg process priorities


// Disk Space and memory usage
df -h
du -h .

[root@RHSCA-2 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00 16G 4.0G 11G 27% /
tmpfs 504M 224K 504M 1% /dev/shm
/dev/sda1 97M 43M 49M 47% /boot
/dev/mapper/VolGroup00-LogVol03
1008M 34M 924M 4% /gman

// summary
[root@RHSCA-2 ~]# du -hs /tmp/
1.2M /tmp/

[root@RHSCA-2 ~]# du -h /tmp/
4.0K /tmp/keyring-Vk7FJD
4.0K /tmp/keyring-xIF0Cp
4.0K /tmp/keyring-fnTGXv
4.0K /tmp/keyring-LebmVF
4.0K /tmp/keyring-fnKEWe

// RAM and swap space in Megabyte
[root@RHSCA-2 ~]# free -m
total used free shared buffers cached
Mem: 1006 384 621 0 15 203
-/+ buffers/cache: 165 841
Swap: 0 0 0

// HW problems
fdisk -l // if kernel detect the hard disk
lspci // pci devices
lsusb // usb devices
dmidecode // BIOS version

// Service problems
system-config-services
chkconfig -list
service <name> status
- check config files

- check service logs
- security context and permissions are set correctly



19.2 Network Troubleshooting

19.2 Network Troubleshooting
--------------------------------------------------------------

Problem Definition:
Unable to access www.redhat.com

[root@localhost ~]# service NetworkManager status
NetworkManager (pid 1808) is running...

[root@localhost ~]# service network status
Configured devices:
lo eth0 eth1 eth2 eth3
Currently active devices:
lo eth0 eth1 eth2 eth3

[root@localhost ~]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:ba:39:ec brd ff:ff:ff:ff:ff:ff
inet 192.168.136.3/24 brd 192.168.136.255 scope global eth0
inet6 fe80::20c:29ff:feba:39ec/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:ba:39:f6 brd ff:ff:ff:ff:ff:ff
inet6 fe80::20c:29ff:feba:39f6/64 scope link
valid_lft forever preferred_lft forever

// DNS server
[root@localhost ~]# cat /etc/resolv.conf
# Generated by NetworkManager
domain localdomain
search localdomain
nameserver 192.168.136.2

// dig command – to check DNS query - part of the bindutils pack
[root@localhost ~]# dig www.redhat.com

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.10.rc1.el6_3.6 <<>> www.redhat.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56880
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;www.redhat.com. IN A

;; ANSWER SECTION:
www.redhat.com. 5 IN CNAME wildcard.redhat.com.edgekey.net.
wildcard.redhat.com.edgekey.net. 5 IN CNAME wildcard.redhat.com.edgekey.net.globalredir.akadns.net.
wildcard.redhat.com.edgekey.net.globalredir.akadns.net. 5 IN CNAME e1890.b.akamaiedge.net.
e1890.b.akamaiedge.net. 5 IN A 184.26.247.214

;; Query time: 164 msec
;; SERVER: 192.168.136.2#53(192.168.136.2)
;; WHEN: Sun Aug 4 13:17:11 2013
;; MSG SIZE rcvd: 191

// route table
[root@localhost ~]# ip route show
192.168.136.0/24 dev eth0 proto kernel scope link src 192.168.136.3 metric 1
default via 192.168.136.2 dev eth0 proto static

[root@localhost ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.136.0 * 255.255.255.0 U 1 0 0 eth0
default 192.168.136.2 0.0.0.0 UG 0 0 0 eth0

// !!! Temp change
// add default route
route add default gw 192.168.136.2 dev eth0( route del -net default gw 192.168.136.8 eth0 )

[root@RHSCA-2 ~]# cat /etc/sysconfig/network
NETWORKING=yes
#HOSTNAME=localhost.localdomain
HOSTNAME=RHSCA-2
GATEWAY=172.16.82.1 // ??? 

// !!! Permanent change
15.4. Configuring Static Routes
create
/etc/sysconfig/network-scripts/route-eth0
default via 192.168.136.2 dev eth0

//Check
[root@RHSCA-2 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0 
DEVICE="eth0"
BOOTPROTO="static"
DNS1=
GATEWAY="192.168.136.2"
HWADDR="00:0c:29:35:62:98"
IPADDR="192.168.136.10"
IPV6INIT="yes"
NETMASK="255.255.255.0"
NM_CONTROLLED="no"
ONBOOT="yes"


// restart network devices
service network restart














19.3 The Rescue Environment


19.3 The Rescue Environment
------------------------------------------------------------

You may not need to use rescue in the exam but
Exam Requirement is:
to know How to use the rescue env.

PROBLEM:
fstab changed

// temp chg the root for easy use
chroot /mnt/sysimage

// How to scp files to another server
// investigate secure logs to see who altered "fstab" file 

scp /var/log/secure root@192.168.136.12:/root

!!! exit shell to reboot

password for /dev/sdd1 (luks-fcf...)

TIPS:
How to setup SSH Server
----------------------------------
1.
[root@localhost ~]# chkconfig --list sshd
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

2. Allow SSH on firewall

3.
[root@RHEL-RHSCA-1 ~]# vim /etc/ssh/sshd_config
PermitRootLogin no
19.4 User Account Troubleshooting

19.4 User Account Troubleshooting
-------------------------------------------------------------


Problem:
User alex is unable to login

// seems fine
[root@localhost ~]# cat /etc/passwd
alex:x:501:501::/home/alex:/bin/bash

// Problem-1
// !! means passwd of alex is locked
How to create the problem:
[root@RHSCA-2 gdm]# passwd -l alex

// Solution-1
// remove "!!"

[root@localhost ~]# cat /etc/shadow
tcpdump:!!:15808::::::
lucent:$1$cOQM3OSi$YR1S5SzNIV3IoyV3hl7Pe/:15808:0:99999:7:::
alex:!!$1$SV.x.Fys$8Bc6awaYkLvrtAkHTs5ND/:15921:0:99999:7:::

or
// Solution-2
[root@localhost ~]# system-config-users 

// Problem-2
// alex home dir owned by root
[root@localhost ~]# ls -ld /home/alex/
drwx------. 27 root root 4096 Aug 4 14:25 /home/alex/

chown -R alex:alex /home/alex
[root@localhost ~]# ls -ld /home/alex/
drwx------. 27 alex alex 4096 Aug 4 14:25 /home/alex/









20. Virtual Machines
20.1 Introduction to Virtualization

20.1 Introduction to Virtualization
---------------------------------------------------------


Virtual Machine : guest
Server runs all the guests: host

Hypervisor: Special SW host runs for virtualization
. RHEL6 uses KVM as hypervisor SW

KVM: Kernel-based Virtual Machine

Virtualization Tools:
virsh: cmd line tools for guest management
virt-manager – gui end for libvirt

To-do-list
use virsh and virt-manager

*** In order to use KVM
must have 64-bit processors is a must for virtualization
cat /proc/cpuinfo | grep “vmx \| svm”
. if output is vmx or svm, KVM can be used
. no output, KVM cannot be used

***How to setup Virtualization
yum groupinstall Virtualization

[root@localhost ~]# yum install libvirt

[root@localhost ~]# service libvirtd start
Starting libvirtd daemon: [ OK ]

yum install virt-manager

**KVM Guest Info

1. Guest XML File
. how much RAM to use
. how many CPU to be used
. XML config files are located:
. Location of hard disk image file
/etc/libvirt/qemu/<name-of-guest>.xml

2. Guest Hard Disk file:
. image files (*.raw or *.qcow format ending .img extension)
. Hard disk files located
/var/lib/libvirt/images

Note: Check security context in those files, SELinux apply to them.
To-do-list
take a look at

https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Virtualization_Getting_Started_Guide/index.html

mang pages
man virsh
man virt-viewer
20.2 virsh

20.2 virsh
------------------------------------------------------------------

*** RHSCA Exam expect to configure a host to use virtual machines

How to manage guest on a host to use virtual machines
-------------------------------------------
[root@virt02 ~]# virsh
Welcome to virsh, the virtualization interactive terminal.

Type: 'help' for help with commands
'quit' to quit

virsh # nodeinfo
CPU model: i686
CPU(s): 1
CPU frequency: 2534 MHz
CPU socket(s): 1
Core(s) per socket: 1
Thread(s) per core: 1
NUMA cell(s): 1
Memory size: 1030680 KiB

virsh # list --all
Id Name State
----------------------------------------------------
9 RHEL6 running

virsh # shutdown guest1
error: Domain not found: No domain with matching name 'guest-1'

virsh # start guest1
error: Domain not found: No domain with matching name 'guest-1'

// ungraceful shutdown
virsh # destroy guest1

virsh# dominfo RHEL6
Id: -
Name: RHEL6
UUID: 9078a4b7-f1b5-71a2-43dc-7e3e000bc0ce
OS Type: hvm
State: shut off
CPU(s): 1
Max memory: 1048576 kB -> the unit should be KiB or k
Used memory: 1048576 kB -> the unit should be KiB or k
Persistent: yes
Autostart: enable // start when host system start
Managed save: no
Security model: selinux
Security DOI: 0

// enable autostart with the host 
virsh# autostart RHEL6
Domain RHEL6 marked as autostarted

// disable autostart with the host 
virsh# autostart rhel63 --disable
Domain rhel63 unmarked as autostarted

to-do-list
install a guest



20.3 virt-manager pt. 1

20.3 virt-manager pt. 1 & 2
---------------------------------------------------------


Applications >Virtual Machine Manager

to-do-list
install a 64-bit host RHEL6 on Win7 to use Virtual Machine Manager


virt-manager pt- 2

RHCSA EXAM:
To Create Red Hat guest

VMM gui > Disk 1 > advanced > storage format 
Disk Bus: Virtio // better performance, guest knows it is virtual mach.

to-do-list
create a new virtual machine using Virtual Machine Manager

20.4 virt-manager pt. 2


Go to
20.3 virt-manager pt. 1 & 2
21. Getting Help

21. Getting Help - Forums
-------------------------------------------------------------


Forums
----------------------

https://www.centos.org/modules/newbb
http://www.linuxquestions.org/
http://forums.fedoraforum.org/
http://www.linuxforums.org/forum/red-hat-fedora-linux/


Mail Lists
----------------------
http://lists.centos.org/mailman/listinfo/centos
http://listserv.fnal.gov/archives/scientific-linux-users.html
https://admin.fedoraproject.org/mailman/listinfo/users

IRC
--------------

RHEL
freenode.net
# rhel

Centos
freenode.net
# rhel