Installation of mod_log_sql for SysCP
2007-12-31
Aders
Florian
florian.aders@syscp.org
Nägler
Frank
2007
2008
SysCP
This work is licensed under the Creative Commons
Attribution-Noncommercial-Share Alike 2.0 Germany License. To view a
copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/2.0/de/
or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San
Francisco, California, 94105, USA.
1
2007-31-12
First version
The first words
Welcome
Welcome to the installation - process for the
mod_log_sql - configsection for the
SysCP server-management-tool. You have chosen a
powerful tool with a very small need of resources. Just execute the
commands we show you in this HowTo and you should be happy. If problems
occur, ask on our discussion mailinglist or visit our forum. Do yourself a favour and use
the powerful search function before asking any question. The results you
get might be more efficient than a single question about a particular
problem.
Naming conventions
In this HowTo, we used the following basic naming
conventions:
Commands executed as root:
syscp ~ #
/execute/this/command
Commands executed as a specific user:
vmail@syscp $
/execute/this/command/as/user/vmail
Output of various programs:
I am the echo of a normal command, executed in a
shell
Content of a file:# The following sets the variable PATH to a useless value
PATH=/dev/nullFilenames:
/etc/apache2/httpd.conf
Variable names: $iamavariable
Requirements
User requirements
It is essentially to be familiar with your Linux-Environment. You
might encounter situations, where you definitely need a shell. If you
wish to install your server according to this HowTo it is advisable to
consult and understand the basics of networking, DNS and - of course -
Linux itself. Should you, however, have no experience at all how to
operate a server which is connected to the Internet, we strongly
recommend the usage of a test-environment. A wrongly configured server
is a target for all kind of attack and misuse.
This HowTo requires also basic-knowledge about the
MySQL database server. Installation and
configuration will not be discussed here. Last but not least you need to
know basics about your Apache Webserver, without
this basic knowledge you wont be able to configure your SysCP
- mod_log_sql setup, and the software might not function
properly. Every admin should be aware what kind of software is running
on his/her system. Please keep in mind one basic thing:
The best admintool can never replace a good
administrator
Server requirements
To perform a successful installation of SysCP -
mod_log_sql it is assumed to have a completed
SysCP installation up and running. A discussion
of how to install SysCP itself will not take
place here. You will find documentations for doing this on its
website
Installing mod_log_sql
Gentoo
Installing mod_log_sql on Gentoo is quite easy. Ensure you have
the ssl - useflag enabled:
syscp ~ # echo "www-apache/mod_log_sql
ssl" >> /etc/portage/package.use
After this easy step, just emerge mod_log_sql:
syscp ~ # emerge
mod_log_sql
Debian
Installing mod_log_sql on Debian is quite
easy. Just add the following repository to your
/etc/apt/sources.list if using stable branch of
Debian (mod_log_sql 1.18 only):
syscp ~ # echo "deb
ftp://ftp.gplhost.com/debian stable main" >>
/etc/apt/sources.list This repository
also includes the following packages: dtc, qmail, ucspi-tcp, mysqmail
and checklocalpasswd. The packages can also be downloaded separately for
version 1.18 and 1.9x on the GPLHost website (http://www.gplhost.com/?rub=softwares&sousrub=logsql).
NOTE: Please direct any issues with these binary releases to Thomas
Goirand (links on the his website), or to the mod_log_sql mailing list.
After this easy step, just install mod_log_sql:
syscp ~ # apt-get install
libapache2-mod-log-sql-mysql
Configuration of apache2
Most configuration files of the services might be already existing
and don't have to be created. They might have been created during the
install process of the service, and will be good enough for a default
setup.
WARNING: Do NOT use any
Microsoft-Windows editor for editing configuration files, they might
become corrupt due to wrong line-breaks. If working with windows, use an
editor that can save files in Unix/Linux format.
Gentoo
Open
"/etc/apache2/modules.d/42_mod_log_sql.conf" and
insert the following: <IfDefine LOG_SQL>
LoadModule log_sql_module modules/mod_log_sql.so
LoadModule log_sql_mysql_module modules/mod_log_sql_mysql.so
</IfDefine>
<IfModule mod_log_sql.c>
LogSQLLoginInfo mysql://syscp:<SYSCPPASSWORD>@localhost/syscp
LogSQLDBParam socketfile /var/run/mysqld/mysqld.sock
LogSQLMassVirtualHosting off
LogSQLCreateTables on
LogSQLMachineID machine_id
LogSQLPreserveFile logs/mod_log_sql_preserve.sql
LogSQLTransferLogFormat AbHhmRSsTUuv
<IfModule mod_ssl.c>
LogSQLTransferLogFormat AbHhmRSsTUuv
</IfModule>
</IfModule>Remember to replace
"<SYSCPPASSWORD>" with your real password.
Now modify "/etc/conf.d/apache2" and add
"-D LOG_SQL" to the
APACHE2_OPTS.
Debian
Open
"/etc/apache2/mods-available/log_sql_mysql.conf"
and insert the following: <IfDefine LOG_SQL>
LoadModule log_sql_module modules/mod_log_sql.so
LoadModule log_sql_mysql_module modules/mod_log_sql_mysql.so
</IfDefine>
<IfModule mod_log_sql.c>
LogSQLLoginInfo mysql://syscp:<SYSCPPASSWORD>@localhost/syscp
LogSQLDBParam socketfile /var/run/mysqld/mysqld.sock
LogSQLMassVirtualHosting off
LogSQLCreateTables on
LogSQLMachineID machine_id
LogSQLPreserveFile logs/mod_log_sql_preserve.sql
LogSQLTransferLogFormat AbHhmRSsTUuv
<IfModule mod_ssl.c>
LogSQLTransferLogFormat AbHhmRSsTUuv
</IfModule>
</IfModule>Remember to replace
"<SYSCPPASSWORD>" with your real password.
Now you have to disable and enable the mod_log_sql, because apt has
enabled it while installing where the config was not present.
syscp ~ # a2dismod
log_sql_mysql
syscp ~ # a2enmod
log_sql_mysql now reload apache2 to use the new
config
syscp ~ # /etc/init.d/apache2
reload
Configuration of SysCP
Please log into SysCP with an admin-account (You need the "Change
serversettings"- privilege). Now go to the "Settings" - area inside the
adminpanel and change the option "Temporary save logs in the database" to
"Yes" to enable mod_log_sql in apache2. After saving the settings, wait
until the SysCP-cronscript recreated the configfile. In the apache-config
written by SysCP a line like "LogSQLTransferLogTable access_log" should be
inserted in every vHost.
Testing
Now open a page managed by SysCP in your
browser. In the SysCP-database a table called
"access_log" should appear holding your access_log. If this happens, you
configured apache and SysCP correct. Gratulations
;) If not: enable the debug - logging of
mod_log_sql, look into the preserve-file and try to
find the error. Mostly it's because mod_log_sql
can't access the SysCP-database. Doublecheck the
"LogSQLLoginInfo", try changing "localhost" to "127.0.0.1" and such
stuff.
The last words
Personal Remarks
Finally! SysCP-mod_log_sql is installed and
fully functional. At this point I wish you much fun with your server and
SysCP-mod_log_sql.
If you have a lot of "Special logfiles" enabled in
SysCP, apache opens two(!) files per domain. This
could result in messages like "Too many open files" - errors appearing.
mod_log_sql may help you to reduce the opened
files by apache. It saves every request in a
database-table called "access_log". Yes, this creates a lot of requests,
but MySQL should be able to manage this ;)
Why I didn't use the "MassVirtualHosting" - Option of
mod_log_sql: This option creates a seperate table
for every vHost (if configured). This may result in a lot of tables
inside this database. MySQL scales better with
big tables than with a lot of tables (and it looks nicer ;) ), I decided
to use my own way of filtering the big "access_log". Currently the
SysCP traffic-script gathers the data out of the
database and inserts this data into the files
apache would have written in the normal mode,
too. This way we are able to use the standard
webalizer-script shipping with
SysCP. After writing the logfile, we delete the
written data out of the database to keep the table smaller.
Possible improvements: Remove webalizer and
write an own real-time-statistic-tool. For this the
MassVirtualHosting-Option should be considered again, because there may
be a lot of read-requests which need to be very fast. A table holding a
few million entries _may_ be a bit slower. This can be circumvented by
optimising MySQL ;) At the moment all error_log -
entries are written into the default error_log.
You may find the documentation / download of
mod_log_sql on its website: http://www.outoforder.cc/projects/apache/mod_log_sql/
Credits
This HowTo was written by Florian Aders.
His "Thanks a lot" goes to some persons:
Luca Longinotti for the idea.
Florian Lippert for creating
SysCP
Mario Peschel for giving me the time to write this ;)
Martin Burchert for countless assistance on many
topics.
Frank Nägler for the debian - part
Disclaimer
This HowTo was written to the best of my knowledge. Although it
will be maintained carefully, the author cannot guarantee a 100% error
free work. Use it at your own risc. The author can not be held
responsible for damage on hard/software due to the usage of this
document. Feel free to distribute this HowTo as long as the Credits and
Disclaimer will remain untouched.