Apparently “ahoy” was a common greeting before the telephone was invented, to the point that Alexander Graham Bell suggested it for use when answering the phone.
I'm not really convinced that "ahoy" was that common beforehand. AFAIK, Graham Bell wanted a different greeting than what was commonly used as to differentiate greeting on the phone with greeting IRL.