Monday, 10 March 2014

IP BONDING IN LINUX



IP BONDING IN LINUX

Linux network Bonding is creation of a single bonded interface by combining 2 or more Ethernet interfaces. This helps in high availability of your network interface and offers performance improvement. Bonding is same as port trunking or teaming.
Bonding allows you to aggregate multiple ports into a single group, effectively combining the bandwidth into a single connection. Bonding also allows you to create multi-gigabit pipes to transport  traffic through the highest traffic areas of your network. For example, you can aggregate three megabits ports into a three-megabits trunk port. That is equivalent with having one interface with three megabytes speed
Steps for bonding in Oracle Enterprise Linux and Redhat Enterprise Linux are as follows..
Step 1.
Create the file ifcfg-bond0 with the IP address, netmask and gateway. Shown below is my test bonding config file.
$ cat /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
IPADDR=192.168.1.12
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
USERCTL=no
BOOTPROTO=none
ONBOOT=yes
Step 2.

Modify eth0, eth1 and eth2 configuration as shown below. Comment out, or remove the ip address, netmask, gateway and hardware address from each one of these files, since 
settingsDescription: http://cdncache-a.akamaihd.net/items/it/img/arrow-10x10.pngshould only come from the ifcfg-bond0 file above. Make sure you add the MASTER and SLAVE configuration in these files.
$ cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
# Settings for Bond
MASTER=bond0
SLAVE=yes
$ cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
BOOTPROTO=none 
ONBOOT=yes
USERCTL=no
# Settings for bonding
MASTER=bond0
SLAVE=yes
$ cat /etc/sysconfig/network-scripts/ifcfg-eth2
DEVICE=eth2
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
Step 3.

Set the parameters for bond0 bonding kernel module. Select the network bonding mode based on you need, The modes are
  • mode=0 (Balance Round Robin)
  • mode=1 (Active backup)
  • mode=2 (Balance XOR)
  • mode=3 (Broadcast)
  • mode=4 (802.3ad)
  • mode=5 (Balance TLB)
  • mode=6 (Balance ALB)
Add the following lines to /etc/modprobe.conf
# bonding commands
alias bond0 bonding 
options bond0 mode=1 miimon=100
Step 4.
Load the bond driver module from the command prompt.
$ modprobe bonding
Step 5.
Restart the network, or restart the computer.
$ service network restart # Or restart computer
When the machine boots up check the proc settings.
$ cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.0.2 (March 2, 2014)
Bonding Mode: adaptive load balancing
Primary Slave: None
Currently Active Slave: eth2
MII status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth2
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:13:72:80: 62:f0
Look at ifconfig -a and check that your bond0 interface is active. You are done!.
To verify whether the failover bonding works..
  • Do an ifdown eth0 and check /proc/net/bonding/bond0 and check the “Current Active slave”.
  • Do a continous ping to the bond0 ipaddress from a different machine and do a ifdown the active interface. The ping should not break.

TCPDUMP IN LINUX AND SNOOP IN SOLARIS



TCPDUMP IN LINUX AND SNOOP IN SOLARIS
 

TCPDUMP IN LINUX:

[root@gagan ~]# tcpdump –help

OPTIONS:

-S  : Print absolute sequence numbers.

-e  : Get the ethernet header.

-q  : Show less protocol information.

-E  : Decrypt IPSEC traffic by providing an encryption key.

-n  : Don't resolve hostnames.

-nn : Don't resolve hostnames or port names.

-X  : Show the packet's contents in both hex and ASCII.

-XX : Same as -X, but also shows the ethernet header.

-v, -vv, -vvv : Increase the amount of packet information you get back.

-c  : Only get x number of packets and then stop.

-s  : Define the snaplength (size) of the capture in bytes. 

      Use -s0 to get everything, unless you are intentionally capturing less.
 
 
Regular Expressions:
AND    -  and or &&

OR     -   or or ||

EXCEPT -  not or !
 
 
 
TCPDUMP COMMAND EXAMPLES:
 
1.  To capture all the interfaces network traffic using tcpdump,just run command “tcpdump”
 
    [root@gagan ~]# tcpdump
 
       2. To capture the network traffic on the particular interface,
    [root@gagan ~]# tcpdump -i eth0
  
   3.To capture the “N” no of network packets , use “-c” option (To    specify“N”  value.)

