Tuesday, August 9, 2011

Issssshhhhh....I mistakenly deleted my interface file

Guys..it command that when we work with root privilege, we tend to make mistake. And the most common mistake is deleting the files. I encountered a situation where I was configuring my DNS Server, and mistakenly I deleted the interface file. I thought, I am gone. Since it was a mission critical server.But quickly I realized, let me create one manually and see if it works. And guess what.....It really worked. I never though, I am so witty :).

[root@localhost~:]#nano /etc/networking/interfaces

Add the following line:

iface eth0 inet dhcp

and exit the editor saving the file.

[root@localhost~:]#/etc/init.d/networking restart

Easy Understanding - Setting the Static Network Configuration

It is not intuitively obvious how to assign Ubuntu 10.04 Lucid Lynx a a static IP address from the command line. However, much of Linux administration involves the editing of text files, and assigning a static IP address is no different. You’ll need to edit the following file:

[root@localhost~:]#/etc/network/interfaces

Initially, the file only contains information about your local loopback address:

auto lo
iface lo inet loopback


To assign a static IP address, you’ll need to make some changes to this file.

Let’s say you want to assign a static IP of 192.168.1.2 to your eth0 network connection (the first Ethernet adapter on your system; if you only have one, it will be eth0), with a subnet mask of 255.255.255.0 and a local gateway of 192.168.1.1. First, make a backup copy of the interfaces file:

[root@localhost~:]#cp /etc/network/interfaces /etc/network/interfaces.bkp

This will make a backup copy in your home directory in case something goes amiss during the editing process. Next, fire up a text editor:

[root@localhost~:]#nano /etc/network/interfaces


Once the file is open, add the following lines:

iface eth0 inet static
address 192.168.1.2
netmask 255.255.252.0
gateway 192.168.1.1


Once you’ve added these lines, save the interfaces file to disk, and exit your text editor. If you want to add a static DNS server, you’ll need to edit the /etc/resolv.conf file with this command:

[root@localhost~:]#nano /etc/resolv.conf


To set a static DNS server with the address of 192.168.1.10, add this line to the file:

nameserver 192.168.1.10

Save the file, and exit your text editor.

You’ll then to need have your system load the new IP configuration. You can do that by rebooting, but if that takes too long, you can use this command to force Ubuntu to re-read the configuration files:
[root@localhost~:]#ifup eth0

Your system will then have a static IP address.

Monday, August 8, 2011

Hey Dude !!! Look into the CPU utilization of the Linux box

Bottleneck....aaahhh. Its a pain for the system administrators.

Whenever a Linux system CPU is occupied by a process, it is unavailable for processing other requests. Rest of pending requests must wait till CPU is free. This becomes a bottleneck in the system. Following command will help you to identify CPU utilization, so that you can troubleshoot CPU related performance problems.
Finding CPU utilization is one of the important tasks. Linux comes with various utilities to report CPU utilization. With these commands, you will be able to find out:
* CPU utilization
* Display the utilization of each CPU individually (SMP cpu)
* Find out your system's average CPU utilization since the last reboot etc
* Determine which process is eating the CPU(s)
We can make use of the tools like mpstat and iostat to more accurately find the issues related to the cpu overload. But before we make use of these utilities, we need to download it from the repos. Kind following the following steps in order to download it.

[root@localhost~:]#apt-get update
[root@localhost~:]#apt-get install sysstat

This will download the utils and put in the default folder (here I presumed that it’s a ubuntu system).

What next…Let’s use the command:
[root@localhost~:]#mpstat
Linux 2.4.27-1-686-smp (test) 16/11/05

09:05:11 CPU %user %nice %system %iowait %irq %soft %idle intr/s

09:05:11 all 0.01 0.00 0.03 0.00 0.00 0.00 99.96 106.03

Commands To Remember - "dmesg"

One of the most widely used command to retrieve the information from the kernel buffer. I will illustrate this with an example - I added a network card, but when I am running the command to check the NIC config, i found that the NIC is not listed there. Find the snap:
[root@localhost~:]#ifconfig

Surprised...I were. Where is my NIC card. Its not listed. I checked the configuration of the system...but of no use. I was not able to make up where's the error. Then I ran the command:
[root@localhost~:]#ifconfig -a

I found that the network card is listed as `eth1`. Then i realized, due to some issue, I renamed my card from eth0 to eth1. I check the file /etc/network/interface and found that the name of the interface is eth1.

