Usage example:
#lsof -i TCP (Show all open TCP files)
#lsof -i TCP:80 (Show open TCP files on port 80)
#lsof -c passwd (to find out what files opened when execute this command)
#lsof /dev/sda3 ( which files opened for a device)
Friday, October 7, 2011
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
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
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
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.
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
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.
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
inet 127.0.0.1 netmask ff000000
ce0: flags=1000843
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
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.
Subscribe to:
Posts (Atom)