7)nginx服务日常操作:: (1)测试配置文件是否正确语法:
[root@xuegod63 nginx-1.8.0]# /server/nginx-1.8.0/sbin/nginx -t
nginx: the configuration file /server/nginx-1.8.0/conf/nginx.conf syntax is ok
nginx: configuration file /server/nginx-1.8.0/conf/nginx.conf test is successful (2)重新加载配置文件
8)在配置文件nginx.conf的最后一行}前,添加以下内容: upstream htmlservers { #定义静态文件负载均衡服务器组名称 server 192.168.1.62:80; server 192.168.1.64:80; } upstream phpservers{ #定义动态文件负载均衡服务器组名称 server 192.168.1.62:80; server 192.168.1.64:80; } upstream picservers { #定义图片文件负载均衡服务器组名称 server 192.168.1.62:80; server 192.168.1.64:80; } #后期工作中,根据工作中的需要,配置成具体业务的IP地址 如图:
9)重新加载nginx服务器配置文件:
[root@xuegod63 conf]# /server/nginx-1.8.0/sbin/nginx -t
nginx: the configuration file /server/nginx-1.8.0/conf/nginx.conf syntax is ok
nginx: configuration file /server/nginx-1.8.0/conf/nginx.conf test is successful
(5)重启apache服务器 [root@xuegod64 html]# service httpd restart 4、测试 (1)测试负载均衡及动静分离---静态页面: =
(2)测试动静分离及负载均衡---动态页面:
(3)测试图片负载均衡:
(4)测试自动剔除坏的节点:
[root@xuegod64 html]# service httpd stop
http://192.168.1.63/pic.jpg
5、测试性能: 扩展: 文件打开数过多 [root@xuegod63html]# ab -n 1000 -c 1000 http://192.168.1.62/index.html #运行正常 [root@xuegod63html]# ab -n 2000 -c 2000 http://192.168.1.62/index.html #报错 This is ApacheBench, Version 2.3 Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 192.168.1.62 (be patient) socket: Too many open files (24) # 测试时,一次打开的socket文件太多。 [root@xuegod63 ~]# ulimit -n 1024#系统默认一个进程最多同时允许打开1024的文件 [root@xuegod63 ~]# ulimit -n 10240#修改默认允许同事打开10240个文件 [root@xuegod63 ~]# ab -n 2000 -c 2000 http://192.168.1.62/index.html This is ApacheBench, Version 2.3 Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.1.62 (be patient) Completed 200 requests Completed 400 requests ....... Completed 1800 requests Completed 2000 requests Finished 2000 requests Server Software: Apache/2.2.15 Server Hostname: 192.168.1.62 Server Port: 80 Document Path: /index.html Document Length: 13 bytes Concurrency Level: 2000 Time taken for tests: 1.119 seconds Complete requests: 2000 Failed requests: 0 Write errors: 0 Total transferred: 560000 bytes HTML transferred: 26000 bytes Requests per second: 1787.69 [#/sec] (mean) Time per request: 1118.765 [ms] (mean) Time per request: 0.559 [ms] (mean, across all concurrent requests) Transfer rate: 488.82 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 56 216.7 1 1062 Processing: 4 71 161.9 24 670 Waiting: 4 70 161.9 24 670 Total: 16 127 271.1 26 1087 Percentage of the requests served within a certain time (ms) 50% 26 66% 26 75% 27 80% 57 90% 717 95% 727 98% 1085 99% 1086 100% 1087 (longest request)