好久毛写博文了!!!!
【APP】安装nginx时的简单优化
原创
©著作权归作者所有:来自51CTO博客作者qzhijun的原创作品,请联系作者获取转载授权,否则将追究法律责任
下面来简单说下安装nginx时的简单优化(没有涉及到后期的优化)
一、编译安装前优化
1.关闭debug模式
在NGINX源码文件被解压后,修改auto/cc/gcc这个文件
#debug
CFLAGS=" $CFLAGS -g"
注释掉这行,也可以删除!
2.指定特定CPU型号编译优化
--with-cc-opt='-O3'
--with-cpu-opt=CPU #有这几种类型 pentium,pentiumpro,pentium4,athlon opteron,amd64,sparc32,sparc64,ppc64等
如何确定:
cat /proc/cpuinfo |grep "model name"
3.利用tcmalloc优化nginx性能
到此站下载:http:///nongnu/libunwind/
tar zxvf libunwind-version.tar.gz
cd libunwind-version
CFLAGS=-fPIC ./configure
make CFLAGS=-fPIC
make CFLAGS=-fPIC install
PS:最新的1.0版本安装可能会问题!!
安装google-perftools 加速--tcmalloc
可以从此站下载:http:///p/google-perftools/
tar zxvf gperftools-version.tar.gz
cd gperftools-version
./configure
make && make install
echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
ldconfig
重新编译安装nginx
编译时加上 --with-google_perftools_module 这个选项
./configure --with-google_perftools_module --user=www --group=www --
prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre --lock-path=/var/run/nginx.lock --pid-path=/var/run/nginx.pid
make && make install
为google-erftools添加线程目录
mkdir /tmp/tcmalloc
chmod 0777 /tmp/tcmalloc
修改nginx主配置文件nginx.conf
在server以上位置加入如下语句:
google_perftools_profiles /tmp/tcmalloc;
重启启动nginx,再验证运行状态
lsof -n | grep tcmalloc
二、关闭不用的服务
略
三、优化写磁盘操作
在Nginx高并发访问下,nginx将频繁访问磁盘中的文件,也就是access操作,这对磁盘写操作产生很大影响,我们可以如下做:
mount -o defaults,noatime,nodiratime -o remount /dev/sdb1
也可以把noatime,nodiratime 写到/etc/fstab文件的对应磁盘挂载项中!!
四、优化对文件描述符和用户可拥有的进程数据
我们可以通过 ulimint -a 查看!
ulimit -SHn 65535
ulimit -SHu 65535
也可以把上面两项的操作写入配置文件中,下次重启后永久生效!
* soft nofile 102400
* hard nofile 102400
* soft nproc 102400
* hard nproc 102400
解释下这两条命令:
ulimit -n : 用于查询单个用户对文件描述符的使用数,默认是1024
ulimit -u : 用于查询单个用户最多所使用的进程数,默认是4096
五、系统TCP/IP内核参数优化
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.core.somaxconn = 262144
net.core.netdev_max_backlog = 262144
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_keepalive_time = 30
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.ip_local_port_range = 1024 65536
net.ipv4.tcp_sack = 0
net.ipv4.tcp_timestamps = 0
net.ipv4.icmp_echo_ignore_all = 0
/sbin/sysctl -p 立即生效!
六、nginx服务器配置优化
更多优化大家来补充!!
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
GoldenDB的简单安装
本文对goldendb配置进行了安装。比较简单。
goldendb集群安装 -
OpenVPN 的简单安装使用服务器 LINUX 虚拟局域网 远程连接 远程登录
-
Nginx简单编译安装
Nginx简单安装
nginx 安装 编译 -
查看nginx安装时的配置
./nginx -V
职场 休闲 nginx -
最简单的nginx安装教程
文章标题前言二:安装编译库和环境三:安装pcre环境(可选)四:下载并安装四:常用命令五:延伸问题六:总结七:往期
nginx安装 nginx linux 服务器 -
优化nginx在高并发时的性能
优化nginx在高并发时的性能
优化nginx在高并发时的性能 -
nginx运维实战之开山篇-安装时优化实战
nginx线上的安装基本优化,这些在安装的时候最好已经做好;为后续的nginx各种动态调优做准备。最大限度的榨干nginx的这个多线程的高效的轻量级的web服务器。
linux nginx nginx安装优化。加速库
