Again, I executed the command,
[root@localhost~:]#dmesg | grep -i network

And heres the output:

Commands To Remember - "lshw"

The `lshw` is among the most important command in the linux system. This command is comparatively better than `ioscan` command of HP-UX as its comes with lot many switches and the output can be formatted in numerous ways.

For example, when we run the command
[root@localhost~:]#lshw -short


It system in the hierarchical way.Out put is similar to `ioscan`

To check the network devices the the various parameters:
[root@localhost~:]#lshw -C network

[root@localhost~:]#lshw -C disk






Sunday, August 7, 2011

Logout Users in Linux

Yet another newbie question that suggests people love to kill and show their power to rest of the world ;)

There is a package called procps. It includes various useful (nifty) utilities. One of such utility is skill which is responsible to send a signal to users and process such as:

Halt user terminal
Kill user and logout

The procps package contains utilities to browse the /proc filesystem, which is not a real file system but a way for the kernel to provide information about the status of entries in its process table. Procps includes ps, free, skill, pkill, pgrep, snice, tload, top, uptime, vmstat, w, watch and pdwx commands.

Task: How To Halt/Stop a User Called vivek
Open a command-line terminal (select Applications > Accessories > Terminal), and then type the following commands. First, switch to the root user by typing su - and entering the root password, when prompted (you can also use sudo if configured). Type the skill command as follows:

#ps -eaf | grep username

This will help you find the PID of the username. Next

#kill -s 9 PID

This will kill the interactive session of the user.

Easy Understanding - Linux Performance Tuning 11


Certain conditions occur on a system that create IO bottlenecks. These conditions may be identified by using a standard set of system monitoring tools. These tools include top, vmstat, iostat, and sar. There are some similarities between the output of these commands, but for the most part, each offers a unique set of output that provides a different aspect on performance. The following subsections describe conditions that cause IO bottlenecks.

Condition 1: CPU Wait on IO Too Much IO at Once

In an ideal environment, a CPU splits  a percentage of its time between user (65%), kernel (30%) and idle (5%). If IO starts to cause the bottleneck on the system, a new condition “Wait on IO (WIO)” appears in the CPU performance statistics. A WIO condition occurs when a CPU is completely idle because all the runnable processes are waiting on IO. This meant that all the applications are in a sleep state because they are waiting for requests to complete in the IO subsystems.

The vmstat command provides WIO statistics in the last 4 fields of output under the “cpu” header.

# vmstat 1
procs ----memory---------- ---swap-- -----io---- --system-- ----cpu----
r b swpd free  buff cache   si so bi    bo  in   cs   us sy id wa
3 2 0    55452 9236 1739020 0  0  9352  0   2580 8771 20 24 0  57
2 3 0    53888 9232 1740836 0  0  14860 0   2642 8954 23 25 0  52
2 2 0    51856 9212 1742928 0  0  12688 0   2636 8487 23 25 0  52

These last 4 columns provide percentages of CPU utilization for user (us), kernel (sys), idle (id), and WIO (wa). In the previous output, the CPU averages 50% idle waiting on IO requests to complete. This means that there is 50% of the processor that is usable for executing applications, but no applications can execute because the kernel is waiting on IO requests to complete. You can observe this in the blocked threads column (b).

It is also worth noting that the major cause of the IO bottleneck is disk reads due to the large amount of disk blocks read into memory (bi). There is no data being written out to disk as the blocks out (bo) column has a zero value. From this output alone, it appears that the system is processing a large IO request.

FIELD DESCRIPTIONS
Procs
r: The number of processes waiting for run time.
b: The number of processes in uninterruptable sleep.
w: The number of processes swapped out but otherwise runnable.

This field is calculated, but Linux never desperation swaps.
Memory
swpd: the amount of virtual memory used (kB).
free: the amount of idle memory (kB).
buff: the amount of memory used as buffers (kB).

Swap
si: Amount of memory swapped in from disk (kB/s).
so: Amount of memory swapped to disk (kB/s).

IO
bi: Blocks sent to a block device (blocks/s).
bo: Blocks received from a block device (blocks/s).

System
in: The number of interrupts per second, including the clock.
cs: The number of context switches per second.

CPU
These are percentages of total CPU time.
us: user time
sy: system time
id: idle time

The top tool can provide enough insight to make an educated guess. Start the top command with a delay of 1 second:

# top -d 1

Once top is running, sort the output by faults (MPF and MnPF) by typing "F" to bring up the sort menu and "u" to sort by faults.