Thousands of people were evacuated to shelters in schools and other public buildings in suburban Beijing and in nearby cities.