The original scoring of the 1812 Overture includes cannon fire, although some performances substitute bombardons or bass drums. The International Music Score Library Project provides scanned copies of various editions. For an example from near the end of the work, click on the first score listed and go to pages 70 and 71 in the PDF (labeled in the image as pages 72 and 73). The cannon line is seventh from the bottom.
Here's a performance by the Japanese Ground Self-Defense Force: part 1, part 2. The good stuff happens in the second video around the 8-minute mark.
Auf der Jagd ("On the Hunt") is a polka by Johann Strauss II that features two gunshots, one around the middle and one at the end. Wikipedia calls them pistol shots, but the piece is often performed at the new year's concert of the Vienna Philharmonic using what seems to be some kind of rifle.
If we expand this to "loud dissonant things in music" there's actually a quite a bit. The use of anvil strikes in music are seemingly so commonplace as to require listing on Wikipedia, Verdi's "Anvil Chorus" is probably the best well-known of the bunch. And of course Mahler's 6th, which has a popular gif going around reddit, where you literally wait for the hammer to drop. And if you aren't too prejudiced against modern music, there's the curiosity piece Helicopter-String Quartet
The score for Tchaikovsky's 1812 Overture calls for a cannon in the percussion section. Obviously this can be difficult to come buly, so a bass drum, a very large hammer (see "Mahler hammer"), or a recorded sound byte is commonly used instead.