Consensus algorithm is widely used in distributed system, which can solve the problems of fault tolerance and data consistency. Raft algorithm is one of the most widely used consensus algorithms to maintain consensus and fault tolerance in some distributed systems. However, the original Raft algorithm may fail to consider the problems of recovering the logs of all servers from failures as well as the increase number of logs under failures such as node downtime and unreliable networks. To this end, we propose an optimized Raft algorithm based on Snapshot technology, called Snapshot Raft (SS-Raft). Snapshot is one of the methods of log compression. When consensus is reached, the SS-Raft algorithm can exploit the snapshot technique to compress the number of entries submitted to the log. The experimental results illustrate that the number of log entries submitted by the server decrease significantly under unreliable network and churn failures, which will effectively reduce the storage space of nodes and greatly improve the system performance. In addition, the SS-Raft algorithm can also operate normally under a variety of failure environments and improve the performance of distributed systems.