Friday, January 28, 2011

Add Virtual IP in Linux

Steps to add virtual IP.

1)Copy existing device etho to new virtual device.
#cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:1

2)Edit device and IP address in ifcfg-eth0:1
#vi ifcfg-eth0:1

3)Restart the network service
#service network restart

4)Verify the virtual device is up. You'll see 2 different IP address.I've purposely hide the IP address,Bcast and Netmask. You should get the reply once ping.

# ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:50:56:BE:00:3B
inet addr:xx.x.xxx.184 Bcast:xx.x.xxx.xxx Mask:xxx.xxx.xxx.x
inet6 addr: fe80::250:56ff:febe:3b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:36 errors:0 dropped:0 overruns:0 frame:0
TX packets:28 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3751 (3.6 KiB) TX bytes:4480 (4.3 KiB)

eth0:1 Link encap:Ethernet HWaddr 00:50:56:BE:00:3B
inet addr:xx.x.xxx.185 Bcast:10.9.135.255 Mask:255.255.248.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
#ping xx.x.xxx.185
PING xx.x.xxx.185 (xx.x.xxx.185) 56(84) bytes of data.
64 bytes from xx.x.xxx.185: icmp_seq=1 ttl=64 time=0.018 ms
64 bytes from xx.x.xxx.185: icmp_seq=2 ttl=64 time=0.018 ms

Wednesday, January 26, 2011

NOHUP:Running a process and log out

Nohup is a POSIX command to ignore the HUP (hangup) signal, enabling the command to keep running after the user who issues the command has logged out. The HUP (hangup) signal is by convention the way a terminal warns depending processes of logout.

nohup is most often used to run commands in the background as daemons. Output that would normally go to the terminal goes to a file called nohup.out if it has not already been redirected. This command is very helpful when there is a need to run numerous batch jobs which are inter-dependent.

If you redirect the streams you can avoid filling up your filesystem with nohup.out files as follow:


$ nohup tar czf /backup/home.tgz . > /dev/null 2>&1

Sunday, January 23, 2011

Adding File System swap(Solaris)

The Solaris OS supports applying swap to a file. To enable a file system swap you need to perform the following tasks:

1. Create a file using mkfile:

#mkfile 250m /opt/myswapfile (can be done in any partition)
This will create a 250 Meg file, which the Solaris OS can use for swap.

2. To use this swap file, enable it with the following command:

#swap -a /opt/myswapfile
3. Check your change:

#swap -l
Note: To enable the new swap file at the next system boot, add the following entry to /etc/vfstab:

/opt/swapfile - - swap - no -

Disabling swap Space
The Solaris OS provides the ability to disable a swap file while the system is running. This is done with the -d option for swap. All allocated blocks are copied to other swap areas.
solaris# swap -d /opt/myswapfile
To check your change, type this:

solaris# swap -l

Saturday, January 22, 2011

Increase your available swap space with a swap file(Linux)

1)At a command line, type swapon -s (you might need to prepend /sbin/ if you're not root). The command should produce a message that looks something like this:

Filename Type Size Used Priority
/dev/hda2 partition 128044 92472 -1

2)Running df -m (short for "disk free") from a command line should produce output something like this:

Filesystem 1M-blocks Used Available Use% Mounted on
/dev/hda1 11443 6191 5252 55% /


3)dd if=/dev/zero of=/extraswap bs=1M count=512
replacing 512 with the number of megabytes you want in your auxiliary swap file. if= and of= are short for infile and outfile. The /dev/zero device file will give us zeroes to be written to the output file. If you want this file on a different partition, say your /var partition, you would replace /extraswap with /var/extraswap.

Again as root, carefully type:

4)mkswap /extraswap

5)swapon /extraswap.

6)swapon -s we should see our existing swap partition and our new swapfile. Also, the free command should show an increase in total swap space.

7)cp /etc/fstab /etc/fstab.mybackup and add the following entry same like existing:

/dev/hda2 none swap sw 0 0 (Existing swap partition)

/extraswap none swap sw 0 0 (New swap file)

Make sure the entry in the fstab file is correct to avoid problem during boot up.

Friday, January 14, 2011

Service Management facility (SMF)

SMF is a new feature to handle services for Solaris 10.

Fault managed resource identifiers (FMRI) identifies services:
svc :/system/system- log:default
svc:(Service type)
/system/system-log(Name)
:default(Instance)
The repository is the source for all known services on the system, it imports the service manifest into the database and then never references the manifest again.

