In stationary power generation units such as distributed remote site power systems and ship power systems, diesel engine generator systems are essential for supplying electricity. This paper proposes a digital twin diesel generator system for teaching and research purposes. A five-layer resilient architecture, including a web interface layer, server cluster layer, real-time data layer, controller layer, and equipment layer, is proposed in this paper. Based on the resilient architecture, users are able to build, implement and monitor the digital twin through web interfaces. Apart from MATLAB/Simulink, a modeling tool called M2PLink is developed to allow users to create mathematical models using a block diagram editor similar to Simulink. Various basic blocks for control systems are provided for users to form sophisticated models. These models are converted into executable codes which are downloaded to the simulator in the controller layer, where the real-time simulations are implemented. A web-based real-time monitoring interface with many widgets such as charts, oscilloscopes, and three-dimensional (3D) animation is also provided for users to customize their monitoring interface. All the signals can be traced and all the parameters can be tuned in the monitoring interface. The users are able to interact with the digital twin just like they do with the real system. The proposed system can not only be used for research such as digital twin-assisted real-time online monitoring but also for educational purposes, which is not only cost-effective but can also ensure the safety of the user as well as the equipment.