Unit 4 MCAUnix
Unit 4 MCAUnix
System Administration:
Conventional disk file systems: ext2, ext3, ext4, XFS, Btrfs, JFS, NTFS,
etc.
Flash storage file systems: ubifs, JFFS2, YAFFS, etc.
Special-purpose file systems: procfs, sysfs, tmpfs, debugfs, etc.
File system hierarchy standards
The Linux system stores files according to a standard layout called the ‘file
system hierarchy’. The most common Linux directory structure is shown in
Figure 1.
[bhargab@localhost~]$man ls
This will provide the manual page of the ls command.
[bhargab@localhost~]$su
[bhargab@localhost~]$touch file1
cat is used to create and view a file. Type the following command to create a
file:
[bhargab@localhost~]$cat>file1
To view a file type, use the command given below:
[bhargab@localhost~]$cat file1
Copying a file: The cp command is used to copy a file from one location to
another, as shown below:
[bhargab@localhost~]$rm file1
Renaming and moving a file: The mv command is used to move and rename
a file. To move a file from one location to another, use the following command:
[bhargab@localhost~]$ls
This command simply lists the file name and directory name. To list all files in
your home directory, including the hidden files, type the following command:
[bhargab@localhost~]$ls –a
To view files in a‘long listing’format, type ls with the –l option, as follows:
[bhargab@localhost~]$ls –l
A portion of the output is shown below.
total 48
drwxr-xr-x. 2 bhargab bhargab 4096 Jan 25 21:32 Desktop
drwxr-xr-x. 2 bhargab bhargab 4096 Apr 24 16:33 Documents
drwxr-xr-x. 6 bhargab bhargab 4096 Jan 20 23:55 Downloads
-rw-rw-r--. 1 bhargab bhargab 1024 Apr 28 22:18 file1
-rw-rw-r--. 1 bhargab bhargab 1024 Apr 28 22:01 file2
-rw-rw-r--. 1 bhargab bhargab 1024 Apr 28 22:01 file3
drwxr-xr-x. 2 bhargab bhargab 4096 Dec 20 08:48 Music
drwxr-xr-x. 2 bhargab bhargab 4096 Dec 20 08:48 Pictures
drwxr-xr-x. 2 bhargab bhargab 4096 Dec 20 08:48 Public
drwxr-xr-x. 2 bhargab bhargab 4096 Dec 20 08:48 Videos
The total, 48, indicates that the total number of disk blocks occupied is 48.
There are nine columns in each of the lines. Each column in the succession
represents the following—permission, number of links, owner name, group
name, size in bytes, date and time, and file name. The permission field consists
of 10 sub-fields. The first field represents the type of file. The next three fields
represent owner (u) permission. The fifth, sixth and seventh fields represent
group (g) permissions. The last three fields represent other (o) permissions. ‘w’
represents write permission, ‘x’ represents execute permission and ‘r’
represents read permission.
[bhargab@localhost~]$pwd
/home/bhargab
This means that the current working directory is /home/bhargab/.
Creating a directory
The mkdir command is used to create a directory, as follows:
[bhargab@localhost~]$mkdir myDir
This will create a directory, myDir, under /home/bhargab/.
Removing a directory
The rmdir command is used to remove an empty directory, as shown below:
[bhargab@localhost~]$rmdir myDir
rmdir with the –p option removes not only the specified directory but also
parent directories.
[bhargab@localhost~]$rmdir – p myDir
++++++++++++++++++++++++++++++
Basic ConfigurationPermalink
These tips cover some of the basic steps and issues encountered during the beginning
of system configuration. We provide a general Getting Started guide for your
convenience if you’re new to Linode and basic Linux system administration.
Additionally, you may find our Introduction to Linux Concepts guide useful.
The first command should show your short hostname, and the second should show your
fully qualified domain name (FQDN).
By default, Linodes are set to UTC. Many operating systems provide built-in, interactive
methods for changing time zones:
dpkg-reconfigure tzdata
2. timedatectl list-timezones
Use the Up, Down, Page Up and Page Down keys to navigate to the correct zone. Remember it,
write it down or copy it as a mouse selection. Then press q to exit the list.
3. Set the time zone (change America/New_York to the correct zone):
4. timedatectl set-timezone 'America/New_York'
You can specify a number of hostnames on each line separated by spaces. Every line
must begin with one and only one IP address. In the above example,
replace 103.0.113.12 with your machine’s IP address. Consider a few
additional /etc/hosts entries:
/etc/hosts
1 198.51.100.30 example.com
2 192.168.1.1 stick.example.com
In this example, all requests for the example.com hostname or domain will resolve to the IP
address 198.51.100.30, which bypasses the DNS records for example.com and returns an
alternate website.
The second entry tells the system to look to 192.168.1.1 for the domain stick.example.com.
These kinds of host entries are useful for using “private” or “back channel” networks to
access other servers in a cluster without needing to send traffic on the public network.
Network DiagnosticsPermalink
In this section, we’ll review some basic Linux commands that will help you assess and
diagnose network problems. If you suspect connectivity issues, adding the output from
the relevant commands to your support ticket can help our staff diagnose your issue.
This is particularly helpful in cases where networking issues are intermittent.
The ping CommandPermalink
The ping command tests the connection between the local machine and a remote
address or machine. The following commands “ping” google.com and 216.58.217.110:
ping google.com
ping 216.58.217.110
These commands send a small amount of data (an ICMP packet) to the remote host
and wait for a response. If the system is able to make a connection, it will report on the
“round trip time” for every packet. Here is the sample output of four pings to
google.com:
The time field specifies in milliseconds the duration of the round trip for an individual
packet. When you’ve gathered the amount of information you need, use Control+C to
interrupt the process. You’ll be presented with some statistics once the process is
stopped. This will resemble:
--- google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3007ms
rtt min/avg/max/mdev = 33.890/40.175/53.280/7.679 ms
Packet Loss, or the discrepancy between the number of packets sent and the number of
packets that return successfully. This number shows the percentage of packets that are
dropped.
Round Trip Time (rtt) statistics on the final line report information about all the ping
responses. For this ping we see that the fastest packet round trip (min) took 33.89
milliseconds. The average round trip (avg) took 40.175 milliseconds. The longest packet
(max) took 53.28 milliseconds. A single standard deviation unit (mdev) for these four packets
is 7.67 milliseconds.
The ping command is useful as an informal diagnostic tool to measure point-to-point
network latency, and as a tool to simply ensure you are able to make a connection to a
remote server.
Often the hostnames and IP addresses on either side of a failed jump are useful in
determining who operates the machine where the routing error occurs. Failed jumps are
designated by lines with three asterisks (* * *).
Adding traceroute output to Linode support tickets is sometimes useful when trying to
diagnose network issues. You may also want to forward traceroute information to your
Internet Service Provider (ISP) if you suspect that the connectivity issue is with your
ISP’s network. Recording traceroute information is particularly useful if you are
experiencing an intermittent issue.
Like the ping command, mtr tracks the speed of the connection in real time until you exit
the program with CONTROL+C. To have mtr stop automatically and generate a report
after ten packets, use the --report flag:
mtr --report
Be aware that mtr will pause for a few moments while generating output. For more
information regarding mtr consider our diagnosing network issues with mtr guide.
System DiagnosticsPermalink
If you’re having an issue with your Linode that is neither related to networking nor
another application issue, it may help to rule out “hardware” and operating system level
issues. Use the following tools to better diagnose and resolve these.
If you determine that you have a problem with memory usage, refer to our guide
on resolving memory usage issues. Use the following tools and approaches to
determine the specific cause of your troubles.
free -m
On a Linode 2GB under moderate use, the output should resemble the following:
This output takes a bit of careful reading to interpret. Out of a total 1999 megabytes of
memory (RAM), the system is using 954 megabytes and has 1044 megabytes
free. However, the system also has 703 megabytes of “stale” data buffered and stored
in cache. The operating system will “drop” the caches if it needs the space, but retains
the cache if there is no other need for the space. It is normal for a Linux system to leave
old data in RAM until the space is needed, so don’t be alarmed if only a small amount of
memory is “free.”
In the above example, there are 1782 megabytes of memory that are actually free. This
means 1782 megabytes are available to your system when you start an additional
process or a running application needs more memory.
vmstat 1 20
This runs a vmstat every second, twenty times, giving a sample of the current state of
the system. The output generated resembles the following:
The memory and swap columns provide the same kind of information provided by the
“free -m” command, albeit in a slightly harder to understand format. The most relevant
information produced by this command is the wa column, which is the final column in
most implementations. This field displays the amount of time the CPU spends waiting
for I/O operations to complete.
If this number is consistently and considerably higher than 0, you might consider taking
measures to address your IO usage. However, if the vmstat output resembles the above,
you can be sure in the knowledge that you’re not experiencing an IO-related issues.
If you are experiencing an intermittent issue, you will need to run vmstat when you
experience the issue in order to properly diagnose or rule out an I/O issue. vmstat output
can sometimes help support diagnose problems.
htop
You can quit at any time by pressing the F10 or Q keys. There are a couple
of htop behaviors that may not be initially intuitive. Take note of the following:
The memory utilization graph displays used memory, buffered memory, and cached memory.
The numbers displayed at the end of this graph reflect the total amount of memory available
and the total amount memory on the system as reported by the kernel.
The default configuration of htop presents all application threads as independent processes,
which may not be clear if you’re not aware of it. You can disable this by selecting the “setup”
option with F2, then “Display Options,” and then toggling the “Hide userland threads” option.
You can toggle a “Tree” view with the F5 key that displays the processes in a hierarchy and
shows which processes were spawned by other processes in an organized format. This is
helpful in diagnosing a problem when you’re having trouble distinguishing among processes.
If you’re new to Linux systems administration, consider our “Tools & Reference” section
and articles including: installing and using WinSCP, using rsync to synchronize
files and using SSH and the terminal.
Caution
If you are giving other users access to upload files to your server, consider the security
implications of all additional access that you grant to third parties.
The command, scp, is followed by the path of the file on the local file system to be
transferred. Next, the username and hostname of the remote machine follow, separated
by an “at” sign (@). Follow the hostname with a colon (:) and the path on the remote
server to where the file should be uploaded. Using a more generalized example:
scp [/path/to/local/file] [remote-username]@[remote-hostname]:[/path/to/remote/file]
This command is available by default on OS X and Linux machines. You can use it to
copy files to a Linode, as well as between remote servers. If you use SSH keys, you can
use the scp command without entering a password for every transfer.
The syntax of scp follows the form scp [source] [destination]. You can copy files from a
remote host to the local machine by reversing the order of the paths in the above
example.
Only give users the permission to do what they need to. This includes application-specific
users.
Only run services on public interfaces that you are actively using. One common source of
security vulnerabilities is in unused daemons that are left running. This includes database
servers, HTTP development servers, and FTP servers.
Use SSH connections whenever possible to secure and encrypt the transfer of sensitive
information.
Manage Files on a Linux SystemPermalink
If you’re new to using Linux and manipulating files on the terminal interface we
encourage you to consider our guide on using the terminal. This section provides a list
of basic commands to manage the contents of your filesystem.
To copy files:
cp /home/username/todo.txt /home/username/archive/todo.01.txt
This copies todo.txt to an archive folder, and adds a number to the file name. If you
want to recursively copy all of the files and subdirectories in a directory to another
directory, use the -R option. This command looks like:
cp -R /home/username/archive/ /srv/backup/username.01/
The following example presents the first few lines of the output of this command on a
production Debian Lenny system.
CentOS and Fedora systems provide the name of the package ( SysVinit), the
architecture it was compiled for (i386), and the version of the build installed on the
system (2.86-15.el5).
For Arch Linux systems:
pacman -Q
This command provides a total list of all packages installed on the system. Arch also
allows you to filter these results to display only packages that were explicitly installed
(with the -Qe option) or that were automatically installed as dependencies (with the -
Qd option). The above command is actually a combination of the output of two
commands:
pacman -Qe
pacman -Qd
perl-www-mechanize 1.60-
perl-yaml 0.70-1
pkgconfig 0.23-1
procmail 3.22-2
python 2.6.4-1
rsync 3.0.6-1
Because there are often a large number of packages installed on any given system, the
output of these commands can be quite large. As a result, it is often useful to use tools
like grep and less to make these results more useful. For example:
dpkg -l | grep "python"
This will return a list of all packages with the word “python” in their name or description.
Similarly, you can use less:
dpkg -l | less
This will return the same list as the plain “dpkg -l; however, the results will appear in
the less pager, which allows you to search and scroll more easily.
You can append | grep "[string]" to these commands to filter package list results, or |
less to display the results in a pager, regardless of distribution.
Find Package Names and InformationPermalink
Sometimes the name of a package isn’t intuitive, based on the name of the software. As
a result, most package management tools make provide an option to search the
package database. These search tools may be helpful if you’re looking for a specific
piece of software but don’t know what it’s called.
This will search the local package database for a given term and generate a list with
descriptions. An excerpt of the output for apt-cache search python follows:
txt2regex - A Regular Expression "wizard", all written with bash2 builtins
vim-nox - Vi IMproved - enhanced vi editor
vim-python - Vi IMproved - enhanced vi editor (transitional package)
vtk-examples - C++, Tcl and Python example programs/scripts for VTK
zope-plone3 - content management system based on zope and cmf
zorp - An advanced protocol analyzing firewall
groovy - Agile dynamic language for the Java Virtual Machine
python-django - A high-level Python Web framework
python-pygresql-dbg - PostgreSQL module for Python (debug extension)
python-samba - Python bindings that allow access to various aspects of Samba
Note that apt-cache search queries the full records for all of the packages and not simply
the titles and the descriptions displayed here, hence the inclusion of vim-
nox and groovy which both mention python in their descriptions. To see the full record on
a specific package:
apt-cache show [package-name]
This provides information regarding the maintainer, the dependencies, the size, the
homepage of the upstream project, and a description of the software.
This generates a list of all packages available in the package database that match the
given term. The following is an example of the output of yum search wget:
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* addons: centos.secsup.org
* base: centos.secsup.org
* extras: centos.secsup.org
* updates: styx.biochem.wfubmc.edu
================================ Matched: wget =================================
wget.i386 : A utility for retrieving files using the HTTP or FTP protocols.
You can use the package management tools to discover more information about a
specific package. Use the following command to get a full record from the package
database:
This output presents more in-depth information concerning the package, its
dependencies, origins, and purpose.
This will perform a search of the local package database. Here is an excerpt of results
for a search for “python”:
extra/twisted 8.2.0-1
Asynchronous networking framework written in Python.
community/emacs-python-mode 5.1.0-1
Python mode for Emacs
The terms “extra” and “community” refer to which repository the software is located in.
To request more information about a specific package issue a command in the following
form:
The first command only searches the database for package names. The second
command searches through the database for package names and descriptions. These
commands will allow you to search your local package tree (i.e., portage) for the specific
package name or term. The output of either command is similar to the excerpt below.
Searching...
[ Results for search key : wget ]
[ Applications found : 4 ]
* app-emacs/emacs-wget
Latest version available: 0.5.0
Latest version installed: [ Not Installed ]
Size of files: 36 kB
Homepage: http://pop-club.hp.infoseek.co.jp/emacs/emacs-wget/
Description: Wget interface for Emacs
License: GPL-2
This will return the subset of the list of packages which matched for the search term
“python” and that mention xml in their name or short description. Similarly:
This will return the same list as the plain apt-cache search python but the results will
appear in the less pager. This allows you to search and scroll more conveniently.
You can append | grep "[string]" to any of these commands to filter package search
results, or | less to display the results in the less pager, regardless of distribution.
Text ManipulationPermalink
Among Linux and UNIX-like systems, nearly all system configuration information is
stored and manipulated in plain text form. These following sections show a list of basic
Linux commands and tools to manipulate text files.
Career Advice
Take a sysadmin skills assessment
Explore training and certification options
Read a guide to human communication for sysadmins
For new Linux administrators, many enter the job from their interests as home
enthusiasts, gamers, or clandestine administrators of college servers. This is
how it happened for me. As soon as I saw Linux for the first time in 1995, I
was hooked. By January of 1996, I had started the local Linux User's Group
(LUG) here in Tulsa, Oklahoma, much to the chagrin of the Unix Special
Interest Group (Unix SIG).
My beginnings with Linux were rocky. I first ran across Linux in a magazine
where I could purchase a 2 CD set in early 1995 when I worked at WorldCom
(Yes, that WorldCom). I installed a group FTP/download server for my
desktop support group coworkers. A few weeks later, I was told by one of the
"gurus" in another group, "We don't allow Lye-nix on our network." I wasn't
convinced of course that it mattered what was allowed and what was not, so I
kept the server but installed Samba on it and changed daemon header
information to make it look like my little system was a Windows server.
Other than sneaking into Linux system administration by some circuitous path,
the more direct and recommended route is to still learn on your own but take
some formalized Linux classes to prove your learning milestones. Being self-
taught is great, but you'll always just be an enthusiast or hobbyist unless you
can formalize your knowledge with certifications or some other proof of
knowledge. Self-education is commendable but you'll have significant gaps in
your learning. You should set certification knowledge as your goal, whether
you become certified or choose not to do so. For a good start, check out
Professor Messer's videos on YouTube.
A Linux system administrator wears many hats and the smaller your
environment, the more hats you will wear. Linux administration covers
backups, file restores, disaster recovery, new system builds, hardware
maintenance, automation, user maintenance, filesystem housekeeping,
application installation and configuration, system security management, and
storage management. System administration covers just about every aspect
of hardware and software management for both physical and virtual systems.
Linux system administration also requires that you stay on top of best
practices, learn new software, maintain patches, read and comply with
security notifications, and apply hardware updates. An SA's day is very full. In
fact, you never really finish, but you have to pick a point in time to abandon
your activities. Being an SA is a 24x7x365 job, which does take its toll on you
physically and mentally. You'll hear a lot about burnout in this field. We, at
Enable Sysadmin, have written several articles on the topic.
Doing the technical stuff is relatively easy. It's dealing with people that makes
the job really hard. That sounds terrible but it's true. On one side, you deal
with your management, which is not always easy. You are the person who
gets blamed when things go wrong and when things go right, it's "just part of
your job." It's a tough place to be.
Coworkers don't seem to make life better for the SA. They should, but they
often don't. You'll deal with lazy, unmotivated coworkers so often that you'll
feel that you're carrying all the weight of the job yourself. Not all coworkers are
bad. Some are helpful, diligent, proactive types and I've never had the
pleasure of working with too many of them. It's hard to do your work and then
take on the dubious responsibility of making sure everyone else does theirs as
well.
And then there are users. Oh the bane of every SA's life, the end user. An SA
friend of mine once said, "You know, this would be a great job if I just didn't
have to interface with users." Agreed. But then again, with no users, there's
probably also not a job. Dealing with computers is easy. Dealing with people
is hard. Learn to breathe, smile, and comply if you want to survive and
maintain your sanity.
+++++++++++++++++++++
That was one demonstration of Linux's security features. Linux, like UNIX, is a multi-
user system and file permissions are one way the system protects against malicious
tampering.
One way to gain entry when you are denied permission is to enter the command su -.
This is because whoever knows the root password has complete access.
However, switching to the superuser is not always convenient or recommended, since it
is easy to make mistakes and alter important configuration files as the superuser.
All files and directories are "owned" by the person who created them. You created the
file foo.txt (refer to Section 4.9.2 Using Redirection) in your login directory,
so foo.txt belongs to you.
That means you can specify who is allowed to read the file, write to the file, or (if it is an
application instead of a text file) who can execute the file.
Reading, writing, and executing are the three main settings in permissions. Since users
are placed into a group when their accounts are created, you can also specify whether
certain groups can read, write to, or execute a file.
Take a closer look at foo.txt with the ls command using the -l option (refer to Figure 4-
11).
A lot of detail is provided here. You can see who can read (r) and write to (w) the file, as
well as who created the file (user), and to which group the owner belongs (user). (By
default, the name of your group is the same as your login name.)
-rw-rw-r--
Those three sets are the owner of the file, the group in which the file belongs, and
"others," meaning other users on the system.
The first item, which specifies the file type, will probably be one of the following:
d — a directory
- (dash) — a regular file (rather than directory or link)
l — a symbolic link to another program or file elsewhere on the system
Others are possible, but are beyond the scope of this manual. Refer to the Red Hat
Enterprise Linux System Administration Guide for more information.
Beyond the first item, in each of the following three sets, you may see one of the
following:
r — file can be read
w — file can be written to
x — file can be executed (if it is a program)
- (dash) — specific permission has not been assigned
When you see a dash in owner, group, or others, it means that particular permission
has not been granted. Look again at the first column of foo.txt and identify its
permissions.
ls -l foo.txt
-rw-rw-r-- 1 user user 150 Mar 19 08:08 foo.txt
The file's owner (in this case, user) has permission to read and write to the file. The
group, user, has permission to read and write to foo.txt, as well. It is not a program, so
neither the owner or the group has permission to execute it.
4.11.1. The chmod Command
Use the chmod command to change permissions. This example shows how to change
the permissions on foo.txt with the chmod command.
The original file looks like this, with its initial permissions settings:
If you are the owner of the file or are logged into the root account, you can change any
permissions for the owner, group, and others.
Right now, the owner and group can read and write to the file. Anyone outside of the
group can only read the file (r--).
In the following example, you want to allow everyone to write to the file, so they can
read it, write notes in it, and save it. That means you must change the "others" section
of the file permissions.
Take a look at the file first. At the shell prompt, type:
ls -l foo.txt
The o+w command tells the system you want to give others write permission to the
file foo.txt. To check the results, list the file's details again. Now, the file looks like this:
By typing go-rw, you are telling the system to remove read and write permissions for the
group and for others from the file foo.txt.
The result looks like this:
Think of these settings as a kind of shorthand when you want to change permissions
with chmod, because all you really have to do is remember a few symbols and letters
with the chmod command.
Here is a list of what the shorthand represents:
Identities
u — the user who owns the file (that is, the owner)
g — the group to which the user belongs
o — others (not the owner or the owner's group)
a — everyone or all (u, g, and o)
Permissions
r — read access
w — write access
x — execute access
Actions
+ — adds the permission
- — removes the permission
= — makes it the only permission
Want to test your permissions skills? Remove all permissions from foo.txt — for
everyone.
Now, see if you can read the file with the command cat foo.txt, which should return the
following:
Removing all permissions, including your own, successfully locked the file. But since the
file belongs to you, you can always change its permissions back with the following
command:
Use the command cat foo.txt to verify that you, the file owner, can read the file again.
Here are some common examples of settings that can be used with chmod:
g+w — adds write access for the group
o-rwx — removes all permissions for others
u+x — allows the file owner to execute the file
a+rw — allows everyone to read and write to the file
ug+r — allows the owner and group to read the file
g=rx — allows only the group to read and execute (not write)
By adding the -R option, you can change permissions for entire directory trees.
Because you can not really "execute" a directory as you would an application, when you
add (or remove) the execute permission for a directory, you are really allowing (or
denying) permission to search through that directory.
Examine the dir1/ directory you created in section FIXME by listing all of the files in your
home directory.
ls -l /home/>user</
If you do not allow others to have execute permission on the dir1/ directory, it does not
matter who has read or write access. No one can access the directory unless they know
the exact file name.
For example, type
If you check your work with ls -l, you can see that only others are denied access to
the /dir1/ directory.
The total for the user is six(4+2+0), the total for the group is six(4+2+0), and the total for
others is four(4+0+0). The permissions setting is read as 664.
If you want to change foo.txt so those in your group do not have write access, but can
still read the file, remove the access by subtracting two (2) from that set of numbers.
The numerical values then become six, four, and four (644).
To implement these new settings, type:
ls -l foo.txt
Now, neither the group nor others have write permission to foo.txt. To return the
group's write access for the file, add the value of w (2) to the second set of permissions.
Here is a list of some common settings, numerical values and their meanings:
Table 4-3. File permissions settings, numerical values, and their meanings
Here are some common settings for directories:
Table 4-4. Directory permissions settings, numerical values, and their meanings
+++++++++++++++++++++++
If you are working as a support in a production environment then most probably you will
need to deal with performance related issues in Linux environment.
Let’s go through some of the most used Linux command line utilities to diagnose
performance-related issues.
Note: Some of the commands listed below may not be installed by default, so you got to
install them manually.
lsof
lsof stands for “list open files” to help you to find all the opened files and processes
along with the one who opened them. The lsof utility can be convenient to use in some
scenarios.
# lsof –p PID
[root@localhost ~]#
pidstat
pidstat can be used to monitor tasks managed by Linux kernel. Troubleshooting I/O
related issue can be the ease with this command.
# pidstat –d
# pidstat –p 4271 –d
If you are doing real-time troubleshooting for some process, then you can monitor the
I/O in an interval. Below example is to monitor every 5 seconds.
top
Probably one of the most used commands on Linux would be top. The top command
can be used to display system summary information and current utilization.
Just executing top command can show you CPU utilization, process details, a number
of tasks, memory utilization, a number of zombie processes, etc.
To display process details for specific user
# top –u username
To kill the process, you can execute top and press k. It will prompt you to enter the PID
to be killed.
ps
ps stands for process status and widely used a command to get a snapshot of the
running process. Very useful to find out if a process is running or not and if running then
prints PID.
tcpdump
Troubleshooting network issue is always challenging, and one of the essential
commands to use is tcpdump.
As you can see above has captured the traffic flow on “eno16777736” interface.
# tcpdump –r filename
# tcpdump –r /tmp/test
iostat
iostat stands for input-output statistics and often used to diagnose performance issue
with storage devices. You can monitor CPU, Device & Network file system utilization
report with iostat.
ldd
ldd stands for list dynamic dependencies to show shared libraries needed by the library.
The ldd command can be handy to diagnose the application startup problem.
If some program is not starting due to dependencies not available then you can ldd to
find out the shared libraries it’s looking for.
netstat
netstat (Network Statistics) is a popular command to print network connections,
interface statistics and to troubleshoot various network related issue.
# netstat –s
free
If your Linux server is running out of memory or just want to find out how much memory
available out of available memory, then the free command will help you.
-g means to show the details in GB. So as you can see total available memory is 5 GB
and 3 GB is free.
sar
sar (System Activity Report) will be helpful to collect a number of a report including
CPU, Memory and device load.
By just executing sar command will show you system utilization for the entire day.
# sar –r
# sar –n ALL
ipcs
ipcs (InterProcess Communication System) provides a report on the semaphore, shared
memory & message queue.
# ipcs –q
# ipcs –s
# ipcs –m
++++++++++++++++++++++++++++++
4. uptime – Tell how long the Linux system has been running
uptime command can be used to see how long the server has been running. The current time, how
long the system has been running, how many users are currently logged on, and the system load
averages for the past 1, 5, and 15 minutes.
# uptime
Output:
1 ? 00:00:02 init
2 ? 00:00:02 migration/0
3 ? 00:00:01 ksoftirqd/0
4 ? 00:00:00 watchdog/0
5 ? 00:00:00 migration/1
6 ? 00:00:15 ksoftirqd/1
....
.....
47394: /usr/bin/php-cgi
.....
......
..
Linux find the memory used by a program / process using pmap command
Fig
.02: General interface statistics: IP traffic statistics by network interface
Fig
.03 Network traffic statistics by TCP connection
Install IPTraf on a Centos / RHEL / Fedora Linux To Get Network Statistics
Linux iotop: Check What’s Stressing And Increasing Load On Your Hard Disks
CentOS / RHEL: Install atop (Advanced System & Process Monitor) Utility
How to keep a detailed audit trail of what’s being done on your Linux systems
Keeping a Log Of Daily Network Traffic for ADSL or Dedicated Remote Linux Server
CentOS / RHEL: Install vnStat Network Traffic Monitor To Keep a Log Of Daily Traffic
CentOS / RHEL: View Vnstat Graphs Using PHP Web Interface Frontend