For cloud computing operating environment, cloud service providers leased cloud resources provider of resources, to provide the service to the user of the scene, taking the optimization of a cloud service provider costs, increase the operation profit as the goal, the design of the virtual machine resource allocation method for cost optimization was proposed. The method comprehensively considered the spot, appointment and on-demand resource allocation model, control factor was introduced to avoid the resource risk, the resource allocation scheme for the optimization of the cost was formulated. The proposed method meets the users' satisfaction, effectively realizes the optimization of virtual machine resource cost, increases the cloud service provider revenue.