مشاهده Log در لینوکس Redhat
Viewing Logs
Log files monitor activity for Admin Server and can help troubleshoot server problems. Admin Server logs use the Common Logfile Format, a broadly supported format that provides information about the server.
Admin Server generates two kinds of logs:
-
Access logs. Access logs show requests to and responses from the Admin Server. By default, the file is located at
/var/log/dirsrv/admin-servaccess
. -
Error logs. Error logs show messages for errors which the server has encountered since the log file was created. It also contains informational messages about the server, such as when the server was started and who tried unsuccessfully to log on to the server. By default, the file is located at
/var/log/dirsrv/admin-serverror
.
The logs can be viewed through Admin Server Console or by opening the log file.
-
Open the Admin Server management window.
-
Click the Configuration tab.
-
Expand the Logs directory, and click the log file name, either Accesses or Error.
The access log, by default, is at
/var/log/dirsrv/admin-servaccess
. To view the access log, open it in an editor such as vi
.Access logs show connections to the Admin Server based on the IP address of the client, the username, and the method that the request was sent. Each line has the following format:
ip_address - bind_DN
[timestamp
-0500] "GET|POSTcgi
"HTTP_response bytes
Example logs are shown in Example 2.1, “Example Access Logs”.
Example 2.1. Example Access Logs
127.0.0.1 - cn=directory manager [23/Dec/2008:19:32:52 -0500] "GET /admin-serv/authenticate HTTP/1.0" 200 338 192.168.123.121 - cn=directory manager [23/Dec/2008:19:33:14 -0500] "POST /admin-serv/tasks/Configuration/ServerSetup HTTP/1.0" 200 244 192.168.123.121 - cn=directory manager [23/Dec/2008:19:33:16 -0500] "GET /admin-serv/tasks/Configuration/ReadLog?op=count&name=access HTTP/1.0" 200 10
The error log, by default, is at
/var/log/dirsrv/admin-serverrors
. To view the error log, open it in an editor such as vi
.Error logs record any problem response from the Admin Server. Like the access log, error logs also records entries based the client’s IP address, along with the type of error message, and the message text:
[timestamp
] [severity
] [clientip_address error_message
The severity message indicates whether the error is critical enough for administrator intervention.
[warning]
, [error]
, and [critical]
require immediate administrator action. Any other severity means the error is informational or for debugging.Example logs are shown in Example 2.2, “Example Error Logs”.
Example 2.2. Example Error Logs
[Mon Dec 22 23:44:59 2008] [notice] [client 127.0.0.1] admserv_host_ip_check: ap_get_remote_host could not resolve 127.0.0.1 [Mon Dec 22 23:44:59 2008] [notice] [client 127.0.0.1] admserv_host_ip_check: host [localhost.localdomain] did not match pattern [*.example.com] -will scan aliases [Mon Dec 22 23:44:59 2008] [notice] [client 127.0.0.1] admserv_host_ip_check: host alias [localhost] did not match pattern [*.example.com] [Mon Dec 22 23:44:59 2008] [notice] [client 127.0.0.1] admserv_check_authz(): passing [/admin-serv/authenticate] to the userauth handler [Mon Dec 22 23:45:16 2008] [notice] [client 192.168.123.121] admserv_host_ip_check: ap_get_remote_host could not resolve 192.168.123.121
The access and error log files’ names can be changed to rotate the files. This rotation has to be done manually to create new files if the existing log files become too large.
-
Open the Admin Server management window.
-
Click the Configuration tab.
-
Click Logs in the left panel.
-
In the Logs window on the right, enter the new log file name.
WARNING
The path to the log file is absolute and cannot be changed. -
Click OK to save the changes.
-
Open the Tasks tab, and click the button to restart the server and apply the changes.
The access and error log files’ names and locations can be changed to rotate the files. This rotation has to be done manually to create new files if the existing log files become too large. The location can be changed if the default location in
/var/log/dirsrv/admin-serv
does not meet the application needs.The Admin Server configuration is stored in two locations. The main entry is an LDAP entry in the Configuration Directory Server’s
o=NetscapeRoot
database. The other is the console.conf
file. Changing the log settings requires changing both settings.-
Edit the Admin Server configuration entry in the Configuration Directory Server.
-
Get the name of the Admin Server entry. Since the Admin Server entry has a special object class,
nsAdminConfig
, it is possible to search for the entry using that object class to retrieve the DN./usr/lib64/mozldap/ldapsearch -D "cn=directory manager" -w secret -p 389 -h server.example.com
-b "o=NetscapeRoot" "(objectclass=nsAdminConfig)" dn
version:1 dn: cn=configuration,cn=admin-serv-example,cn=Red Hat Administration Server,cn=Server Group,cn=server.example.com,ou=example.com,o=NetscapeRoot -
The Admin Server entry can be edited using
ldapmodify
. The access and error log settings are stored in thensAccessLogs
andnsErrorLogs
attributes, respectively. For example:/usr/lib64/mozldap/ldapmodify -D "cn=directory manager" -w secret -p 389 -h server.example.com dn: cn=configuration,cn=admin-serv-example,cn=Red Hat Administration Server,cn=Server Group,cn=server.example.com,ou=example.com,o=NetscapeRoot changetype:modify replace:nsAccessLog nsAccessLog:/var/log/dirsrv/admin-serv/access_new
Hit Enter twice to submit the operation, and then Control+C to closeldapmodify
.
-
-
Open the Admin Server configuration directory.
cd /etc/dirsrv/admin-serv
-
Edit the
console.conf
file. For the access log, edit the path and filename in theCustomLog
parameter. For the error log, edit the path and filename in theErrorLog
parameter.CustomLog /var/log/dirsrv/admin-serv/access_new common ErrorLog /var/log/dirsrv/admin-serv/error_new
Leave the termcommon
after the access log path; this means that the access log is in the Common Log Format. -
Restart the Admin Server.
service dirsrv-admin restart
By default, the logs show the IP address of the clients which connect to the Admin Server. This is faster for the Admin Server, since it does not have to do a DNS lookup for every connection. It is possible to set the Admin Server to perform a DNS lookup so that hostnames are used in the logs. Along with being friendlier to read and search, using hostnames instead of IP addresses also removes some unnecessary error messages about being unable to resolve hostnames.
To configure the Admin Server to perform DNS lookups:
-
Edit the
console.conf
file for the Admin Server.cd /etc/dirsrv/admin-serv vim console.conf
-
Set the
HostnameLookups
parameter toon
. By default, this is turned off, so that IP addresses are recorded in logs instead of hostnames.HostnameLookups on