Traditional Optimal Iterative Learning Control (TOILC) can effectively improve the tracking performance of the servo system. However, there may be parameter perturbation in the running process of the servo system, and its parameters are constantly changing slowly. As a result, the convergence of TOILC becomes worse, and the tracking performance of the system deteriorates seriously. Therefore, in view of the time-varying characteristics of the system, a least squares optimal iterative learning control (LSAOILC) algorithm is proposed. In the process of iteration, the nominal model of the system is identified according to the input and output signals so as to update the optimal iterative learning controller, which does not need to obtain the exact system model information in advance, making up for the shortage of TOILC. The simulations and experiments prove the effectiveness of the proposed strategy for the servo system.