The gunman opened fire at the famous archaeological site just outside Mexico City before killing himself, the authorities said.