You are on page 1of 29

Faculty of Automatic Control and Computer Engineering

Domain: Computer Engineering and Information Technologies

Master: Distributed Systems and Web Technologies


Academic Year: 2015 2016

Network Service
Management 1
System services
Processes
Basic system configuration

System services
start, stop and restart services

execute the script /etc/rc.d/init.d/service_name


with one of the following parameters:

start start the service


stop stop the serviciul
restart restart the service
status check the service status

The followin command can be used:


service service_name action

The list of services can be configured with:

ntsysv current runlevel


chkconfig all runlevels

[NSM I - 2015-2016]

Lecture 3 - Linux basics

2/29

System services
xinetd

xinetd daemon supervize services like ftp,telnet,


pop3 etc.
listens on all service ports for the services listed
in its configuration file and launches the
appropriate service for that request
Configuration file /etc/xinetd.conf
To enable or disable an xinetd service, edit its
configuration file in the /etc/xinetd.d directory.
To edit any of the xinetd configuration files or
change its enabled status - ntsysv or chkconfig

[NSM I - 2015-2016]

Lecture 3 - Linux basics

3/29

System services
chkconfig
Chkconfig configure system services:
Chkconfig [--list] [--add] [--del] [--level
runlevel_list ] service [action]

Runlevel_list list of runlevels where service is


enabled/disabled
action on/off to enable/disable the service
list display all registered services and all
setting for each runlevel
add add new service
del remove a registered service

[NSM I - 2015-2016]

Lecture 3 - Linux basics

4/29

