/[gentoo]/xml/htdocs/doc/en/virt-mail-howto.xml
Gentoo

Contents of /xml/htdocs/doc/en/virt-mail-howto.xml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.40 - (hide annotations) (download) (as text)
Wed Dec 22 21:33:10 2004 UTC (9 years, 4 months ago) by swift
Branch: MAIN
Changes since 1.39: +6 -5 lines
File MIME type: application/xml
#73609 - Update doc to webapp-config

1 vapier 1.32 <?xml version='1.0' encoding='UTF-8'?>
2 swift 1.40 <!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/virt-mail-howto.xml,v 1.39 2004/12/10 17:32:41 neysx Exp $ -->
3 swift 1.16 <!DOCTYPE guide SYSTEM "/dtd/guide.dtd">
4    
5 neysx 1.39 <guide link="/doc/en/virt-mail-howto.xml">
6 vapier 1.25 <title>Virtual Mailhosting System with Postfix Guide</title>
7 neysx 1.39
8     <author title="Author">
9     <mail link="antifa@gentoo.org">Ken Nowack</mail>
10 zhen 1.3 </author>
11 neysx 1.39 <author title="Author">
12     <mail link="ezra@revoltltd.org">Ezra Gorman</mail>
13 zhen 1.3 </author>
14 klasikahl 1.22 <author title="Editor">
15 neysx 1.39 <mail link="klasikahl@gentoo.org">Zack Gilburd</mail>
16 klasikahl 1.22 </author>
17 neysx 1.39
18     <abstract>
19     This document details how to create a virtual mailhosting system based upon
20     postfix, mysql, courier-imap, and cyrus-sasl.
21     </abstract>
22    
23 swift 1.40 <version>1.0.17</version>
24     <date>2004-12-22</date>
25 neysx 1.39
26 zhen 1.3 <!--
27     Contents
28    
29     I. Introduction
30     II. Postfix Basics
31     III. Courier-imap
32     IV. Cyrus-sasl
33     V. SSL Certificates for Postfix and Apache
34     VI. Adding SSL and SASL support to Postfix
35     VII. MySQL
36     VIII. Apache and phpMyAdmin
37     IX. The vmail user
38     X. Configuring MySQL Authentication and vhosts
39     XI. Squirrelmail
40     XII. Mailman
41     XIII. Content Filtering and Anti-Virus
42     XIV. Wrap Up
43     XV. Troubleshooting
44 neysx 1.39 -->
45 zhen 1.1
46 neysx 1.39 <chapter>
47 zhen 1.1 <title>Introduction</title>
48 swift 1.26 <section>
49 zhen 1.3 <body>
50 neysx 1.39
51     <p>
52     For most gentoo users, a simple mail client and fetchmail will do. However, if
53     you're hosting a domain with your system, you'll need a full blown MTA (Mail
54     Transfer Agent). And if you're hosting multiple domains, then you'll definitely
55     need something more robust to handle all of the email for your users. This
56     system was designed to be an elegant solution to that problem.
57     </p>
58    
59     <p>
60     A virtual mail system needs to be able to handle email for numerous domains
61     with multiple users over a variety of interfaces. This presents some issues
62     that must be dealt with. For instance, what if you have two users on different
63     domains that want the same user name? If you are providing imap access and
64     smtp-auth, how do combine the various authentication daemons into a single
65     system? How do you provide security for the numerous components that comprise
66     the system? How do you manage it all?
67     </p>
68    
69     <p>
70     This howto will show you how to set up with a mail system capable of handling
71     mail for as many domains as your hardware can handle, supports virtual mail
72     users that don't require shell accounts, has domain specific user names, can
73     authenticate web, imap, smtp, and pop3 clients against a single database,
74     utilizes ssl for transport layer security, has a web interface, can handle
75     mailing lists for any domain on the machine, and is controlled by a nice,
76     central and easy mysql database.
77     </p>
78    
79     <p>
80     There are quite a variety of ways to go about setting up a virtual mailhosting
81     system. With so may options, another may be the best choice for your specific
82     needs. Consider investigating <uri>http://www.qmail.org/</uri> and
83     <uri>http://www.exim.org/</uri> to explore your options.
84     </p>
85    
86     <p>
87     The following packages are used in this setup: apache, courier-imap, pam_mysql,
88     postfix, mod_php, phpmyadmin, squirrelmail, cyrus-sasl, mysql, php, and
89     mailman.
90     </p>
91    
92     <p>
93     Make sure to turn on the following USE variables in <path>/etc/make.conf</path>
94     before compiling the packages: <c>USE="mysql pam-mysql imap libwww maildir
95     sasl ssl"</c>. Otherwise you will most likely have to recompile things to
96     get the support you need for all the protocols. Further, it's a good idea to
97     turn off any other mail and network variables, like ipv6.
98     </p>
99    
100     <impo>
101     This howto was written for postfix-2.0.x. If you are using postfix &lt; 2 some
102     of the variables in this document will be different. It is recommended that you
103     upgrade. Some other packages included in this howto are version sensitive as
104     well. You are advised to read the documentation included with packages if you
105     run into issues with this.
106     </impo>
107    
108     <impo>
109     This document uses apache-1.3.x. Apache-2 has been marked stable in portage.
110     However there are still a number of issues with php integration. Until php
111     support in apache-2.0.x is marked stable, this guide will continue to use the
112     1.3.x version.
113     </impo>
114    
115     <impo>
116     You need a domain name to run a public mail server, or at least an MX record
117     for a domain. Ideally you would have control of at least two domains to take
118     advantage of your new virtual domain functionality.
119     </impo>
120    
121     <impo>
122     Make sure <path>/etc/hostname</path> is set to the right hostname for your mail
123     server. Verify your hostname is set correctly with <c>hostname</c>. Also
124     verify that there are no conflicting entries in <path>/etc/hosts</path>.
125     </impo>
126    
127     <note>
128     It is recommended that you read this entire document and familiarize yourself
129     with all the steps before attempting the install. If you run into problems with
130     any of the steps, check the troubleshooting guide at the end of this document.
131     Also, not all the referenced packages are necessary, this set up is very
132     flexible. For instance, if you do not desire a web interface, feel free to skip
133     the squirrelmail section.
134     </note>
135    
136 zhen 1.3 </body>
137 swift 1.26 </section>
138 zhen 1.1 </chapter>
139 swift 1.26
140 zhen 1.1 <chapter>
141     <title>Postfix Basics</title>
142 swift 1.26 <section>
143 zhen 1.3 <body>
144 neysx 1.39
145     <pre caption="Install postfix">
146     # <i>emerge postfix</i>
147 zhen 1.3 </pre>
148 neysx 1.39
149     <warn>
150     Verify that you have not installed any other MTA, such as ssmtp, exim, or
151     qmail, or you will surely have BIG problems.
152     </warn>
153    
154     <p>
155     After postfix is installed, it's time to configure it. Change the following
156     options in <path>/etc/postfix/main.cf</path>:
157     </p>
158    
159     <pre caption="/etc/postfix/main.cf">
160 rajiv 1.14 myhostname = $host.domain.name
161     mydomain = $domain.name
162     inet_interfaces = all
163     mydestination = $myhostname, localhost.$mydomain $mydomain
164     mynetworks = my.ip.net.work/24, 127.0.0.0/8
165     home_mailbox = .maildir/
166     local_destination_concurrency_limit = 2
167 neysx 1.39 default_destination_concurrency_limit = 10
168     </pre>
169    
170     <p>
171     Next change the following in <path>/etc/postfix/master.cf</path>. This will
172     turn on verbose output for debugging:
173     </p>
174    
175     <pre caption="/etc/postfix/master.cf">
176 rajiv 1.14 # service type private unpriv chroot wakeup maxproc command + args
177     # (yes) (yes) (yes) (never) (50)
178     #
179     ==========================================================================
180 neysx 1.39 <comment>(Just add the "-v" after the smtpd in the following line)</comment>
181 rajiv 1.14 smtp inet n - n - - smtpd -v
182 neysx 1.39 </pre>
183 rajiv 1.14
184 neysx 1.39 <p>
185     Next, edit <path>/etc/mail/aliases</path> to add your local aliases. There
186     should at least be an alias for root like: <c>root: your@email.address</c>.
187     </p>
188    
189     <pre caption="Starting postfix for the first time">
190 rajiv 1.14 # <i>/usr/bin/newaliases</i>
191 neysx 1.39 <comment>(This will install the new aliases. You only need to do this
192     when you update or install aliases.)</comment>
193 zhen 1.3
194 rajiv 1.14 # <i>/etc/init.d/postfix start</i>
195 zhen 1.3 </pre>
196 neysx 1.39
197     <p>
198     Now that postfix is running, fire up your favorite console mail client and send
199     yourself an email. I use <c>mutt</c> for all my console mail. Verify that
200     postfix is delivering mail to local users, once that's done, we're on to the
201     next step.
202     </p>
203    
204     <note>
205     I strongly recommend that you verify this basic postfix setup is functioning
206     before you progress to the next step of the howto.
207     </note>
208    
209 zhen 1.3 </body>
210 swift 1.26 </section>
211 zhen 1.1 </chapter>
212 neysx 1.39
213 zhen 1.1 <chapter>
214     <title>Courier-imap</title>
215 swift 1.26 <section>
216 zhen 1.3 <body>
217 neysx 1.39
218     <pre caption="Install courier-imap">
219     # <i>emerge courier-imap</i>
220 zhen 1.3 </pre>
221 neysx 1.39
222     <pre caption="Courier-imap configuration">
223 rajiv 1.14 # <i>cd /etc/courier-imap</i>
224 neysx 1.39 <comment>(If you want to use the ssl capabilities of courier-imap or pop3,
225     you'll need to create certs for this purpose.
226     This step is recommended. If you do not want to use ssl, skip this step.)</comment>
227 rajiv 1.14
228     # <i>nano -w pop3d.cnf</i>
229     # <i>nano -w imapd.cnf</i>
230 neysx 1.39 <comment>(Change the C, ST, L, CN, and email parameters to match your server.)</comment>
231 rajiv 1.14
232     # <i>mkpop3dcert</i>
233     # <i>mkimapdcert</i>
234 zhen 1.3 </pre>
235 neysx 1.39
236     <pre caption="Start the courier services you need.">
237 rajiv 1.14 # <i>/etc/init.d/courier-imapd start</i>
238     # <i>/etc/init.d/courier-imapd-ssl start</i>
239     # <i>/etc/init.d/courier-pop3d start</i>
240     # <i>/etc/init.d/courier-pop3d-ssl start</i>
241 zhen 1.3 </pre>
242 neysx 1.39
243     <p>
244     Start up your favorite mail client and verify that all connections you've
245     started work for receiving and sending mail. Now that the basics work, we're
246     going to do a whole bunch of stuff at once to get the rest of the system
247     running. Again, please verify that what we've installed already works before
248     progressing.
249     </p>
250    
251 zhen 1.3 </body>
252 swift 1.26 </section>
253 zhen 1.1 </chapter>
254 neysx 1.39
255 zhen 1.1 <chapter>
256     <title>Cyrus-sasl</title>
257 swift 1.26 <section>
258 zhen 1.3 <body>
259 neysx 1.39
260     <p>
261     Next we're going to install cyrus-sasl. Sasl is going to play the role of
262     actually passing your auth variables to pam, which will in turn pass that
263     information to mysql for authentication of smtp users. For this howto, we'll
264     not even try to verify that sasl is working until mysql is set up and contains
265     a test user. Which is fine since we'll be authenticating against mysql in the
266     end anyway.
267     </p>
268    
269     <note>
270     Now for some reason, sasl will not play nicely with pam against the shadow
271     file. I banged my head against this problem for, well, a long time. If anyone
272     knows why sasl will not auth against the shadow file in its current gentoo
273     incarnation, please <mail link="ken@kickasskungfu.com">email me</mail> as I'd
274     love to hear a solution to this.
275     </note>
276    
277     <pre caption="Configuring and installing the cyrus-sasl ebuild">
278 swift 1.36 <comment>(We don't have ldap and we're using sasl's mysql capabilities
279     so we need to set the appropriate USE flags, but only if your USE flags
280     doesn't already contain the mysql USE flag and not the ldap one)</comment>
281     # <i>mkdir /etc/portage</i>
282     # <i>echo "dev-libs/cyrus-sasl -ldap mysql" &gt;&gt; /etc/portage/package.use</i>
283     # <i>emerge cyrus-sasl</i>
284 zhen 1.3 </pre>
285 neysx 1.39
286     <p>
287     Next, edit <path>/etc/sasl2/smtpd.conf</path>.
288     </p>
289    
290     <pre caption="Starting sasl">
291 swift 1.27 # <i>nano -w /etc/sasl2/smtpd.conf</i>
292 swift 1.34 pwcheck_method: auxprop
293     auxprop_plugin: sql
294     sql_engine: mysql
295     sql_hostnames: localhost
296     sql_user: mailsql
297     sql_passwd: <comment>&lt;password&gt;</comment>
298     sql_database: mailsql
299     sql_select: select clear from users where email = '%u@%r'
300     mech_list: plain login
301 rajiv 1.14 pwcheck_method: saslauthd
302     mech_list: LOGIN PLAIN
303 neysx 1.39 <comment>(It's important to turn off auth methods we are not using.
304     They cause problems for some mail clients.)</comment>
305 rajiv 1.14 # <i>/etc/init.d/saslauthd start</i>
306 zhen 1.3 </pre>
307 neysx 1.39
308 zhen 1.3 </body>
309 swift 1.26 </section>
310 zhen 1.1 </chapter>
311 neysx 1.39
312 zhen 1.1 <chapter>
313     <title>SSL Certs for Postfix and Apache</title>
314 swift 1.26 <section>
315 zhen 1.3 <body>
316 neysx 1.39
317     <p>
318     Next we're going to make a set of ssl certificates for postfix and apache.
319     </p>
320    
321     <pre caption="Making ssl certicates">
322 rajiv 1.14 # <i>cd /etc/ssl/</i>
323     # <i>nano -w openssl.cnf</i>
324    
325 neysx 1.39 <comment>Change the following default values for your domain:</comment>
326 rajiv 1.14 countryName_default
327     stateOrProvinceName_default
328     localityName_default
329     0.organizationName_default
330     commonName_default
331     emailAddress_default.
332    
333 neysx 1.39 <comment>(If the variables are not already present, just add them in a sensible place.)</comment>
334 zhen 1.1
335 rajiv 1.14 # <i>cd misc</i>
336     # <i>nano -w CA.pl</i>
337 neysx 1.39 <comment>(We need to add -nodes to the # create a certificate and
338     #create a certificate request code in order to let our new ssl
339     certs be loaded without a password. Otherwise when you
340     reboot your ssl certs will not be available.)</comment>
341 rajiv 1.14
342     # create a certificate
343 neysx 1.39 system ("$REQ -new -nodes -x509 -keyout newreq.pem -out newreq.pem $DAYS");
344 rajiv 1.14
345     # create a certificate request
346 neysx 1.39 system ("$REQ -new -nodes -keyout newreq.pem -out newreq.pem $DAYS");
347 zhen 1.1
348 rajiv 1.14 # <i>./CA.pl -newca</i>
349     # <i>./CA.pl -newreq</i>
350     # <i>./CA.pl -sign</i>
351     # <i>cp newcert.pem /etc/postfix</i>
352     # <i>cp newreq.pem /etc/postfix</i>
353     # <i>cp demoCA/cacert.pem /etc/postfix</i>
354 neysx 1.39 <comment>(Now we do the same thing for apache.)</comment>
355 zhen 1.3
356 rajiv 1.14 # <i>openssl req -new > new.cert.csr</i>
357     # <i>openssl rsa -in privkey.pem -out new.cert.key</i>
358     # <i>openssl x509 -in new.cert.csr -out new.cert.cert -req -signkey new.cert.key -days 365</i>
359 neysx 1.39 <comment>(Just leave the resulting certificates here for now.
360     We'll install them after Apache is installed.)</comment>
361 zhen 1.3 </pre>
362 neysx 1.39
363 zhen 1.3 </body>
364 swift 1.26 </section>
365 neysx 1.39
366 zhen 1.1 </chapter>
367     <chapter>
368     <title>Adding SSL and SASL support to Postfix</title>
369 swift 1.26 <section>
370 zhen 1.3 <body>
371 neysx 1.39
372     <p>
373     Now edit the postfix config's to make it aware of your new sasl and ssl
374     capabilities. Add the following parameters to the end of the file where they
375     will be easy to find.
376     </p>
377    
378     <pre caption="/etc/postfix/main.cf">
379 rajiv 1.14 # <i>nano -w /etc/postfix/main.cf</i>
380    
381     smtpd_sasl_auth_enable = yes
382     smtpd_sasl2_auth_enable = yes
383     smtpd_sasl_security_options = noanonymous
384     broken_sasl_auth_clients = yes
385     smtpd_sasl_local_domain =
386    
387 neysx 1.39 <comment>(The broken_sasl_auth_clients option and the login auth method
388     are for outlook and outlook express only and are undocumented.
389     Isn't having to hack software for stupid, broken, M$ BS great?
390     smtpd_sasl_local_domain appends a domain name to clients using
391     smtp-auth. Make sure it's blank or your user names will get
392     mangled by postfix and be unable to auth.)</comment>
393 zhen 1.1
394 rajiv 1.14 smtpd_recipient_restrictions =
395     permit_sasl_authenticated,
396     permit_mynetworks,
397     reject_unauth_destination
398    
399    
400     smtpd_use_tls = yes
401     #smtpd_tls_auth_only = yes
402     smtpd_tls_key_file = /etc/postfix/newreq.pem
403     smtpd_tls_cert_file = /etc/postfix/newcert.pem
404     smtpd_tls_CAfile = /etc/postfix/cacert.pem
405     smtpd_tls_loglevel = 3
406     smtpd_tls_received_header = yes
407     smtpd_tls_session_cache_timeout = 3600s
408     tls_random_source = dev:/dev/urandom
409    
410 neysx 1.39 <comment>(smtpd_tls_auth_only is commented out to ease testing the system.
411     You can turn this on later if you desire.)</comment>
412 rajiv 1.14
413     # <i>postfix reload</i>
414 zhen 1.3 </pre>
415 neysx 1.39
416     <p>
417     Now we're going to verify that the config's we added were picked up by postfix.
418     </p>
419    
420     <pre caption="Verifying sasl and tls support">
421 rajiv 1.14 # <i>telnet localhost 25</i>
422 zhen 1.1
423 rajiv 1.14 Trying 127.0.0.1...
424     Connected to localhost.
425     Escape character is '^]'.
426     220 mail.domain.com ESMTP Postfix
427     <i>EHLO domain.com</i>
428     250-mail.domain.com
429     250-PIPELINING
430     250-SIZE 10240000
431     250-VRFY
432     250-ETRN
433     250-STARTTLS
434     250-AUTH LOGIN PLAIN
435     250-AUTH=LOGIN PLAIN
436     250-XVERP
437     250 8BITMIME
438     <i>^]</i>
439     telnet> <i>quit</i>
440 zhen 1.3 </pre>
441 neysx 1.39
442     <p>
443     Verify that the above AUTH and STARTTLS lines now appear in your postfix
444     install. As I said before, as it stands now AUTH will not work. that's because
445     sasl will try to auth against it's sasldb, instead of the shadow file for some
446     unknown reason, which we have not set up. So we're going to just plow through
447     and set up mysql to hold all of our auth and virtual domain information.
448     </p>
449    
450 zhen 1.3 </body>
451 swift 1.26 </section>
452 zhen 1.1 </chapter>
453 neysx 1.39
454 zhen 1.1 <chapter>
455     <title>MySQL</title>
456 swift 1.26 <section>
457 zhen 1.3 <body>
458 neysx 1.39
459     <p>
460     Next we're going to install and configure MySQL. You'll need the <uri
461     link="http://www.gentoo.org/doc/en/files/genericmailsql.sql">genericmailsql.sql</uri>
462     dumpfile for this step.
463     </p>
464    
465     <pre caption="Installing and configuring MySQL">
466 rajiv 1.14 # <i>emerge mysql</i>
467 zhen 1.3
468 rajiv 1.14 # <i>/usr/bin/mysql_install_db</i>
469 neysx 1.39 <comment>(After this command runs follow the onscreen directions
470     for adding a root password with mysql,
471     not mysqladmin, otherwise your db will be wide open.)</comment>
472 zhen 1.1
473 rajiv 1.14 # <i>/etc/init.d/mysql start</i>
474     # <i>mysqladmin -u root -p create mailsql</i>
475     # <i>mysql -u root -p mailsql &lt; genericmailsql.sql</i>
476    
477     # <i>mysql -u root -p mysql</i>
478     mysql> <i>GRANT SELECT,INSERT,UPDATE,DELETE</i>
479     -> <i>ON mailsql.*</i>
480     -> <i>TO mailsql@localhost</i>
481     -> <i>IDENTIFIED BY '$password';</i>
482    
483     -> <i>quit</i>
484 neysx 1.39 <comment>(Verify that the new mailsql user can connect to the mysql server.)</comment>
485 rajiv 1.14
486     # <i>mysql -u mailsql -p mailsql</i>
487 zhen 1.3 </pre>
488 cam 1.30
489     <p>
490 neysx 1.39 Your new database has default values and tables set up for two domains. The
491     following tables are included:
492 cam 1.30 </p>
493    
494     <ul>
495 neysx 1.39 <li>alias - local email alias and mailman alias information.</li>
496     <li>relocated - relocated user email address maps</li>
497     <li>
498     transport - default mail transport information for all domains you are
499     hosting
500     </li>
501     <li>users - all user account information</li>
502     <li>virtual - virtual domain email alias maps</li>
503 zhen 1.3 </ul>
504 cam 1.30
505 neysx 1.39 <pre caption="alias table sample">
506 rajiv 1.15 id alias destination
507     1 root foo@bar.com
508     2 postmaster foo@bar.com
509 rajiv 1.14 </pre>
510 neysx 1.39
511     <pre caption="user table sample">
512     <comment>(Line wrapped for clarity.)</comment>
513 rajiv 1.15 id email clear name uid gid homedir \
514     maildir quota postfix
515     10 foo@virt-bar.org $password realname virtid virtid /home/vmail \
516     /home/vmail/virt-bar.org/foo/.maildir/ y
517     13 foo@bar.com $password realname localid localid /home/foo \
518     /home/foo/.maildir/ y
519 rajiv 1.14 </pre>
520 swift 1.37
521     <p>
522     The values of the <c>virtid</c> uid and gid should be those of the <c>vmail</c>
523     user and group.
524     </p>
525    
526 neysx 1.39 <pre caption="transport table sample">
527 rajiv 1.15 id domain destination
528     1 bar.com local:
529     2 virt-bar.org virtual:
530 rajiv 1.14 </pre>
531 neysx 1.39
532     <pre caption="virtual table sample">
533 rajiv 1.15 id email destination
534     3 root@virt-bar.org other@email.address
535 rajiv 1.14 </pre>
536 neysx 1.39
537 zhen 1.3 </body>
538 swift 1.26 </section>
539 zhen 1.1 </chapter>
540 neysx 1.39
541 zhen 1.1 <chapter>
542     <title>Apache and phpMyAdmin</title>
543 swift 1.26 <section>
544 zhen 1.3 <body>
545 neysx 1.39
546     <p>
547     Next we'll set up apache and add an interface to interact with the database
548     more easily.
549     </p>
550    
551     <pre caption="Setting up apache and phpmyadmin">
552 swift 1.17 # <i>emerge apache mod_php phpmyadmin</i>
553 zhen 1.3 </pre>
554 cam 1.30
555     <p>
556 neysx 1.39 There are plenty of guides out there about how to set up apache with php. Like
557     this one: <uri>http://www.linuxguruz.org/z.php?id=31</uri>. There are also
558     numerous posts on <uri>http://forums.gentoo.org</uri> detailing how to solve
559     problems with the installation (search for 'apache php'). So, that said, I'm
560     not going to cover it here. Set up the apache and php installs, then continue
561     with this howto. Now, a word for the wise: .htaccess the directory that you put
562     phpmyadmin in. If you do not do this, search engine spiders will come along and
563     index the page which in turn will mean that anyone will be able to find your
564     phpmyadmin page via google and in turn be able to come change your database
565     however they want which is <e>BAD!</e> There are many howtos on this
566     including: <uri>http://www.csoft.net/docs/micro/htaccess.html.en</uri>.
567     </p>
568    
569     <p>
570     Now we're going to install the Apache certificates we made previously. The
571     Apache-SSL directives that you need to use the resulting cert are:
572 cam 1.30 </p>
573    
574     <ul>
575 neysx 1.39 <li>SSLCertificateFile /path/to/certs/new.cert.cert</li>
576     <li>SSLCertificateKeyFile /path/to/certs/new.cert.key</li>
577 zhen 1.3 </ul>
578 cam 1.30
579 neysx 1.39 <pre caption="Install Apache SSL certificates">
580 rajiv 1.14 # <i>cp /etc/ssl/misc/new.cert.cert /etc/apache/conf/ssl/</i>
581     # <i>cp /etc/ssl/misc/new.cert.key /etc/apache/conf/ssl/</i>
582     # <i>nano -w /etc/apache/conf/vhosts/ssl.default-vhost.conf</i>
583 neysx 1.39
584     <comment>(Change the following parameters)</comment>
585 rajiv 1.14
586     ServerName host.domain.name
587     ServerAdmin your@email.address
588     SSLCertificateFile /etc/apache/conf/ssl/new.cert.cert
589     SSLCertificateKeyFile /etc/apache/conf/ssl/new.cert.key
590    
591     # <i>/etc/init.d/apache restart</i>
592 zhen 1.3 </pre>
593 neysx 1.39
594     <note>
595     If you have an existing apache install, you'll likely have to perform a full
596     server reboot to install your new certificates. Check your logs to verify
597     apache restarted successfully.
598     </note>
599    
600     <p>
601     Next, configure phpMyAdmin.
602     </p>
603    
604     <pre caption="Configuring phpMyAdmin">
605 pylon 1.21 # <i>nano -w /var/www/localhost/htdocs/phpmyadmin/config.inc.php</i>
606 neysx 1.39 <comment>(Change the following parameters.)</comment>
607 rajiv 1.14
608 rajiv 1.15 $cfg['Servers'][$i]['host'] = 'localhost'; // MySQL hostname
609     $cfg['Servers'][$i]['controluser'] = 'mailsql'; // MySQL control user settings
610     // (this user must have read-only
611 neysx 1.39 $cfg['Servers'][$i]['controlpass'] = '$password'; // access to the "mysql/user"
612     // and "mysql/db" tables)
613 rajiv 1.15 $cfg['Servers'][$i]['user'] = 'mailsql'; // MySQL user
614     $cfg['Servers'][$i]['password'] = '$password'; // MySQL password
615 rajiv 1.14 </pre>
616 neysx 1.39
617     <p>
618     Now enter the phpmyadmin page and browse the tables. You'll want to add in your
619     local aliases, edit your user table to add a test user, and change your
620     transport table to add information about your domains. The default values
621     supplied with the dumpfile should be a sufficient guide to what values need to
622     go where. Make sure that if you put information in the database that it is
623     accurate. For instance, make sure the local users home dir exists and that the
624     correct uid/gid values are in place. The maildirs should be created
625     automatically by postfix when the user receives their first email. So, in
626     general, it's a good idea to send a "Welcome" mail to a new user
627     after you setup their account to make sure the .maildir gets created.
628     </p>
629    
630 zhen 1.3 </body>
631 swift 1.26 </section>
632 zhen 1.1 </chapter>
633 neysx 1.39
634 zhen 1.1 <chapter>
635     <title>The vmail user</title>
636 swift 1.26 <section>
637 zhen 1.3 <body>
638 neysx 1.39
639     <p>
640     At this point you may be wondering what user and directory to use for virtual
641     mail users, and rightly so. Let's set that up.
642     </p>
643    
644     <pre caption="Adding the vmail user">
645 rajiv 1.14 # <i>adduser -d /home/vmail -s /bin/false vmail</i>
646     # <i>uid=`cat /etc/passwd | grep vmail | cut -f 3 -d :`</i>
647     # <i>groupadd -g $uid vmail</i>
648     # <i>mkdir /home/vmail</i>
649 cam 1.29 # <i>chown vmail: /home/vmail</i>
650 zhen 1.3 </pre>
651 neysx 1.39
652     <p>
653     So now when you're setting up vmail accounts, use the vmail uid, gid, and
654     homedir. When you're setting up local accounts, use that users uid, gid, and
655     homedir. We've been meaning to create a php admin page for this setup but
656     haven't gotten around to it yet, as phpmyadmin generally works fine for us.
657     </p>
658    
659 zhen 1.3 </body>
660 swift 1.26 </section>
661 zhen 1.1 </chapter>
662 neysx 1.39
663 zhen 1.1 <chapter>
664     <title>Configuring MySQL Authentication and vhosts</title>
665 swift 1.26 <section>
666 zhen 1.3 <body>
667 neysx 1.39
668     <p>
669     Next we'll reconfigure our authentication to use the mailsql database in
670     courier-imap and postfix. In all of the following examples, replace
671     <c>$password</c> with the password you set for the mailsql mysql user.
672     </p>
673    
674     <pre caption="Configuring authentication">
675 swift 1.20 # <i>emerge pam_mysql</i>
676 rajiv 1.14 # <i>nano -w /etc/pam.d/imap</i>
677 neysx 1.39 <comment>(Comment out the existing auth lines and add the following as shown.)</comment>
678 zhen 1.1
679 rajiv 1.14 #auth required pam_nologin.so
680     #auth required pam_stack.so service=system-auth
681     #account required pam_stack.so service=system-auth
682     #session required pam_stack.so service=system-auth
683    
684 swift 1.18 auth optional pam_mysql.so host=localhost db=mailsql user=mailsql \
685 rajiv 1.14 passwd=$password table=users usercolumn=email passwdcolumn=clear crypt=0
686 swift 1.18 account required pam_mysql.so host=localhost db=mailsql user=mailsql \
687 rajiv 1.14 passwd=$password table=users usercolumn=email passwdcolumn=clear crypt=0
688 zhen 1.1
689 rajiv 1.14 # <i>nano -w /etc/pam.d/pop3</i>
690     # <i>nano -w /etc/pam.d/smtp</i>
691 neysx 1.39 <comment>(Make the same changes to the pop3 and smtp files.)</comment>
692 zhen 1.3 </pre>
693 neysx 1.39
694     <p>
695     Next, we need to edit courier's authentication config's.
696     </p>
697    
698     <pre caption="Configuring authentication">
699 rajiv 1.14 # <i>nano -w /etc/courier-imap/authdaemonrc</i>
700 neysx 1.39 authmodulelist="authmysql authpam"
701 zhen 1.1
702 rajiv 1.14 # <i>nano -w /etc/courier-imap/authdaemond.conf</i>
703 neysx 1.39 AUTHDAEMOND="authdaemond.mysql"
704 zhen 1.1
705 rajiv 1.14 # <i>nano -w /etc/courier-imap/authmysqlrc</i>
706     MYSQL_SERVER localhost
707     MYSQL_USERNAME mailsql
708     MYSQL_PASSWORD $password
709     MYSQL_DATABASE mailsql
710     MYSQL_USER_TABLE users
711 neysx 1.39 <comment>(Make sure the following line is commented out since we're storing plaintext.)</comment>
712     #MYSQL_CRYPT_PWFIELD crypt
713 rajiv 1.14 MYSQL_CLEAR_PWFIELD clear
714     MYSQL_UID_FIELD uid
715     MYSQL_GID_FIELD gid
716     MYSQL_LOGIN_FIELD email
717     MYSQL_HOME_FIELD homedir
718     MYSQL_NAME_FIELD name
719     MYSQL_MAILDIR_FIELD maildir
720 zhen 1.1
721 rajiv 1.14 # <i>/etc/init.d/authdaemond restart</i>
722     # <i>/etc/init.d/saslauthd restart</i>
723 zhen 1.3 </pre>
724 neysx 1.39
725     <p>
726     We're almost there I promise! Next, set up the rest of the necessary config's
727     for postfix to interract with the database for all it's other transport needs.
728     </p>
729    
730     <pre caption="/etc/postfix/mysql-aliases.cf">
731 rajiv 1.14 # <i>nano -w /etc/postfix/mysql-aliases.cf</i>
732     # mysql-aliases.cf
733 zhen 1.1
734 rajiv 1.14 user = mailsql
735     password = $password
736     dbname = mailsql
737     table = alias
738     select_field = destination
739     where_field = alias
740     hosts = unix:/var/run/mysqld/mysqld.sock
741     </pre>
742 neysx 1.39
743     <pre caption="/etc/postfix/mysql-relocated.cf">
744 rajiv 1.14 # <i>nano -w /etc/postfix/mysql-relocated.cf</i>
745     # mysql-relocated.cf
746 zhen 1.1
747 rajiv 1.14 user = mailsql
748     password = $password
749     dbname = mailsql
750     table = relocated
751     select_field = destination
752     where_field = email
753     hosts = unix:/var/run/mysqld/mysqld.sock
754     </pre>
755 neysx 1.39
756     <pre caption="/etc/postfix/mysql-transport.cf (optional)">
757 rajiv 1.14 # <i>nano -w /etc/postfix/mysql-transport.cf</i>
758     # mysql-transport.cf
759 zhen 1.1
760 rajiv 1.14 user = mailsql
761     password = $password
762     dbname = mailsql
763     table = transport
764     select_field = destination
765     where_field = domain
766     hosts = unix:/var/run/mysqld/mysqld.sock
767     </pre>
768 neysx 1.39
769     <pre caption="/etc/postfix/mysql-virtual-gid.cf (optional)">
770 rajiv 1.14 # <i>nano -w /etc/postfix/mysql-virtual-gid.cf</i>
771     #myql-virtual-gid.cf
772 zhen 1.1
773 rajiv 1.14 user = mailsql
774     password = $password
775     dbname = mailsql
776     table = users
777     select_field = gid
778     where_field = email
779     additional_conditions = and postfix = 'y'
780     hosts = unix:/var/run/mysqld/mysqld.sock
781     </pre>
782 neysx 1.39
783     <pre caption="/etc/postfix/mysql-virtual-maps.cf">
784 rajiv 1.14 # <i>nano -w /etc/postfix/mysql-virtual-maps.cf</i>
785     #myql-virtual-maps.cf
786 zhen 1.1
787 rajiv 1.14 user = mailsql
788     password = $password
789     dbname = mailsql
790     table = users
791     select_field = maildir
792     where_field = email
793     additional_conditions = and postfix = 'y'
794     hosts = unix:/var/run/mysqld/mysqld.sock
795     </pre>
796 neysx 1.39
797     <pre caption="/etc/postfix/mysql-virtual-uid.cf (optional)">
798 rajiv 1.14 # <i>nano -w /etc/postfix/mysql-virtual-uid.cf</i>
799     # mysql-virtual-uid.cf
800 zhen 1.1
801 rajiv 1.14 user = mailsql
802     password = $password
803     dbname = mailsql
804     table = users
805     select_field = uid
806     where_field = email
807     additional_conditions = and postfix = 'y'
808     hosts = unix:/var/run/mysqld/mysqld.sock
809     </pre>
810 neysx 1.39
811     <pre caption="/etc/postfix/mysql-virtual.cf">
812 rajiv 1.14 # <i>nano -w /etc/postfix/mysql-virtual.cf</i>
813     # mysql-virtual.cf
814 zhen 1.1
815 rajiv 1.14 user = mailsql
816     password = $password
817     dbname = mailsql
818     table = virtual
819     select_field = destination
820     where_field = email
821     hosts = unix:/var/run/mysqld/mysqld.sock
822     </pre>
823 neysx 1.39
824     <p>
825     Lastly, edit <path>/etc/postfix/main.cf</path> one more time.
826     </p>
827    
828     <pre caption="/etc/postfix/main.cf">
829 rajiv 1.14 # <i>nano -w /etc/postfix/main.cf</i>
830     alias_maps = mysql:/etc/postfix/mysql-aliases.cf
831     relocated_maps = mysql:/etc/postfix/mysql-relocated.cf
832    
833     local_transport = local
834     local_recipient_maps = $alias_maps $virtual_mailbox_maps unix:passwd.byname
835    
836     virtual_transport = virtual
837     virtual_mailbox_domains =
838     virt-bar.com,
839     $other-virtual-domain.com
840    
841     virtual_minimum_uid = 1000
842     virtual_gid_maps = static:$vmail-gid
843     virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-maps.cf
844     virtual_alias_maps = mysql:/etc/postfix/mysql-virtual.cf
845     virtual_uid_maps = static:$vmail-uid
846     virtual_mailbox_base = /
847     #virtual_mailbox_limit =
848     </pre>
849 swift 1.24
850     <p>
851     For security reasons you should change the permissions of the various
852     <path>/etc/mail/mysql-*.cf</path>:
853     </p>
854    
855     <pre caption="Changing file permission">
856     # <i>chmod 640 /etc/postfix/mysql-*.cf</i>
857     # <i>chgrp postfix /etc/postfix/mysql-*.cf</i>
858     </pre>
859    
860 neysx 1.39 <p>
861     As of Postfix 2.0.x, there were a number of significant changes over the 1.1.x
862     release. Notably the transport, virtual-gid, and virtual-uid tables are no
863     longer necessary. The tables are still included if you wish to use them.
864     </p>
865    
866     <note>
867     It is recommended that you read VIRTUAL_README included with the postfix docs
868     for more information.
869     </note>
870    
871     <pre caption="Make postfix reload its tables">
872     # <i>postfix reload</i>
873 zhen 1.3 </pre>
874 neysx 1.39
875     <p>
876     Now, if all went well, you should have a functioning mailhost. Users should be
877     able to authenticate against the sql database, using their full email address,
878     for pop3, imap, and smtp. I would highly suggest that you verify that
879     everything is working at this point. If you run into problems (with as many
880     things as this setup has going on, it's likely that you will) check the
881     troubleshooting section of this howto.
882     </p>
883    
884 zhen 1.3 </body>
885 swift 1.26 </section>
886 zhen 1.1 </chapter>
887 neysx 1.39
888 zhen 1.1 <chapter>
889     <title>Squirrelmail</title>
890 swift 1.26 <section>
891 zhen 1.3 <body>
892 neysx 1.39
893     <pre caption="Install squirrelmail">
894 rajiv 1.14 # <i>emerge squirrelmail</i>
895 swift 1.40 <comment>(Install squirrelmail to localhost so that it's accessed by http://localhost/mail)
896     (Substitute 1.4.3a-r2 with the version you use)</comment>
897 zhen 1.3
898 swift 1.40 # <i>webapp-config -I -h localhost -d /mail squirrelmail 1.4.3a-r2</i>
899 swift 1.31 # <i>cd /var/www/localhost/htdocs/mail/config</i>
900     # <i>perl ./conf.pl</i>
901 neysx 1.39 <comment>(Change your Organization, Server, and Folder settings for squirrelmail.
902     Now you should be able to login to squirrelmail, again - with your full email address,
903     and use your new webmail setup.)</comment>
904 zhen 1.3 </pre>
905 neysx 1.39
906 zhen 1.3 </body>
907 swift 1.26 </section>
908 zhen 1.1 </chapter>
909 neysx 1.39
910 zhen 1.1 <chapter>
911     <title>Mailman</title>
912 swift 1.26 <section>
913 zhen 1.3 <body>
914 neysx 1.39
915     <p>
916     Last step: mailman. The new version of mailman has very nice virtual domain
917     support, which is why I use it, not to mention it's really a great package. To
918     get this package installed and working correctly for virtual domains is going
919     to require a bit of hacking. I really recommend reading all of the mailman
920     documentation, including README.POSTFIX.gz, to understand what's being done
921     here.
922     </p>
923    
924     <p>
925     One further note, current versions of mailman install to /usr/local/mailman. If
926     you're like me and wish to change the default install location, it can be
927     overridden in the ebuild filoe by changing the INSTALLDIR variable.
928     </p>
929    
930 zhen 1.3 <pre caption="/usr/portage/net-mail/mailman/mailman-$ver.ebuild">
931 rajiv 1.14 # <i>nano -w /usr/portage/net-mail/mailman/mailman-$ver.ebuild</i>
932     MAILGID="280"
933 neysx 1.39 <comment>(Set MAILGID to the mailman group instead of nobody
934     This is needed for postfix integration.)</comment>
935 zhen 1.3 </pre>
936 neysx 1.39
937     <pre caption="Install mailman">
938 rajiv 1.14 # <i>emerge mailman</i>
939 neysx 1.39 <comment>(This package is currently masked as well, so you'll need to unmask it or give
940     emerge an explicit path to the ebuild. Once it's installed, follow the directions
941     in the README.gentoo.gz *except* do not add your aliases to /etc/mail/aliases.
942     We will instead be linking the entire alias db into postfix.)</comment>
943 zhen 1.3
944 rajiv 1.14 # <i>zless /usr/share/doc/mailman-$ver/README.gentoo.gz</i>
945 zhen 1.3 </pre>
946 neysx 1.39
947 antifa 1.12 <pre caption="Setting defaults: Mailman/Defaults.py">
948 rajiv 1.14 # <i> nano -w /var/mailman/Mailman/Defaults.py</i>
949 neysx 1.39 <comment>(Change the values below to reflect your primary domain, virtuals will be set next.)</comment>
950 rajiv 1.14 DEFAULT_EMAIL_HOST = 'domain.com'
951     DEFAULT_URL_HOST = 'www.domain.com'
952 antifa 1.12 </pre>
953 neysx 1.39
954 zhen 1.3 <pre caption="mailman config: mm_cfg.py">
955 rajiv 1.14 # <i>nano -w /var/mailman/Mailman/mm_cfg.py</i>
956     MTA = "Postfix"
957     POSTFIX_STYLE_VIRTUAL_DOMAINS = ['virt-domain.com', 'virt.domain2.com']
958     add_virtualhost('www.virt.domain.com', 'virt.domain.com')
959     add_virtualhost('www.virt.domain2.com', 'virt.domain2.com')
960 neysx 1.39 <comment>(This is required for your virtual domains for mailman to function.)</comment>
961 zhen 1.3 </pre>
962 neysx 1.39
963     <pre caption="And last but not least">
964     <comment>(Once that's finished, add your first list.)</comment>
965 zhen 1.3
966 rajiv 1.14 # <i>su mailman</i>
967     # <i>cd ~</i>
968     # <i>bin/newlist test</i>
969 neysx 1.39 Enter the email of the person running the list: <i>your@email.address</i>
970 rajiv 1.14 Initial test password:
971     Hit enter to continue with test owner notification...
972 neysx 1.39 <comment>(Virtual domain lists may be specified with
973     list@domain.com style list names.)</comment>
974 rajiv 1.14 # <i>bin/genaliases</i>
975 neysx 1.39 <comment>(Now that your aliases have been generated,
976     verify that they were added successfully.)</comment>
977 rajiv 1.14
978     # <i>nano -w data/aliases</i>
979     # STANZA START: test
980     # CREATED:
981     test: "|/var/mailman/mail/mailman post test"
982     test-admin: "|/var/mailman/mail/mailman admin test"
983     test-bounces: "|/var/mailman/mail/mailman bounces test"
984     test-confirm: "|/var/mailman/mail/mailman confirm test"
985     test-join: "|/var/mailman/mail/mailman join test"
986     test-leave: "|/var/mailman/mail/mailman leave test"
987     test-owner: "|/var/mailman/mail/mailman owner test"
988     test-request: "|/var/mailman/mail/mailman request test"
989     test-subscribe: "|/var/mailman/mail/mailman subscribe test"
990     test-unsubscribe: "|/var/mailman/mail/mailman unsubscribe test"
991     # STANZA END: test
992    
993     # <i>/etc/init.d/mailman start</i>
994     # <i>rc-update add mailman default</i>
995 neysx 1.39 <comment>(To start mailman at once and on every reboot.)</comment>
996 zhen 1.3 </pre>
997    
998     <pre caption="Adding mailman alias support to postfix">
999 rajiv 1.14 # <i>nano -w /etc/postfix/main.cf</i>
1000     owner_request_special = no
1001     recipient_delimiter = +
1002 neysx 1.39 <comment>(Read README.POSTFIX.gz for details on this.)</comment>
1003 rajiv 1.14
1004     alias_maps =
1005     hash:/var/mailman/data/aliases,
1006     mysql:/etc/postfix/mysql-aliases.cf
1007    
1008     virtual_alias_maps =
1009     hash:/var/mailman/data/virtual-mailman,
1010     mysql:/etc/postfix/mysql-virtual.cf
1011 neysx 1.39 <comment>(This adds mailman alias file support to postfix
1012     You may of course use the mysql tables for this,
1013     but I hate doing that by hand. Also, if you are not
1014     using virtual domains, adding the virtual alias maps
1015     to postfix may cause problems, be warned.)</comment>
1016 zhen 1.3 </pre>
1017 neysx 1.39
1018     <p>
1019     You should now be able to setup mailing lists for any domain on your box. Last
1020     note on this, make sure you run all mailman commands as the user mailman (<c>su
1021     mailman</c>) or else the permissions will be wrong and you'll have to fix them.
1022     Read the mailman doc's for more information on setting up and managing mailman
1023     lists.
1024     </p>
1025    
1026 zhen 1.3 </body>
1027 swift 1.26 </section>
1028 zhen 1.3 </chapter>
1029 neysx 1.39
1030 zhen 1.3 <chapter>
1031     <title>Content Filtering and Anti-Virus</title>
1032 swift 1.26 <section>
1033 neysx 1.39 <body>
1034    
1035     <p>
1036     Coming soon...it would be done already but I need some perl help and testing to
1037     make it so. If you'd like to volunteer for that, please email me.
1038     </p>
1039    
1040     </body>
1041 swift 1.26 </section>
1042 zhen 1.1 </chapter>
1043 neysx 1.39
1044 zhen 1.1 <chapter>
1045     <title>Wrap Up</title>
1046 swift 1.26 <section>
1047 zhen 1.3 <body>
1048 neysx 1.39
1049     <p>
1050     Ok, you're all set, edit <path>/etc/postfix/master.cf</path> and turn off
1051     verbose mode for production use. You'll probably also want to add the services
1052     to your startup routine to make sure everything comes back up on a reboot. Make
1053     sure to add all the services you're using - apache, mysql, saslauthd, postfix,
1054     courier-imapd, courier-imapd-ssl, courier-pop3d, and courier-pop3d-ssl are all
1055     up to your decision on what access you want to provide. I generally have all
1056     the services enabled.
1057     </p>
1058    
1059     <pre caption="Wrap up">
1060 rajiv 1.14 # <i>postfix reload</i>
1061     # <i>rc-update add $service default</i>
1062 zhen 1.3 </pre>
1063 neysx 1.39
1064 zhen 1.3 <p>
1065     <e>Have fun!</e>
1066     </p>
1067 neysx 1.39
1068 zhen 1.3 </body>
1069 swift 1.26 </section>
1070 zhen 1.1 </chapter>
1071 neysx 1.39
1072 zhen 1.1 <chapter>
1073     <title>Troubleshooting</title>
1074     <section>
1075 zhen 1.3 <title>Introduction</title>
1076     <body>
1077 neysx 1.39
1078     <p>
1079     Troubleshooting: This is a short troubleshooting guide for the set up we've
1080     detailed how to install here. It is not exhaustive, but meant as a place to get
1081     you started in figuring out problems. With a complicated setup such as this,
1082     it's imperative that you narrow down the problem to the particular component
1083     that is malfunctioning. In general I do that by following a few steps. Start
1084     from the base of the system and work your way up, ruling out components that
1085     work along the way until you discover which component is having the problem.
1086     </p>
1087    
1088 zhen 1.3 </body>
1089 zhen 1.1 </section>
1090     <section>
1091 neysx 1.39 <title>Step 1: Check your config files</title>
1092 zhen 1.3 <body>
1093 neysx 1.39
1094     <p>
1095     Typos are killers, especially when dealing with authentication systems. Scan
1096     your config's and mailsql database for typo's. You can debug all you want, but
1097     if you're not passing the right information back and forth to your mail system,
1098     it's not going to work. If you make a change to a config file for a service,
1099     make sure you restart that service so that the config change gets picked up.
1100     </p>
1101    
1102     <pre caption="How to restart a service">
1103 rajiv 1.14 # <i>/etc/init.d/service restart</i>
1104 zhen 1.3 </pre>
1105 neysx 1.39
1106 zhen 1.3 </body>
1107 zhen 1.1 </section>
1108     <section>
1109 zhen 1.3 <title>Step 2: Are all the necessary services actually running?</title>
1110     <body>
1111 neysx 1.39
1112     <p>
1113     If it's not running, start it up. It's awful hard to debug a service that isn't
1114     running. Sometimes a service will act like it's started but still not function.
1115     Sometimes, when a bad config is used, or a bad transmission comes into a mail
1116     component, the service will hang and keep the port from being used by another
1117     process. Sometimes you can detect this with netstat. Or, if you've been at it
1118     awhile, just take a break and reboot your box in the meantime. That will clear
1119     out any hung services. Then you can come back fresh and try it again.
1120     </p>
1121    
1122     <pre caption="Checking the status of a service">
1123 rajiv 1.14 # <i>/etc/init.d/$service status</i>
1124     # <i>netstat -a | grep $service (or $port)</i>
1125 zhen 1.3 </pre>
1126 neysx 1.39
1127 zhen 1.3 </body>
1128 zhen 1.1 </section>
1129     <section>
1130 zhen 1.3 <title>Step 3: Are all the service using the current config's?</title>
1131     <body>
1132 neysx 1.39
1133     <p>
1134     If you've recently made a change to a config file, restart that service to make
1135     sure it's using the current version. Some of the components will dump their
1136     current config's to you, like postfix.
1137     </p>
1138    
1139     <pre caption="Some services can dump their current config">
1140 rajiv 1.14 # <i>apachectl fullstatus</i> (needs lynx installed)
1141     # <i>apachectl configtest</i> (checks config sanity)
1142     # <i>postconf -n</i> (will tell you exactly what param's postfix is using)
1143     # <i>/etc/init.d/$service restart</i>
1144 zhen 1.3 </pre>
1145 neysx 1.39
1146 zhen 1.3 </body>
1147 zhen 1.1 </section>
1148     <section>
1149 neysx 1.39 <title>Step 4: Check the logs</title>
1150 zhen 1.3 <body>
1151 neysx 1.39
1152     <p>
1153     Repeat after me, logs are my friend. My next troubleshooting stop is always the
1154     logs. Sometimes it's helpful to try a failed operation again then check the
1155     logs so that the error message is right at the bottom (or top depending on your
1156     logger) instead of buried in there somewhere. See if there is any information
1157     in your log that can help you diagnose the problem, or at the very least,
1158     figure out which component is having the problem.
1159     </p>
1160    
1161     <pre caption="Checking the logs">
1162 rajiv 1.14 # <i>kill -USR1 `ps -C metalog -o pid=`</i>(to turn off metalog buffering)
1163     # <i>nano -w /var/log/mail/current</i>
1164     # <i>cat /var/log/mysql/mysql.log</i>
1165     # <i>tail /var/log/apache/error_log</i>
1166 zhen 1.3 </pre>
1167 neysx 1.39
1168     <p>
1169     You may also find the debug_peer parameters in main.cf helpful. Setting these
1170     will increase log output over just verbose mode.
1171     </p>
1172    
1173 zhen 1.3 <pre caption="adding debug_peer support">
1174 rajiv 1.14 # <i>nano -w /etc/postfix/main.cf</i>
1175     debug_peer_level = 5
1176     debug_peer_list = $host.domain.name
1177 neysx 1.39 <comment>(Uncomment one of the suggested debugger
1178     commands as well.)</comment>
1179 zhen 1.3 </pre>
1180 neysx 1.39
1181 zhen 1.3 </body>
1182 zhen 1.1 </section>
1183     <section>
1184 neysx 1.39 <title>Step 5: Talk to the service itself</title>
1185 zhen 1.3 <body>
1186 neysx 1.39
1187     <p>
1188     SMTP, IMAP, and POP3 all respond to telnet sessions. As we've seen earlier when
1189     we verified postfix's config. Sometimes it's helpful to open a telnet session
1190     to the service itself and see what's happening.
1191     </p>
1192    
1193     <pre caption="Connect to a service with telnet">
1194 rajiv 1.14 # <i>telnet localhost $port</i>
1195 neysx 1.39 <comment>(SMTP is 25, IMAP is 143, POP3 is 110. You should receive at least an OK string,
1196     letting you know that the service is running and ready to respond to requests.)</comment>
1197 zhen 1.1
1198 rajiv 1.14 Trying 127.0.0.1...
1199     Connected to localhost.
1200     Escape character is '^]'.
1201 rajiv 1.15 * OK Courier-IMAP ready. Copyright 1998-2002 Double Precision, Inc.
1202 rajiv 1.14 </pre>
1203 neysx 1.39
1204 zhen 1.3 </body>
1205 zhen 1.1 </section>
1206     <section>
1207 neysx 1.39 <title>Step 6: Sometimes only the big guns will give you the information you need: strace</title>
1208 zhen 1.3 <body>
1209 neysx 1.39
1210     <p>
1211     You should have this installed anyway. This is an invaluable tool for debugging
1212     software. You can start commands from the command line with strace and watch
1213     all the system calls as they happen. It often dumps a huge amount of
1214     information, so you'll either need to watch it realtime as you retry a failed
1215     transaction with the mail system, or dump the output to a file for review.
1216     </p>
1217    
1218     <pre caption="Using strace">
1219 rajiv 1.14 # <i>emerge strace</i>
1220     # <i>strace $command</i>
1221     # <i>strace -p `ps -C $service -o pid=`</i>
1222 zhen 1.3 </pre>
1223 neysx 1.39
1224 zhen 1.3 </body>
1225 zhen 1.1 </section>
1226     <section>
1227 zhen 1.3 <title>Step 7: Research</title>
1228     <body>
1229 neysx 1.39
1230     <p>
1231     Once you have the information, if you can diagnose and fix the problem, great!
1232     If not, you'll probably need to go digging on the net for information that will
1233     help you fix it. Here's a list of sites you can check to see if your error has
1234     already been resolved. There's also a really good howto on setting up smtp-auth
1235     which contains some great debugging ideas.
1236     </p>
1237 cam 1.30
1238 zhen 1.3 <ul>
1239 neysx 1.39 <li><uri>http://forums.gentoo.org/</uri> - Great forums for gentoo users</li>
1240     <li>
1241     <uri>http://bugs.gentoo.org/</uri> - Bugs database for gentoo - great place
1242     to look for specific errors
1243     </li>
1244     <li><uri>http://postfix.state-of-mind.de/</uri> - smtp-auth howto</li>
1245     <li>
1246     <uri>http://marc.theaimsgroup.com/?l=postfix-users</uri> - Postfix mailing
1247     lists - searchable
1248     </li>
1249     <li>
1250     <uri>http://sourceforge.net/mailarchive/forum.php?forum_id=6705</uri> -
1251     Courier-imap mailing list archives - not searchable
1252     </li>
1253     <li>
1254     <uri>http://www.google.com/</uri> - If all else fails, there's always
1255     google, which has never failed me
1256     </li>
1257     <li>
1258     I also spend a lot of time on irc.freenode.net #gentoo. Irc is a great
1259     place to go for help.
1260     </li>
1261 zhen 1.3 </ul>
1262 cam 1.30
1263 zhen 1.3 </body>
1264 zhen 1.1 </section>
1265     </chapter>
1266     </guide>

  ViewVC Help
Powered by ViewVC 1.1.20