Page 53 - Open Soource Technologies 304.indd
P. 53

Open Source Technologies



                   Notes                   ServerName domain3.com
                                           ErrorLog /home/sites/domain3/logs/error.log
                                           CustomLog /home/sites/domain3/logs/web.log
                                           </VirtualHost>

                                 In the above example, we have three domains with three unique Web logs (using the combined
                                 format we defined earlier). A traffic analysis package could then be scheduled to process these
                                 logs and generate reports for each domain independently.

                                 This method works well for most hosts. However, there may be situations where this could
                                 become  unmanageable.  Apache  recommends  a  special  single  log  file  for  large  virtual  host
                                 environments and provides a tool for generating individual logs per individual domain.
                                 We will call this log type the cvh format, standing for “common virtual host.” Simply by adding
                                 a  %v  (which  stands  for  virtual  host)  to  the  beginning  of  the  combined  log  format  defined
                                 earlier and giving it a new nickname of cvh, we can compile all domains into one log file, then
                                 automatically split them into individual log files for processing by a traffic analysis package.

                                 LogFormat “%v %h %l %u %t “%r” %>s %b “%{Referer}i” “%{User-Agent}i”” cvh

                                 In this case, we do not make any CustomLog entries in the <VirtualHost> containers and simply
                                 have one log file generated by Apache. A program created by Apache called split_logfile is
                                 included in the src/support directory of your Apache sources. from your master log file will
                                 be named for each domain (virtual host) and look like: virtualhost.log.
                                 4.3.4  Log Rotation

                                 Finally, we want to address log rotation. High traffic sites will generate very large log files,
                                 which will quickly swallow up valuable disk space on your server. You can use log rotation to
                                 manage this process. There are many ways to handle log rotation, and various third party tools
                                 are available as well. However, we’re focusing on configurations native to Apache, so we will
                                 look at a simple log rotation scheme here. I’ll include links to more flexible and sophisticated
                                 log rotation options in a moment.
                                 This example uses a rudimentary shell script to move the current Web log to an archive log,
                                 compresses the old file and keeps an archive for as long as 12 months, then restarts Apache
                                 with a pause to allow the log files to be switched out.
                                           mv web11.tgz web12.tgz

                                           mv web10.tgz web11.tgz

                                           mv web9.tgz  web10.tgz
                                           mv web8.tgz  web9.tgz
                                           mv web7.tgz  web8.tgz

                                           mv web6.tgz  web7.tgz

                                           mv web5.tgz  web6.tgz
                                           mv web5.tgz  web6.tgz
                                           mv web4.tgz  web5.tgz




        48                                LOVELY PROFESSIONAL UNIVERSITY
   48   49   50   51   52   53   54   55   56   57   58