The officer whose duty it is to attend to the quarters of the soldiers. He superintends the issue of stores, food, and clothing. (See Quarters.)
As a nautical term, a quartermaster is a petty officer who, besides other duties, attends to the steering of the ship.
Source: Dictionary of Phrase and Fable, E. Cobham Brewer, 1894
More on Quartermaster from Infoplease: