Since he has been having diarrhea on and off, I am guessing that his anal glands are not emptying as they should. For the anal glands to successfully empty, a dog needs solid stools.
When anal glands do not empty as they should, they become impacted. Your dog will feel uncomfortable, and this will trigger licking, biting and scooting. Since he is discharging some anal gland secretions, I am guessing he has been biting the area or scooting which has caused his bum to get all red.
There is really no quick fix. You will need to correct the diarrhea as it is the underlying cause. Sometimes feeding some plain pumpkin (not the pumpkin pie type with spices added) may help firm up the stools. However, sometimes diarrhea can be caused by parasites, dietary indiscretions, or systemic disorders, so a vet visit is in order if the diarrhea is persistent.
As a temporary measure, you can try limiting his biting to the area by using an Elizabethan collar. The skin can be soothed a bit with a warm compress. If you have antibacterial soap (Hibitane or chlorhexidine soap would be ideal), you can add a small amount to a cup of warm water. Place a washcloth in the mixture, and place it over the red area for 10 minutes, re-warming it every few minutes, then pat dry. You can add some plain Neosporin after, just make sure your dog doesn't lick it.
This is just a temporary fix that may help sooth the area. Your dog may need a course of antibiotics by your vet if there is an infection or abscess.