我们在各种VPS评测博客,以及在一些广告渠道看到各种优惠的VPS的优惠信息都比较心动其价格和配置性能,在选购的时候我们是要参考一些用户的评论以及自己的评价标准。最为实际的在我们卖到或者能得到免费测试机器的时候,可以通过下面简单实用的VPS性能测试方法看看我们即将选择的VPS产品性能如何,如果在自己的可选标准范围之内,那就选择,如果认为不可以,就放弃。

第一,CPU、内存、硬盘检测

cat /proc/cpuinfo (查看CPU信息)
cat /proc/meminfo (查看内存信息)
df -lh (查看硬盘信息)

这个命令可以看到我们购买的VPS CPU信息是否与官方标准一样,有些时候告诉我们的与实际检测的不同。

第二,硬盘IO性能测试

dd if=/dev/zero of=test bs=64k count=4k oflag=dsync
dd if=/dev/zero of=test bs=8k count=256k conv=fdatasync

在"VPS性能测试工具之三: dd硬盘读写命令"有详细介绍这个命令的使用及具体的性能对比。

第三,UB跑分测试

在"VPS性能测试工具之二: UnixBench"有介绍到UB跑分测试的方法,可以根据自己的跑分测试性能,如果低于100分的直接不考虑,一般肯定会在400分左右。

第四,WGET下载测试

wget http://cachefly.cachefly.net/100mb.test

测试下载速度。

第五,PING及TOP测试

我们在拿到VPS的IP之后,可以用第三方的PING工具进行PING测试速度,或者在我们本地机器上PING测试,可以反应器机器的速度,如果我们做中文站点,一般PING在250之内可以接受的,也有些机器PING速度比较高,但是打开速度还不错。所以说PING只能是参考。

我们还可以用top命令来测试CPU占用情况(扩展阅读:检测MySQL负载过高及解决方法(详解SSH TOP命令))

总之,通过上述的5个方法及参考命令基本上可以测试到这款机器的性能对比。

转自: http://www.laozuo.org/1592.html | 老左博客

http://npm.taobao.org/

淘宝 NPM 镜像

这是一个完整 npmjs.org 镜像,你可以用此代替官方版本(只读),同步频率目前为 10分钟 一次以保证尽量与官方服务同步。

  • 当前 registry.npm.taobao.org 是从 registry.npmjs.org 进行全量同步的.
  • 当前 npm.taobao.org 运行版本是: cnpmjs.org@2.0.0-beta3
  • 本系统运行在 Node.js@v0.11.14 上.
  • nodejs.org/dist 镜像: npm.taobao.org/dist
  • phantomjs downloads 镜像: phantomjs mirror
  • Node.js 文档镜像: Node.js Document
113,488 个模块 615,221 个模块版本 7 次删除
22,867 次本日下载 474,895 次本周下载 1,792,093 次本月下载
68,299 次昨日下载 488,804 次上周下载 2,211,639 次上月下载

同步状态

This registry will sync all packages from official registry.

上次同步完成时间: Fri Nov 28 2014 13:55:10 GMT+0800 (中国标准时间)

转:http://my.oschina.net/feedao/blog/223497

当我们把CentOS 6.5安装好以后,可以使用这个脚本来使用国内的阿里云镜像源

?
1
2
3
4
5
6
7
#!/bin/bash
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum makecache

 

 

有了国内的源地址,后面安装东西就方便了。

搜索docker,可以看到docker-io.x86_64和docker-registry.noarch,安装docker就简单了。

[root@localhost ~]# yum search docker
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
======================================================== N/S Matched: docker =========================================================
python-docker-py.x86_64 : An API client for docker written in Python
docker-io.x86_64 : Automates deployment of containerized applications
docker-registry.noarch : Registry server for Docker
fedora-dockerfiles.noarch : Example dockerfiles to assist standing up containers quickly
imagefactory-plugins-Docker.noarch : Cloud plugin for Docker
docker.x86_64 : KDE and GNOME2 system tray replacement docking application

varnishstat是查看varnish状态的工具,但里面有些参数官方网站都没介绍清楚,在这里备忘一下。

346

Hitrate ratio由三个数字组成,第一个数字范围0-10,第二个数字范围0-100,第三个数字范围0-1000。分别表示过去N秒内的Hitrate avg。上图由于我是刚打开varnishstat,因此三个数字都是4,表示过去4秒内的平均hitrate,如果打开的时间足够长,以上三个数字就会 逐渐变成10,100,1000。

Hitrate avg里的内容是命中率,需要乘以100转换成百分比,例如上图表示命中率为99.23%

