"horizontal bar passing from one post or support to another," c. 1300, from Old French raille, reille "bolt, bar," from Vulgar Latin *regla, from Latin regula "rule, straight piece of wood," diminutive form related to regere "to straighten, guide" (from PIE root *reg- "move in a straight line").
In U.S. use, "A piece of timber, cleft, hewed, or sawed, inserted in upright posts for fencing" [Webster, 1830]. Used figuratively for thinness from 1872. By 1830s as "iron or steel bar or beam used on a railroad to support and guide the wheels." To be off the rails "out of the normal or proper condition" in a figurative sense is from 1848, an image from railroads.
"small wading bird," mid-15c., rale, from Old French raale (13c.), related to râler "to rattle," which is of unknown origin, perhaps imitative; the bird would be so called for its cry.
"complain, speak vehemently and bitterly," late 15c., railen, from Old French raillier "to tease or joke" (15c.), which is perhaps from Old Provençal ralhar "scoff, to chat, to joke," from Vulgar Latin *ragulare "to bray" (source also of Italian ragghiare "to bray"), from Late Latin ragere "to roar," probably of imitative origin. See rally (v.2). Related: Railed; railing.