Is there anything you can do to avoid developing glaucoma?

Not aware. Best prevention is early detection; especially noteworthy is that eye pressure is notoriously inadequate as a screening tool with only about 1 out of 3 new glaucoma cases presenting with high eye pressure.
Exercise. There have been several studies now showing that regular aerobic exercise, 30 minutes 3-5 times a week can lower intraocular pressure, and I have also seen this in my practice, where I have been recommending aerobic exercise for the past 15+ years to my patients with elevated intraocular pressures. The mechanism is unknown, but may be improved circulation at the optic nerve with neuroprotection.
Unclear... Research has not yet proven lifestyle changes which help reduce glaucoma risk. There are some types of glaucoma such as neovascular which are complications of diabetes so good overall health reduces your risks. Regular eye checkups can reduce risks from glaucoma.