In public Infrastructure-as-a-Service (IaaS), virtual machines, servers, storage, and network are provided by cloud service providers. As a cloud service provider, who is facing a task for time constraint, how to schedule the service resources to achieve the lowest cost becomes more and more important. Recently, most of works about MapReduce task scheduling are focus on homogeneous MapReduce framework. In this paper, we present the ILP formulation for solving the MapReduce task scheduling for time constrains problem in heterogeneous environment. This method considers processing speed, energy cost and time constrains at the same time. By using the method, we can finish the task in time and achieving lowest energy cost. Then, we solve this problem efficiently by using genetic algorithm(GA). According to our experimental results, the ILP formulation we proposed can always achieve the best solution, it also reduced the energy consumption by 10.15% compared to genetic algorithm.