Shaping the Safety Boundaries: Understanding and Defending Against Jailbreaks in Large Language Models