其他不再赘述,发挥二的性格,我们直奔主题。

    用户打开网站的整个流程中,DNS解析时第一环,当用户输入域名并敲回车后,windows系统调用DNS client,寻找到用户配置或者自动分配的DNS IP,之后就开始整个解析过程。

    DNS解析,变快有意义吗?

    有,呵呵,很多小型网站,DNS解析时间都接近0.5s,甚至我见过一个网站,需要1.2s才可以解析出结果的。这是个非常令人吃惊的数据,因为对于一般网站打开时间超过8s用户即将放弃访问,而对于电子商务网站,4s就是用户忍耐极限。而一般经过优化的小型网站,DNS解析时间都可以控制在200MS左右,而带宽在100M左右的网站,经过优化,DNS解析时间可以控制在50-100ms。

    如何优化呢?

    首先利用好TTL,因为要尽量多的让用户直接从运营商的DNS缓存中拿到A记录,这样才能保证最快,但是也要保证,当你的服务器出问题时,需要尽快的切换,所以,这个TTL设置也是有一些情况需要综合研究的。

1、 你肯定清楚,自己的服务器有没有多台或者备份。如无备份,那服务器宕机时,你只能生抗,所以,TTL时间对于你来说是越长越好,因为TTL短的目的是服务器发生问题时,可以及时切换,这个对于没有备份的网站基本利用不上。所以,你的TTL设置就是越长越好,当然了,也不能无限长,一般设置TTL 3600即可。

2、 如有备份或者多台服务器,会发生由于服务器宕机需要及时做切换,TTL时间越短,切换越及时,但是TTL时间越短,也就意味着运营商DNS经常缓存不住,一般用户,设置为TTL 600即可,如果对及时切换,要求特别苛刻的网站,设置TTL 120即可。

其次寻找足够热的域名解析商。很多网站,都是自己做一个域名解析服务器,看着自己掌控方便了,但是大错特错,因为你的域名解析服务器,基本上都不被缓存,每次从根服务器询问一圈,绕了大半个地球,才给出最后的结果,那自然会效果很差。所以,要寻找足够热的域名解析商。什么叫热,就是被访问的次数特别多。足够热的话,域名解析服务器的A记录基本上会被各地运营商的DNS一直缓存着。如何判断域名解析商够不够热呢?其实,也很简单,看看这个域名解析商的客户够不够多,他们客户网站够不够热门,访问的人够不够多。

也给大家推荐一个更好的方法,就是找CDN厂商做域名解析。因为CDN厂商服务的客户,有很多是很热很大用户群很多的,所以,这些CDN厂商的域名解析服务器,服务效果那是岗岗的好。

最后是进阶技巧---巧用CNAME。不少网站拥有者,在同样的一个或多个服务器上运营很多小网站;或者自己运营一个网站,但是拆分了很多个二级域名。针对这些情况,严重需要善用CNAME,把所有的这些小网站的域名或者二级域名,cname到一个自己定义的统一域名。然后设置这个cname对应的TTL时间足够长。这样的话,保证网站的第一次解析,可以直接从运营商的DNS缓存中拿到,也就是直接拿到cname后的记录。然后,第二个cname记录,再设置一个相对合理的TTL值。通过这样,变相加热了第二级域名,通过加热的第二级和缓存时间足够长的第一级,最大化的优化DNS解析时间。该技巧,一定要确保,最后A记录得到的IP,可以服务这些原始域名。

例子:

www.abc.com.  7200 IN  CNAME  hot.abc.com.

hot.abc.com.   600  IN  A       127.0.0.1

      什么叫拆分域名?

         很多网站,在搭建网站的时候,只是申请和购买了一个域名,然后所有内容:图片、js、css、html、php等等,都放在一个域名下。

         而拆分域名,指的就是根据不同的应用,而将域名拆分出来。

         拆分域名有什么好处?

         使用IE6和IE7内核的浏览器,针对同个域名,只会同时发起2个连接。

         使用IE8内核的浏览器,针对同个域名,可以同时发起6个连接。

         很重要吗?

         非常重要,请看图示。

         使用IE6打开一个所有内容均在同个域名下的网站

         

         使用IE8打开一个所有内容均在同个域名下的网站

我们看到的是,在IE6的情况下,请求第7个元素,需要0.7s,而在IE8的情况下,0.277就开始请求第7个元素。

由此可以看到,并发连接更多的时候,网页打开速度会更快。

使用IE6访问情况如下:

域名个数

页面大小

耗时

1个

500KB大小的首页

7s

多个

540KB大小的首页

3.6s

使用IE8访问情况如下:

域名个数

页面大小

耗时

1个

500KB大小的首页

4.6s

多个

540KB大小的首页

