Single Node Persistence
Problem this snippet solves:
A really slick & reliable way to stick to one and only one server in a pool.
Requirement: Direct traffic to only a single node in a pool at a time. Initially, traffic should always go to node A. If Node A fails, then traffic will go to Node B. When Node A comes back online, traffic should continue to go to Node B. When Node B fails, then the traffic should go to Node A.
To send traffic to only 1 pool member at a time, you can use an iRule and Universal Persistence to set a single persistence record that applies to all connections.
- Create a virtual server.
- Create a pool with the real servers in it.
- Create an iRule like this:
- Create a Persistence profile of type Universal which uses the iRule you just created. Set the timeout high enough so it will never expire under typical traffic conditions.
- In the virtual server definition, apply pool as the default pool, and the new persistence profile as the default persistence profile (both on the virtual server "resources" screen).
The first connection will create a single universal persistence record with a key of "1". All subsequent connections will look up persistence using "1" as the key, resulting in truly universal persistence for all connections. (Use 1 or any constant value. 0 will have the same affect as using 1. One of my customers uses "persist uie TCP__local_port"
When one node fails, the other is persisted to by all comers. When the 2nd node fails, the 1st again becomes the preferred node for all, ad infinitum.
Doesn't offer the capability of manual resume after failure, or true designation of a "primary" and "secondary" instance (sometimes required for db applications), but it sure does solve the problem of "only use one node at a time, I don't care which one, please" (You can use priority to gravitate towards the top of a list...)
Note: Priority-based load balancing with or without dynamic persistence doesn't quite address this requirement. Priority load balancing allows you to set a preferred server to which traffic should return once it recovers. With just Priority, and with dynamic persistence of any kind enabled, when a higher priority nodes come back up after failing, you will see traffic distributed across multiple pool members until old connections/sessions die off. With just Priority and no persistence, existing sessions will break once the preferred node again becomes available.
Code :
rule PriorityFailover { when CLIENT_ACCEPTED { persist uie 1 } }
- AgungDes_195148NimbostratusHi Guys, I tried to using this code for the iRules but it still show another error for the iRules The Error Message like This One : 01070151:3: Rule [/Common/single_node] error: /Common/single_node:1: error: [undefined procedure: rule][rule PriorityFailover { when CLIENT_ACCEPTED { persist uie 1 } }]
- slouma_210072Nimbostratusthe same problem please help us if somebody has an idea
- CharlesCS_14932NimbostratusOnly specify the 2nd line when creating the iRule. The "rule" line and the closing brace are created by the GUI.
- Adam_Ali_246975Nimbostratusis this solution applicable to BIG-IP v10.x?
- lenny19_269578Nimbostratusvery good stuff, worked a treat
- JTB_63532Nimbostratus
This iRule just made my day! Thanks!
- Stanislas_Piro2Cumulonimbus
Hi,
Another solution is to use a destination address persistence profile.
As the destination (IP address of the virtual server) is always the same, all requests will use only one pool member.
- Michael_Gilin_1Historic F5 Account
Hi, Using "persist uie 1" iRule is not recommended, since under certain conditions when a chosen pool member/node goes down it may lead to inconsistent persistence entries between TMMs (i.e. different TMMs may end up with persistence entries to different nodes).
If you need to persist to single pool member/node, use destination address persistence profile.
- jdeeby_270877Nimbostratus
I am getting this error when writing the rule.
1: error: [undefined procedure: persist uie 1 ][{ persist uie 1 }]
Here is the syntax when CLIENT_ACCEPTED { { persist uie 1 } }
- Stanislas_Piro2Cumulonimbus
@jdeeby why didn't you copy / paste the code?
provided code :
when CLIENT_ACCEPTED { persist uie 1 }
your code:
when CLIENT_ACCEPTED { { persist uie 1 } }
or as I and Michael commented, use destination address persistence