source: npl/mailserver/dspam/dspam-3.10.2/doc/mysql_drv.txt @ c5c522c

gcc484ntopperl-5.22
Last change on this file since c5c522c was c5c522c, checked in by Edwin Eefting <edwin@datux.nl>, 8 years ago

initial commit, transferred from cleaned syn3 svn tree

  • Property mode set to 100644
File size: 10.0 KB
Line 
1$Id: mysql_drv.txt,v 1.5 2011/06/28 00:13:48 sbajic Exp $
2
3COPYRIGHT (C) 2002-2012 DSPAM Project
4http://dspam.sourceforge.net
5
6LICENSE
7
8This program is free software: you can redistribute it and/or modify
9it under the terms of the GNU Affero General Public License as
10published by the Free Software Foundation, either version 3 of the
11License, or (at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16GNU Affero General Public License for more details.
17
18You should have received a copy of the GNU Affero General Public License
19along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21ABOUT
22
23mysql_drv is a MySQL storage driver for DSPAM v3.0 and above. This driver
24enables DSPAM to read and write all token, signature, and statistics data
25from a MySQL database. The advantages of using a SQL backend are obvious:
26
27- Centralized data storage
28- Structured queries for information
29- No need for context locking mechanisms
30- Replication and other MySQL features
31
32DSPAM support MySQL 5.0 and greater.
33
341. CONFIGURING DSPAM
35
36To configure DSPAM to use mysql_drv, use the following arguments while running
37DSPAM's configure:
38
39--with-storage-driver=mysql_drv
40Tells DSPAM to use the mysql_drv driver
41
42--with-mysql-libraries=/path/to/libs
43Tells DSPAM where to find the MySQL client libraries. They are usually
44located in /usr/local/mysql/lib
45
46--with-mysql-includes=/path/to/libs
47Tells DSPAM where to find the MySQL headers. They are usually located in
48/usr/local/mysql/include
49
50--enable-virtual-users
51Tells DSPAM to create virtual user ids for each dspam user. Use this if your
52users don't really exist on the system (e.g. via getpwuid) or if you're doing
53something weird like sharing uids.
54
55After configure has successfully finished, build and install DSPAM using the
56instructions from DSPAM's readme.
57
582. CREATING MYSQL OBJECTS
59
60Before mysql_drv will function, you must run the mysql_objects-4.1.sql file
61(located in src/tools.mysql_drv) to create the table objects required by the
62driver. See your MySQL documentation for further information.
63
64This script assumes that you have already created a database for DSPAM objects
65and a user with full access to SELECT, INSERT, UPDATE, and DELETE.
66
67If you plan on enabling virtual users (something you'll need to do if the users
68don't actually exist on your system), also run virtual_users.sql.
69
70You may also wish to add this line to the mysqld portion of /etc/my.cnf:
71
72set-variable = max_allowed_packet=8192000
73
74This will extend the query size from 1MB to 8MB; some larger queries may
75cause MySQL to drop connection without this set.
76
77NOTE: The mysql_objects-space.sql, mysql_objects-speed.sql and purge,sql files
78located in src/tools.mysql_drv were originally created for older MySQL versions.
79They can be used on recent MySQL versions, but do not use MySQL features for
80improved performance available since MySQL 4.1. For new setups, you should
81always use the *-4.1.sql files.
82
833. UPDATING DSPAM.CONF
84
85mysql_drv needs to know how to connect to your MySQL database. You will need to
86specify this information in dspam.conf. This file already contains some example
87data:
88
89MySQLServer    /var/lib/mysql/mysql.sock
90MySQLPort
91MySQLUser      dspam
92MySQLPass      changeme
93MySQLDb        dspam
94MySQLCompress  true
95MySQLReconnect true
96
97If you are using MySQL >= 5.0.13 and have problems with DSPAM dropping the
98connection to your MySQL instance, then set MySQLReconnect to true to allow
99the mysql_drv to try to re-establish stale and/or dead connections.
100
101Or if you'd like to connect via TCP, use the IP address and port of the
102MySQL server. DSPAM checks to see if the first character of the HOSTNAME field
103is a slash, and if so will treat it like a socket file.
104
1054. NIGHTLY PURGE
106
107If you would like to purge the many stale tokens DSPAM will have lying around
108the database, you should run one of the provided purge scripts nightly.
109The dspam_clean tool can be configured to perform more granular cleansing,
110such as that of uninteresting data. See DSPAM's README for more information
111about the dspam_clean tool.
112
113If you are supporting TOE or TUM-mode users on your system, you will want to
114do one of the following:
115
116  1. Preferences Extensions
117
118     It is recommended you activate preferences extension support.
119     purge-4.1.sql will skip certain types of purges for users with TOE/TUM
120     specified in their preferences.
121
122     NOTE: You should add a preference for any global users on your system, so
123     that their data is purged as if TOE-based (since global user data is
124     rarely updated). You can do this using:
125
126     dspam_admin add pref [username] trainingMode TOE
127
128  2. Global TOE Support
129
130     If you are using TOE globally (and not in individual user preferences),
131     then you should update purge-4.1.sql, and set the default training mode
132     to TOE:
133
134     SET @TrainingMode    = 'TOE';
135
136     This will prevent the purging of stale tokens, which could cause serious
137     data loss in TOE databases (because tokens are never touched unless
138     an error has occured). All other purges should be safe even for TOE-mode
139     users.
140
141If you will NOT be supporting TOE users on your system, you may simply run
142the purge-4,1.sql script nightly, as-is.
143
1445. TUNING
145
146If you have a busy server, and find a lot of table locks, you may consider
147making a few tweaks to the MySQL configuration. Alternatively, you may
148consider InnoDB which performs row-level locking, but this is rarely necessary.
149
150  Increase key_buffer_size. If you have the memory, try at least 256M or 512M.
151
152  Increase table_cache. Try a higher value (some systems go as high as 1024).
153  This is related to the max_connections option and allows many file descriptors
154  to be shared among threads.
155
156  Increase myisam_sort_buffer_size to a higher value, depending on your memory.
157  Ideally, a few hundred MB would be great, but at least 64M would be an
158  improvement.
159
160  5.1 USING INNODB
161
162  On very large tables using InnoDB instead of MyISAM could speedup DSPAM because
163  InnoDB uses row-level locking while MyISAM uses table-level locking. The row-
164  level locking (used in InnoDB) may be faster because additional updates are not
165  waiting for the entire table (used in MyISAM) to unlock. In most cases using
166  table-level locking instead of row-level locking is considered to be faster but
167  since DSPAM can use many concurrent processes (especially if running in daemon
168  mode) where each of the processes maintains his own connection to MySQL, switching
169  to row-level locking (as used in InnoDB) could noticeable speedup the processing
170  throughput of DSPAM.
171
172  To convert all DSPAM tables to use InnoDB engine, execute the following SQL
173  commands against your DSPAM database:
174    ALTER TABLE `dspam_signature_data`
175      ENGINE = InnoDB;
176    ALTER TABLE `dspam_stats`
177      ENGINE = InnoDB;
178    ALTER TABLE `dspam_token_data`
179      ENGINE = InnoDB;
180    ALTER TABLE `dspam_virtual_uids`
181      ENGINE = InnoDB;
182
183  If you are using the preference extension then issue the following SQL command
184  to convert the preference extension table to InnoDB:
185    ALTER TABLE `dspam_preferences`
186      ENGINE = InnoDB;
187
188  When using InnoDB you can add additional constrains to the DSPAM tables so that
189  automatically when you remove a user in DSPAM all his/her tokens, signatures,
190  preferences and statistic data get removed as well.
191
192  !! IMPORTANT: Do not add those constrains if you are using DSPAM virtual user
193  aliases (aka: DSPAM in relay mode) !!
194
195  To add the additional constrains execute the following SQL commands against your
196  DSPAM database:
197    SET FOREIGN_KEY_CHECKS=0;
198    ALTER TABLE `dspam_signature_data`
199      ADD CONSTRAINT `dspam_signature_data_ibfk_1`
200      FOREIGN KEY (`uid`)
201      REFERENCES `dspam_virtual_uids` (`uid`)
202      ON DELETE CASCADE;
203    ALTER TABLE `dspam_stats`
204      ADD CONSTRAINT `dspam_stats_ibfk_1`
205      FOREIGN KEY (`uid`)
206      REFERENCES `dspam_virtual_uids` (`uid`)
207      ON DELETE CASCADE;
208    ALTER TABLE `dspam_token_data`
209      ADD CONSTRAINT `dspam_token_data_ibfk_1`
210      FOREIGN KEY (`uid`)
211      REFERENCES `dspam_virtual_uids` (`uid`)
212      ON DELETE CASCADE;
213    SET FOREIGN_KEY_CHECKS=1;
214
215  If you are using the preference extension then issue the following SQL
216  commands to add the additional constrain to the preference extension table:
217    SET FOREIGN_KEY_CHECKS=0;
218    ALTER TABLE `dspam_preferences`
219      ADD CONSTRAINT `dspam_preferences_ibfk_1`
220      FOREIGN KEY (`uid`)
221      REFERENCES `dspam_virtual_uids` (`uid`)
222      ON DELETE CASCADE;
223    SET FOREIGN_KEY_CHECKS=1;
224
225  If you have added those constrains and later decide to switch to DSPAM virtual
226  user aliases or decide that you don't need/want those constrains then issue the
227  following SQL commands against your DSPAM database to remove the constrains:
228    SET FOREIGN_KEY_CHECKS=0;
229    ALTER TABLE `dspam_signature_data`
230      DROP FOREIGN KEY `dspam_signature_data_ibfk_1`;
231    ALTER TABLE `dspam_stats`
232      DROP FOREIGN KEY `dspam_stats_ibfk_1`;
233    ALTER TABLE `dspam_token_data`
234      DROP FOREIGN KEY `dspam_token_data_ibfk_1`;
235    SET FOREIGN_KEY_CHECKS=1;
236
237  If you have enabled the preference extension in DSPAM then do not forget to
238  remove the constrain from the dspam_preferences table as well:
239    SET FOREIGN_KEY_CHECKS=0;
240    ALTER TABLE `dspam_preferences`
241      DROP FOREIGN KEY `dspam_preferences_ibfk_1`;
242    SET FOREIGN_KEY_CHECKS=1;
243
2446. REPAIRING
245
246If your database gets corrupt, you'll need to repair it. This could take a
247long time, and so it may make sense to keep a hot backup somewhere. You can
248run a command like this to repair the database:
249
250mysqlcheck --all-databases --fast --auto-repair
251
252ERRORS
253
254Any SQL errors will be reported to LOGDIR/sql.errors as well as the standard
255syslog facilities (although the query will be truncated).
256
257QUESTIONS
258
259Please contact the dspam-dev mailing list with any questions or constructive
260feedback.
261
262Initial storage driver written by Jonathan A. Zdziarski <jonathan@nuclearelephant.com>
263and later enhanced by Stevan Bajic <stevan@bajic.ch> for DSPAM 3.9.0.
Note: See TracBrowser for help on using the repository browser.