Module 2 - System Administration
Module 2 - System Administration
●
Service startup
●
Daemons are processes that wait or run in the background
performing various tasks.
●
Daemons start automatically at boot time and continue to run until
shutdown or until they are manually stopped.
●
Service often refers to one or more daemons.
●
Service units have a .service extension and represent system
services.
The init process (History)
# systemctl get-default
Commands
●
reboot the system
# Init 6
# systemctl reboot
●
Shut down and halt the system
# Init 0
# systemctl halt
●
Shut down and power-off the system
# systemctl poweroff
●
System shutdown immediately
# shutdown -h now
●
system shutdown after 10 minutes
# shutdown -h + 10
●
system will be rebooted at 14:30
# shutdown –r 14:30
Linux services
●
Linux services are called deamons, out of them, the following are
most widely used: By convention, the names of many daemon
programs end in the letter “d”.
●
List the state of all units to verify a system startup
# systemctl
●
List a service is active and show if the unit is enabled at boot time.
●
List the active state of all loaded units. The –-all option will add
inactive units
●
Command syntax
Example
●
To enable a service so it starts automatically at boot time, type the
following:
●
To disable a service so it doesn't start automatically at boot time,
type the following:
●
Command to display the run level mode
#runlevel
●
Service command
Network configuration
Outline
●
In this Lesson we will learn about:
●
TCP/IP primer
Introducing TCP/IP
IP addresses
Network and host components
CIDR notation
A typical internet
IP routing decisions
The routing table
MAC addresses
The ARP protocol
The ARP cache
The naming of network interfaces
Services and port numbers
The /etc/services file
Traceroute
●
Tracing data path from US (Netwok-tools.com) to Ethiopia (AAiT)
– Select “Trace” and click “Go”
Hop (ms) (ms) (ms) IP Address Host name
1 0 0 0 206.123.64.233 - Missouri, US
2 1 1 1 129.250.202.253 xe-0-4-
012.r01.dllstx04.us.bb.gin.ntt.net Colorado, US–NTT America (ISP)
3 1 1 1 89.221.40.162 ae0.dallas2.dal.seabone.net
Dallas, US – NTT America (ISP)
4 362 343 342 185.70.202.2 - Italy, RIPE ISP
5 386 386 385 185.70.202.9 - Italy, RIPE ISP
6 404 403 404 197.254.194.22 - Sudan
7 Timed out Timed out Timed out
Introducing TCP/IP
●
Linux systems communicate using a protocol suite called TCP/IP
– IP is a network layer protocol and is responsible for routing packets across
an interconnected set of networks (an “internet”) to the correct machine
IP address 192.168.0.5
Network and host components
●
An IP address is divided into two parts: a network ID and a host ID
– The network ID is used to route packets to the correct network
– The host ID is used to deliver packets to the correct host on the network
●
A subnet mask defines how an IP address is split between network
and host components
255.255.255.0
Network ID Host ID
CIDR notation
●
CIDR (Classless Inter-Domain Routing) notation allows an interface's
IP address and subnet mask to be represented compactly:
192.168.0.5/24
The number of bits in the
IP address that should be
interpreted as the network ID
A B C D 176.13.4.92
The Internet
P Q R S
●
IP decides how to route a packet to its destination based on the
network component of the destination IP address
Example:
Do I have a direct Yes Send the packet
connection to A to C
on this connection
this network?
No
Send the packet
Do I know a route Yes A to Q
to the IP address
to this network? via S
specified in the
routing table
No
Yes Send the packet A to the
Do I have a
default gateway? to the default outside world
gateway via D
No
Network unreachable
The routing table
●
Linux holds IP routing information in an internal routing table
– May be displayed with the command route -n
– This example is from machine 'A' and has been edited to fit the page:
# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Iface
192.168.0.0 0.0.0.0 255.255.255.0 U eth0
192.168.1.0 192.168.0.254 255.255.255.0 U eth0
0.0.0.0 192.168.0.4 0.0.0.0 UG eth0
●
The most specific matching route (the one with the longest
“Genmask”) is used
– The packet is sent to the specified gateway via the specified interface
The routing table explained
●
First entry:
– Says that the local network (192.168.0.0/24) is connected directly to the
network interface called eth0. There is no gateway (the IP address is
shown as 0.0.0.0)
●
Second entry:
– Says that packets destined for the network 192.168.1.0/24 should be sent
to the gateway 192.168.0.254 using network interface eth0
●
Third entry:
– This route always matches because the “genmask” is zero
– Specifies 192.168.0.4 as the default gateway
– Says where to send the packet if there is no more specific match
Routing table flags
●
The flags in the fourth column of the routing table show how the
kernel will interpret the entry and have the following meanings:
●
! - learned routes for network are rejected
●
A – route added by addconf (an IPv6 address resolution protocol )
●
C – cache entry
●
D – route created by a routing daemon or ICMP redirect
●
G – use the gateway given in the Gateway column for traffic going to the
network specified in the routing entry
●
M – route has been modified by a routing daemon or ICMP redirect
●
R – reinstate routing to permit routing updates for this particular routing
entry
●
U – network route is created (up) and will be used by kernel to make
routing decisions
MAC addresses
●
When an IP packet is transmitted on a physical medium (eg ethernet)
it is encapsulated inside a frame which includes the physical address
(“MAC address”) of the network interface it is being sent to
●
The MAC address is permanently assigned to the interface
– 48 bits; written in hex with colons, e.g. 00:06:5B:BA:6E:FB
A B C
00:06:44:6C:E6:8A 00:06:5B:B6:54:B9 00:06:5B:BA:6E:FB
IP Datagram 00:06:5B:BA:6E:FB
The ARP protocol
●
ARP (address resolution protocol) is used to discover MAC addresses
A B C
00:06:44:6C:E6:8A 00:06:5B:B6:54:B9 00:06:5B:BA:6E:FB
●
To avoid an ARP broadcast prior to every transmission, known IP-to-
MAC address bindings are stored in the ARP cache
– The cache is always consulted first
– Entries remain in the cache for about 15 minutes then time out
● The arp command can also be used to examine the cache and to
manually add or delete entries, though this is rarely necessary
– Show all entries:
# arp -a
– Add an entry:
# arp -s 192.168.0.3 00:60:97:1A:37:BF -i eth0 temp
– Add a permanent entry:
# arp -s 192.168.0.3 00:60:97:1A:37:BF -i eth0
– Delete an entry:
# arp -d 192.168.0.3
The naming of network interfaces
●
The linux kernel assigns names to network interfaces
Point-to-point dial-up
connection via modem
Ethernet interfaces
eno16777736 ppp0
ens33 lo
●
An IP address identifies a specific machine for packet delivery.
Beyond that, a port number identifies a specific service (application
program) to which data should be delivered.
– Port number is 16 bits
(0-65535) Web ftp ssh
●
To connect to a specific server server server
server, a client needs to
know the IP address of
the machine, and the
service's port number
80 21 22
– e.g. 192.168.0.5:80
●
TCP and UDP each has
its own set of ports
– TCP port 21 is not the
same as UDP port 21
192.168.0.5
The /etc/services file
●
There is a fixed, standardised association between services, the port
numbers at which they listen, and the protocols (TCP orUDP) they use
– Maintained by the Internet Assigned Numbers Authority (www.iana.org)
– Held in the /etc/services file
– Here is a heavily edited extract:
ftp-data
ftp-data 20/tcp
20/tcp ## File
File Transfer
Transfer [Default
[Default Data]
Data]
ftp
ftp 21/tcp
21/tcp ## File Transfer [Control]
File Transfer [Control]
ssh
ssh 22/tcp
22/tcp ## SSH
SSH Remote
Remote Login
Login Protocol
Protocol
telnet
telnet 23/tcp
23/tcp ## Telnet
Telnet
smtp
smtp 25/tcp
25/tcp mail
mail ## Simple
Simple Mail
Mail Transfer
Transfer
time
time 37/tcp
37/tcp ## Time
Time
time
time 37/udp
37/udp ## Time
Time
domain
domain 53/tcp
53/tcp ## Domain
Domain Name
Name Server
Server
domain
domain 53/udp
53/udp ## Domain Name Server
Domain Name Server
http
http 80/tcp
80/tcp ## World
World Wide
Wide Web
Web HTTP
HTTP
Configuring a network interface
●
Configuring a
network interface
●
Example:
# ifconfig
ens33 Link encap:Ethernet HWaddr 00:06:5B:BA:6E:FB
inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::206:5bff:feba:6efb/64 Scope:Link
UP BROADCAST NOTRAILERS RUNNING MULTICAST MTU:1500 Metric:1
RX packets:9749 errors:0 dropped:0 overruns:0 frame:0
TX packets:7215 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:8034188 (7.6 Mb) TX bytes:793559 (774.9 Kb)
Interrupt:10 Base address:0x3000
Configuring an interface with ip command
●
To show the ip address
#ip addr show
●
Display the statistics
#ip -s link
●
NetworkManager is a service that manages network connections, but
it doesn’t manage ip command assigned configurations
Configuring an interface with nmcli
● nmcli can also be used to configure interface settings temporarily:
# nmcli
Note: at this network demo exercise we should have add additional NIC from VirtualBox.
Note: after we add two additional NICs they can be reach Ips from DHCP or Static. Once they get IP we can
connect using the newly created IP to the server.
# systemctl restart NetworkManager --- then the newly changed IP will work.
Enable the interface
#nmcli con down “Wired connection 1”
●
Display NIC adapter
●
Display NIC adapter status
Configuring static IP
● # vi /etc/sysconfig/network-scripts/
● # Vi /etc/NetworkManager/system-connections
DEVICE=enp0s9
BOOTPROTO=none
ONBOOT=yes
NETMASK=255.255.255.0
IPADDR=192.168.1.15
USERCTL=no
GATEWAY=192.168.1.1
# nmcli connection down enp0s9
# nmcli connection up enp0s9
# systemctl restart NetworkManager
# nmcli connection show
# nmcli connectionn delete UUID ---- to delete the
connection by UUID.
Configuring an interface with nmcli (continued)
● Create adapter with new name: add additional NIC on the VMware
setting
# nmcli con add con-name test type ethernet ifname ens33
●
Assign IP address to the new adapter interface
# nmcli dev modify test ipv4.addresses 192.168.1.10/24
ipv4.method manual
●
Activate the new created adapter
# nmcli con up test
●
To delete adapter
# nmcli con delete test
●
Restart and enable network service using NetworkManager service
# systemctl restart NetworkManager
# systemctl enable NetworkManager
Configuring an interface with ip addr
●
Add Ip Addres using the following command
# ip addr add 192.168.30.62/24 dev enp0s3
# ip addr show enp0s3
●
To delete Ip Address
# ip addr del 192.168.30.63/24 dev enp0s3
●
Restart and enable network service using NetworkManager service
# systemctl restart NetworkManager
# systemctl enable NetworkManager
Configuring an interface with nmtui
●
A system can be configured to obtain network settings automatically
from a DHCP (Dynamic Host Configuration Protocol) server
– IP address, subnet mask, default gateway, DNS server, ...
– Settings are leased for a specified time; client must renew the lease
before it expires if it wants to keep using the settings
●
Advantages:
– No manual configuration needed. In particular, machines which often
move between different physical networks (e.g. laptops) do not have to
be manually re-configured each time
– IP addresses can be re-used – you can have more machines than you
have IP addresses if they are not all needed at once
●
Disadvantages
– You need a DHCP server
– Machines offering services (e.g. Web servers) cannot be guarenteed to
stay on the same IP address
● dhclient command runs a DHCP client software
Where are the network settings stored?
●
The permanent network settings for the interface eth0 are stored in
the file /etc/sysconfig/network-scripts/ifcfg-eth0
# vi /etc/sysconfig/network-scripts/ifcfg-ens33
●
For a statically configured
machine it might look like
this:
BOOTPROTO='static'
BOOTPROTO='static'
ONBOOT='yes'
ONBOOT='yes'
BROADCAST='192.168.1.255'
BROADCAST='192.168.1.255'
IPADDR='192.168.1.1'
IPADDR='192.168.1.1'
NETMASK='255.255.255.0'
NETMASK='255.255.255.0'
NETWORK='192.168.1.0'
NETWORK='192.168.1.0'
●
For a machine configured via BOOTPROTO='dhcp'
BOOTPROTO='dhcp'
DHCP it might look like this: STARTMODE='onboot'
STARTMODE='onboot'
Network Monitoring
●
Name resolution
Name services
Hostname
The /etc/hosts file
Domain Name resolution
The name service switch
Configuring a DNS client
Name services
●
Users prefer to identify computers using names, not IP addresses
– Simple names: server01, pluto, mars, galaxy, ...
– Fully qualified domain names:
server01.example.com, www.ftt.co.uk, …
●
Naming services translate names to IP addresses
●
The resolvers (doing the name lookup) can be made to look in several
places
– A local file (/etc/hosts)
– A NIS server (Network Information Service)
– A NIS+ server (successor to NIS)
– A DNS server (Domain Name Service)
Host Name
●
Host name configuration file /etc/hostname
$hostname server01
The /etc/hosts file
27.0.0.1
27.0.0.1 localhost
localhost localhost.localdomain
localhost.localdomain The loopback address
:1
:1 localhost
localhost localhost.localdomain
localhost.localdomain
192.168.1.1
192.168.1.1 server01
server01 server01.example.com
server01.example.com
●
DNS (Domain Name System) implements a distributed database of
machine name to IP address mappings, encompassing all “globally
visible” machines on The Internet
●
The implementation of DNS for UNIX / Linux is called BIND
– Berkeley Internet Name Domain
– Discussed next week
●
To use DNS, all that most computers need to know is the IP address
of a single (local) DNS server; the rest is magic
●
DNS can also do reverse lookups, to map IP addresses to host names
The name service switch
●
The only DNS 'client' command-line tools are diagnostic programs
such as dig and nslookup
●
The true DNS clients are the resolver functions in the C library
– They are configured by the file /etc/resolv.conf
●
Basic diagnostic
tools
to this address
$ ping -c2 -i5 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=47 time=188 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=47 time=189 ms
●
Overview: In this exercise we will perform basic configuration of the
network, assigning a hostname, a static IP address, a subnet mask
and a default gateway to each network interface.
●
We will configure our machines to do name resolution using a
combination of a local hosts file and DNS
●
We will test connectivity and name resolution on the network
●
Note: The machines are configured with a regular account called
'lpiuser' or using root user.
●
“Static” (permanent) routes can be added to the routing table using
the route command
– For the two-network intranet we saw earlier in the chapter:
# route add -net 192.168.0.0 netmask 255.255.255.0 gw
192.168.1.1 dev ens33
to reach this
send via this using this network ...
gateway ... interface
/etc/sysconfig/network-scripts/ifcfg-bond0
NIC Teaming/Bonding
/etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
ONBOOT=yes
IPADDR=192.168.1.150
NETMASK=255.255.255.0
BOOTPROTO=none
BONDING_OPTS="mode=active-backup"
GATEWAY=192.168.1.1
DEVICE=eth0
MASTER=bond0
SLAVE=yes
BOOTPROTO=none
ONBOOT=yes
NIC Teaming/Bonding config..
/etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=eth1
MASTER=bond0
SLAVE=yes
BOOTPROTO=none
ONBOOT=yes
DEVICE=eth2
MASTER=bond0
SLAVE=yes
BOOTPROTO=none
ONBOOT=yes
Bonding-Options
1- balance-rr (mode=balance-rr): This mode is known as balance-rr (Round-robin).
It provides load balancing and fault tolerance by transmitting packets in sequential
order to each network interface in the bond.
●
A machine needs to send an IP packet to address 192.168.9.44 from
an interface with an assigned address and subnet mask of
192.168.0.5/20. Can the packet be sent directly, or does it need to be
routed?
●
What is the name of the protocol used to convert IP addresses to MAC
addresses?
●
Which file defines the association between service names and port
numbers?
●
Name one advantage and one disadvantage of using DHCP to assign
network settings
●
Name three ways of doing name resolution
– Which file would you edit to specify the order in which these three ways
are tried?
Lesson 3: File system and storage management
●
The training should be begin by adding five disks on the VirtualBox
●
Native linux file system formats
●
Linux supports many file system formats
●
ext2
–Probably the most common 'native' linux file system format
●
ext3
–Extension of ext2 to support journaling (log of changes), backwards
compatible
–Much faster to check file system consistency after a crash
●
ext4
–ext4 file system is based on the ext3 file system and features a number
of improvements
●
Xfs
–xfs - is a highly scalable, high-performance file system
-This file system is selected by default and is highly recommended
File system formats of other systems
Linux also supports the native file systems of other operating systems
●
●
Linux can also mount file systems from remote file servers using a
number of file sharing protocols
NFS (Network File System)
●
–The native UNIX file sharing protocol, originally from Sun Microsystems
SMB (Server Message Block)
●
$ mkfs.xfs /dev/sda5
The ext4 file system format
• ext4 - The ext4 file system is based on the ext3 file system and
features a number of improvements.
•These include support for larger file systems and larger files, faster and
more efficient allocation of disk space, no limit on the number of
subdirectories within a directory, faster file system checking, and
more robust journaling.
$ mkfs.ext4 /dev/sda5
The ext3 file system format
• ext3 — The ext3 file system is based on the ext2 file system and has
one main advantage -journaling.
$ mke2fs -j /dev/sda5
The ext2 file system format
●
ext2 — file system supports standard Unix file types, including
regular files, directories, or symbolic links.
• It provides the ability to assign long file names, up to 255 characters.
• The maximum supported size of an ext2 file system in Red Hat
Enterprise Linux is currently 16 TiB
$ mke2fs /dev/sda5
The virtual file system
●
The linux kernel provides a virtual filesystem layer which hides the
differences between the physical filesystem layouts
–Supports standard UNIX open/close/read/write operations
–Providesillusion of UNIX filesystem semantics (e.g. rwx-style access
permissions on FAT filesystems)
Process
Partition management
●
Naming of partitions
Swap partitions
Partitioning guidelines
Partitioning examples
Primary Secondary
IDE Interface IDE Interface
Master Master
/dev/hda /dev/hdc
On a typical PC with
one hard drive and
one CD or DVD drive,
Slave Slave
the CD/DVD may be
/dev/hdb /dev/hdd
connected as hdb or
hdc
Naming of SCSI drives
SCSI controller
Second device
/dev/sdb
Third device
/dev/sdc
Naming of partitions
●
The simplest partitioning scheme is to put the entire file system into the
root partition
–Easy, no need to make any up-front decisions about partition sizes
●
However, there are good reasons for using more partitions
–Keeping the root partition small minimises the amount of file system
that must be intact and available for the system to boot successfully
–Partitions provide a crude way to impose disk space quotas on pieces of
the file system
–Partitions
are the “unit of administration” of the file system (e.g. Repair,
backup and restore of the file system is on a per-partition basis)
–Partitions
for “static” pieces of the filesystem (e.g. /usr) can be
mounted read-only, improving security
–If
your file system spans multiple hard drives, you necessarily have
multiple partitions
Partitioning guidelines (continued)
–/boot On early PCs this partition needs to be within the first 1024
cylinders. Suggested minimum size 50 Mbyte.
–/home On a server, this partition may be exported to client machines
This is likely to be the largest partition
–/tmp Hard to give a specific guideline on the size but 1 Gbyte is
probably
more than enough
–/opt
Partitioning example: dual-boot desktop machine
/boot partition Linux root partition Linux swap Linux /opt partition
/dev/hda1 /dev/hda2 /dev/hda3 /dev/hda4
/home partition
/dev/hdb1
# fdisk -l /dev/sda
Disk /dev/sda: 85.9 GB, 85899345920 bytes, 167772160 sectors
(parted) print
# fdisk /dev/sda
Display the existing
Command (m for help): p
partition table
Disk /dev/sda: 255 heads, 63 sectors, 3648 cylinders
Units = cylinders of 16065 * 512 bytes
#partprobe
It is apparently necessary
to reboot to force the
kernel to use the new table
Creating a file system
# mke2fs -j /dev/sda3
# mkfs.xfs /dev/sda3
●
To Create an ext4 file system
# mkfs.ext4 /dev/sda5
Mounting a file system
# mkdir /media/new1
Now attach the partition to the mount point:
●
# cp -r /usr/share/man /media/new1
To unmount the partition:
●
In this exercise we will create two new disk partitions, each of 500 Mbytes, on
the free space on the hard drive. We will format one of these partitions as an
ext2 file system and the other as an ext4 file system. Create the first partition
using fdisk:
1. Log in as root
# fdisk /dev/sda
3. At the fdisk command prompt, enter the command 'p' to show the current
partition table.
How many partitions are currently defined? _____________________________
What are the device names of these partitions? _________________________
What is the highest cylinder number on the hard drive? __________________
What is the highest cylinder number currently in use in a partition? _______
continued ...
Exercise (continued)
4. Following the example in the notes, use fdisk to create an extended partition
(sda4) spanning the whole of the remaining free space on the disk
5. Print the partition table to verify the result.
Write down the device name of your new partition: _____________________
6. Write out the partition table and exit from fdisk
7. Back at the shell prompt, enter the command 'partprobe'.
8. After the machine has rebooted, log back in as root.
9. Following the example in the notes, create an ext2 filesystem with a journal on
the new partition.
( Be very careful not to re-format any of the other partitions. If you are in any
doubt what the device name of the new partition is, ask your instructor.)
Exercise (continued)
# ls -a /new1
What directory exists on an empty ext2 file system? ______________________
End of exercise
Partitioning using GUI
●
GParted enables point-and-click partition management, including
partition moving and resizing.
$ apt-get install gparted
Mount options and the fstab file
●
Mount options and
the fstab file
Mount options
Option Meaning
-r Mount the partition read-only
Mount a file system of the specified type (for example, ext2, ext3,
-t type iso9660, msdos, nfs, reiserfs, smbfs) Normally not necessary as mount
will figure out the file system type automatically
-a Mount all the file systems listed in /etc/fstab
-o noexec Do not allow files on this file system to be executed
-o nodev Do not allow device files to be recognised on this filesystem
-o nosuid Do not allow programs on this file system to run “set user ID”
-o ro Mount the partition read-only (same as -r)
-o remount Remount the partition (e.g. To change from read-only to read-write)
●
The fourth field in fstab supplies options to use with the mount
command.
The noauto option
●
–There
is a common requirement to allow non-root users to mount and
unmount removable media such as floppies, CDs and DVDs
–The user option allows ordinary users to mount and unmount this
filesystem. (Once mounted, only the user who mounted it can unmount
it)
●
Removable media allow the introduction of 'uncontrolled' files and may
carry security risks; e.g.
–A shell owned by root with the setuid bit on
–A device file entry for /dev/hda1 with mode rw-rw-rw
–Any malicious executable
There are mount options to eliminate these risks:
●
●
Plug the flash drive on the virtual machine and issue fdisk -l again
# fdisk -l
Disk /dev/sda: 255 heads, 63 sectors, 3648 cylinders
Units = cylinders of 16065 * 512 bytes
1. Modify your fstab so that the two partitions you previously created are
automatically mounted onto /new1 and /new2 when the system is
booted.
2. Reboot the system to verify.
Maintaining integrity of File Systems
●
Can run fsck to check or repair the filesystems of the target system
# fsck /dev/sda3
●
●
du displays disk usage statistics for directories
# du /etc/rc.d
Option Meaning
-c show grand total
-a show all file not just directories
-h human readable format as M (Megabytes) or G(Giga bites)
-S include subdirectories too
●
df file system info
# df /dev/sda3
Logical Volume Manager {PV, VG, and LV}
Logical Volume Manager {PV, VG, and LV}
# pvcreate /dev/sdg ---> to create Physical Volume (pv)
# pvs
---
# vgcreate vg_app /dev/sdg ---> to create Volume Group (vg)
# vgs
---
# lvcreate -L 40G -n lv_app vg_app ---> to create Logical
Volume (lv)
# lvs
---
# mkfs.xfs /dev/vg_app/lv_app ---> to format and create file
system
# mkdir /app
# mount /dev/vg_app/lv_app /app ---> to mount the drive
# df -Th
# vi /etc/fstab ---> to permanently mount the drive it should
be record on the fstab.
Logical Volume Manager {lvextend, vgextend}
# lvextend -L +20G /dev/vg_app/lv_app
# xfs_growfs /dev/vg_app/lv_app or # resize2fs
/dev/vg_app/lv_app – if it’s ext4 partition.
# lvs
# df -Th
1. clone server1 VM
2. on server1, add 100 GB for App Partition
3. create Volume:
# pvcreate /dev/sdb
# vgcreate vg_app /dev/sdb
# lvcreate -L 70G -n lv_dba vg_dba
# mkfs.xfs /dev/vg_dba/lv_dba
# mount /dev/vg_dba/lv_app /dba
# df -Th
4. creating sample files on the /dba
# echo "Welcome to DBA Log File" >> dba1.log
# echo "Welcome to DBA Log File" >> dba2.log
# echo "Welcome to DBA Log File" >> dba3.log
5. power off server1 and remove attached 100 GB DBA disk
from the virtual Machine --- assume this server has failed.
6. power off server2 and attached 100 GB DBA disk from the
virtual Machine.
7. Power on Server2
Quiz
●
What is the device name for the slave IDE drive attached to the primary
IDE controller?
●
What is the device name for the first logical partition on the master IDE
drive attached to the secondary IDE controller?
●
In a long directory listing (i.e. The output of ls -l) what does it mean if
the first character on the line is a 'b'?
–In which directory might you find such an entry?
●
Give two reasons why you might prefer not to put the entire file system
of a linux system into the root partition
Assuming this line in /etc/fstab:
●
–Linux
can read the NTFS file system format as used by Microsoft
Windows
–Microsoft windows can read the ext2 file system as used by Linux
–On an ext2 file system the inode table is expanded on demand
–Only root can mount removable media into the file system
–All
the file systems listed in /etc/fstab are automatically mounted at
boot time
Lesson 4: Process management
Process management
Outline
●
In this lesson we will learn about:
✓ Examining processes
●
Process concepts
Processes
Typical process life cycle
Processes
●
A process represents an active instance of a program
●
Some processes are started by users
●
Typing commands on a command line
●
Selecting applications from a desktop menu
●
Some processes are started automatically, usually at boot time
●
Provide system sevices e.g. file servers, print services, web servers
●
Known as “daemons”
●
At any one time, a linux system is likely to have between 50 and 500
processes
●
Linux performs pre-emptive multitasking between processes allowing
them to share resources (including CPU time) on the computer
●
Each process has a numeric identifier, called its process ID (PID)
●
Systemd has process ID 1
Examining processes
●
Examining processes
●
A confusing set of option flags control which processes are shown and
how much detail is shown about each process
$ps aux
●
Process selection flags include:
Flag Meaning
x List processes that have no controlling terminal
a Show processes belonging to other users
U user Show processes owned by user
●
Process detail flags include:
Flag Meaning
l Show long format (more detail)
u Show detailed “user oriented” format
e Show the process environment
f Show processes as a hierarchical tree
“Long” process listings
●
The 'l' option provides additional detail for each process
$$ ps
ps ll
FF UID
UID PIDPID PPID
PPID PRI
PRI NI
NI VSZ
VSZ RSS
RSS WCHAN
WCHAN STAT
STAT TTY
TTY TIME
TIME COMMAND
COMMAND
00 00 3540
3540 3539 15
3539 15 0 2884 1700 wait4
0 2884 1700 wait4 SS pts/1
pts/1 0:00 /bin/bash
0:00 /bin/bash
00 00 3553
3553 2186 15
2186 15 0 2868 1648 schedu S
0 2868 1648 schedu S tty1
tty1 0:00
0:00 -bash
-bash
00 00 4107
4107 3540 19
3540 19 0 3680 1708 -
0 3680 1708 - RR pts/1
pts/1 0:00
0:00 ps ll
ps
$$
Memory
usage
ID of the Process status:
user running “NICE” value R Runnable
the process S Sleeping
Priority (lower values T Suspended
mean higher priority) Z Zombie
ID of the parent What the process
process is waiting for
ID of the process
“Long” process listings (continued)
●
The 'u' option shows a slightly different set of fields:
$$ ps
ps uu
USER
USER PID
PID %CPU
%CPU %MEM
%MEM VSZ
VSZ RSS
RSS TTY
TTY STAT
STAT START
START TIME
TIME COMMAND
COMMAND
root
root 3540 0.0 0.3 2884 1700
3540 0.0 0.3 2884 1700 pts/1 pts/1 SS 16:07
16:07 0:00 /bin/bash
0:00 /bin/bash
root
root 3553
3553 0.0
0.0 0.3
0.3 2868
2868 1648
1648 tty1
tty1 SS 16:07
16:07 0:00
0:00 -bash
-bash
root
root 4172 0.0 0.1 2668 720
4172 0.0 0.1 2668 720 pts/1 pts/1 RR 20:39
20:39 0:00
0:00 ps uu
ps
$$
├─NetworkManager───2*[{NetworkManager}]
├─VGAuthService
├─abrt-dbus───3*[{abrt-dbus}]
├─2*[abrt-watch-log]
├─abrtd
├─accounts-daemon───2*[{accounts-daemon}]
├─alsactl
├─at-spi-bus-laun─┬─dbus-daemon───{dbus-daemon}
│ └─3*[{at-spi-bus-laun}]
├─at-spi2-registr───2*[{at-spi2-registr}]
To list processes we can use glances
●
We can install atop and htop command to
view the system view
# Dnf install atop htop
Exercise: Using ps and top
●
Process priority and
job control
●
Process priorities are adjusted dynamically and cannot be set
explicitly
● The nice command adjusts the 'nice' level of a process which affects
its dynamic priority
●
Nice values range from -20 (highest priority) to +19 (lowest priority)
$ nice -7 firefox
●
Only root can start a process with negative niceness (nastiness?)
● The renice command adjusts the nice level of a running process
$ renice +1 -u lpiuser All processes owned by lpiuser
$ renice -2 1712 Process 1712 only
Job control in the shell
●
The bash shell is able to manage multiple jobs
●
Jobs can be started in the foreground – shell waits for it to finish
●
Jobs can be started in the background by appending '&' to the command –
shell prompts for another command immediately
●
The following job control commands are available:
jobs Lists the current jobs
^Z Stop (pause) the current foreground job
bg Restart a foreground job in the background
fg Bring a background job into the foreground
kill Terminate a job by job number and process by process ID
pkill Terminate a process by name
Job control in the shell (continued)
$$ sleep
sleep 120
120 && Job started in background
[1]
[1] 3197
3197 Shell reports job number and PID
$$ sleep
sleep 180
180 &&
[2]
[2] 3198
3198
$$ jobs
jobs
[1]-
[1]- Running
Running sleep
sleep
[2]+
[2]+ Running
Running sleep
sleep &&
$$ fg '+' indicates the current
fg job
Bring current job
sleep
sleep into foreground
[2]+ Stopped ^Z stops (pauses)
sleep the current job
[2]+ Stopped sleep
$$ kill
kill %1
%1
$$ fg
fg '%1' means job number 1
sleep
sleep
^C terminates the
[1]
[1] Terminated
Terminated xclock
foreground
xclock -update
job-update 11
Shell reports
termination of job 1
Exercise: Using job control
●
Signals, orphans and zombies
Sending signals
Signal types
Signal handlers
Orphan processes
Zombie processes
Getting rid of zombies
Sending signals
●
Signals are software interrupts delivered to a process by the kernel
– Linux defines over 30 signal types, kill -l will give the full list
●
Some signals can be generated by the terminal driver in response to
specific key combinations
– This only works for programs running in the foreground
^C Send SIGINT signal
^\ Send SIGQUIT signal
●
If a program is not running in the foreground, or has no attached
terminal, signals can be delivered using the kill command:
$ kill -15 4321
$ kill -SIGTERM 4321
Signals can only be sent to a process
$ kill 4321
by its owner (or by root)
● The killall command is similar but specifies
SIGTERM processes
is the default by by
type sent name
kill
$ killall -SIGHUP xinetd
● Manual page
$man 7 signal
Command man 7 signal lists signal types
Signal Default
Number Description
Name Handling
Most shells send this signal to all
Kill
1 SIGHUP child processes when they
process
terminate
Sent by terminal driver in response
Kill
2 SIGINT to ^C. Intended as a graceful
process
termination
Kill
Sent by terminal driver in response process
3 SIGQUIT
to ^\ and write
core dump
This signal cannot be caught or Kill
9 SIGKILL
ignored process
This is the default signal sent by Kill
15 SIGTERM
the kill command process
Causes a stopped or traced process Continue
18 SIGCONT
to continue process
Signal handlers
●
A process can elect how it wants to react on receipt of a signal by
nominating a handler for that signal type
– A function that will be called when the signal is delivered
– Within a shell script, the trap command defines signal handlers
●
If a handler is not specified, each signal type has a default behaviour
– For most signals, the default is to kill the process
– For some signals, the default is to ignore the signal
●
Signals 9 (SIGKILL) and 19 (SIGSTOP) cannot be caught or ignored
– Use SIGKILL as a last resort – the program has no opportunity to clean up
●
Some programs respond to a signal by re-reading their config file
– The SIGHUP signal is conventionally used for this
– Allows services to be re-configured on the fly without stopping them
Orphan processes
●
Sometimes, a parent process exits without waiting for its child(ren) to
finish
– Any children are automatically inherited by the init process
fork()
fork()
init
fork()
process
exit()
orphan
wait() exit()
Zombie processes
●
Occasionally, a parent process will not wait for its children but will
block on some other event
●
Processes that exit when no process is waiting for them become
'zombies'
– Cannot be laid to rest as they want to pass back their exit status
– Marked as <defunct> in a ps listing
– In the worst case, zombies accumulate and fill the process table so that
no more processes can be started
●
The way to get rid of zombies is to kill their parent
– The zombies will then be inherited by init
●
Zombies are generally a result of bad program design
Getting rid of zombies
●
Name four programs that allow you to display a list of processes
●
Describe the circumstances that lead to the formation of zombies
●
Which type of signal cannot be caught or ignored?
●
Which type of signal is sent by the terminal driver in response to ^C?
● Explain the difference between the commands kill 1 and kill %1
● In the output from ps l, what does an 'R' in the STAT column mean?
●
True or false?
– The ps command can display the processes running on a remote machine
– A program's priority can be set to a fixed level using the bash shell
– The command kill 1234 sends a SIGTERM signal to process 1234
– The top command can order processes based on %CPU utilisation
Lesson 5: Backup and recovery strategies
●
Archiving and
backup tools
Creating archives with tar
tar examples
Backing up and Restoring
Files from a tar Archive
Install from source code
Creating archives with tar
1. Following the examples in the notes, create two tar archives of the
files in /etc:
– The first should be called /tmp/etc.tar and should be uncompressed
– The second should be called /tmp/etc.tar.gz and should be gzipped
2. Compare the sizes of the files /tmp/etc.tar and /tmp/etc.tar.gz
– What compression factor is achieved? _____________________
3. List the files in the compressed archive and verify that the file motd is
present (hint: use grep)
4. Remove the file /etc/motd, using rm
5. Restore the file /etc/motd from the compressed archive and verify
that it is now present
●
Congratulations! You have created a tar archive and restored a file
from it.
Backing up and Restoring Files from a tar Archive
●
To backup a directory by creating a tar file
# tar czvf /tmp/etc.tar.gz /etc
●
To restore a directory content by extracting from a tar file:
# mkdir /backuptest Create target directory
# cd /backuptest
# tar xzvf /tmp/etc.tar.gz Extract to the target
Installing from source code: the pros and cons
●
Source distributions are most commonly supplied as “tarballs”
– Compressed archives built using the tar utility
● Here is the command sequence for building the net-snmp package
from source; it is very typical
● First, download the tarball net-snmp-5.1.tar.gz from a suitable
internet archive such as sourceforge.net, into /tmp (say)
●
We will learn how to use cron to run jobs at regular
intervals and to use at to run jobs at a specific time.
●
The key knowledge areas are:
– Cron Facility
– At Facility
– Cron Files
CRON, CROND & CRONTAB
●
A Cron is a time scheduled jobs on the Linux system. The
configuration template file is stored /etc/crontab
●
For any administrative tasks that have to be run regularly,
such as Back Ups and Network Services, then the cron
facility is the best way to do it.
●
The cron facility, consists of the crond daemon on Red hat
and cron on ubuntu.
●
crontabs - describing what work is to be done, when and
how frequently.
●
The daemon, which is started by systemd, wakes up every
minute and checks the crontab to determine what is to
be done.
●
Users manage crontabs using the crontab command.
CRONTAB File
●
To create a crontab, the crontab command with the (-e for
edit, -l for list ,-r for remove) option will open a text editor
where your specifications of the cron job can be specified.
#crontab [-u user] [-l | -e | -r] [file]
●
Every crontab entry will contain six fields:
●
Minute, hour, day of the month, month of the year, day of
the week and String to be executed by sh.
●
The respective ranges for the time fields are: 0-59, 0-23,
1-31 and 1-12, 0-7 (Sunday=0 or 7).
●
Start cron service
#systemctl restart cron
#systemctl enable cron
CRONTAB File
●
The basic usage of cron is to execute a job in a specific
time as shown below. This will execute the Full backup
shell script (full-backup) on 10th June 08:30 AM.
●
Please note that the time field uses 24 hours format. So,
for 8 AM use 8, and for 8 PM use 20.
30 08 10 06 * /home/ramesh/full-backup
30 – 30th Minute
08 – 08 AM
10 – 10th Day
06 – 6th Month (June)
* – Every day of the week
CRONTAB File (cont...)
●
The final field will always be interpreted as a string to
pass to the Bash
●
crontab -l -u (Display scheduled jobs by user)
●
crontab -r (Deletes scheduled jobs)
At Facility
●
Sometimes you just want to run a job once.
●
Linux provides the at command. The instructions to be
executed are read from a file specified with the -f option.
#at -f backup.sh
●
To display the time for the job to run, you can use the -v
#at -f backup.sh -v 05:45
●
Runs the script back up at 05:45
At Facility (cont...)
●
The at command also has a -q option. When used, this
option increases the nice value for the job.
●
For jobs scheduled using the at command, you can delete
them using the command with the job
●
atrm (deletes scheduled jobs using at command)
●
atq (lists scheduled jobs using at command)
Crontab Example
●
Add administrative task to crontab file
#crontab -e
*/1 * * * * echo “hello”>>~/crontest
●
Restart the cron service Administrative
#systemctl restart cron
●
Verify the scheduled task
#tail -f ~/crontest
More Examples
●
Add administrative task to crontab file
#crontab -e
*/1 * * * * ping -c 1 127.0.0.1
>>~/pingsuccess 2>>~/pingfailure
●
Restart the cron service Administrative
#systemctl restart cron
●
Verify the scheduled task
#tail -f ~/pingsuccess
at Example
●
Run administrative task using at command
#at -f pingtest.sh -v 17:48
Exercise
●
Copy pingtest.sh script and testservers.txt from flash disk
and save on /root directory.
●
Change the permission of pingtest.sh script
#chmod 777 /root/pingtest.sh
●
Add the following line in crontab
#crontab -e
*/1 * * * * /root/pingtest.sh
●
To verify run the following command
#tail -f ~/pingerr