Use a robots.txt
file to prevent spiders from crawling and indexing your content.
From Alexa's "for webmasters" page:
User-agent: ia_archiver
Disallow: /
From Googe's robots.txt help page:
User-Agent: Googlebot
Disallow: /
If you want to block all robots and prevent all spiders from crawling and indexing your content:
User-Agent: *
Disallow: /
Alexa does not need to crawl or index your content to display an "Alexa Ranking" for your website. It bases its rankings on the number of people that visit your website. It gets this data from its toolbar or by purchasing data from ISPs. As such, blocking the crawler will not prevent Alexa from displaying the ranking. There does not appear to be a way to have your site opt-out of the Alexa rankings.