3.1s

         由以上数据可以看到,多个域名,不管是在IE6和IE8的情况下,拆分域名,都会使网站的打开速度变快。

         现实中也是如此,新浪、淘宝等大型网站,他们无一不是在拆分域名。

         另外,要纠正一个IT人的误区。因为IT人一般都热衷技术,很多人的操作系统等版本都很新,用的都是IE8甚至以上的浏览器。但是整个中国,到目前为止,使用IE6和IE7的用户,仍然非常另IT人震惊的80%左右。所以,拆分域名,基本上可以缩减你20%以上的打开速度。

         一个简单的操作,就能带来巨大的效果提升,何乐不为?

         当然了,肯定会有人问,拆分域名,那不就会导致域名热度不够,DNS缓存不住的问题吗?这个问题,请看我上一篇博文,已经给出了答案。

         按照什么原则拆分域名呢?

         个数多少合适?

         一般50M以下网页类网站,域名保持在4、5个即可,过多后范围会导致你的维护和使用变得复杂。

         100-500M以下网页类网站,域名保持在8-10个左右。

         1G以上的网页类网站,域名无所谓个数,保持10个以上,具体个数根据自己的业务和管理特点随心制定。

         什么内容放到同个域名下?

         页面类:html、htm等

         样式类:js、css等

         图片类:jpg、png、gif等

         动态类:php、asp等

         这样的分配方式,将来有利于你进一步优化你的网站,并且在你需要寻找加速工具时,也可以针对性的选择不同的加速方式。

  老鸟请直接看开启压缩进阶篇。

      菜鸟还是慢慢随着老夫的思路看吧,哇哈哈。

      

       什么是压缩?

         大家还记得我们第一次接触winzip软件吗?非常神奇,一个文件,经过winzip压缩后,大小可以压缩成原来的30%左右。记得当年,很多文件,都是压缩后才可以放到自己的软盘中。

而对于网站,也有这样的压缩技术,可以让你的网页中的文本类文件瘦身,在用户完全不知情的情况下,通过gzip和deflate压缩程序有效减少了网页,让用户更快的打开网站。

压缩有多大用处?

         通过一个小小的测试软件,我对新浪、网易等门户网站进行了访问。

         新浪首页访问情况:

网易首页访问情况:

大家可以明显的看到,网易和新浪的首页,经过压缩后,都缩小了70%以上。

相信大家都知道,当一个网页,减小到30%后,对于最终用户来说,打开网站的效率会提升为原来的3

备注:

该工具地址http://www.gidnetwork.com/tools/gzip-test.php  大家也可以测试下自己的网站压缩后的情况。

用户不支持压缩怎么办?

开启压缩后,会不会由于用户无法访问这种压缩文件,导致用户访问文件失败?

不会,因为Trident、Gecko、Webkit三种内核的浏览器,都在发起请求时,告知服务器,他们支持什么压缩格式,如下图:

而服务器都是按照发起请求中用户支持的压缩格式,进行对应反馈。如果用户发起的请求头中,无Accept-Enconding头,就将返回给用户非压缩格式。

如何开启压缩?

请百度娘之,网上太多教程了,不再赘述。

对哪些内容开启压缩呢?

只需要针对文本类文件的域名开启压缩。图片等,已经都是压缩格式了,再使用压缩,不会减少什么文件大小,反而会导致服务器负载变高,以及会由于这种对图片的不规范压缩使用导致各种各样意想不到的问题。

所以,开启压缩之前,最好先完成域名拆分的工作,具体见如何让网站打开更快第二弹。

技巧点:

开启压缩,建议使用apache服务器。

因为IIS服务器在处理压缩时有个小问题,就是第一次被访问的时候,IIS给出的文件时非压缩的,后续的访问,才直接给出压缩文件。

这个小的bug,其实问题并不大,但是现在很多网站都在用一些缓存服务器或者是CDN,就会导致这个问题被放大,会导致压缩启用并不能完全成功。

而apache是第一次就直接给出压缩后的文件。

当然了,如果你用的是IIS,并且无法替换apache,那就自己麻烦一些,写个脚本,将常用的页面,在开启压缩后,访问2次,可以减少很多问题发生。

开启压缩之进阶篇

当下的中国网络状况

中国网络谁当家,当然是电信和联通两朵花,但是现在越来越看到的现象是百花争艳,除了这两朵花之外,越来越多的涌现小ISP。如移动、电信通、长城、方正、歌华有线、光环新网、甚至南方地区还有些香港过来的小运营商。

这些小运营商都有一个特点,就是会cache文件,他们会为了减少网间结算带宽,而尽量想办法缓存文件,让他们的用户本地访问。

其次,对于很多中大型公司来说,他们也会搭建自己的缓存服务器。

另外,还有很多网站,自身都搭建或者在使用第三方的CDN,也都是缓存服务器。

所以,当下的中国网络情况,基本上就是缓存服务器在提供众多的服务。所以,你的开启压缩,如果不主动配合这些各种各样的缓存服务器,那么你out了,你会发现,你的很多努力,都是笑谈,并无实际作用。

