HAProxy Enterprise Documentation 1.6r1

set map

Change the value of a map file entry.


Use set map to find an entry in a map file and replace its value.


Assume that you have a map file named /etc/hapee-1.6/routes.map with the following contents where the first column contains the keys and the second contains the values:

/cart/     cart_api
/reviews/  reviews_api

In the HAProxy Enterprise configuration, we reference this map file on a use_backend line with the map_beg fetch method. This tells the load balancer to choose the backend from the map file by matching the beginning of the requested URL path with a key in the file:

frontend fe_main
   bind :80
   use_backend %[path,map_beg(/etc/hapee-1.6/routes.map,be_servers)]
  1. Use the show maps command to list map files and their unique IDs. Here, the map file /etc/hapee-1.6/routes.map has an ID of 0:

    $ echo "show map" | socat stdio tcp4-connect:
    # id (file) description
    0 (/etc/hapee-1.6/routes.map) pattern loaded from file '/etc/hapee-1.6/routes.map' used by map at file '/etc/hapee-1.6/hapee-lb.cfg' line 61
  2. Pass the map file's unique ID to show map to display entries in the file:

    $ echo "show map #0" | socat stdio tcp4-connect:
    0x563bbeeee160 /cart/ cart_api
    0x563bbeeee1a0 /reviews/ reviews_api
  3. Pass to the set map command the map's ID, the key in the map to find, and a value that should replace the existing value.

    Alternatively, use the map file's path instead of its ID.

    In the example below, we replace the value cart_api with web_servers for the key /cart/:

    $ echo "set map #0 /cart/ web_servers" | socat stdio tcp4-connect:
  4. Call show map again to see that the value has been replaced:

    $ echo "show map #0" | socat stdio tcp4-connect:
    0x563bbeeee160 /cart/ web_servers
    0x563bbeeee1a0 /reviews/ reviews_api

See also

Next up

set maxconn frontend