[root@gagan ~]# tcpdump -c 8 -i eth0
    4. To capture the network traffic between two IP address.
           Source IP address: Local system IP
            Destination IP address:Remote system IP
  [root@gagan ~]# tcpdump src 10.0.0.2 and dst host 10.0.04 -c 10
 
       5. To capture the specific local port traffic using tcpdump,
  [root@gagan ~]# tcpdump src port 21 -c 9
 
       6. To capture network traffic of destination port ,
  [root@gagan ~]# tcpdump dst port 21 -c 8
  
       7. To filter the network traffic using destination IP address and local port number,
  [root@gagan ~]# tcpdump dst 10.0.0.4  and src port 21 -c 9
 
      8. To filter the specific network traffic,use the below command.
  [root@gagan ~]# tcpdump net 10.0.0.0/24 -c 8
 
     9. To filter the traffic using the protocal, Ex:ICMP
  [root@gagan ~]# tcpdump icmp
 
    10. To filter the traffic using port range,
  [root@gagan ~]# tcpdump portrange 21-25 -c 9
 
   11. To capture the network packets to the file, use “-w” option.File should have extension with the name “pcap”.
   [root@gagan ~]# tcpdump portrange 21-25 -w saveme.pcap
 
 
 
 
SNOOP IN SOLARIS
 
OPTIONS:
 
snoop
        [ -a ]                  # Listen to packets on audio
        [ -d device ]           # settable to le?, ie?, bf?, tr?
        [ -s snaplen ]          # Truncate packets
        [ -c count ]            # Quit after count packets
        [ -P ]                  # Turn OFF promiscuous mode
        [ -D ]                  # Report dropped packets
        [ -S ]                  # Report packet size
        [ -i file ]             # Read previously captured packets
        [ -o file ]             # Capture packets in file
        [ -n file ]             # Load addr-to-name table from file
        [ -N ]                  # Create addr-to-name table
        [ -t  r|a|d ]           # Time: Relative, Absolute or Delta
        [ -v ]                  # Verbose packet display
        [ -V ]                  # Show all summary lines
        [ -p first[,last] ]     # Select packet(s) to display
        [ -x offset[,length] ]  # Hex dump from offset for length
        [ -C ]                  # Print packet filter code
        [ -q ]                  # Suppress printing packet count
        [ -r ] 
 
 
EXAMPLES OF SNOOP:
 
1. capture all packets going to and from the box gagan007.
  # snoop host gagan007
2. We can also see all packets that goes through specific port. In this case it is port 22.
  # snoop port 22
3. To examine only packets on specific interface (eth0) and store the output to the file, enter the following:
  # snoop -d eth0 -o /tmp/output1.file
4. You can read your captured output file by issuing following command:
  # snoop -i /tmp/output.file
  # snoop -v host system2 port 513
5. Observing Traffic by Identifying the Zone
  # snoop -I eth0 gagan1 -I eth1 gagan2





 
 
 
 

 
 
 
 


Monday, 19 August 2013

JBOSS EAP6 extension,subsystems and profiles

                              JBOSS EAP6 extension,subsystems and profiles

Jboss eap 6 application server default is very lightweight and extremely fast.you can start default standalone server instance more or less than in 3 sec.

For understanding jboss eap6 it is very important to understand extension,subsystems and profiles.

so let start with extensions..

Extensions

In simple terms extension are modules that extends core capabilities of EAP.
Java EE capabilities, clustering, transactions, security and logging are all extensions of the EAP core.

An extension is added using the <extension> tag in the beginning of the EAP configuration file. (standalone.xml or domain.xml)

Subsystems 

A subsystem is the set of capabilities added by an extension.It defines how it will be used and configured. It is also defined in the EAP configuration file (standalone.xml or domain.xml) using the <subsystem> tag under a profile.

                             For every extension added in an EAP instance, the  capabilities and attributes of that extension are configured with the <subsystem> element. If no setting is required then you may simply leave the element empty. (e.g. <subsystem xmlns=”urn:jboss:domain:ee:1.0″/>)

Profiles

A profile is defined in the EAP configuration file using the <profile> element.It is  a collection of subsystems, along with the details of each subsystem’s configuration.

                     Profile is a set of subsystems combined for different purposes. For domain-mode, four profiles are defined by default. (default, ha, full, full-ha) For standalone-mode, an un-named profile is set.