如何适合当下的状况?如何才可以保证用户支持压缩时,网络间传递的就是你想给他的的压缩文件?

那么,请紧记以下要点,并逐个落实。

开启压缩时,需要针对压缩和非压缩文件,都返回Vary:Accept-Encoding头。

这个头部是告诉缓存服务器,要根据用户支持的编码方式提供对应的文件。

该项很重要,很多网站,只是对压缩文件开启该头。在缓存服务器中,如果给出的非压缩的文件不包含该头部,也就是告知缓存服务器,当用户请求时,不需要判断用户支持的编码格式,而直接将该文件传递。所以,最后导致用户请求到缓存服务器时,无论用户支持不支持压缩,都是直接返回非压缩的文件。

开启压缩时,需要同时对HTTP1.1HTTP1.0均开启压缩。

大家都是认为,HTTP1.0协议的用户,肯定是特别老的用户,肯定是不支持压缩的,所以,很多网站,都是针对HTTP1.0协议提供非压缩文件。

但是,实际中,太多太多的缓存服务器,为了追求最大的兼容性,还在使用HTTP1.0协议。所以,当你只是对HTTP1.1协议开启压缩时,等于抛个媚眼给瞎子看。

例如,新浪的缓存服务器,也是HTTP1.0协议的,但是他们就很聪明的针对HTTP1.0也开启了压缩服务,如下图:

  为什么要讲HTTP头?

1、  非常简单的通过HTTP头,可以让你的用户打开速度快10倍

2、  网上讲HTTP头的文章,都讲的太玄乎和专业,实际价值不大

3、  太多人看了太多乱七八糟的文章,加了很多自己也不知道干嘛用的HTTP头

4、  HTTP头过大会阻塞你的用户访问,你考虑过吗?如何让你的HTTP头正好够用,能够起到效果又不要过于臃肿堵塞你的用户,你考虑过吗?

什么是HTTP头?

         HTTP协议采用了请求/响应模型。

客户端向服务器发送一个请求,请求头包含请求的方法、URI、协议版本、以及包含请求修饰符、客户信息和内容的类似于MIME的消息结构。服务器以一个状态行作为响应,相应的内容包括消息协议的版本,成功或者错误编码加上包含服务器信息、实体元信息以及可能的实体内容。
         以上是抄来的,其实我不想讲,呵呵,但是普及下吧。

下面是我们这一篇中主讲的

HTTP响应头的管理

哪些是常用的HTTP响应头?

      看图:

                    总结来看,常用的HTTP头如下:

 

协议 状态码 HTTP/1.0 200 OK
服务器时间 Date:
服务器 Server:
文件类型 Content-Type:
自适应 Vary: Accept-Econding
备注:sohu的网站用的Vary后有很多选项,是为了手机访问给对应格式页面的,但是这个方式,哥甚不赞同
最后修改时间 Last-Modified:
备注:www.qq.com没有该项,所以,悲剧的qq,当他的用户每次点击刷新时,别的网站都是个发送If-Modify-Since请求,返回304无变化只需要几百字节,而qq的用户则需要直接请求,全新拿文件,从几百字节消耗变成5W多个字节
压缩格式 Content-Econding: gzip
备注:了解这个妙用,看俺的第三弹
过期时间 Expires:
备注:哥一直认为,这是个非常渣的HTTP头,没想到四大门户都有这个头,啧啧,预计在第五弹我会批判这个
缓存设置 Cache-Control: max-age=
经过缓存服务器后的各种头 Age: X-cache: Via: FSS-cahe: 等等
备注:这个再一次说明了,中国的互联网早就是缓存服务器的天下了,具体见第三弹
综合以上的以上,我充满信心的说,以前我和很多人争论过的,Etag头对于99%的网站就是垃圾这件事情,得到了充分证实,这四大门户首页,没有一个用Etag头的。

 

哪些头需要好好管理?

Cache-Control

这是个无比妙用的头,它可以让你的首页,从2MB,变成200KB。

没错,就是它。

我们先看看别人用了它之后,做到了啥。

 

网站

首次打开大小

再次打开大小

首次请求数

再次请求数

www.qq.com

505KB

45KB

92

18

www.sina.com.cn

1261KB

800KB

186

94

www.sohu.com

738KB

296KB

151

61

www.163.com

1784KB

487KB

247

66

 

减少了这么多,网站和用户双赢,靠的就是这个头。下面我将讲下具体如何用。

Last-Modify

这个头好用,那就用是了,为什么还要单独拿出来说?

是因为这个头,有个小的隐藏风险,见过很多人中标,我指出来,希望更多的人可以看到,之后避免。

很多网站,在更新网站或者发布网站临时维护信息时,会采用将老的文件,剪切到其他目录,然后本地再上传一个同名文件进行文件更新或者网站的页面更新。当更新的页面出问题或者维护结束他们使用正常页面给用户服务,会立刻把老的文件剪切回来,覆盖旧文件。

