To earn a salary is to be paid a fixed sum that secures your services over an agreed period. The alternative is to be paid wages, which means a sum of money for each job or hour worked.
To be paid a salary was at one time the mark of being middle class, the word wages being reserved for the working classes.
The word salary has been used in English since the 14th century, when it was mainly used to describe the pay of a priest. It comes from the Latin salarium, meaning salary or stipend, particularly that paid to soldiers. The word derives ultimately from sal, meaning salt.
It has long been believed that this is because Roman soldiers were paid in salt, an idea that lives on in the expression 'to be worth your salt'. It's more likely they got an allowance for salt on top of their normal pay. Or their salarium was what they were paid to guard the 'salt roads' leading to Rome or the 'salt beds' where the precious substance was extracted from sea water.
Like so many etymological stories, these are best taken with a pinch of salt.