This paper investigates a distributed optimization problem for heterogeneous linear multi-agent systems with uncertain parameters and external disturbances. For each agent, the optimal solution of the global objective functions can be regarded as an unknown constant reference signal. From this angle, the problem is transformed into an output regulation problem for an exosystem whose states and outputs are to be estimated. To ensure the trackability of the estimated signal, a fundamental design condition for the exosystem observer to achieve robust output regulation is given in the context of internal model control. Exact global optimization is then realized by embedding an appropriate distributed optimization algorithm (i.e., the exosystem observer) in each agent to estimate the global optimal solution. The result for exosystem observer design is extended to yield an adaptive fault-tolerant control algorithm to deal with a class of practical actuator fault uncertainties. The exosystem observer-based output regulation method provides a general distributed robust optimization framework for uncertain systems with disturbances and actuator faults, which can directly apply to various consensus problems. Simulations are provided to illustrate the effectiveness of the method.