Tuesday, 13 August 2013

Difference between JSON and XML

                                Difference between JSON and XML


JSON's concise syntax makes it very light and compact. It is also easier to parse from JavaScript, and that’s one of the main reasons it’s preferred for browser-based client-side applications (note that JSON stands for JavaScript Object Notation, it’s just natural). If you want to work with XML from JavaScript, you'll need to use an extra library for that. With JSON, you can just parse the message (let’s say with JSON.Parse() ) and work directly with js objects.


JSON.parse('{"name":"ram"}');

Difference between SOAP and REST

                                Difference Between soap and REST

SOAP

- A service architecture
- XML based
- Runs on HTTP but envelopes the message
- Slower than REST
- Very mature, a lot of functionality
- Not suitable for browser-based clients

REST

- A service architecture (resource-oriented)
- Uses the HTTP headers to hold meta information (although it is protocol-agnostic)
- Can be used with XML, JSON or whatever necessary
- Usually used with JSON due to the easily parsable content
- Faster than SOAP
- It uses semantic media types


The Representational State Transfer (REST) is another architectural pattern (resource-oriented), an alternative to SOAP. Unlike SOAP, RESTful applications use the HTTP build-in headers (with a variety of media-types) to carry meta information and use the GET, POST, PUT and DELETE verbs to perform CRUD operations. REST is resource-oriented and uses clean URLs (or RESTful URLs). 

 
For example :
http://www.developingthefuture.com/index.php?page=foo

 
becomes
 
http://www.developingthefuture.com/foo

 
This kind of URLs syntax greatly improves both visibility and usability. It doesn’t use any query strings, and it also provides certain SEO benefits (the crawlers just love plain text). The body of the REST message can be XML, JSON or any other format, although JSON is usually the preferred choice. On the other hand, you can’t use JSON with SOAP. Or at least not entirely, because SOAP uses XML by definition for it’s envelope. It should also mentioned that REST is, by design, protocol-agnostic, although it is usually used with HTTP
 

Saturday, 1 December 2012

Garbage collection Document



What is Garbage Collection?
Garbage Collection in computer science is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage, or memory occupied by objects that are no longer in use by the program. Garbage collection does not traditionally manage limited resources other than memory that typical programs use, such as network sockets, database handles, user interaction windows, and file and device descriptors.

History:
Garbage collection was invented by John McCarthy around 1959 to solve problems in Lisp.

Basic principle of Garbage Collection:
The basic principles of garbage collection are:
Find data objects in a program that cannot be accessed in the futureReclaim the resources used by those objects
It is kind of interesting to know how the objects without reference are found. Java normally finds all the objects that have reference and then regards rest of the objects are reference less – which is in fact a very smart way of finding the unreferenced java objects.

Types of Java Garbage Collectors/Garbage Collection Algorithms:
On J2SE 5.0 and above, one can normally find the following types of Java Garbage collectors that the programmers can normally choose to do a garbage collection through JVM Parameters.

1.) Serial Collector:
JVM Option Parameter: -XX:+UseSerialGC

2.) Throughput Collector or The Parallel Collector:
 JVM Option Parameter: -XX:+UseParallelGC
    Young Generation GC done in parallel threads
    Tenured Generation GC done in serial threads.

Parallel Old Generation Collector:
 JVM Option Parameter: -XX:+UseParallelOldGC
    Certain phases of an ‘Old Generation’ collection can be performed in parallel, speeding up a old generation collection.

The Concurrent Low Pause Collector:
  JVM Option Parameter -Xincgc or -XX:+UseConcMarkSweepGC
    The concurrent collector is used to collect the tenured generation and does most of the collection concurrently with the execution of the application. The application is paused for short periods during the collection.
    A parallel version of the young generation copying collector is used with the concurrent collector.
    The concurrent low pause collector is used if the option -XX:+UseConcMarkSweepGC is passed on the command line.
    -XX:+UseConcMarkSweepGC -XX:+UseParNewGC
        Selects the Concurrent Mark Sweep collector.
        This collector may deliver better response time properties for the application (i.e., low application pause time).
        It is a parallel and mostly-concurrent collector and and can be a good match for the threading ability of an large multi-processor systems.

