-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathINSTALL
253 lines (185 loc) · 7.24 KB
/
INSTALL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
== Install ==
-
Make sure you have Apache installed, and can edit its configuration file,
usually it is something like
/etc/httpd/httpd.conf
or
/usr/local/apache/conf/httpd.conf
-
Make sure you have MySQL 4 installed and can edit its configuration file,
usually it is something like
/etc/my.cnf
You need to have the development libraries for MySQL available. If you
installed it from source this is no problem, but if you installed from RPMs or
other packages, you should check that the development packages are installed.
Note that LogToMysql will only work with MySQL version 4.0 and above.
-
Untar/unzip the LogToMysql software into wherever you like to compile software.
-
Edit the LogToMysql Makefile to correctly point to the headers and libraries
for MySQL on your system. Typical locations to look in are
Includes:
/usr/local/mysql/include/mysql
/usr/local/include/mysql
/usr/include/mysql
Libraries:
/usr/local/mysql/lib/mysql
/usr/local/lib/mysql
/usr/lib/mysql
-
Type
make
This should compile everything in a couple of seconds. If you are having
problems with the MySQL libraries not being found it can help to set up the
directories
/usr/local/include/mysql
/usr/local/lib/mysql
and copy or link the required files from wherever your distribution has put
them.
-
Two executable files are produced
logtomysql
logerrortomysql
for access logs and error logs respectively. Copy these to
/usr/local/bin
and make sure that root (or whichever user Apache starts as) can execute them.
-
Set up the MySQL database for logging. Assuming that you are connected to the
MySQL server with permissions to create a database and user for logging, type
the following to set up your database (change passwords and IP numbers for your
set-up):
CREATE DATABASE weblog;
For logging on the local machine
GRANT ALL PRIVILEGES ON weblog.* TO weblogger@localhost IDENTIFIED BY 'secret';
or if logging to a remote machine from 192.168.0.2
GRANT ALL PRIVILEGES ON weblog.* TO [email protected] IDENTIFIED BY
'secret';
CREATE TABLE log (hostname text,datetime varchar(100),
url text,refer text,agent varchar(150),
ident varchar(150),resp_code int unsigned,xfer_size int unsigned);
CREATE TABLE errorlog (datetime timestamp(14) NOT NULL, message varchar(255));
If you need to use an existing user or database, just create the tables, and
modify the options in section (8) below to match.
-
LogToMysql reads passwords and other configuration information from the MySQL
configuration file. Details of the entries are:
- Socket is the local unix socket for connections to MySQL running on the same
server as Apache. Set to NULL if logging to a remote machine.
- Database is the name of the database in which your log files will be stored.
It needs to agree with whatever you set up in section 7.
- Host is 'localhost' or remote host IP on which MySQL is running.
- Port should be 0 for logging to the localhost using a socket, otherwise,
3306 for a standard MySQL installation on a remote machine.
- User is the MySQL user name through which logging will take place. It needs
to agree with whatever you set up in section 7.
- Password is the MySQL user password. It needs to agree with whatever you set
up in section 7.
- Logging is the level of information generated by the LogToMysql programs and
send to their log files. It has nothing to do with the Apache logging level.
Set to zero for minimal information, 1 for important messages, and 2 to show
you all the queries sent to MySQL. Level 1 is usually best.
- Logfile is the place that LogToMysql programs will use to store their log
information. Different files are needed for logtomysql and logerrortomysql.
- Sysuser and sysgroup are the username and group under which logtomysql and
logerrortomysql will run once they have started. Just like Apache itself, it is
best to avoid running these logging programs as root.
Examples of the configuration information are below, which you will need to
edit for your system. Examples are given for logging on the same machine as the
Apache installation, and for logging to a remote machine.
*Example 1:*
If MySQL is running on the same machine as the Apache server, edit and copy the
lines below into /etc/my.cnf (or whichever file is used on your system). Set
the 'socket' to match the value in the [mysqld] section of my.cnf.
[logtomysql]
socket = /tmp/mysql.sock
database = weblog
host = localhost
port = 0
user = weblogger
password = secret
logging = 1
logfile = /tmp/logtomysql.log
sysuser = apache
sysgroup = apache
[logerrortomysql]
socket = /tmp/mysql.sock
database = weblog
host = localhost
port = 0
user = weblogger
password = secret
sysuser = apache
sysgroup = apache
logfile = /tmp/logerrortomysql.log
logging = 1
*Example 2:*
If MySQL is on a remote machine, edit and copy the lines below into /etc/my.cnf
ON THE MACHINE ON WHICH APACHE IS RUNNING. Create the file if it doesn't exist.
Change 'host' to the machine on which MySQL is running.
[logtomysql]
socket = NULL
database = weblog
host = 192.168.0.3
port = 3306
user = weblogger
password = secret
logging = 1
logfile = /tmp/logtomysql.log
sysuser = apache
sysgroup = apache
[logerrortomysql]
socket = NULL
database = weblog
host = 192.168.0.3
port = 3306
user = weblogger
password = secret
sysuser = apache
sysgroup = apache
logfile = /tmp/logerrortomysql.log
logging = 1
When logging both access and errors both sections of options are needed, even
though there might be duplication between them. If you only want to log access
just include the [logtomysql] and not the [logerrortomysql], and visa versa if
you just want to log errors.
-
Configure Apache to use the piped logs.
*Access Logs*
Anywhere that you would normally use piped logs, use lines like the ones below
to use LogToMysql. This works in both server wide and virtual server domains.
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""
combined
CustomLog "|/usr/local/bin/logtomysql" combined
making sure that the logtomysql binary is in the place you enter here.
*Error Logs*
Using logerrortomysql in the server wide ErrorLog directive is dangerous, and
likely to cause you trouble. This is because the server may attempt to log
information during start-up before the piped logging process is fully up and
running. Virtual hosts for SSL are particularly bad at causing trouble this
way.
To prevent problems use a file based ErrorLog directive for the server wide
configuration, and then put a logerrortomysql based ErrorLog directive inside
each virtual host. Example:
#Virtual host for SSL
<VirtualHost *:443>
#Rest of virtual host config goes here
LogLevel warn
ErrorLog "|/usr/local/bin/logerrortomysql"
</VirtualHost>
#Virtual host for port 80
</VirtualHost *:80>
#Rest of virtual host config goes here
LogLevel warn
ErrorLog "|/usr/local/bin/logerrortomysql"
</VirtualHost>
#Server wide error log
ErrorLog /usr/local/apache/logs/error_log
Again, make sure that the logerrortomysql binary is in the place you enter in
the httpd.conf file.
-
Start or re-start Apache
Once you have set all this up, restart Apache and logging will begin to the
database. If it doesn't, see troubleshooting.
SELinux:
semanage fcontext -a -t httpd_exec_t "/usr/bin/logtomysql"
restorecon -v /usr/bin/logtomysql