|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
Your VPS2 has four main types of log files
Each log file contains helpful diagnostic information, and while logs are quite useful, they can also cause problems if they are not regularly maintained. E-mail Log FilesEach time a message passes through the SMTP servers, Sendmail logs the transaction to /var/log/maillog. (POP and IMAP account accesses also log to this file.) By default, /var/log/maillog is rotated daily, with eight days' worth of backups kept. (The sendmail.st (sendmail statistics file) is rotated weekly and is configured in /etc/syslog.conf.) Viewing the /var/log/maillog FileMaillog is useful when you are troubleshooting e-mail problems.
Note: Before resetting the log, you can prepare archival copies with tar or zip and then transfer them using FTP from your server to your local computer. maillog data look similar to the following two-part message sample from a default Sendmail configuration of level 9. Part 1Mar 19 18:10:19 envy sm-mta[4247]: h2JIAImx004247: from=<bob@your_company.com>, size=978, class=0, nrcpts=1, msgid=<20030319113738.W87363-100000@your_company.com>, proto=ESMTP, daemon=MTA, relay=other_company.com [199.104.125.167] The sender of the above message is bob@your_company.com. Its queue identifier is h2JIAImx004247. The message body has 978 bytes. It was sent first-class priority (class=0). It had a single recipient. Its message ID is 20030319113738.W87363-100000@your_company.com. It uses the ESMTP protocol. The mail transfer agent daemon received the message. The host that sent the message was other_company.com, whose IP address is 199.104.125.167. Part 2Mar 19 18:10:25 envy sm-mta[4283]: h2JIAImx004247: to=<bob@your_company.com>, delay=00:00:06, xdelay=00:00:06, mailer=esmtp, pri=30899, relay=personalmailserver.com. [128.121.230.54], dsn=2.0.0, stat=Sent (h2JIAKFq089777 Message accepted for delivery) The message is addressed to bob@your_company.com. Delivery required 6 seconds. The transaction delay (for this address only) was also 6 seconds. (That makes sense, since this message was sent to only one recipient--see nrcpts in first log entry.) Since this message is being relayed--because of a virtusertable entry--to another address, on another server), it will be "delivered" by the ESMTP mailer. The priority for this delivery attempt is 30899.The outgoing server that this mail is being relayed to is personalmailserver.com, whose IP address is 128.121.230.54. The delivery status (DSN=delivery status notification) of 2.0.0 means that delivery was successful. DSN (delivery status notification) of:
The mail was sent successfully (stat=Sent). The parenthetical expression after the "Sent" is the message that the receiving server replied with. The following table explains a maillog entry in more detail.
Resetting the /var/log/maillog File To reset /var/log/maillog, type:
This action clears the file. FTP Log FilesFTP transactions and accesses are logged to the /var/log/messages file. By default, the messages file is rotated periodically. Each entry, one per line, contains the following:
Viewing the /var/log/messages File
To view the messages file:
Resetting the /var/log/messages File
Before resetting (clearing) the log, prepare archival copies, if necessary. You can do this, for example, by archiving your files with tar or zip and then copying them using FTP from your server to your local computer. To reset /var/log/messages, type:
This action clears the file. Web LogsYour VPS2 Web service logs all traffic at your Web site to log files located in the /usr/local/apache/logs directory. Your VPS2 is configured to use the Combined Log Format, comprised of two log files:
The default directive definitions in /www/conf/httpd.conf should be adequate for most circumstances. However, if you want to modify these directives, see “Advanced Web Server Configuration” Viewing the access_log FileThe access log contains TransferLog, AgentLog, and ReferrerLog data, If your log file is not empty, the tail command displays an echo of the latest entries in the access log file. Each entry line represents a resource request.
The following table explains this example in more detail.
Testing the access_log File Use a browser to access the main index page of your VPS2.
As you access the page using a browser, new log entries append to the log file.
The entries appear as follows:
some.IP.address - user - [access date and time]
"request" status bytes_sent file_sent referrer agent
Viewing the error_log File
The error log contains any errors that users experienced when they tried to download pages from your Web site. Download the error log file from time to time and take a look at what it contains. It may help you discover broken links on your site or external links on someone else's site.
You can control the detail level of the error log file by using the LogLevel directive in the /www/conf/httpd.conf file. Testing the error_log FileOpen a browser and go to: http://www.your_company.com/bogus-filename.html Assuming that the file bogus-filename.html doesn't exist, a new entry will be added to your error log file that looks like this: [date and time] access to /usr/local/etc/httpd/htdocs/bogus-filename.html failed for some.remote.host, reason: File does not exist Resetting access_log and error_logYour VPS2 is configured to rotate these log files weekly. Check the /etc/syslog.conf file to see the schedule. If you want to use another tool to manually clear the log files, you may install Savelogs. Rotatelogs is a wrapper that you include in the Log definition in the /usr/local/apache/conf/httpd.conf. System Logs The VPS2 environment has additional complexity when dealing with system logs. A system log is any file created on the computer to provide more information about a process. What you log and what you disable is your decision. This section covers the more common logs and the data that are kept in the file. The majority of services also offer the ability to configure your own logs and content of each file. The common location for these logs is the /var/log directory. The main configuration file is the /etc/syslog.conf. You can read additional information about logs setup with the process syslog in the FreeBSD Handbook. This is the default file. If you make any changes to this file, you need to send an HUP to the process, to reread the configuration file, by killing the syslog daemon. To do this, type
syslog.conf looks like this:
You can enable a log file that will write every message that the system is receiving, but this is not recommended unless you are closely monitoring your disk space. You can also enable remote logging but this can potentially cause a significant load on the machine. The following are priority levels within syslog.conf.
syslog.conf: generates the following files in the /var/log directory. Check syslog.conf for exact information that each contains. Emergency messages are printed to the screen for the accounts such as the machine rebooting.
syslog is a powerful feature that automatically rotates the logs to ensure that your disk quota is not negatively affected. However, unforeseen problems can drastically affect the size of these logs. See the syslog man page for more information. Analyzing Log FilesThe amount of actual data logged in your Web server log files is intimidating even on relatively low traffic sites. To make any sense of the data, you might want to use a log file analysis program to process, analyze, and generate reports for you. Fortunately, there are numerous programs available that analyze Web server log files and create HTML, text, or e-mail reports of your Web server traffic. Some log analysis programs require a specific log format (i.e. combined or common). Make sure the log format configured on your VPS2 is appropriate for the log analysis program you select. (The default configuration is the combined log format.) Urchin and Analog are just two of the available tools you can use. Some software packages are more difficult to use since they must be run from the command prompt, but they are simple to install and free of charge. For more details about log analysis software packages, see VPS Hosting's Web site. Rotating and Clearing Log FilesThe following programs rotate logs on your VPS2. syslog (on your <product_name by default) is a powerful feature that automatically rotates the logs to ensure that your disk quota is not negatively affected. The main configuration file is /etc/syslog.conf. Syslog generates the log files found in /var/log. The other configuration file, /etc/syslog.conf controls what gets rotated and when. The default configuration rotates /var/log/maillog and /var/log/messages, but not Apache logs. rotatelogs (/usr/local/apache/bin/rotatelogs) is a wrapper you can use in the log definitions. Add the following two lines in the Web server configuration file, /www/conf/httpd.conf to rotate Web log files:
where path/to/logs is the path to access and error logs on your VPS2. The last argument (86400) is how often (in seconds) you want to rotate the log file. savelogs is an archival program you can vinstall and use to move (rename) the log file, filter data from the log file, store the log file in an archive (using tar or gtar), and compress the archive (using gzip or compress). After successful compression, the original log file is deleted. Using the cron SchedulerThe cron daemon is a system scheduler on your VPS2 that runs events daily, weekly, monthly, hourly, or whenever. Any command or set of commands you can run from a command prompt, can also be run from cron. For detailed information on cron , read the cron man page Any user with shell access can create a cronjob. The user who creates the cronjob is the only user (except for root) who can edit it. The most effective way to use cron is to load the scheduled tasks into the cron daemon from a file that you have created and stored on the VPS2. Although it is possible to manipulate cron directly, loading cron jobs from pre-formatted files will ensure that you have a copy of the file around for editing and for archival purposes. A common place to put such a cron file is in a directory called cronfiles in the /etc. To create a cronjob, you must first create a file (or files) on the server to hold the cronjobs. Name it whatever you want (cronfiles), and place it anywhere on the server you have access to. The following example uses “cronjob”.
Creating and Using the cronfiles Directory You need a directory to store your cron information.
Cron Files and Commands In a cron file, blank lines are ignored. Lines beginning with a pound sign (#) are comments. There are two types of cron entries: environment variables and cron commands. Environment VariablesEnvironment variables have the form: name = value The spaces around the equal sign are optional and any spaces in the "value" will be included in the value being set. The value string may be placed in quotes (either single or double) to preserve leading or trailing spaces. One environment variable that can be set is the MAILTO variable. If MAILTO is defined, any mail that is sent by cron, such as error notifications, is sent to the address assigned to the variable. If this value is not explicitly defined, error mail messages will be sent to the VPS2's Administrative User. For example, if your VPS2's administrative user login name were "joe", administrative e-mail from the cron daemon would be sent to joe@your_company.com. An example MAILTO entry might look like: MAILTO=johndoe@your_company.com If MAILTO is defined as follows, no mail will be sent from cron : MAILTO="" cron CommandsEach command entry in a cron file is composed of a series of fields that cron uses to determine what event to run at a specific time and date. The first five fields (space delimited) specify time and date information as follows:
The following command runs at midnight every day, every month, and every week.
An asterisk may be used as a wildcard meaning "first through last". The asterisk is used when you want an event to occur for every allowable value. For example, if you wanted to schedule your log files to be purged on a monthly basis you could place an asterisk in the Day of Month field. As you might imagine, it would be unwise to put an asterisk in the Minute field of the cron file as it may cause too much of a load on your VPS2. Ranges such as two numbers separated with a hyphen ("-") are allowed. For example, if you wanted the cron to send you e-mail to warn you that your taxes are due April 15th, and you want to be warned starting in January until they are due in April, you could create a cron file with the value 1-4 in the month field, and the cron would run starting in January until April. You can specify a list of values by separating the numbers with a comma. For example, 1,7,9,10 would be the months January, July, September, and October. Skip values can be specified with the / sign. For example, 1-12/2 would be every other month. Names can also be used for the month and day of the week fields. The first three letters of the month or day can be used. This option is not allowable with ranges or lists. Here are some additional examples of valid time/date values:
The sixth field in a cron file (i.e., rest of the cron line) is where you place the command you want to run. The entire command portion, up to the new line character or the % character will be executed by /bin/sh (or the shell you have specified with the SHELL environmental variable). Percent signs in the command, unless they are escaped with a backslash (\) will be changed into new line characters and all data after the first % will be sent to the command as standard input. The following is an example of using cron for mailing a notice about taxes:
Note: Do not place hard returns in cron commands, because the line wraps on its own. Hard returns tell cron that the end of the cron command has occurred. The following is an example of using cron to delete logs every month:
Notice the use of the command in the above example. The command is used to run scripts from the user's home directory. cron jobs do not run in the VPS2's environment. They run in the physical server's environment, but they run under the VPS2's User ID (a special number that keeps track of users, what files they own, and what processes they own). For this reason, when you try and run scripts or programs from cron, you must include the full path to the script. This includes the path to your home directory. For example, if my SSH login were "joe", the path to my home directory would be /usr/home/joe/. This is the path from the physical server's root file structure. The following is an example of using cron for sending a notice to occasionally mail information to Judy:
The following is an example of using cron for automating stats with getstats:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||