centos中安装nginx
163.的一个镜像:
下载的是,先用liveCD,直接启动安装,且文件小,然后再下liveDVD。
还是用了liveDVD
1、mkdir nginx;
cd nginx ;要联网
wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
下载到nginx文件夹中
2、然后要登入root账户rpm -ivh nginx-release-centos-6-0.el6.ngx.noarch.rpm
3 开始正式安装nginx
yum install nginx
自动下载了1.4.2-1
4 nginx的几个默认目录
whereis nginx :::查找
nginx: /usr/sbin/nginx /etc/nginx /usr/share/nginx
1 配置所在目录:/etc/nginx/
2 PID目录:/var/run/nginx.pid
3 错误日志:/var/log/nginx/error.log
4 访问日志:/var/log/nginx/access.log
5 默认站点目录:/usr/share/nginx/html
5、配置文件:绝对通过
user nginx; worker_processes 1; error_log /usr/local/nginx/logs/nginx_error.log warn; pid /usr/local/nginx/logs/nginx.pid; worker_rlimit_nofile 51200; events { use epoll; worker_connections 51200; } http { include mime.types; default_type application/octet-stream; #charset gb2312; log_format access '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /usr/local/nginx/logs/access.log access; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; sendfile on; tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; #gzip on; #include /etc/nginx/conf.d/*.conf; upstream abc.com{ server 192.168.16.100:8080; server 192.168.16.100:18080; } server{ listen 80; server_name www.abc.com; index index.php index.html index.htm; root /http; location /nginxstatus{ stub_status on; access_log off; } location /{ proxy_pass http://abc.com; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #proxy_set_header Host $host; } client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 600; proxy_read_timeout 600; proxy_send_timeout 600; proxy_buffer_size 8k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; } }
nginx -s stop 更新配置线关闭nginx
必须是root用户 su root,才能执行
chown 当前用户 nginx.conf 才能保存
主机无法访问虚拟机centos中的nginx(http://vm-centos/nginxstatus),关闭虚拟机的防火墙--ok
Jmeter终于可以超过511个并发了,测试1024对2*tomcat(200并发),大约是8s
但是10240个并发时,大约是开始有1000多个失败,
centos的默认文件句柄数多少?
ulimit -SHn 51200 #设置打开文件句柄
ulimit -a
open file =1024
这个值变动后好像没有什么反应。
nginx(centos,1cpu,connection=10240)+2*tomcat(windows7,500并发)
但是当connect=1024时,并发512,出现连接io失败
修改为2cpu,connection=1024时,并发1024,还是出现少量失败
当2cpu+(conn=10240),1024并发,平均耗时2050ms;500并发(64ms);800(632ms)
调整了句柄数为51200没有影响
性能最终测试::
worker_processes=2,worker_connections=51200+2*tomcat(windows7,maxThreads=1024,acceptCount=500)
1)tomcat配置
connectionTimeout="20000"
redirectPort="8443"
maxThreads="1024"
minSpareThreads="300"
acceptCount="500"
enableLookups="false"
2)Jmeter配置
set HEAP=-Xms2048m -Xmx2048m
set NEW=-XX:NewSize=512m -XX:MaxNewSize=512m
set SURVIVOR=-XX:SurvivorRatio=8 -XX:TargetSurvivorRatio=50%
set TENURING=-XX:MaxTenuringThreshold=2
set RMIGC=-Dsun.rmi.dgc.client.gcInterval=600000 -Dsun.rmi.dgc.server.gcInterval=600000
set PERM=-XX:PermSize=128m -XX:MaxPermSize=128m
3)结果
并发1024::平均2260ms
并发2048::平均3288ms
并发4096::失败105
并发3072::失败76
worker_processes=2,worker_connections=51200+
2*tomcat(windows7,maxThreads=2048,acceptCount=800)
结果:还是少量失败
创建4个tomcat,可惜系统开始卡机了,没法子测试啦
并发1024::平均1664ms
并发2048::平均3927ms,已经不太真实了,测试环境不足!没啥意义了
测试代码jsp
<html> <%@ page language="java"%> <%@ page contentType="text/html; charset=utf-8"%> <%@ page import="java.util.*"%><!-- 获取系统时间必须导入的 --> <%@ page import="java.text.*"%><!-- 获取系统时间必须导入的 --> <body> test---tomcat <% System.out.println("=========" + new Date() + "=================="); Thread.sleep(10000); System.out.println("=========" + new Date() + "=================="); %> </body> </html>