Before you query an agent, you need to do research, so you know what they represent and what they have sold. This is important; querying agents who do not represent your genre is a waste of everybody's time. And looking for a track record of sales to legitimate publishers is a good way to protect yourself from scams.
Querytracker: This site has a fairly comprehensive list of agents, and each agent's page on Querytracker is linked to their listings on AquentQuery and Publisher's Marketplace, as well as a link to the agency website and, often a list of books sold. You can also use their page to keep track of agents you have queried, and the responses you get.
AgentQuery: Agents put their own profiles on this site, and typically supply their submission guidelines and information about what they represent and what they're looking for.
Publisher's Marketplace: Contains pages for agents and agencies with information about what they represent and what they have sold. You can look at the agency listings for free. PM also reports on deals, which is a paid service that costs $20 per month. If you are curious to see what is selling, or you want a comprehensive, searchable resource containing information about who represents and edits your favorite authors, it might be worthwhile.
Predators and Editors: If you're at this stage, hopefully you know what a real literary agent is, and what a real literary agent does. There are a lot of writers submitting fiction, and some unscrupulous people and companies are looking to fleece the naive. The best way to protect yourself is to be informed and educated. P&E will warn you about people who aren't on the level.
"'Allo, Guv-nah! Pay an up-front fee, I'll submit your work to vanity presses!"
Before you send your query out, you need to get it polished and perfect. The people on Absolute Write's forums are experts in the field and generous with their time. I can't link straight into the Share Your Work forums, because they're behind a password wall (so people's critique materials will not show up on search engines), but that is where you will find what is probably the best query workshop online.
If you want to learn from the mistakes of others check out Janet Reid's QueryShark query critique blog. See, also: Flogging the Quill, where author Ray Rhamey shreds people's first pages.
Literary Agent Nathan Bransford also recently started doing regular critiques on his blog, but if you want him to dissect at your letter, you have to be lucky; he chooses at random and has at least a hundred people volunteering their work every time he does a critique.
Finally, because I am a pathological narcissist, here are links to a couple of my older query-related posts, which are admittedly sarcastic and unhelpful:
Wish form rejections were less vague? You won't after you read this,
Novels Under Consideration at a Literary Agency (humor essay published at Yankee Pot Roast).