这就有一个非常大的问题。

因为对于已经访问过网站的人来说,他们已经把文件缓存到了本地。当用户再次访问网站时,会发送一个If-Modify-Since请求。

老文件  Last-Modified: 旧时间

新文件  Last-Modified: 新时间

当你用旧文件替换新文件后,由于新文件的最后修改时间要早于旧文件的,所以,IE不会让用户拿到没有问题的旧文件,而是让他们使用新文件。

所以,如果你使用用旧文件替代新文件,一定要对旧文件做个小的处理,使其更新最后修改时间,不然,用户依然会访问出问题的页面或者是维护页面。

如何用好Cache-Control

当你不想让用户缓存时,你只需要添加一个头,no-store即可,其他no-cache、must、must-revalidate、proxy-revalidate等都没必要用,因为no-store一般默认为最高级。

其他可以让用户缓存的页面,区分目录,根据不同的目录,配置不同的max-age头。

max-age啥用处?

用户得到HTTP响应头后,会根据本地时间,加上max-age的时间,形成一个过期时间。例如,用户本次时间为11:00,max-age设置为600,那么文件拿到后,过期时间为11:10分。也就是这个用户,在11:10分以前,访问这个文件,就会直接缓存命中,而不会对服务器发出请求。

所以,max-age的运用就可以让你的网站像那四大门户一样,大小减少到原来的10分之一,请求数也会短期内得到巨大的减少。

如何设置Cache-Control

如何设置百度娘之。

管理上的建议:

你不可能针对每个文件配置Cache-Control,所以,最好是先拆分域名,将不同应用(文件类一个域名,图片类一个域名等等)配置不同的缓存控制头。

如果你的网站属于大中型网站,如网页访问带宽在100M以上的,可能针对域名配置不同缓存控制头,已经不能满足你的需求了,这个时候,就可以管理好你的目录。

将文件根据你们网站特点分到不同目录,然后针对目录,配置不同的缓存控制头。

max-age设置多大?

以下提出的均为建议值,但是最适合你的,是你自己根据网站特点进行的缓存时间配置。

首页,建议为900,也就是15分钟。

文本类文件,建议为10800,也就是3小时。

图片类文件,建议为86400,也就是24小时。

Swf类文件,建议为604800,也就是7天。

flv、exe类文件,建议为31536000,也就是1年。

作者:王康

文章来源:xmw2.blog.chinaunix.net

原贴:http://joyleley.spaces.live.com/blog/cns!E162F872A7449BAC!158.entry

(一)参数优化.("telnet localhost 5000"后,输入"param.show"可以看到所有系统运行中的参数.输入"param.set thread_pools 8"可以调整参数.)
    thread_pools                  8 [pools]
thread_pool_max            2000 [threads]
thread_pool_min             100 [threads]
thread_pool_timeout        10 [seconds]
    #这四个参数要一起看.
    #thread_pools是系统sess进入处理的pools.理想的情况下是一个cpu一个pool,如果pools过多会消耗cpu时间和mem.但是,pools多一点,处理并发的能力会更强.
    #thread_pool_min是每个pools的最小threads数.当pools侦测到可处理sess后,就分配给所属的空余threads处理.
    #thread_pool_max是所有pools所属的threads总和数的上限值.这个值不要设置的太高,一般是系统期望峰值的90%.太高了会发生"pile-ups",不知道怎么翻译,是不是"拥挤"?
    #thread_pool_timeout是thread的过期时间.当threads数大于thread_pool_min的时候,thread的空闲超过thread_pool_timeout时间,thread就被释放.
    listen_depth               1024 [connections]     #tcp链接队列size.默认是512,适当调大一点,处理并发能力增强.
    lru_interval               3600 [seconds]
    #优雅时间参数(不知道是不是应该这么翻译),意思就是,如果一个object,在内存中超过了这个时间还没有被重用,则把这个对象移动到 LRU(Least Recently Used)队列中.一种普遍的cache算法.个人理解,提高这个时间,会减少object在内存中的copy,以提高运行效率.
(二)VCL优化.
    vcl_recv:      set req.grace = 30s;
    vcl_fetch:     set obj.grace = 30s;
(三)系统环境优化
    ulimit -HSn 131072
ulimit -HSc unlimited
(四)tcp/ip网络环境参数优化
    修改"/etc/sysctl.conf".(官网上说,这个配置可以支持4000-8000 req/s的压力.)
    net.ipv4.ip_local_port_range = 1024 65536
