I bought the magnets at Harbor Frieght, Item No. 98406. They have a 3# pull each. Take the package and stick it to a metal shelf and pick the strongest ones -- there's some variation and you should be able to feel it. Cost from $1 to $2/pk, depending on sales etc. There's also a 5# set, 97504 that the local store doesn't stock.

The metal plate is a mending plate from any hardware store, usually less than 50 cents. Even if you use velcro as an attachment method, use a metal backing plate, it acts as a "keeper" for the magnets.

Glue magnets to plate, spacing to miss holes. Align the poles of the magnets so they don't fight each other, and leave a small gap between the magnets. Lay one magnet on a smooth surface, and move the other around. They'll jump to align. Any decent glue will work, but degrease the plate first. Spray paint is to protect pistol finish, you can get as fancy or sloppy as you want.
A simple magnetic pistol holder for $2.00
Top picture was the MK-1 model, two magnets glued to a 1" wide mending plate. The plate has stick on velcro, and the other half of the heavy duty stick on velcro is on the furniture. I did this because I didn't want to put holes in a piece of antique furniture.

Bottom picture is the Mk-2, the plate screwed to the bottom of the shelf. The pistol is a full sized 1911 with a full magazine of 230g, and weighs quit a bit. Even with a curved top on the pistol, it holds securely.

The pistols remove easily, but hold securely. A strong smack on the furniture at the correct angle can dislodge it, so use common sense in where you place the holder, or more/stronger magnets.

The 3# (6# total) magnets are strong enough to hold most plstols flat against the shelf, but pistols are easier to get at with the handle down. The examples are show out in the open, but the usefullness of this holder is that it can be hidden inside and under furniture, behind pictures, etc., and still provide a quick release.