In this paper, the operation of a microgrid under imbalance and nonlinear load conditions is studied, and a consensus algorithm-based distributed control strategy is proposed for the microgrid power allocation, frequency, and voltage restoration. Furthermore, a double-layer optimization allocation model for the energy storage capacity of microgrids is constructed, in which the upper layer optimizes the energy storage allocation capacity and the lower layer optimizes the operation plans of microgrids in each typical scenario.