From a historic point of view, the Spanish language comes from the Latin language. In Latin there were three possible terminations for verbs: -are, -ere, -ire. These terminations have reached our days, in some cases unchanged as is the case of the Italian language. In Spanish the last e was simply dropped.
Now, where did the Latin verbs come from? I don't know, but in the theoretical common language Proto-Indo-European the verbs were formed by adding a suffix to a root to form the verb, and then adding an ending to form the word. If those suffixes were a reduced set, it would set the origin for every language with common terminations for verbs.
It's not uncommon to have a common termination for every verb in a language. Take the Japanese language, for instance. In that language, every verb ends with a -u syllable (-u, -ku, -su, ...). The English way seems to be more flexible as you can render any word into a verb. To do the same, we have to verbalise the word (as the invented word "googlear", meaning "to search something in Google".
Another example is the German language, a language I consider somewhat close to English, where every verb ends with -n. Thus, "to have" in German is haben. In fact, in Middle English this was the termination for every verb, so "to sing" comes from Middle English singen, and verbs were conjugated (singe, singest, singeþ, singen, singen, singen). Modern English just dropped the termination from the infinitive (but added the initial to) and simplified the conjugation, and the only thing that remains is the -s from the third person singular.
About your second question, the endings -ar, -er, -ir do not have a special meaning, and didn't have it even in Latin. One could think that the ending could depend on the last consonant or consonants of the stem, but in Spanish you have abrir and labrar, with very similar stems (abr- and labr-) but different terminations. You can even have different terminations for the same stem: morar and morir, and you get two completely different verbs.