File location
SMF log files(/var/svc/log)
SMF log files(/etc/svc/volatile)
SMF manifests(/var/svc/manifest/*)
SMF method(/lib/svc/method/*)

Daemons
start svc daemon :svc.startd
svc configuration daemon :svc.configd

Service Commands

Show the state of all services:svcs –a
Show detailed information:svcs –l
Show the dependencies:svcs –d
Show the dependents:svcs –D
show the processes of a service:svcs –p
Explain why the service failed: svcs –x
verbose information:svcs –v
Disable a service (stop):svcadm disable
Enabled a service (start):svcadm enable
restart a service:svcadm restart
Reread the config file (HUP):svcadm refresh
Put service into maintenance/degrade mode:svcadm mark
Start a service to the desired milestone level: svcadm milestone
Show values for a given property:svcprop –p
show details from a snapshot:svcprop –s

INETD services commands

List all configured inetd services:inetadm
Detailed information on a inetd service:inetadm -l
enable a inetd service:inetadm -e
disable a inetd service:inetadm -d

Administration

If a service fails to start:
# svcs –xv

To modify the properties of an inetd service:
# inetadm –m spray bind_addr=”192.168.0.1”
# inetadm –l spray

Repair a corrupt repository using the default repository:
Script # /lib/svc/bin/restore_repository (follow the prompts)
Note: all old repositories are in /etc/svc you can use an old one in place of the global

Manually
# pstop “ pgrep svc.startd”
# kill svc.configd
# cp /etc/svc/repository.db /etc/svc/repository.bad

Global zone
# cp /lib/svc/seed/global.db /etc/svc/repository.db
# reboot

Non-Global zone
# cp /lib/svc/seed/nonglobal.db /etc/svc/repository.db
# reboot (only reboot zone)


Start service interactively during boot
Ok> boot –m milestone=none (login as root)
# svcadm milestone –t all (enable all services)
# svcs –l (look for hanging services and check log files /var/svc/log)

continue with normal boot procedures

Other boot commands are:

Ok> boot –m verbose (verbose output)
Ok> boot –m debug (very verbose output)

Manifests:
To check the integrity of a manifest xml file:
# /usr/bin/xmllint mysvc.xml

To import your service manifest:
# /usr/sbin/svccfg -v import /var/svc/manifest/site/mysvc.xml

Friday, January 7, 2011

Virtual Network Interface(Solaris)

Virtual network interface on Solaris box created by associate multiple IP addresses with the same host and NIC.

Here’s a quick guide. Let’s assume our network card is ce0, and we want to create a virtual interface called ce0:1

Create the virtual interface:
# ifconfig ce0:1 plumb

Configure the virtual interface:
# ifconfig ce0:1 10.10.64.93 netmask 255.255.255.0 broadcast 10.10.79.255

Check to make sure it worked:

# ifconfig -a

lo0: flags=1000849 mtu 8232 index 1
inet 127.0.0.1 netmask ff000000
ce0: flags=1000843 mtu 1500 index 2
inet 10.11.64.70 netmask fffff000 broadcast 10.11.79.255
groupname ipmp
ether 0:3:ba:93:91:64
ce0:1: flags=9040843 mtu 1500 index 2
inet 10.11.64.93 netmask fffff000 broadcast 10.11.79.255

Finally bring up your new virtual interface:
# ifconfig ce0:1 up

To make it come up on start:

create /etc/hostname.ce0:1 with hostname in it
make sure the hostname is in /etc/hosts

NOTE: The IP addresses in this story have been changed to protect the innocent.

Thursday, June 11, 2009

All about Linux swap space

Linux divides its physical RAM (random access memory) into chucks of memory called pages. Swapping is the process whereby a page of memory is copied to the preconfigured space on the hard disk, called swap space, to free up that page of memory. The combined sizes of the physical memory and the swap space is the amount of virtual memory available.

Swapping is necessary for two important reasons. First, when the system requires more memory than is physically available, the kernel swaps out less used pages and gives memory to the current application (process) that needs the memory immediately. Second, a significant number of the pages used by an application during its startup phase may only be used for initialization and then never used again. The system can swap out those pages and free the memory for other applications or even for the disk cache.

However, swapping does have a downside. Compared to memory, disks are very slow. Memory speeds can be measured in nanoseconds, while disks are measured in milliseconds, so accessing the disk can be tens of thousands times slower than accessing physical memory. The more swapping that occurs, the slower your system will be. Sometimes excessive swapping or thrashing occurs where a page is swapped out and then very soon swapped in and then swapped out again and so on. In such situations the system is struggling to find free memory and keep applications running at the same time. In this case only adding more RAM will help.

Linux has two forms of swap space: the swap partition and the swap file. The swap partition is an independent section of the hard disk used solely for swapping; no other files can reside there. The swap file is a special file in the filesystem that resides amongst your system and data files.

To see what swap space you have, use the command swapon -s. The output will look something like this:

Filename Type Size Used Priority

/dev/sda5 partition 859436 0 -1

Each line lists a separate swap space being used by the system. Here, the 'Type' field indicates that this swap space is a partition rather than a file, and from 'Filename' we see that it is on the disk sda5. The 'Size' is listed in kilobytes, and the 'Used' field tells us how many kilobytes of swap space has been used (in this case none). 'Priority' tells Linux which swap space to use first. One great thing about the Linux swapping subsystem is that if you mount two (or more) swap spaces (preferably on two different devices) with the same priority, Linux will interleave its swapping activity between them, which can greatly increase swapping performance.

To add an extra swap partition to your system, you first need to prepare it. Step one is to ensure that the partition is marked as a swap partition and step two is to make the swap filesystem. To check that the partition is marked for swap, run as root:

fdisk -l /dev/hdb

Replace /dev/hdb with the device of the hard disk on your system with the swap partition on it. You should see output that looks like this:

Device Boot Start End Blocks Id System

/dev/hdb1 2328 2434 859446 82 Linux swap / Solaris

If the partition isn't marked as swap you will need to alter it by running fdisk and using the 't' menu option. Be careful when working with partitions -- you don't want to delete important partitions by mistake or change the id of your system partition to swap by mistake. All data on a swap partition will be lost, so double-check every change you make. Also note that Solaris uses the same ID as Linux swap space for its partitions, so be careful not to kill your Solaris partitions by mistake.

Once a partition is marked as swap, you need to prepare it using the mkswap (make swap) command as root:

mkswap /dev/hdb1

If you see no errors, your swap space is ready to use. To activate it immediately, type:

swapon /dev/hdb1

You can verify that it is being used by running swapon -s. To mount the swap space automatically at boot time, you must add an entry to the /etc/fstab file, which contains a list of filesystems and swap spaces that need to be mounted at boot up. The format of each line is:

Since swap space is a special type of filesystem, many of these parameters aren't applicable. For swap space, add:

/dev/hdb1 none swap sw 0 0

where /dev/hdb1 is the swap partition. It doesn't have a specific mount point, hence none. It is of type swap with options of sw, and the last two parameters aren't used so they are entered as 0.

To check that your swap space is being automatically mounted without having to reboot, you can run the swapoff -a command (which turns off all swap spaces) and then swapon -a (which mounts all swap spaces listed in the /etc/fstab file) and then check it with swapon -s.
Swap file

As well as the swap partition, Linux also supports a swap file that you can create, prepare, and mount in a fashion similar to that of a swap partition. The advantage of swap files is that you don't need to find an empty partition or repartition a disk to add additional swap space.

To create a swap file, use the dd command to create an empty file. To create a 1GB file, type:

dd if=/dev/zero of=/swapfile bs=1024 count=1048576

/swapfile is the name of the swap file, and the count of 1048576 is the size in kilobytes (i.e. 1GB).

Prepare the swap file using mkswap just as you would a partition, but this time use the name of the swap file:

mkswap /swapfile

And similarly, mount it using the swapon command: swapon /swapfile.

The /etc/fstab entry for a swap file would look like this:

/swapfile none swap sw 0 0

How big should my swap space be?

It is possible to run a Linux system without a swap space, and the system will run well if you have a large amount of memory -- but if you run out of physical memory then the system will crash, as it has nothing else it can do, so it is advisable to have a swap space, especially since disk space is relatively cheap.

The key question is how much? Older versions of Unix-type operating systems (such as Sun OS and Ultrix) demanded a swap space of two to three times that of physical memory. Modern implementations (such as Linux) don't require that much, but they can use it if you configure it. A rule of thumb is as follows: 1) for a desktop system, use a swap space of double system memory, as it will allow you to run a large number of applications (many of which may will be idle and easily swapped), making more RAM available for the active applications; 2) for a server, have a smaller amount of swap available (say half of physical memory) so that you have some flexibility for swapping when needed, but monitor the amount of swap space used and upgrade your RAM if necessary; 3) for older desktop machines (with say only 128MB), use as much swap space as you can spare, even up to 1GB.

The Linux 2.6 kernel added a new kernel parameter called swappiness to let administrators tweak the way Linux swaps. It is a number from 0 to 100. In essence, higher values lead to more pages being swapped, and lower values lead to more applications being kept in memory, even if they are idle. Kernel maintainer Andrew Morton has said that he runs his desktop machines with a swappiness of 100, stating that "My point is that decreasing the tendency of the kernel to swap stuff out is wrong. You really don't want hundreds of megabytes of BloatyApp's untouched memory floating about in the machine. Get it out on the disk, use the memory for something useful."

One downside to Morton's idea is that if memory is swapped out too quickly then application response time drops, because when the application's window is clicked the system has to swap the application back into memory, which will make it feel slow.

The default value for swappiness is 60. You can alter it temporarily (until you next reboot) by typing as root:

echo 50 > /proc/sys/vm/swappiness

If you want to alter it permanently then you need to change the vm.swappiness parameter in the /etc/sysctl.conf file.
Conclusion

Managing swap space is an essential aspect of system administration. With good planning and proper use swapping can provide many benefits. Don't be afraid to experiment, and always monitor your system to ensure you are getting the results you need.