net.core.rmem_max=16777216
net.core.wmem_max=16777216
net.ipv4.tcp_rmem=4096 87380 16777216
net.ipv4.tcp_wmem=4096 65536 16777216
net.ipv4.tcp_fin_timeout = 3
net.ipv4.tcp_tw_recycle = 1
net.core.netdev_max_backlog = 30000
net.ipv4.tcp_no_metrics_save=1
net.core.somaxconn = 262144
net.ipv4.tcp_syncookies = 0
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2

    执行优化:
sysctl -p

CentOS5(X86)  http://mirrors.sohu.com/fedora-epel/5/i386/epel-release-5-4.noarch.rpm

CentOS6(X64) http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm

http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-7.noarch.rpm

其他版本以此地址自行搜索即可

-----------------------------

CentOS 5.5 yum更新源推荐--163、搜狐、中科大

更新方法如下:

先进入yum源配置目录cd /etc/yum.repos.d备份系统自带的yum源
mv CentOS-Base.repo CentOS-Base.repo.save

下载其他更快的yum源
中科大的yum源:
wget http://centos.ustc.edu.cn/CentOS-Base.repo

163的yum源:
wget http://mirrors.163.com/.help/CentOS-Base-163.repo

sohu的yum源
wget http://mirrors.sohu.com/help/CentOS-Base-sohu.repo

更新玩yum源后,建议更新一下,使操作立即生效
yum makecache

转:http://hi.baidu.com/%C0%B4%C1%BD%B8%F9%CF%E3%B3%A6/blog/item/a59a610fa26207ed37d12224.html

各文档所在位置
日志文件 /var/log/varnish/varnish.log
可执行程序 /usr/local/varnish/bin
缓冲文件 /var/vcache
配置文件 /usr/local/varnish/vcl.conf
启动参数 /etc/sysconfig/varnish
启动脚本 /etc/rc.d/init.d/varnish
/etc/rc.d/init.d/varnishlog

创建www用户和组,以及Varnish缓存文件存放目录(/var/vcache):
/usr/sbin/groupadd www -g 48
/usr/sbin/useradd -u 48 -g www www
mkdir -p /var/vcache
chmod +w /var/vcache
chown -R www:www /var/vcache

创建日志文件,并授予www用户权限访问
mkdir -p /var/log/varnish
chmod +w /var/log/varnish
chown -R www:www /var/log/varnish

可能需要安装如下包
[CENTOS]yum install ncurses-devel
[UBUNTU]apt-get install libncurses5-dev

编译安装
./configure –prefix=/usr/local/varnish
make
make install

转:http://www.uplook.cn/kbase-Index-show-view10393.html

#!/bin/bash
# BY kerryhu
# MAIL:king_819@163.com
# BLOG:http://kerry.blog.51cto.com
# Please manual operation yum of before Operation.....
#============================ 更新系统时间 ============================
yum install -y ntp
ntpdate time.nist.gov
echo "00 01 * * * ntpdate time.nist.gov" >> /etc/crontab

#============================ Varnish安装 =============================

如果是RedHat/CentOS系统,在安装varnish的时候首先要安装以下软件包
automake
autoconf
libtool
ncurses-devel
libxslt
groff
pcre-devel
pkgconfig

groupadd www
useradd www -g www -s /sbin/nologin
mkdir -p /data/varnish/{cache,logs}
chmod +w /data/varnish/{cache,logs}
chown -R www:www /data/varnish/{cache,logs}
cd /opt
yum install -y automake autoconf libtool ncurses-devel libxslt groff pcre-devel pkgconfig
wget http://sourceforge.net/projects/varnish/files/varnish/2.1.3/varnish-2.1.3.tar.gz/download
tar -zxvf varnish-2.1.3.tar.gz
cd varnish-2.1.3
./configure --prefix=/usr/local/varnish
make;make install

yum -y install wget --noplugins
wget freevps.us/downloads/nginx-centos-6.sh -O - | bash

注意安装完成后 php-fpm 默认跑在 apache 用户上。

安装完成后,如果你需要的 PHP 扩展未安装,可输入如下命令查询:

yum list | grep ^php*

找到了扩展的名字,就可以直接安装了:

# 以 php memcache 扩展为例
yum install -y php-pecl-memcached

此外还遇到的问题是 DOMDocument 找不到,直接 yum 安装 php-xml:

yum install -y php-xml

所有扩展 yum 安装完成后都需要重新启动 / 载入 php-fpm。
贴下内容来看看(非最新版本,请直接下载 .sh 文件):

#!/bin/bash

##################
# disable apache #
##################
service httpd stop 
chkconfig httpd off
service xinetd stop
chkconfig xinetd off
service saslauthd stop
chkconfig saslauthd off
service sendmail stop
chkconfig sendmail off
service postfix stop
chkconfig postfix off

#Optimize yum on OpenVZ
if [ -e "/proc/user_beancounters" ]
then
  sed -i 's/plugins=1/plugins=0/' /etc/yum.conf
