Realistically we can go in one of two directions. We can try to lock everything down, which as you've detailed eventually means locking EVERYTHING down. Constant surveillance by a police state everywhere you go.
Or we can go in the direction of happiness and freedom. Happy and content people generally don't want to kill other people. Especially not if it puts themselves at risk. You do this by:
Reducing income disparities (not necessarily full communism or even socialism, but at the very least narrowing the gap between the 1% and everyone else, and making sure people either have universal basic income or a _guarantee_ of a job if they want one.)
Ensuring equality for _everyone_. No downtrodden racial or religious or gender or whatever group that will feel the need to rebel.
Funding _effective_ mental health treatment.
Legalizing drugs and eliminating the DEA (if you know someone whose life is being ruined by addiction that's very sad, but let's try to convince them to get counseling and treatment rather than trying to make them and lots of other people criminals while inadvertently funding murderous drug cartels.)
And most importantly, we need to work on seeing that all these improvements happen worldwide. Not necessarily all at once, but there needs to be obvious progress. It's no good if you fix everything in your own country but the next country over is still in a crappy situation and blames you for it, regardless of whether that blame is fair or not.
Even then there will still be the occasional person who's mentally unbalanced and upset that some group they dislike is getting "preferential" (i.e. fair) treatment and will decide to go kill some people. But you can't stop all the bad stuff form happening in life. We just need to accept that some risks are unavoidable (like the much higher risk of injury or death if you choose to travel by automobile, which 99% of us seem to be just fine with) and get on with our lives.