首页 技术 正文
技术 2022年11月21日
0 收藏 707 点赞 3,301 浏览 6324 个字

环境:根据http://www.cnblogs.com/zzzhfo/p/6032095.html环境配置

  • 在web01或web02上查看用户访问日志

先客户端访问

[root@web_backup /]# for n in {..} ;do curl www.test.com;sleep  ;done
<h1>www.test.com<h1/>
<h1>www.test.com<h1/>
<h1>www.test.com<h1/>
<h1>www.test.com<h1/>
<h1>www.test.com<h1/>
<h1>www.test.com<h1/>
<h1>www.test.com<h1/>
<h1>www.test.com<h1/>
<h1>www.test.com<h1/>
<h1>www.test.com<h1/>
<h1>www.test.com<h1/>
<h1>www.test.com<h1/>
<h1>www.test.com<h1/>
<h1>www.test.com<h1/>
<h1>www.test.com<h1/>
<h1>www.test.com<h1/>
<h1>www.test.com<h1/>
<h1>www.test.com<h1/>
<h1>www.test.com<h1/>
<h1>www.test.com<h1/>

查看日志

[root@web01 /]# tail -f /etc/httpd/logs/www.test.com.access_log
192.168.119.128 - - [/Sep/::: +] "GET / HTTP/1.0"
192.168.119.128 - - [/Sep/::: +] "GET / HTTP/1.0"
192.168.119.128 - - [/Sep/::: +] "GET / HTTP/1.0"
192.168.119.128 - - [/Sep/::: +] "GET / HTTP/1.0"
192.168.119.128 - - [/Sep/::: +] "GET / HTTP/1.0"
192.168.119.128 - - [/Sep/::: +] "GET / HTTP/1.0"
192.168.119.128 - - [/Sep/::: +] "GET / HTTP/1.0"
192.168.119.128 - - [/Sep/::: +] "GET / HTTP/1.0"
192.168.119.128 - - [/Sep/::: +] "GET / HTTP/1.0"
192.168.119.128 - - [/Sep/::: +] "GET / HTTP/1.0"
192.168.119.128 - - [/Sep/::: +] "GET / HTTP/1.0"
192.168.119.128 - - [/Sep/::: +] "GET / HTTP/1.0"
192.168.119.128 - - [/Sep/::: +] "GET / HTTP/1.0"
192.168.119.128 - - [/Sep/::: +] "GET / HTTP/1.0"
192.168.119.128 - - [/Sep/::: +] "GET / HTTP/1.0"

web端记录的都是nginx的IP

修改nignx负载均衡器的/usr/local/nginx/conf/nginx.conf;在location  / 添加  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

