1. Be aware of your surroundings. Your best defense against danger is identifying potential threats before they become a problem. Watch your sensor panel for any hollow signatures, and check the comms panel for ships nearby. An FDL in local chat is far more dangerous than say, a Type 6. They may be minding their own business, but it's safe to always assume hostility.
2. Equip a decent shield. ~500mj @ full pips to systems will go a lot farther than people realize. More is better, especially for larger ships.
3. If you are not actively seeking PvP, focus on escape. Your trade/mining/passenger/multirole ship will not likely stand a chance against a PvP or gank-spec ship if you stick around to fight-- however it doesn't take a battle-built FDL or ace piloting skills to get away from danger. If you escape a few times, you may very well be left alone. Competence is respected by many, even those who gank.
4. Want to dispense some justice? Build a dedicated combat ship, and practice, practice, practice. While some gankers aren't particularly good at the game (It doesn't take much skill to frag a T7 to death), that isn't always the case. Many ganking types are dedicated PvP pilots as well, and will likely stomp you-- engineering is not enough on its own to be competitive.
5. Befriend the bad guys. If you wish to learn more about PvP, ship building, or anything like that, they are often open to questions. They may be 'bad guys' in game, but like you and your buddies, they are often just friends playing the game the way the like to play it. Do not mistake criminal behavior in-game as a representation of someone's real-life character. Some of the best friends I've ever made online also happen to be space-terrorists in a video game, and had they never shot at me, I never would have met them.