Impacted anal glands can often be relieved by manually expressing, or squeezing out, the fluid they contain. This is a very smelly process, but if you're game you can have your vet or groomer teach you how to do it. Most people whose dogs need their anal glands expressed periodically prefer to pay to have it done.
If your dog's anal glands get impacted frequently, ask your vet to recommend a high-fiber diet to create bulkier stools. If that doesn't work, and if your dog has repeated infections or abscesses from impaction, the anal glands may need to be removed.