fi

#remove all current PHP and MySQL, will reinstall later. Also, remove apache 
yum -y remove httpd php mysql rsyslog sendmail postfix

###################
# Add a few repos #
###################
# install the Atomic repo for php and nginx (may use epel for nginx depending on version)
wget -q -O - http://www.atomicorp.com/installers/atomic | sh

# RPMForge for nginx dependencies
rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm

#EPEL for syslog-ng and nginx (may use atomic for nginx depending on version)
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm

################################
# Install PHP, NGINX and MySQL #
################################
#yum install GeoIP libGeoIP.so.1 --enablerepo=repoforge
yum -y install mysql-server php-fpm php-mysql php-gd nginx nano exim syslog-ng

#################
# install MySQL #
#################
#yum -y install mysql-server
cat > /etc/my.cnf <<END
[mysqld]
default-storage-engine = myisam
key_buffer = 8M
query_cache_size = 8M
query_cache_limit = 4M
max_connections=25
thread_cache=1
skip-innodb 
query_cache_min_res_unit=0
tmp_table_size = 4M
max_heap_table_size = 4M
table_cache=256
concurrent_insert=2 
END
echo  Do not worry if you see a error stopping MySQL or NGINX
/etc/init.d/mysqld stop
/etc/init.d/mysqld start

####################
# Set up NGINX PHP #
####################
cat > /etc/nginx/php <<END
index index.php index.html index.htm;

location ~ \.php$ {

   include fastcgi_params;
    fastcgi_intercept_errors on;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
  try_files \$uri =404;
    fastcgi_pass 127.0.0.1:9000;
    error_page 404 /404page.html; #makes nginx return it's default 404 
#	page instead of a blank page

} 
END

cat > /etc/nginx/nginx.conf <<END
user              nginx nginx;
worker_processes  2;

error_log         logs/error.log;

