They mean almost the same thing. But they all have different nuances. I will try and tell you what each makes me feel:
1. Danger up ahead!
Its a short and sharp warning, makes me think that there is danger immediately up ahead.
2. Be careful of danger up ahead!
This is much less urgent, much calmer, it is also less of a warning. To me it almost sounds like someone is wishing you good luck for the journey ahead of you.
3. Danger alert up ahead!
This one doesnt read very well at all. It is more likely to be Alert! Danger up Ahead!. The rewritten version is a lot like the first one, but it doesn't sound as colloquial because people don't tend to use the word alert.
4. Attention! Danger up ahead!
This is a lot like the first one. It is very urgent. The addition of the word Attention! at the start possably makes it sound a little more urgent, because it adds emphasis.
If I had to choose which one to use I would choose Attention! Danger up ahead!
Student or Learner