The incremental (sometimes called train) low pause collector:
JVM Option Parameter: -XX:+UseTrainGC
This collector has not changed since the J2SE Platform version 1.4.2 and is currently not under active development.
It will not be supported in future releases.

Note that -XX:+UseParallelGC should not be used with -XX:+UseConcMarkSweepGC .

Benefits of Garbage Collection:
Garbage collection frees the programmer from manually dealing with memory deallocation. As a result, certain categories of bugs are eliminated or substantially reduced:
 Dangling pointer bugs, which occur when a piece of memory is freed while there are still pointers to it, and one of those pointers is then used. By then the memory may have been re-assigned to another use, with unpredictable results.
    Double free bugs, which occur when the program tries to free a region of memory that has already been freed, and perhaps already been allocated again.
    Certain kinds of memory leaks, in which a program fails to free memory occupied by objects that will not be used again, leading, over time, to memory exhaustion.

Disadvantages of Garbage Collection:
 Consumes computing resources in deciding what memory is to be freed, reconstructing facts that may have been known to the programmer often leading to decreased or uneven performance.
    Interaction with memory hierarchy effects can make this overhead intolerable in circumstances that are hard to predict or to detect in routine testing.
    The moment when the garbage is actually collected can be unpredictable, resulting in stalls scattered throughout a session.
    Memory may leak despite the presence of a garbage collector, if references to unused objects are not themselves manually disposed of. This is described as a logical memory leak.The belief that garbage collection eliminates all leaks leads many programmers not to guard against creating such leaks.
    In virtual memory environments, it can be difficult for the garbage collector to notice when collection is needed, resulting in large amounts of accumulated garbage, a long, disruptive collection phase, and other programs’ data swapped out.
    Garbage collectors often exhibit poor locality (interacting badly with cache and virtual memory systems), occupy more address space than the program actually uses at any one time, and touch otherwise idle pages.
    Garbage collectors may cause thrashing, in which a program spends more time copying data between various grades of storage than performing useful work.



what's the difference between the serial, parallel and CMS (Concurrent-Mark-Sweep) collectors?
 first of all, let's take a look which collectors operate on the young generation and which on the tenured (old) generation:
 the following collectors operate on the young generation:
-XX:+UseSerialGC
-XX:+UseParallelGC
-XX:+UseParNewGC

the following collectors operate on the old generation:
-XX:+UseParallelOldGC
-XX:+UseConcMarkSweepGC

what's the difference between the Serial and the Parallel collector?
both the serial and parallel collectors cause a stop-the-world during the GC.
so what's the difference between them?
a serial collector is a default copying collector which uses only one GC thread for the GC operation, while a parallel collector uses multiple GC threads for the GC operation.

what's the difference between the Parallel and the CMS collector?
the CMS performs the following steps (all made by only one GC thread):
- initial mark
- concurrent marking
- remark
- concurrent sweeping
 there are two differences between a parallel and a CMS collectors:
1) the parallel uses multiple GC threads, while the CMS uses only one.
2) the parallel is a 'stop-the-world' collector, while the CMS stops the world only during the initial mark and remark phases.
during the concurrent marking and sweeping phases, the CMS thread runs along with the application's threads.
  if you wish to combine both parallelism and concurrency in your GC, you can use the following:
-XX:UserParNewGC for the new generation (multiple GC threads)
-XX:+UseConcMarkSweepGC for the old generation (one GC thread, freezes the JVM only during the initial mark and remark phases)

Selecting a Garbage Collector
 If the application has a small data set (up to approximately 100MB), then
        select the serial collector with -XX:+UseSerialGC.

    If the application will be run on a single processor and there are no pause time requirements, then
        let the VM select the collector, or
        select the serial collector with -XX:+UseSerialGC.

    If (a) peak application performance is the first priority and (b) there are no pause time requirements or pauses of one second or longer are acceptable, then
        let the VM select the collector, or
        select the parallel collector with -XX:+UseParallelGC and (optionally) enable parallel compaction with -XX:+UseParallelOldGC.

    If response time is more important than overall throughput and garbage collection pauses must be kept shorter than approximately one second, then
        select the concurrent collector with -XX:+UseConcMarkSweepGC. If only one or two processors are available, consider using incremental mode

Parameter to Enable Garbage Collection Logs
-XX:+PrintGCTimeStamps
-XX:+PrintGCDetails