When a disease causing microbe enters our body, the immune system first sees and remembers it. So the next time the same microbe or its close relative enters our body the immune system remember the microbe and respond to it with even more vigour, thus eliminating the disease causing microbe from our body.
When a microbe enter the body of the healthy human the immune system sends wbc's that fight the microbe and flush it out of the body. When the microbe trys to enter again the immune system identifies the microbe and does not allow the passage of it.