The origin of magnetic fields in the universe remains an outstanding problem in cosmology. We propose that these fields are produced by shocks during the large-scale structure formation. We discuss the mechanism of the field generation via the counter-streaming (Weibel) instability. We also show that these Weibel-generated fields are long-lived and weakly coupled to dissipation. Subsequent field amplification by the intra-cluster turbulence may also take place, thus maintaining the magnetic energy density close to equipartition.