worker_processes  ;
events {
worker_connections ;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout ;upstream web_pools {
server 192.168.119.130: weight=;
server 192.168.119.133: weight=;
server 192.168.119.131: weight= backup;
} server {
listen ;
server_name www.test.com;
location / {
root html;
index index.html index.htm;
proxy_pass http://web_pools;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}

重启nginx服务

[root@lb01 /]# nginx -s stop
[root@lb01 /]# nginx
[root@lb01 /]# netstat -anpt | grep nginx
tcp 0.0.0.0: 0.0.0.0:* LISTEN /nginx

在web01和web02上修改 /etc/httpd/conf/httpd.conf

[root@web01 /]# vim /etc/httpd/conf/httpd.conf
LogFormat "\"%{x-forwarded-for}i\" %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined<VirtualHost *:>
DocumentRoot "/var/www/www"
ServerName www.test.com
ErrorLog "logs/www.test.com.error_log"
CustomLog "logs/www.test.com.access_log" combined
</VirtualHost><VirtualHost *:>
DocumentRoot "/var/www/bbs"
ServerName bbs.test.com
ErrorLog "logs/bbs.test.com.error_log"
CustomLog "logs/bbs.test.com.access_log" combined
</VirtualHost>
[root@web01 /]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@web02 /]# vim /etc/httpd/conf/httpd.conf
LogFormat "\"%{x-forwarded-for}i\" %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined<VirtualHost *:>
DocumentRoot "/var/www/www"
ServerName www.test.com
ErrorLog "logs/www.test.com.error_log"
CustomLog "logs/www.test.com.access_log" combined
</VirtualHost><VirtualHost *:>
DocumentRoot "/var/www/bbs"
ServerName bbs.test.com
ErrorLog "logs/bbs.test.com.error_log"
CustomLog "logs/bbs.test.com.access_log" combined
</VirtualHost>

测试:客户端访问

[root@web_backup /]# for n in {..} ;do curl www.test.com;sleep  ;done
<h1>www.test.com<h1/>
<h1>www.test.com<h1/>
<h1>www.test.com<h1/>
<h1>www.test.com<h1/>
<h1>www.test.com<h1/>
<h1>www.test.com<h1/>
<h1>www.test.com<h1/>
<h1>www.test.com<h1/>
<h1>www.test.com<h1/>
<h1>www.test.com<h1/>

到web节点查看日志

[root@web02 /]# tail -f /etc/httpd/logs/www.test.com.access_log
192.168.119.128 - - [/Sep/::: +] "GET / HTTP/1.0"
192.168.119.128 - - [/Sep/::: +] "GET / HTTP/1.0"
192.168.119.128 - - [/Sep/::: +] "GET / HTTP/1.0"
192.168.119.128 - - [/Sep/::: +] "GET / HTTP/1.0"
192.168.119.128 - - [/Sep/::: +] "GET / HTTP/1.0"
192.168.119.128 - - [/Sep/::: +] "GET / HTTP/1.0"
192.168.119.128 - - [/Sep/::: +] "GET / HTTP/1.0"
192.168.119.128 - - [/Sep/::: +] "GET / HTTP/1.0"
192.168.119.128 - - [/Sep/::: +] "GET / HTTP/1.0"
192.168.119.128 - - [/Sep/::: +] "GET / HTTP/1.0"
"192.168.119.131" - - [/Sep/::: +] "GET / HTTP/1.0" "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"
"192.168.119.131" - - [/Sep/::: +] "GET / HTTP/1.0" "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"
"192.168.119.131" - - [/Sep/::: +] "GET / HTTP/1.0" "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"
"192.168.119.131" - - [/Sep/::: +] "GET / HTTP/1.0" "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"
"192.168.119.131" - - [/Sep/::: +] "GET / HTTP/1.0" "-" "curl/7.b/1.2.3 libidn/1.18 libssh2/1.4.2"
[root@web01 /]# tail -f /etc/httpd/logs/www.test.com.access_log
"192.168.119.131" - - [/Sep/::: +] "GET / HTTP/1.0" "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"
"192.168.119.131" - - [/Sep/::: +] "GET / HTTP/1.0" "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"
"192.168.119.131" - - [/Sep/::: +] "GET / HTTP/1.0" "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"
"192.168.119.131" - - [/Sep/::: +] "GET / HTTP/1.0" "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"
"192.168.119.131" - - [/Sep/::: +] "GET / HTTP/1.0" "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"
"192.168.119.131" - - [/Sep/::: +] "GET / HTTP/1.0" "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"
"192.168.119.131" - - [/Sep/::: +] "GET / HTTP/1.0" "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"
"192.168.119.131" - - [/Sep/::: +] "GET / HTTP/1.0" "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"
"192.168.119.131" - - [/Sep/::: +] "GET / HTTP/1.0" "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"
"192.168.119.131" - - [/Sep/::: +] "GET / HTTP/1.0" "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"

这是apahce的日志信息

如果web节点为nginx服务、则不需要修改、默认已经支持、只需在代理上添加:proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;即可

[root@lb02 /]# vim /usr/local/nginx/conf/nginx.conf
http {
include mime.types;
default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main;
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,489
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,904
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,737
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,490
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,128
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,291