Minecraft wiki entry for Multiplayer_PvP_bases, associated text: Minefields are a good idea. Get a bunch of stone, build a load of pressure plates, and place them all around your base. You can make a fake minefield (it is also good for spotting invisible players), if you aren't planning on making that much TNT to bury in the ground. It will be a great bluff as the mere thought of that many explosives under their feet will scare away just about anyone, and they will never know that it was fake. If you do go putting TNT under the ground, it's recommended that you surround it with water. It will still damage entities but won't make big craters in your base. Attaching observers to the TNT can activate it if a player attempts to disable it.
Dispensers with arrows or fire charges can be hooked to pressure plates or tripwires to weaken or even kill your enemies without you lifting a finger, but ensure that these dispensers aren't directly connected to your base—remember, dispensers can also be used to light and dispense TNT.
If you're expecting an imminent and immediate raid, scouting nearby areas for enemy cannons might be a good idea, as the owners might be offline. If they're unclaimed, claim them to avoid having the raiders come back and raid your base, and dismantle them. If they're claimed, try to blow them up before the raiders come back, or (if you're good at PVPing) wait until the raiders come back online and kill them to overclaim their cannon.
Defensive TNT cannons atop your base might be a good idea if your base happens to be aboveground. Getting rid of those pesky claimed enemy cannons outside your base would be made a whole lot easier. Just don't give raiders direct access to these cannons of yours by loading them beforehand.
A trapped Wither can be used as an active defense, as although it is unable to break out of the area, it is able to shoot at any passing players.