This paper focuses on the challenges facing network security in the digital era and proposes a network security posture optimization method based on data clustering. Three mainstream network security models, namely, P2DR security operation and maintenance model, line defense model, and three-dimensional defense model, are analyzed, and the limitations of existing security products are pointed out. The application potential of big data technology in network security is emphasized, and a comprehensive technical process containing information extraction, posture modeling, security trend prediction, and security policy deployment is constructed. The ARMA model and reinforcement learning building model are introduced, and the improved K-means algorithm is proposed to address the shortcomings of traditional methods. Experiments are conducted using the DARPA2000 dataset, and the results show the enhanced algorithm’s significant improvement in clustering accuracy and stability, with a maximum threat value of about 160, demonstrating better stability and effectiveness than the traditional method. The posture value exceeds 500 in a specific period, highlighting the dynamic changes in network security and confirming the practicality and effectiveness of the technique. The results of this study provide new strategies and perspectives for network security protection, and have essential reference and guidance value for practical applications and future research.