System services
chkconfig usage example
$ echo "ndbd" > /etc/rc.d/init.d/ndbd
$ chmod +x /etc/rc.d/init.d/ndbd
$ cat ndbd
#!/bin/bash
# chkconfig: 345 98 50
#
| | |
#
| | | - priority for kill scripts
#
| |---- priority for start scripts
#
|-------- run levels at which to start service
# description: MySQL Cluster NDB daemon
ndbd
$ chkconfig --add ndbd
$ for i in 0 1 2 3 4 5 6; do ls rc$i.d/*ndb* ; done
rc0.d/K50ndbd
rc1.d/K50ndbd
rc2.d/K50ndbd
rc3.d/S98ndbd
rc4.d/S98ndbd
rc5.d/S98ndbd
rc6.d/K50ndbd
$ chkconfig --list ndbd
ndbd
0:off 1:off 2:off 3:on 4:on 5:on 6:off

[NSM I - 2015-2016]

Lecture 3 - Linux basics

5/29

Chkconfig and Upstart


Upstart regards a change in runlevel as an event
services use their old rc style init scripts.
Consequence -> you can still use chkconfig to
control these startup scripts or use the service
command to manipulate these services.
NOTE: setting up serial console you will have
to use an upstart job instead of the old way of
doing it through inittab (refer to course #2 and
http://www.codarama.be/drupal/?q=node/6).

[NSM I - 2015-2016]

Lecture 3 - Linux basics

6/29

Processes

Processes user program and daemons


Process state codes

running R - Running or runnable (on run queue)


sleep S - Interruptible sleep (waiting for an event to
complete)
wait D - Uninterruptible sleep (usually IO)
stopped T - Process is stopped or halted and can be
restarted by some other process
paging W - not valid since the 2.6.xx kernel
dead X - should never be seen
zombie Z - process terminated, but information is still
there in the process table.

Running mode

foreground interaction with user


background

[NSM I - 2015-2016]

Lecture 3 - Linux basics

7/29

Processes

All processes are created by a parent process


At boot: pseudoproces with PID=0 ,which executes the init
process (PID=1)
Init ancestor of all processes
Process = is an instance of a computer program that is
being executed.
Each process has an owner and a group
Access rights

When user starts the program, the process itself and all
processes started by that process will be owned by that user
Processes permissions to access files and system resources are
determined by using permissions for that user.
Users can control only their processes (except root)
Access rights inherited from parent

orphaned child process - PPID will be set to 1

[NSM I - 2015-2016]

Lecture 3 - Linux basics

8/29

Processes

ps list running processes

a all processes
u extended format
x include daemon processes
w print long lines

top displays currently running processes and


important information about them including their
memory and CPU usage

Program can run in background by adding & at


the end of the command line (become job)

jobs print all jobs


CTRL+Z -> process supsended and moved to
background
fg job move a process to foreground
bg job move a process to background

[NSM I - 2015-2016]

Lecture 3 - Linux basics

9/29

Process priority
Processes

have different priorities


Priority range:
-20 (high priority)
20 (less priority)
default 10

nice

n priority program

run a process with given priority

[NSM I - 2015-2016]

Lecture 3 - Linux basics

10/29

Interprocess communication

Signals is a limited form of inter-process communication


used in Unix, Unix-like, and other POSIX-compliant
operating systems
Signal - a number
Processes can redefine thir hignal handler or can ignore
some signals (excep SIGKILL and SIGSTOP)
Usual signals:

SIGHUP (1) - parent is terminated (used by system daemons


to reload the configuration file)
SIGINT (2) - interrupt a process
SIGQUIT (3) - terminate a process (CTRL+C)
SIGILL (4) - illegal instruction
SIGSEGV (11) - segmentation violation
SIGPIPE (13) - Write to pipe with no one reading
SIGTERM (15) process termination (request to terminate)

[NSM I - 2015-2016]

Lecture 3 - Linux basics

11/29

Interprocess communication

SIGUSR1 (16) - user define signal


SIGUSR2 (17) - user define signal
SIGCHLD (18) - child process terminated, stopped (or
continued)
SIGSTOP (23) - stop executing temporarily
SIGCONT (25) - continue if stopped

kill signal PID send a signal to a process


identified by PID
Users can sent signals only to its own processes
Root can send signals to all processes

[NSM I - 2015-2016]

Lecture 3 - Linux basics

12/29

Processes
/proc
/proc filesystem is a virtual filesystem that
permits communication between the Linux
kernel and user space.
Allmos all files are read-only
Can be used to modify kernel parameters
(/proc/sys)

[NSM I - 2015-2016]

Lecture 3 - Linux basics

13/29

/proc

/proc includes a directory for each running process


(including kernel processes) at /proc/PID

Directory name is the same with the process PID-ul


contains information about processes
Some examples:

[NSM I - 2015-2016]

/proc/PID/cwd - a symlink to the current working directory of the


process.
/proc/PID/exe - a symlink to the original executable file
/proc/PID/maps - the memory map showing which addresses
currently visible to that process are mapped to which regions in
RAM or to files.
/proc/PID/environ - a file containing the names and contents of the
environment variables that affect the process.
/proc/PID/status - a file containing basic information about a
process including its run state and memory usage
/proc/PID/mem - the memory of the process that accesses the
/dev/mem device
Lecture 3 - Linux basics

14/29

[NSM I - 2015-2016]

Lecture 3 - Linux basics

15/29

/proc

/proc/self/

/proc/bus/

A text listing of the file systems which are supported by


the kernel

/proc/fs

containing directories representing various buses on the


computer

/proc/filesystems

A symbolic link to the process directory of the program


that is looking at /proc

Exported filesystems

/proc/ide/

exists on systems with the IDE bus

[NSM I - 2015-2016]

Lecture 3 - Linux basics

16/29

/proc

/proc/net/

/proc/scsi/

information about any devices connected via a SCSI or


RAID controller

/proc/sys/

really useful information about the network stack

Access to dynamically-configurable kernel options


Directories representing the areas of kernel, containing
readable and writable virtual files.
It is recommendend to use sysctl to change the kernle
parameters

/proc/sysvipc/

containing memory sharing and IPC information


message queues (msg), semaphores (sem) and shared
memory (shm).

[NSM I - 2015-2016]

Lecture 3 - Linux basics

17/29

/sys

/sys

The sysfs filesystem is a special filesystem similar to /proc that is usually mounted on the /sys
directory
A goal of the sysfs filesystem is to expose the hierarchical relationships among the components
of the device driver model
starting with kernel 2.6 there's a new /sys directory for PnP configuration.
it's something like the /proc filesystem since the "files" represent information in the kernel
memory and are not on your harddrive.
each device which exists on your system has it's own directory which contains files showing the
resources allocated to it.
is also used for configuration using sysctl - interface for examining and dynamically
changing parameters in the BSD and Linux operating systems

In Linux, the sysctl is implemented as a wrapper around file system routines that access contents of files in the
/proc directory
The top level sysfs directory looks like:
block/
bus/
class/
dev/
devices/
firmware/
net/
fs/

[NSM I - 2015-2016]

Lecture 3 - Linux basics

18/29

/sys

/sys/devices/

/sys/bus/

contains a directory for each device driver that is loaded for devices on that particular
bus (this assumes that drivers do not span multiple bus types).

/sys/dev/

contains flat directory layout of the various bus types in the kernel.

/sys/drivers/

contains a filesystem representation of the device tree. It maps directly to the internal
kernel device tree, which is a hierarchy of struct device.

contains two directories char/ and block/. Inside these two directories there are
symlinks named <major>:<minor>. These symlinks point to the sysfs directory for the
given device

/sys/fs/

contains a directory for some filesystems. Currently each filesystem wanting to export
attributes must create its own hierarchy below fs/ (see ./fuse.txt)

The /sbin/sysctl command is used to view, set, and automate kernel


settings in the /proc/sys/ directory
To preserve custom settings, add them to the /etc/sysctl.conf file.

[NSM I - 2015-2016]

Lecture 3 - Linux basics

19/29

Disk partitioning

Disk partitioning commands

Create filesystem

fdisk, parted
mkfs (mkfs.ext3, mkfs.vfat, ...)

Tune filesystem parameters

tune2fs (for ext2 and ext3)

[NSM I - 2015-2016]

Lecture 3 - Linux basics

20/29

Filesystem automount

Filesystem mounting process is controlled via /etc/fstab file.


Structure: lines with 6 fields
1.
2.
3.
4.
5.

6.

Device name
Mount point
Filesystem type
Options (coma separated)
command to determine which filesystems need to be dumped. If the field
is not present, a value of zero is returned and dump will assume that the
filesystem does not need to be dumped.
order in which filesystem checks are done at reboot time (1 for root, 0 for
swap and other filesystems)

All filesystem in /etc/fstab are automatically mounted at system


boot (except the ones with noauto) and unmounted at system
shutdown
Mount options

defaults Use default options: rw, suid, dev, exec, auto, nouser, and
async.
ro readonly
nosuid Do not allow SUID or SGID bits to take effect.
noauto Can only be mounted explicitly
user Allow an ordinary user to mount the filesystem.

[NSM I - 2015-2016]

Lecture 3 - Linux basics

21/29

Filesystem check and repair

Fsck program

Can run only on unmounted filesystems


(except root filesystem needs single user
mode

Executed at system boot if a filesystem


has errors or was unmounted successfully
Usage:

fsck device_name

lost+found directory location of files


recovered by fsck

[NSM I - 2015-2016]

Lecture 3 - Linux basics

22/29

Filesystem usage control

Quota - specify limits on two aspects of disk storage: the


number of inodes a user or a group of users may possess;
and the number of disk blocks that may be allocated to a
user or a group of users.
Two kind of limits:

Soft limits: indicates the maximum amount of disk usage a


quota user has on a partition; user receive warnings on his
disk usage and receives a grace period
Hard limits: works only when grace period is set

filesystem has their own limits setings


Useful commands:

quotaon initalize system quota


quotaoff disable sustem quota
setquota set quota limits

[NSM I - 2015-2016]

Lecture 3 - Linux basics

23/29

Installing Packages
- package managers

RPM

Specific to: RedHat, Fedora, CentOS, Suse, Mandriva,RedFlag,


Yellow Dog Linux, TurboLinux, Scientific Linux etc.
initial name: Red Hat Package Manager
actual name: RPM package manager
Presents an uniform way to install/uninstall applications
Support an non-interactive mode useful in install automation
Sources delivered as srpm package to verify authenticity an
MD5 check sum is provided
Criticized for package name inconsistency difficulties in
resolving dependencies
The problem doesn't resides in the rpm format, it comes
from the rpm building rules implemented by various Linux
distributions that use it

[NSM I - 2015-2016]

Lecture 3 - Linux basics

24/29

Installing Packages
- package managers

RPM

Package database located in /var/lib/rpm


Store informations about all installed packages
The database

[NSM I - 2015-2016]

It uses Berkeley DB as its back-end


Used to keep track of installed packages using rpm
command
If the database gets corrupted (which is possible if
the RPM client is killed), the index databases can be
recreated with the rpm --rebuilddb command

Lecture 3 - Linux basics

25/29

Installing Packages
- package managers

YUM - Yellowdog Updater, Modified

command-line package-management utility for RPM-compatible Linux


operating systems
Started as a full rewrite of its predecessor tool, Yellowdog Updater
(YUP), yum evolved primarily in order to update and manage Red Hat
Linux systems used at the Duke University department of Physics
packages are grouped into repository (metadata can be stored in XML
or in sqlite database)
solve the problem of dependencies
Plug-in/module system for extensions (Python API)
Files:

/etc/yum.repos.d/*.repo - Repository config files


/etc/yum.conf yum config files

[NSM I - 2015-2016]

Lecture 3 - Linux basics

26/29

Yum .repo file


# CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#mirrorlist=http://mirrorlist.centos.org/?release=6.5&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
#baseurl=ftp://192.168.243.80/pub/CentOS/x86_64/6.5
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#released updates
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
#mirrorlist=http://mirrorlist.centos.org/?release=6.5&arch=$basearch&repo=updates
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
#baseurl=http://mirror.centos.org/centos/6.5/updates/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

[NSM I - 2015-2016]

Lecture 3 - Linux basics

27/29

Reading assignment

The Linux System Administrator's Guide


Chapters 5,6,7

[NSM I - 2015-2016]

Lecture 3 - Linux basics

28/29

References
This presentation is intended for lecturing purposes only and it is based on the references
listed below. Therefore, the students are encouraged to (and they should) read
thoroughly the original documents listed below in order to improve their skills.
1.
Matthew West - The Linux System Administrator's Guide
http://www.learnlinux.org.za/courses/build/fundamentals/index.html
2.

Advanced Bash-Scripting Guide


http://www.tldp.org/LDP/abs/abs-guide.pdf

3.

The Linux System Administrators' Guide


http://www.tldp.org/LDP/sag/sag.pdf

4.

The Linux Network Administrator's Guide, Second Edition


http://www.tldp.org/LDP/nag2/nag2.pdf

5.

Securing & Optimizing Linux: The Ultimate Solution


http://www.tldp.org/LDP/solrhe/Securing-Optimizing-Linux-The-Ultimate-Solution-v2.0.pdf

6.

Red Hat Enterprise Linux Documentation


https://access.redhat.com/knowledge/docs/Red_Hat_Enterprise_Linux/

7.

Filesystem Hierarchy Standard


http://www.pathname.com/fhs/pub/fhs-2.3.pdf

8.
9.
10.
11.
12.

http://en.wikipedia.org/wiki/Procfs
http://linux.die.net/man/5/proc
http://linux.die.net/man/8/mount
sysfs - The filesystem for exporting kernel objects.
https://www.kernel.org/doc/Documentation/filesystems/sysfs.txt
Daniel P. Bovet, Marco Cesati, Understanding the Linux Kernel - Third Edition, O'Reilly, 2005

[NSM I - 2015-2016]

Lecture 3 - Linux basics

29/29

You might also like