This paper is concerned with developing a distributed k-means algorithm for the wireless sensor networks (WSN) where each node is equipped with sensors. The underlying topology of the WSN is supposed to be strongly connected. The consensus algorithm in multi-agent consensus theory is utilized to exchange the measurement information of the sensors in WSN. To obtain a faster convergence speed as well as a higher possibility of having the global optimum, a distributed k-means++ algorithm is firstly proposed to find the initial centroids before executing the distributed k-means algorithm. The proposed distributed k-means algorithm is capable of partitioning the data observed by the nodes into measure-dependent groups which have small in-group and large out-group distances. Simulation results show that the proposed distributed algorithms can achieve almost the same results as that achieved by the centralized clustering algorithms.