http://www.cnblogs.com/codingcloud/p/5095066.htmlphp
参考地址 html
https://www.zybuluo.com/phper/note/89391linux
http://www.04007.cn/article/276.htmlnginx
http://blog.csdn.net/lmx88/article/details/9012939算法
1.根据访问IP统计UV后端
awk '{print $1}' access.log|sort | uniq -c |wc -l缓存
2.统计访问URL统计PVtomcat
awk '{print $7}' access.log|wc -l服务器
3.查询访问最频繁的URLsession
awk '{print $7}' access.log|sort | uniq -c |sort -n -k 1 -r|more
4.查询访问最频繁的IP
awk '{print $1}' access.log|sort | uniq -c |sort -n -k 1 -r|more
5.根据时间段统计查看日志
cat access.log| sed -n '/14\/Mar\/2015:21/,/14\/Mar\/2015:22/p'|more
netstat -na | grep ESTAB | grep 80 | wc -l
netstat -nat||grep ESTABLISHED|wc
配置文件
nginx 经常使用命令
启动 start nginx.exe
中止 nginx.exe -s stop
从新加载 软件正在运行 不想重启 从新加载地址生效 ,, nginx.exe -s reload
#user nobody;
worker_processes 1; //进程数
#error_log logs/error.log;
#error_log logs/error.log noti
worker_processes 线程数 在生产环境 下 应该与 服务器的cpu的核数同样 linux 下 按top 1 可查看内核数量
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_
表明http协议 若是是http协议请求 由 http{} 中的配置来进行处理
server {
listen 80;
server_name manage.my.com;
#charset koi8-r;
#access_log logs/host.access.log main;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location / {
proxy_pass http://127.0.0.1:8081;
proxy_connect_timeout 600;
proxy_read_timeout 600;
}
}
就会有不少的http请求进入 nginx 有http{} 中的不一样 的 server 进行处理
若是访问路径是 manage.my.com 就由本server 进行处理
nginx 下会有不少tomcat
-- 经过server name 进行匹配
-- 监听端口 listen 监听80 多个listen 不会 冲突 由于都属于nginx 内部
-- proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
代理头 地址 由于是反向代理 因此是代理头信息
-- location /
/表明 全部 就是全部的 manage.my.com 请求 由括号中来处理
启动nginx 不能启动 问题 两个
第一个目录有中文
第二 nginx 80 端口被占用 能够直接用 nginx.exe 查看 是否占用 ,若是占用会有报错
集群配置
1. 在http节点下,添加upstream节点。
1 2 3 4 |
|
2. 将server节点下的location节点中的proxy_pass配置为:http:// + upstream名称,即“
1 2 3 4 5 |
|
3. 如今负载均衡初步完成了。upstream按照轮询(默认)方式进行负载,每一个请求按时间顺序逐一分配到不一样的后端服务器,若是后端服务器down掉,能自动剔除。虽然这种方式简便、成本低廉。但缺点是:可靠性低和负载分配不均衡。适用于图片服务器集群和纯静态页面服务器集群。
除此以外,upstream还有其它的分配策略,分别以下:
weight(权重)
指定轮询概率,weight和访问比率成正比,用于后端服务器性能不均的状况。以下所示,10.0.0.88的访问比率要比10.0.0.77的访问比率高一倍。
1 2 3 4 |
|
ip_hash(访问ip)
每一个请求按访问ip的hash结果分配,这样每一个访客固定访问一个后端服务器,能够解决session的问题。
1 2 3 4 5 |
|
fair(第三方)
按后端服务器的响应时间来分配请求,响应时间短的优先分配。与weight分配策略相似。
1 2 3 4 5 |
|
url_hash(第三方)
按访问url的hash结果来分配请求,使每一个url定向到同一个后端服务器,后端服务器为缓存时比较有效。
注意:在upstream中加入hash语句,server语句中不能写入weight等其余的参数,hash_method是使用的hash算法。
1 2 3 4 5 6 |
|
upstream还能够为每一个设备设置状态值,这些状态值的含义分别以下:
down 表示单前的server暂时不参与负载.
weight 默认为1.weight越大,负载的权重就越大。
max_fails :容许请求失败的次数默认为1.当超过最大次数时,返回proxy_next_upstream 模块定义的错误.
fail_timeout : max_fails次失败后,暂停的时间。
backup: 其它全部的非backup机器down或者忙的时候,请求backup机器。因此这台机器压力会最轻。
1 2 3 4 5 6 7 |
|