The process of long-distance hot oil pipeline is complicated, and its safety and optimization are contradictory. In actual production and operation, the theoretical calculation model of oil temperature along the pipeline has some problems, such as large error and complex application. This research relies on actual production data and uses big data mining algorithms such as BP neural network, ARMA, seq2seq to establish oil temperature prediction model. The prediction result is less than 0.5 C, which solves the problem of accurate prediction of dynamic oil temperature during pipeline operation. Combined with pigging, the friction prediction model of standard pipeline section is established by BP neural network, and then the economic pigging period of 80 days is given; and after the friction database is established, the historical friction data are analyzed by using the Gauss formula, and 95% of the friction is set as the threshold data to effectively monitor the variation of the friction due to the long period of waxing in pipelines. The closed loop operation system of hot oil pipeline safety and optimization was formed to guide the daily process adjustment and production arrangement of pipeline with energy saving up to 92.4%. The prediction model and research results based on production big data have good adaptability and generalization, which lays a foundation for future intelligent control of pipelines.