Chinaunix首页 | 论坛 | 博客
  • 博客访问: 161225
  • 博文数量: 42
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 377
  • 用 户 组: 普通用户
  • 注册时间: 2014-04-01 11:18
个人简介

虔诚运维

文章分类

全部博文(42)

文章存档

2014年(42)

我的朋友

分类: 系统运维

2014-07-23 16:58:36

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://liuyu.blog.51cto.com/183345/293947

申明:本连载的文章来自:Nginx官网、张宴BLOG、linuxtone论坛、互联网、本人原创。并尽力在官网文档的基础发表原创作品。并保证文档的质量与错误率。如有作者认为本文有涉及版权问题请与我联系:

liuyu105#gmail.com。

一、Nginx安装配置

1、 安装依赖库及pcre
2、 编译参数及优化编译
A、 CPU优化
B、 Tcmalloc优化
C、 系统优化
D、 减肥
 

1、安装依赖和pcre

本文以centos 为例。采用yum的安装方法

	
  1. yum -y install ntp vim-enhanced gcc gcc-c++gcc-g77 flex bison autoconf automake \  
  2. bzip2-devel ncurses-devel openssl-devel libtool*zlib-devel libxml2-devel libjpeg-devel \  
  3. libpng-devel libtiff-devel fontconfig-devel freetype-devel libXpm-develgettext-devel \  
  4. curl curl-devel pam-devel e2fsprogs-devel krb5-devel libidn libidn-devel  

#Download pcre

官方下载地址: 下载最新版本
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/

	
  1. wget pcre-laster.tar.gz  
  2. tar zxvf pcre-laster.tar.gz  
  3. cd pcre-laster  
  4. ./configure && make && makeinstall 
2、编译参数

#Download nginx 最版本下载地址:

	
  1. Wget 
  2. tar zxvf nginx-0.8.35.tar.gz  
  3. cd nginx-0.8.35  
  4. /configure --user=www --group=www --prefix=/usr/local/nginx/  
  5. --with-http_stub_status_module --with-http_ssl_module  
  6. --with-md5=/usr/lib --with-sha1=/usr/lib  
  7. make && make install  


更详细的解释请参与官方WIKI

3、优化

A、 为特定的CPU指定CPU类型编译优化.

默认nginx使用的GCC编译参数是-O
需要更加优化可以使用以下两个参数
--with-cc-opt='-O3' \
--with-cpu-opt=opteron \
使得编译针对特定CPU以及增加GCC的优化.
此方法仅对性能有所改善并不会有很大的性能提升,供朋友们参考.
CPUD类型确定: # cat /proc/cpuinfo | grep "model name"
编译优化参数参考:

B、Tcmalloc优化Nginx 性能

wget

	
  1. # tar zxvf libunwind-0.99-alpha.tar.gz  
  2. # cd libunwind-0.99-alpha/  
  3. # CFLAGS=-fPIC ./configure  
  4. # make CFLAGS=-fPIC  
  5. # make CFLAGS=-fPIC install  
  6. # wget 
  7. # tar zxvf google-perftools-0.98.tar.gz  
  8. # cd google-perftools-0.98/  
  9. # ./configure  
  10. # make && make install  
  11. # echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf  
  12. # ldconfig  
  13. # lsof -n | grep tcmalloc  
编译nginx 加载google_perftools_module: ./configure --with-google_perftools_module 在主配置文件加入nginx.conf 添加: google_perftools_profiles /path/to/profile;


C、内核参数优化

# vi /etc/sysctl.conf #在末尾增加以下内容:

	
  1. net.ipv4.tcp_fin_timeout = 30  
  2. net.ipv4.tcp_keepalive_time = 300  
  3. net.ipv4.tcp_syncookies = 1  
  4. net.ipv4.tcp_tw_reuse = 1  
  5. net.ipv4.tcp_tw_recycle = 1  
  6. net.ipv4.ip_local_port_range = 5000 65000  
#使用配置生效 sysctl -p


D、减肥

减小nginx编译后的文件大小 (Reduce file size of nginx)

默认的nginx编译选项里居然是用debug模式(-g)的(debug模式会插入很多跟踪和ASSERT之类),编译以后一个nginx有好几兆。去掉nginx的debug模式编译,编译以后只有几百K

在 auto/cc/gcc,最后几行有:

# debug

CFLAGS=”$CFLAGS -g”

注释掉或删掉这几行,重新编译即可。

 注: 我这里没有写伪装服务器的版本。大家可以上网搜索进行配置安装。

本文出自 “seven” 博客,请务必保留此出处http://liuyu.blog.51cto.com/183345/293947

阅读(1163) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~