The invention provides compounds represented in formula (I) in the description or pharmaceutically acceptable salts or prodrugs of the compounds. The compounds have novel structure, high efficiency, low toxicity and excellent CXCR4 antagonistic activity, and can block HIV from invading and infecting human target cells, treat or prevent AIDS or mobilize human bone marrow hematopoietic cells, mesenchymal stem cells and stem cells, interfere with CXCL12/CXCR4 mediated cell migration and adhesion, prevent and treat CXCR4 mediated tumor metastasis, invasion and growth, or block CXCL12/CXCR4 mediated autoimmune and inflammatory reactions. The compounds can be used as an active ingredient in pharmaceutical composition for preventing and treating HIV in combination with other anti-HIV drugs, or for preventing and treating tumors in combination with other drugs for treating or preventing leukemia, lymphoma, myeloma and solid tumors.