Before the development of vaccines, the only way to develop immunity to a disease was to be exposed to the germs that cause that disease. This could mean that you actually got the disease, or it could mean that you were exposed to it by people around you.
In general, vaccines give you immunity by putting a relatively small number of germs inside your body. At that point, your immune system starts to produce antibodies in response to the introduction of the germs.
In the old days, you got however many germs you happened to get exposed to -- not a controlled dose like in a vaccine. If you survived, you had more immunity to the disease.
Sad fact is that before development of vaccines, not many people acquired immunity to diseases, at least not the very serious ones. The only way for people to acquire the kind of immunity provided by vaccines, was to get infected by a disease accidentally and survive the disease that followed the infection.
As a matter of fact the concept of vaccination occurred to Edward Jenner (1749-1823), by observing that people who acquired cowpox did not catch smallpox. This represented cases of people developing immunity from smallpox when accidentally infected with cowpox.
The fact that one could catch smallpox only once, was well known in times before Jenner. People did try to develop immunity from smallpox by inoculating themselves by smallpox sores. But usually this method proved fatal.