Make sure the tracks are well lit so that mobs won't spawn on them, and put fences or other barriers either side to prevent mobs from walking onto the tracks.
You may consider completely encasing the tracks if you wish to prevent skeleton arrows and spiders.