  We consider a self-gravitating system consisting of perfect fluid with
spherical symmetry. Using the general expression of entropy density, we
extremize the total entropy $S$ under the constraint that the total number of
particles is fixed. We show that extrema of $S$ coincides precisely with the
relativistic Tolman-Oppenheimer-Volkoff (TOV) equation of hydrostatic
equilibrium. Furthermore, we apply the maximum entropy principle to a charged
perfect fluid and derive the generalized TOV equation. Our work provides a
strong evidence for the fundamental relationship between general relativity and
ordinary thermodynamics.
