"What is a good exercise to help avoid knee pain, shin splints and other ailments when starting to train for races?"
Having a proper base of strength is crucial when beginning a running program. The best way to achieve this is by having strong legs and a stable core.
Weighted squats will always rule the day when choosing exercises to enhance athletic ability and avoid injury. Uni-lateral exercises, such as lunges, Bulgarian squats and one leg Romanian dead lifts are also very import to build strength, stabilization and power.
Post exercise - foam rolling is an important post exercise, rolling will help to prevent repetitive injury. Most Importantly, don't go by the "seat of your pants." Have a plan of when to implement your strength work, and when and how far to run.
Failing to prepare is preparing to fail.