It is better to say "元気ですか?” when greeting a friend. If they do not look alright though, like something is wrong, you can say "大丈夫ですか?” It will sound weird to just ask someone randomly is everything is alright (大丈夫ですか).
But yeah, Wozitoya was correct with his answer definitions.