The invention discloses a corrosion inhibitor, comprising the following ingredients: modified imidazoline derivative, 1,4-butynediol, thiourea, sodium dodecyl benzene sulfonate, urotropine and solvent, wherein, the weight ratio of modified imidazoline derivative to 1,4-butynediol to thiourea to sodium dodecyl benzene sulfonate to urotropine is (20-50):(1-2):(1-12):(1-5):(2-4), and the quality of the solvent accounts for 30-70% of the total mass of the corrosion inhibitor. The invention also discloses a preparation method of the corrosion inhibitor, comprising the following steps: adding the modified imidazoline derivative, 1,4-butynediol, thiourea, sodium dodecyl benzene sulfonate, urotropine in the solvent, stirring uniformly to obtain the corrosion inhibitor. The corrosion inhibitor disclosed in the invention has good corrosion inhibition effect for CO2 corrosion in the near neutral oil field water system (PH value: 5-6.8).