
부하가 적은 int에 다른 Apache 서버가 있음라거의 DHCP 클라이언트만 있는 네트워크에서는 IP 주소 대신 호스트 이름을 기록해야 합니다. DHCP 환경은 매우 동적이므로 나중에 IP를 호스트 이름으로 다시 매핑하려고 하면 잘못된 결과가 나올 가능성이 높습니다.
" "이 있지만 HostnameLookups On
액세스 로그만 호스트 이름을 순종적으로 기록하지만 ErrorLog는 그렇지 않습니다.
에 대해 읽으면서 ErrorLogFormat
아무 것도 없다는 것을 알았습니다.%시간, 하지만 그냥%ㅏ("클라이언트 IP 주소 및 포트"를 의미)
그렇다면 Apache가 오류 로그에 호스트 이름도 기록하도록 할 수 있는 방법이 실제로 없을까요?
답변1
ErrorLog 지시어에는 기본이 아닙니다.
내가 할 일은 당신을 위해 해결을 수행하고 이를 통해 ErrorLog를 연결하는 스크립트를 작성하는 것입니다. Apache 구성에서 다음과 같습니다.
Errorlog "|/usr/local/bin/errorlog_resolver.pl"
그리고 샘플 Perl 스크립트는 다음과 같습니다.
#!/usr/bin/perl -w
# errorlog_resolver.pl
# Give apache ErrorLog on STDIN, outputs them with numeric IP addresses
# in the likely (host) field converted to hostnames (where possible).
# based on clf_lookup.plx from "Perl for Web Site Management"
# http://oreilly.com/catalog/perlwsmng/chapter/ch08.html
#
use strict;
use Socket;
open LOGFILE, ">>/tmp/my_error_log" or die "Couldn't open file: $!";
my %hostname;
while (<>) {
my $line = $_;
my($day, $month, $dayn, $hour, $year, $err, $client, $host, $rest) = split / /, $line, 9;
if ( $client ~~ "[client" ) {
# remove the ] trailing the likely ip-address.
my $chr = chop($host);
if ($host =~ /^\d+\.\d+\.\d+\.\d+$/) {
# looks vaguely like an IP address
unless (exists $hostname{$host}) {
# no key, so haven't processed this IP before
$hostname{$host} = gethostbyaddr(inet_aton($host), AF_INET);
}
if ($hostname{$host}) {
# only processes IPs with successful lookups
$line = "$day $month $dayn $hour $year $err $client $hostname{$host}\($host\)\] $rest)";
}
}
}
print LOGFILE $line;
}