While there is no 100% foolproof way of doing away with spam completely here are a few tips that I use on my own website that have worked for me:
(Note this is generally for most spam and unintended content posted or registered on the q2a website, choose what works for you)
Main:
- Use the latest version of q2a.
- Require user registration for posting content ( I do this for all content and interactions →questions, answers, comments, votes, messages, flags, etc)
- Use a spam plugin as mentioned in Wiechers' answer. Both Spam Registration Stopper and Registration Blocker work well (although not 100% at stopping spam but they're a good deal).
- Require email confirmation for all registered users.
- Next, use moderation. Especially if you want to control the quality of content on your site. The best way to do this is to set the number of points a user must have in order to automatically publish posts. Posts from users with low points will need to be checked before being published.
- Also set who can do what by going to admin→permissions. For my case, only users that have their emails confirmed can ask or answer questions. Others can only view. You can use either "Registered users with email confirmed" or "Registered users with enough points" as the threshold for posting.
- Also go to admin→spam and set the rate limiting for posting questions or answers per user or IP address per hour. This way you reduce the amount of content posted by spammers.
More tips that could help:
- Go to Admin→users and enter usernames that you want to disallow for registration. For example disallow users to register as "admin" or "owner" or even disallow usernames that are profane. If you notice a spam user on your site, delete them and enter the username here so that they can't register again with the same username or any string of it.
- On admin→posting enter the minimum and maximum length for both quesion title and question body and even for answers or comments if possible, but more important is the length question title and body. I realized that most spammers (both humans and bots) do copy long texts into the question body so setting a maximum length might cut you some slack. Note that this one will not stop the spam but it will reduce the spam content (length) incase it gets published on the frontend. A 300 words content may have fewer spam links than a 3000 words content. The idea here is to cut the chances where possible.
- Use updated, tested or reputable themes and plugins. Also install them from official directories.
- Use the UserManager plugin to check, block or remove unwanted users.
Generally speaking there's no guaranteed way to deal away with spam completely because spammers adapt to new methods everyday. The best you can do is to reduce the amount of spam or its impact and extent thereof.
You will need to perform some tweaks every now and then to see what works and what doesn't.
Moderation is a great way to start with. Always moderate.