Diamox can help, but it will make you pee every hour. Don't drink alcohol just before your hike (or while you're hiking). Drink a lot of water. Acclimate ahead of time if possible and sleep low if you can. Hiking in the San Juans the year before our CDT hike, we first spent 3 or 4 days visiting Durango and Mesa Verde. I had a horrible headache the whole time, but by the time we started our hike, I was okay.
Getting sick on one hike doesn't necessarily mean you will always have issues with altitude either. Our first time in CO, my husband had the flu just before we started our hike. He got pretty dehydrated. About 7 days in, he ended up with pulmonary edema and we had to bail. Carry enough maps that you can find a trail out if you need to. When Jim was coughing up froth, we knew we needed to get down quickly and the map showed a trail to the south that would lead to a road. What we didn't realize was that it was a 600' climb up to get over the pass. I wasn't sure he was going to make it. His cough lasted for about a month. A year later, we thruhiked the CDT and he had no issues whatever. We also did the PCT without any problems, but when we did the CDT a second time, in Colorado he ended up with aphasia where he actually passed out briefly. He said he felt like he was drunk. But we finished the hike. I could always tell when we reached 10,000', because I would slow down and feel like it was so much harder than it should be, but I never got anything more serious than a headache for the first few days.