pid               logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    client_max_body_size 64M;
    sendfile        on;
    tcp_nopush      on;

    keepalive_timeout  3;

    gzip  on;
    gzip_comp_level 2;
    gzip_proxied any;
    gzip_types      text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    server_tokens off;

    include /etc/nginx/conf.d/*;
} 
END
rm /etc/nginx/conf.d/*
cat > /etc/nginx/conf.d/default.conf <<END
server {
    listen 80 default;
    server_name _;
    root /var/www/html;
    include php;

  } 
END
mkdir /usr/share/nginx/logs/
service nginx restart
chkconfig nginx on
chkconfig mysqld on

cat > /etc/php-fpm.d/www.conf <<END
; Start a new pool named 'www'.
[www]

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses on a
;                            specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = 127.0.0.1:9000

; Set listen(2) backlog. A value of '-1' means unlimited.
; Default Value: -1
;listen.backlog = -1

; List of ipv4 addresses of FastCGI clients which are allowed to connect.
; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original
; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address
; must be separated by a comma. If this value is left blank, connections will be
; accepted from any ip address.
; Default Value: any
listen.allowed_clients = 127.0.0.1

; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server. Many
; BSD-derived systems allow connections regardless of permissions. 
; Default Values: user and group are set as the running user
;                 mode is set to 0666
;listen.owner = nobody
;listen.group = nobody
;listen.mode = 0666

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = apache
; RPM: Keep a group allowed to write in log dir.
group = apache

; Choose how the process manager will control the number of child processes.
; Possible Values:
;   static  - a fixed number (pm.max_children) of child processes;
;   dynamic - the number of child processes are set dynamically based on the
;             following directives:
;             pm.max_children      - the maximum number of children that can
;                                    be alive at the same time.
;             pm.start_servers     - the number of children created on startup.
;             pm.min_spare_servers - the minimum number of children in 'idle'
;                                    state (waiting to process). If the number
;                                    of 'idle' processes is less than this
;                                    number then some children will be created.
;             pm.max_spare_servers - the maximum number of children in 'idle'
;                                    state (waiting to process). If the number
;                                    of 'idle' processes is greater than this
;                                    number then some children will be killed.
; Note: This value is mandatory.
pm = dynamic

; The number of child processes to be created when pm is set to 'static' and the
; maximum number of child processes to be created when pm is set to 'dynamic'.
; This value sets the limit on the number of simultaneous requests that will be
; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
; CGI.
; Note: Used when pm is set to either 'static' or 'dynamic'
; Note: This value is mandatory.
pm.max_children = 5

; The number of child processes created on startup.
; Note: Used only when pm is set to 'dynamic'
; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
pm.start_servers = 1

; The desired minimum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.min_spare_servers = 1

; The desired maximum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.max_spare_servers = 3

; The number of requests each child process should execute before respawning.
; This can be useful to work around memory leaks in 3rd party libraries. For
; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.
; Default Value: 0
pm.max_requests = 500

; The URI to view the FPM status page. If this value is not set, no URI will be
; recognized as a status page. By default, the status page shows the following
; information:
;   accepted conn    - the number of request accepted by the pool;
;   pool             - the name of the pool;
;   process manager  - static or dynamic;
;   idle processes   - the number of idle processes;
;   active processes - the number of active processes;
;   total processes  - the number of idle + active processes.
; The values of 'idle processes', 'active processes' and 'total processes' are
; updated each second. The value of 'accepted conn' is updated in real time.
; Example output:
;   accepted conn:   12073
;   pool:             www
;   process manager:  static
;   idle processes:   35
;   active processes: 65
;   total processes:  100
; By default the status page output is formatted as text/plain. Passing either
; 'html' or 'json' as a query string will return the corresponding output
; syntax. Example:
;   http://www.foo.bar/status
;   http://www.foo.bar/status?json
;   http://www.foo.bar/status?html
; Note: The value must start with a leading slash (/). The value can be
;       anything, but it may not be a good idea to use the .php extension or it
;       may conflict with a real PHP file.
; Default Value: not set 
;pm.status_path = /status

; The ping URI to call the monitoring page of FPM. If this value is not set, no
; URI will be recognized as a ping page. This could be used to test from outside
; that FPM is alive and responding, or to
; - create a graph of FPM availability (rrd or such);
; - remove a server from a group if it is not responding (load balancing);
; - trigger alerts for the operating team (24/7).
; Note: The value must start with a leading slash (/). The value can be
;       anything, but it may not be a good idea to use the .php extension or it
;       may conflict with a real PHP file.
; Default Value: not set
;ping.path = /ping

; This directive may be used to customize the response of a ping request. The
; response is formatted as text/plain with a 200 response code.
; Default Value: pong
;ping.response = pong

; The timeout for serving a single request after which the worker process will
; be killed. This option should be used when the 'max_execution_time' ini option
; does not stop script execution for some reason. A value of '0' means 'off'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
;request_terminate_timeout = 0

; The timeout for serving a single request after which a PHP backtrace will be
; dumped to the 'slowlog' file. A value of '0s' means 'off'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
;request_slowlog_timeout = 0

; The log file for slow requests
; Default Value: /var/log/php-fpm.log.slow
;slowlog = /var/log/php-fpm.log.slow

; Set open file descriptor rlimit.
; Default Value: system defined value
;rlimit_files = 1024

; Set max core size rlimit.
; Possible Values: 'unlimited' or an integer greater or equal to 0
; Default Value: system defined value
;rlimit_core = 0

; Chroot to this directory at the start. This value must be defined as an
; absolute path. When this value is not set, chroot is not used.
; Note: chrooting is a great security feature and should be used whenever 
;       possible. However, all PHP paths will be relative to the chroot
;       (error_log, sessions.save_path, ...).
; Default Value: not set
;chroot = 

; Chdir to this directory at the start. This value must be an absolute path.
; Default Value: current directory or / when chroot
;chdir = /var/www

; Redirect worker stdout and stderr into main error log. If not set, stdout and
; stderr will be redirected to /dev/null according to FastCGI specs.
; Default Value: no
;catch_workers_output = yes

; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from
; the current environment.
; Default Value: clean env
;env[HOSTNAME] = $HOSTNAME
;env[PATH] = /usr/local/bin:/usr/bin:/bin
;env[TMP] = /tmp
;env[TMPDIR] = /tmp
;env[TEMP] = /tmp

; Additional php.ini defines, specific to this pool of workers. These settings
; overwrite the values previously defined in the php.ini. The directives are the
; same as the PHP SAPI:
;   php_value/php_flag             - you can set classic ini defines which can
;                                    be overwritten from PHP call 'ini_set'. 
;   php_admin_value/php_admin_flag - these directives won't be overwritten by
;                                     PHP call 'ini_set'
; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no.

; Defining 'extension' will load the corresponding shared extension from
; extension_dir. Defining 'disable_functions' or 'disable_classes' will not
; overwrite previously defined php.ini values, but will append the new value
; instead.

; Default Value: nothing is defined by default except the values in php.ini and
;                specified at startup with the -d argument
;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com
;php_flag[display_errors] = off
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
;php_admin_value[memory_limit] = 32M
php_admin_value[upload_max_filesize] = 32M
END

mkdir /var/www
mkdir /var/www/html/
useradd apache
service php-fpm start
chkconfig php-fpm on
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
service iptables save

wget freevps.us/downloads/setup-vhost.sh -O /bin/setup-vhost
chmod 755 /bin/setup-vhost
echo "alias nano='nano -w'" >> ~/.bashrc
clear
echo Installation done.
echo to create a vhost, run
echo setup-vhost example.com
echo do not include the www. subdomain.