Pilot contamination due to the pilot reuse in adjacent cells is a serious problem in time-division duplex (TDD) massive multi-input multiple-output (MIMO) system. Therefore, the pilot allocation is significant for improving the performance of the system. In this paper, we formulate the pilot allocation optimization problem for maximizing uplink sum rate of the system. To reduce the required complexity for finding the optimum pilot allocation, we propose a low-complexity pilot allocation algorithm, where the formulated problem is decoupled into multiple subproblems; in each subproblem, the pilot allocation at a given cell is optimized while fixing the pilot allocation in other cells. This process is continued until the achievable sum rate converges. Through multiple iterations, the optimum pilot allocation is found. In addition, to improve users' fairness, we formulate a fairness aware pilot allocation as maximization problem of sum of user's logarithmic rate and solve the formulated problem using a similar algorithm. Simulation results show that the proposed algorithms obtain good performance comparable to the exhaustive search algorithm, meanwhile the users' fairness is improved.