Tuesday, April 19, 2011

SAMBA - Windows Linux file Sharing Notes

Some basic notes on using SAMBA on a home network with linux and windows machines, like my home network setup.

Running SAMBA on a Linux machine

To start, stop or restart samba,
/etc/init.d/smd start
/etc/init.d/smd stop
/etc/init.d/smd restart
All options for the SAMBA goes to /etc/samba/smb.conf This is my smb.conf
Notable changes I made are:
My linux machine is a gateway server with two ethernet interfaces eth0 and eth1. For security reasons I set up SAMBA to run only on the internal interface
interfaces = 192.168.0.1/24 127.0.0.1/24
bind interfaces only = Yes
Also set hosts allow to only allow internal and localhoist
hosts allow = 127. 192.168.0.
hosts deny = *

SAMBA authentification

For the file access permissions for the shares to work, you have to set up the SAMBA username/password by running smbpasswd program on the linux box.
Then on the Windows machine login with the username/password created above with smbpasswd. Otherwise the file sharing will not work.

NFS Setup on Home Fileserver: Linux to Linux File Sharing

1. Install NFS Server and Client Software

Using the command line (terminal):
me@myhost$ sudo apt-get install nfs-common nfs-kernel-server
or use the Synaptic pacage manager to install the two packages listed on your home file-server. The client machine only needs the "nfs-common" package, which contains the NFS client software. Not completely obvious to a new-comer, but now you know there is no "nfs-client" package.

2. Give Your Computers Fixed IP Addresses

The simplest way to do refer to your computers in a home or SOHO LAN is to use fixed IP addresses. This eliminates an extra step of matching computer names to IP addresses. You can give you system a fixed IP address, even if you use DHCP on your Linksys or other type of router. I give a description how to do this in a separate Linux Fixed IP Address page. Put all the fixed IP addresses you are using in the /etc/hosts file per the example in the default file. I show an example /etc/hosts file on my Virtual Hosts page.

Tuesday, April 12, 2011

Linux display each multiple SMP CPU processors utilization individually

Q. My AMD sever is quad processor with SMP kernel, How do I display the utilization of each CPU individually?
A. Linux can display each multiple SMP CPU processors utilization individually using mpstat command.
The mpstat command displays output activities for each available processor, processor 0 being the first one. Global average activities among all processors are also reported. The mpstat command can be used both on SMP and UP machines, but in the latter, only global average activities will be printed.
# mpstat -P ALL.
Where, -P cpu | ALL option indicate the processor number for which statistics are to be reported. cpu is the processor number. Note that processor 0 is the first processor. The ALL keyword indicates that statistics are to be reported for all processors.
Output:
Linux 2.6.9-55.ELsmp (server.xyz.com)     06/11/2007

04:13:29 PM  CPU   %user   %nice %system %iowait    %irq   %soft   %idle    intr/s
04:13:29 PM  all    5.63    0.01    2.33    0.85    0.01    0.10   91.06   2255.03
04:13:29 PM    0    5.74    0.00    2.17    0.88    0.01    0.15   91.05   1170.16
04:13:29 PM    1    5.53    0.01    2.49    0.83    0.01    0.06   91.07   1084.87

Understanding mpstat output

The report generated by the mpstat command has the following format:

Howt o collect Linux system utilization data into a file

I’ve already documented the procedure to find out CPU utilization under Linux and UNIX oses using various tools.
However I received a couple of email questions via email:
Howdo I collect Linux system utilization data into a file? How do I email the data or move to another computer?
To be frank you don’t have to do anything data is collected and stored in /var/log/sa location using sa1 and sa2 scripts. It is part of sadc - System activity data collector tools.
The sadc command samples system data a specified number of times ( count ) at a specified interval measured in seconds ( interval ). It writes in binary format to the specified output file.
The sa1 command is a shell procedure variant of the sadc command and handles all of the flags and parameters of that command. The sa1 command collects and store binary data in the /var/log/sa/sadd file, where the dd parameter indicates the current day. The interval and count parameters specify that the record should be written count times at interval seconds.
The sa1 command is designed to be started automatically by the cron command. Type the following command to list files:
# ls /var/log/sa

How much RAM does my Ubuntu / Fedora Linux desktop PC have?

Here is one of the most frequently asked questions from my mailbag:
Hey I need to know how much ram memory I have in my Ubuntu Linux computer. Under Windows XP I can find out memory by visiting Start > Control Panels > System in control panel. So how do I find out RAM information under Linux PC?
The best way to find out RAM information is open a terminal and type the following command:
$ free -m
OR
$ free -mt
Output:
total       used       free     shared    buffers     cached
Mem:          2008       1837        170          0         50        963
-/+ buffers/cache:        822       1185
Swap:         1027          0       1027
free command print the total amount of free and used physical and swap memory in the system, as well as the buffers used by the Linux kernel. You can pass following options
  • -b switch displays the amount of memory in bytes
  • -k switch (set by default) displays it in kilobytes
  • -m switch displays it in megabytes.
  • -t switch displays a line containing the totals.
  • -o switch disables the display of a "buffer adjusted" line. If the -o option is not specified, free subtracts buffer memory from the used memory and adds it to the free memory reported.
  • -s switch activates continuous polling delay seconds apart. You may actually specify any floating point number for delay, usleep(3) is used for microsecond resolution delay times.

GUI tool - gnome-system-monitor

The gnome-system-monitor provides an overall view of the resource usage on your system, including memory and CPU allocation. Start gnome-system-monitor from Menus or just type:
$ gnome-system-monitor &
overall view of the resource usage  on  your Linux  system,  including memory and CPU allocation.

 

Linux Track NFS Directory / Disk I/O Stats

How do I track NFS client metrics (disk I/O) under Linux operating system?

  The iostat command is used for monitoring system input/output device loading by observing the time the devices are active in relation to their average transfer rates. The iostat command generates reports that can be used to change system configuration to better balance the input/output load between physical disks. The -n option displays the NFS-directory statistic. Data displayed are valid only with kernels 2.6.17 and newer. This option is exclusive to the -x option:
# iostat -x -n

Linux Limit CPU Usage Per Process

I don't want background process to eat all my CPU. I know how to find out CPU utilization but how do I limit the cpu usage of a process under Linux operating system? How do I force a process to limit itself to 25% only?

You can use cpulimit program that attempts to limit the cpu usage of a process. Limits are expressed in percentage and not in cpu time. cpulimit does not act on the nice value or other scheduling priority stuff, but on the real cpu usage. Also, it is able to adapt itself to the overall system load, dynamically and quickly.

Install cpulimit

Type the following commands to install latest stable release:
# cd /tmp
# wget 'http://downloads.sourceforge.net/cpulimit/cpulimit-1.1.tar.gz'
# tar -zxvf cpulimit-1.1.tar.gz
# cd cpulimit-1.1
# make
# cp cpulimit /usr/local/sbin/
# rm -rf cpulimit*

A note about Debian / Ubuntu Linux users

Type the following command to install cpulimit:
$ sudo apt-get update
$ sudo apt-get install cpulimit

How do I use cpulimit?

To limit CPU usage of the process called firefox to 30%, enter:
# cpulimit -e firefox -l 30
To limit CPU usage of the process to 30% by using its PID, enter:
# cpulimit -p 1313 -l 30
To find out PID of the process use any of the following:
# ps aux | less
# ps aux | grep firefox
# pgrep -u vivek php-cgi
# pgrep lighttpd

You can also use absolute path name of the executable, enter:
# cpulimit -P /opt/firefox/firebox -l 30
Where,