Advanced LIGOs second observing run (O2), conducted from November 30, 2016 to August 25, 2017, combined with Advanced Virgos first observations in August 2017 witnessed the birth of gravitational-wave multi-messenger astronomy. The first ever gravitational-wave detection from the coalescence of two neutron stars, GW170817, and its gamma-ray counterpart, GRB 170817A, led to an electromagnetic follow-up of the event at an unprecedented scale. Several teams from across the world searched for EM/neutrino counterparts to GW170817, paving the way for the discovery of optical, X-ray, and radio counterparts. In this article, we describe the online identification of gravitational-wave transients and the distribution of gravitational-wave alerts by the LIGO and Virgo collaborations during O2. We also describe the gravitational-wave observables which were sent in the alerts to enable searches for their counterparts. Finally, we give an overview of the online candidate alerts shared with observing partners during O2. Alerts were issued for 14 candidates, six of which have been confirmed as gravitational-wave events associated with the merger of black holes or neutron stars. Eight of the 14 alerts were issued less than an hour after data acquisition.