Tuesday, January 8, 2013
Steps To Add Swap Space In AIX
1) Run lsps -a command to retrieve all the swap space in the system.
#lsps -a
Page Space Physical Volume Volume Group Size %Used Active Auto Type Chksum
hd6 hdisk2 rootvg 4608MB 81 yes yes lv 0
#
2) Run prtconf and look for hdisk2 physical volume. From below we noticed that there are free PPs so we are able to add more swap space.
#prtconf
←-- snipped ---->
=====================================================================
rootvg:
PV_NAME PV STATE TOTAL PPs FREE PPs FREE DISTRIBUTION
hdisk2 active 639 172 35..00..00..09..128
hdisk3 active 639 172 35..00..00..09..128
=====================================================================
←-- snipped ---->
3) To check more details on rootvg volume group follow this:
#lsvg rootvg
VOLUME GROUP: rootvg VG IDENTIFIER: 00f619aa00004c0000000131f69ac173
VG STATE: active PP SIZE: 32 megabyte(s)
VG PERMISSION: read/write TOTAL PPs: 1278 (40896 megabytes)
MAX LVs: 256 FREE PPs: 344 (11008 megabytes)
LVs: 11 USED PPs: 934 (29888 megabytes)
OPEN LVs: 10 QUORUM: 1 (Disabled)
TOTAL PVs: 2 VG DESCRIPTORS: 3
STALE PVs: 0 STALE PPs: 0
ACTIVE PVs: 2 AUTO ON: no
MAX PPs per VG: 32512
MAX PPs per PV: 1016 MAX PVs: 32
LTG size (Dynamic): 256 kilobyte(s) AUTO SYNC: no
HOT SPARE: no BB POLICY: relocatable
PV RESTRICTION: none INFINITE RETRY: no
4) To add 250MB swap space you need to add 8 PPs(8 x 32MB).
# mkps -a -n -s 8 rootvg
paging00
#
5)Verify the newly added paging space:
#cat /etc/swapspaces
* /etc/swapspaces
*
* This file lists all the paging spaces that are automatically put into
* service on each system restart (the 'swapon -a' command executed from
* /etc/rc swaps on every device listed here).
*
* WARNING: Only paging space devices should be listed here.
*
* This file is modified by the chps, mkps and rmps commands and referenced
* by the lsps and swapon commands.
hd6:
dev = /dev/hd6
auto = yes
checksum_size = 0
paging00:
dev = /dev/paging00
Check the status using lsps command.
#lsps -a
Page Space Physical Volume Volume Group Size %Used Active Auto Type Chksum
hd6 hdisk2 rootvg 4608MB 78 yes yes lv 0
paging00 hdisk2 rootvg 250MB 0 yes yes lv 0
#
Now to remove the paging space, we need to use the below commands.
# swapoff /dev/paging00
#
# rmps paging00
rmlv: Logical volume paging00 is removed.
#
#lsps -a
Page Space Physical Volume Volume Group Size %Used Active Auto Type Chksum
hd6 hdisk2 rootvg 4608MB 78 yes yes lv 0#
Thursday, January 3, 2013
ksh: 0403-030 The fork function failed. Too many processes already exist.
ksh: 0403-030 The fork function failed. Too many processes already exist.
Steps to resolve the above issue:
1) Check the process and look for defunct processes and owner of the process.
Defunct process is zombie process and do not take much resources but in this cases caused too many files exist for the particular user which generate the above error. We have to kill this processes in order to release it. The only way is to kill the parent processes for that particular owner. Reboot help too but we can avoid it.
2) Communicate with the user and retrieve all the parent processes that running under this owner. Request permission to kill all the process in order to release all the defunct processes.
Wednesday, January 2, 2013
Linux Rename Eth0/Eth1 Network Interface Card Name [ Udev ]
We can use udev to change these settings.
Step #1: Find out the MAC address of the Ethernet device
Type the following command:
# ifconfig -a | grep -i --color hwaddr
Sample outputs:
#ifconfig -a | grep -i --color hwaddr
eth1 Link encap:Ethernet HWaddr 00:0C:29:CD:5A:7F
virbr0 Link encap:Ethernet HWaddr 52:54:00:7F:E6:58
virbr0-nic Link encap:Ethernet HWaddr 52:54:00:7F:E6:58
Note down the MAC address.
Step #2: Rename eth0 as wan0
To rename eth0 as wan0, edit a file called 70-persistent-net.rules in /etc/udev/rules.d/ directory, enter:
# vi /etc/udev/rules.d/70-persistent-net.rules
The names of the Ethernet devices are listed in this file as follows:
# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:cd:5a:7f", ATTR{type}=="1", KERNEL=="eth*", NAME
="eth1"
Locate and identify the line with the NIC from step 1 (look for the MAC address). It may look like above. In this example, the interface eth1 will be renamed to wan0 (change NAME="eth1" to NAME="wan0"):
# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:cd:5a:7f", ATTR{type}=="1", KERNEL=="eth*", NAME
="wan0"
Save and close the file. Reboot the system to test changes:
# reboot
Verify new settings:
# ifconfig -a
# ifconfig wan0
Friday, December 21, 2012
Automation - System Administration.
System administrator writes scripts that the system can execute at a particular time each day,week or month. Tasks that are common and often repeated,tedious are best performed through automation. Two question came in our mind when think about automation which are "What can be automated?" and "What should be automated?". Following are few tasks that can be performed through automation.
1) Adding new users
2) Process monitoring
3) File search and removal.
4) Configuration changes on servers.
5) Getting servers information.( Big environment)
6) Software Installation.
7) Remote administration tasks.
The above tasks can be performed by writing scripts. Scripts are program that can interact with the operating system using OS commands.There are many scripting language that can be used to write scripts like shell(Korn,bash),Perl,Python and others.
Tasks can be automated with cron services where we can execute certain scripts at a particular time,day,week or month.
1) Adding new users
2) Process monitoring
3) File search and removal.
4) Configuration changes on servers.
5) Getting servers information.( Big environment)
6) Software Installation.
7) Remote administration tasks.
The above tasks can be performed by writing scripts. Scripts are program that can interact with the operating system using OS commands.There are many scripting language that can be used to write scripts like shell(Korn,bash),Perl,Python and others.
Tasks can be automated with cron services where we can execute certain scripts at a particular time,day,week or month.
Tuesday, December 18, 2012
5 Useful Linux Touch command
1) Create an empty file
Below will create 0 bytes file called 'test123'. It will change the modification/access timestamp.
#touch test123
Touch -c avoid creating non-existence file.
2)Create new file's timestamp
#touch -t 05070915 test123
3)Change modification time
# touch -m test123
4) Change access time
# touch -a test123
5)Copy other file's timestamp.
#touch try123 -r test123
Below will create 0 bytes file called 'test123'. It will change the modification/access timestamp.
#touch test123
Touch -c avoid creating non-existence file.
2)Create new file's timestamp
#touch -t 05070915 test123
3)Change modification time
# touch -m test123
4) Change access time
# touch -a test123
5)Copy other file's timestamp.
#touch try123 -r test123
Friday, June 15, 2012
$PATH
To export
export PATH=$PATH:/home/velayuts/Desktop
To delete
del=':/home/velayuts/Desktop';export PATH="${PATH//$del}"
export PATH=$PATH:/home/velayuts/Desktop
To delete
del=':/home/velayuts/Desktop';export PATH="${PATH//$del}"
Tuesday, November 22, 2011
SSH Trust:SSHv2 to SSHv2
Steps To configure as follows:
FSecure SSH v2 --> FSecure SSH v2Case Study: ssh trust for user kumar from Sun to Moon
1) sun:-->ssh-keygen2 -t dsa (Key will be generated at user's home - /home/kumar/.ssh2)
2) sun:/home/kumar/.ssh2-->cp id_dsa_1024_sun_a kumar@sun. (This step is done to give some useful name and to avoid confusion.)
3) sun:/home/kumar/.ssh2-->cp id_dsa_1024_sun_a.pub kumar@sun.pub (This step is done to give some useful name and to avoid confusion.)
4) sun:/home/kumar/.ssh2-->echo 'IdKey kumar@sun' > identification ('Identification' file will be created)
5) Copy kumar@sun.pub to remote host's(moon) /export/home/kumar/.ssh
6) moon#:/home/kumar/.ssh2-->echo 'Key mathamsv@oktstcl1.okla.seagate.com.pub' > authorization
7)Done.Now user 'kumar' can ssh without password from Sun to Moon.
FSecure SSH v2 --> FSecure SSH v2Case Study: ssh trust for user kumar from Sun to Moon
1) sun:-->ssh-keygen2 -t dsa (Key will be generated at user's home - /home/kumar/.ssh2)
2) sun:/home/kumar/.ssh2-->cp id_dsa_1024_sun_a kumar@sun. (This step is done to give some useful name and to avoid confusion.)
3) sun:/home/kumar/.ssh2-->cp id_dsa_1024_sun_a.pub kumar@sun.pub (This step is done to give some useful name and to avoid confusion.)
4) sun:/home/kumar/.ssh2-->echo 'IdKey kumar@sun' > identification ('Identification' file will be created)
5) Copy kumar@sun.pub to remote host's(moon) /export/home/kumar/.ssh
6) moon#:/home/kumar/.ssh2-->echo 'Key mathamsv@oktstcl1.okla.seagate.com.pub' > authorization
7)Done.Now user 'kumar' can ssh without password from Sun to Moon.
Wednesday, October 12, 2011
To Capture/Record Unix command
There is way to record/capture what ever commands executed in Unix. You can use 'script' command where all the command dumped to a file that we specify and this process executed at the background. This is very useful when we do some software installation and we are able to capture all the steps and commands that we used.
#script ApacheInstallationSteps.txt
Script started, file is ApacheInstallationSteps.txt
#
#exit
Script done, file is ApacheInstallationSteps.txt
#
#script ApacheInstallationSteps.txt
Script started, file is ApacheInstallationSteps.txt
#
#exit
Script done, file is ApacheInstallationSteps.txt
#
Friday, October 7, 2011
Linux:Steps to change root password
Steps to change root password:
1)When GRUB is started press any key followed by 'a' to modify the kernel arguments before booting.
2) Add 1 or single at the end of line and press 'b' to boot to the single user mode.
3) Once single user mode started you can run 'passwd' command to set new password for 'root'.
4) Exit or reboot the server once password has been reset.
1)When GRUB is started press any key followed by 'a' to modify the kernel arguments before booting.
2) Add 1 or single at the end of line and press 'b' to boot to the single user mode.
3) Once single user mode started you can run 'passwd' command to set new password for 'root'.
4) Exit or reboot the server once password has been reset.
LSOF command
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)
#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, 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.
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.
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.
Monday, April 6, 2009
How to Use a Query String in Perl
A query string is the part of a URL which is attached to the end, after the file name. It begins with a question mark and usually includes information in pairs. The format is parameter=value, as in the following example:
www.mediacollege.com/cgi-bin/myscript.cgi?topic=intro
Query strings can contain multiple sets of parameters, separated by an ampersand (&) like so:
www.mediacollege.com/cgi-bin/myscript.cgi?topic=intro&heading=1
The idea is that the information contained in the query string can be accessed and interpreted by a script. Specifically, the query string data is contained in the variable $ENV{'QUERY_STRING'}.
To Access the Query String Data
You can use a block of code like the one below to access and organise the query string:
if (length ($ENV{'QUERY_STRING'}) > 0){
$buffer = $ENV{'QUERY_STRING'};
@pairs = split(/&/, $buffer);
foreach $pair (@pairs){
($name, $value) = split(/=/, $pair);
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$in{$name} = $value;
}
}
This code will create a hash called $in, from which you can call specific variables like so:
$topic = $in{'topic'};
$heading = $in{'heading'};
Sample code:
#!/usr/bin/perl
# Whether the method used is GET or POST, store the parameters passed in $QueryString
if($ENV{'REQUEST_METHOD'} eq "POST") {
read(STDIN, $QueryString, $ENV{'CONTENT_LENGTH'});
} else {
$type = "display_form";
$QueryString = $ENV{QUERY_STRING};
}
# split the QueryString at &'s to give you a list with each element with a format like "name=value"
@NameValuePairs = split (/&/, $QueryString);
# Split each NameValue pair, replace +'s by spaces, get the character equivalent of any data in hex (%XX) and finally, store it in an associative array
foreach $NameValue (@NameValuePairs) {
($Name, $Value) = split (/=/, $NameValue);
$Value =~ tr/+/ /;
$Value =~ s/%([\dA-Fa-f][\dA-Fa-f])/ pack ("C",hex ($1))/eg;
$in{$Name} = $Value;
$color =$in{'color'};
$name =$in{'name'};
}
print "Content-type: text/html", "\n\n";
HTML CODE HERE
www.mediacollege.com/cgi-bin/myscript.cgi?topic=intro
Query strings can contain multiple sets of parameters, separated by an ampersand (&) like so:
www.mediacollege.com/cgi-bin/myscript.cgi?topic=intro&heading=1
The idea is that the information contained in the query string can be accessed and interpreted by a script. Specifically, the query string data is contained in the variable $ENV{'QUERY_STRING'}.
To Access the Query String Data
You can use a block of code like the one below to access and organise the query string:
if (length ($ENV{'QUERY_STRING'}) > 0){
$buffer = $ENV{'QUERY_STRING'};
@pairs = split(/&/, $buffer);
foreach $pair (@pairs){
($name, $value) = split(/=/, $pair);
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$in{$name} = $value;
}
}
This code will create a hash called $in, from which you can call specific variables like so:
$topic = $in{'topic'};
$heading = $in{'heading'};
Sample code:
#!/usr/bin/perl
# Whether the method used is GET or POST, store the parameters passed in $QueryString
if($ENV{'REQUEST_METHOD'} eq "POST") {
read(STDIN, $QueryString, $ENV{'CONTENT_LENGTH'});
} else {
$type = "display_form";
$QueryString = $ENV{QUERY_STRING};
}
# split the QueryString at &'s to give you a list with each element with a format like "name=value"
@NameValuePairs = split (/&/, $QueryString);
# Split each NameValue pair, replace +'s by spaces, get the character equivalent of any data in hex (%XX) and finally, store it in an associative array
foreach $NameValue (@NameValuePairs) {
($Name, $Value) = split (/=/, $NameValue);
$Value =~ tr/+/ /;
$Value =~ s/%([\dA-Fa-f][\dA-Fa-f])/ pack ("C",hex ($1))/eg;
$in{$Name} = $Value;
$color =$in{'color'};
$name =$in{'name'};
}
print "Content-type: text/html", "\n\n";
HTML CODE HERE
Thursday, April 2, 2009
Linux Remote Desktop For Controlling Windows XP / Vista / Server 2003 ( rdesktop )
Connect to MS Windows 2000/2003 server from Linux, type the following command at a shell prompt (connect to Windows server called mw2sn100.mycorp.com)
$ rdesktop mw2sn100.mycorp.com
Or connect to windows XP/Vista workstation having IP 192.168.1.17:
$ rdesktop -a 24 -r sound:remote pg-svelayut &
Remote windows XP desktop
Please note that you must first enable remote desktop connection under Windows Server/XP.
* Go to Windows XP Desktop
* Right Click on My Computer
* Select properties
* Select Remote tab
* Enable Remote desktop.
* Save the changes.
Make sure enterprise firewall allows incoming connection on TCP port 3389. rdesktop supports many other options, see man page of rdesktop or visit main website of rdesktop for more information.
$ rdesktop mw2sn100.mycorp.com
Or connect to windows XP/Vista workstation having IP 192.168.1.17:
$ rdesktop -a 24 -r sound:remote pg-svelayut &
Remote windows XP desktop
Please note that you must first enable remote desktop connection under Windows Server/XP.
* Go to Windows XP Desktop
* Right Click on My Computer
* Select properties
* Select Remote tab
* Enable Remote desktop.
* Save the changes.
Make sure enterprise firewall allows incoming connection on TCP port 3389. rdesktop supports many other options, see man page of rdesktop or visit main website of rdesktop for more information.
Wednesday, April 1, 2009
Map Linux nfs drive from DOS
How to map a drive using command prompt
First click on Start and then Run. Type cmd in the Open box.
Then type the following DOS command to map the network drive:
net use x: \\computer name\share name
where x: is the drive letter you want to assign to the shared folder.
You can delete a mapped network drive using the command prompt by typing in
net use x: /delete
First click on Start and then Run. Type cmd in the Open box.
Then type the following DOS command to map the network drive:
net use x: \\computer name\share name
where x: is the drive letter you want to assign to the shared folder.
You can delete a mapped network drive using the command prompt by typing in
net use x: /delete
Subscribe to:
Posts (Atom)