<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Debian Tutorials &#187; MySQL</title>
	<atom:link href="http://www.debiantutorials.com/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.debiantutorials.com</link>
	<description>Copy/Paste tutorials for Debian Linux</description>
	<lastBuildDate>Wed, 18 Aug 2010 00:35:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Install and configure MailWatch monitoring tool for MailScanner</title>
		<link>http://www.debiantutorials.com/install-and-configure-mailwatch-monitoring-tool-for-mailscanner/</link>
		<comments>http://www.debiantutorials.com/install-and-configure-mailwatch-monitoring-tool-for-mailscanner/#comments</comments>
		<pubDate>Wed, 18 Aug 2010 00:35:59 +0000</pubDate>
		<dc:creator>aip</dc:creator>
				<category><![CDATA[Lenny]]></category>
		<category><![CDATA[Mail]]></category>
		<category><![CDATA[Monitoring]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[mailscanner]]></category>
		<category><![CDATA[mailwatch]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.debiantutorials.com/?p=349</guid>
		<description><![CDATA[MailWatch for MailScanner is a web-based front-end to MailScanner written in PHP, MySQL and JpGraph. It comes with a CustomConfig module for MailScanner which causes MailScanner to log all message data (excluding body text) to a MySQL database which is then queried by MailWatch for reporting and statistics. 
1. Install Apache2, MySql server and PHP5 [...]]]></description>
			<content:encoded><![CDATA[<p>MailWatch for MailScanner is a web-based front-end to MailScanner written in PHP, MySQL and JpGraph. It comes with a CustomConfig module for MailScanner which causes MailScanner to log all message data (excluding body text) to a MySQL database which is then queried by MailWatch for reporting and statistics. </p>
<p>1. Install Apache2, MySql server and PHP5 with required modules. You may already have some or all of these packages installed.</p>
<p><code>apt-get install apache2 php5-cli php5 mysql-server libdbd-mysql-perl php5-gd php5-mysql libapache2-mod-php5<br />
</code><span id="more-349"></span></p>
<p>2. Download the latest version of MailWatch</p>
<p><code>wget http://downloads.sourceforge.net/project/mailwatch/mailwatch/1.0.5/mailwatch-1.0.5.tar.gz<br />
</code></p>
<p><em>At the time this tutorial was written, version 1.0.5 was the latest version. Check this location for latest version: http://sourceforge.net/projects/mailwatch/files/</em></p>
<p>3. Extract and enter the mailwatch directory</p>
<p><code>tar zxvf mailwatch-1.0.5.tar.gz<br />
cd mailwatch-1.0.5<br />
</code></p>
<p>4. Create the database and tables</p>
<p><code>mysql -p < create.sql<br />
</code></p>
<p>5. Create a MySql user used for MailScanner logging (mysql -u root -p)</p>
<p><code>GRANT ALL ON mailscanner.* TO '{username}'@'localhost' IDENTIFIED BY '{password}';<br />
FLUSH PRIVILEGES;<br />
</code></p>
<p><em>Replace {username} and {password} with a username and password of choice.</em></p>
<p>6. Configure the MailScanner logger (pico MailWatch.pm)</p>
<p><code>my($db_user) = '{username}';<br />
my($db_pass) = '{password}';<br />
</code></p>
<p><em>On line 43 and 44, input your MySql user created in step 5</em></p>
<p>7. Move the MailScanner logger to correct directory</p>
<p><code>mv MailWatch.pm /usr/share/MailScanner/MailScanner/CustomFunctions/<br />
</code></p>
<p>8. Edit Mail Scanner config to enable MailWatch logger (pico /etc/MailScanner/MailScanner.conf)</p>
<p><code>Always Looked Up Last = &#038;MailWatchLogging<br />
</code></p>
<p>9. Create a MailWatch web admin user (mysql -u root -p)</p>
<p><code>USE mailscanner;<br />
INSERT INTO users VALUES ('{username}',md5('{password}'),'Administrator name','A','0','0','0','0','0');<br />
</code></p>
<p><em>Replace {username} and {password} with a username and password used to enter the web interface.</em></p>
<p>10. Move the web interface to the web server's root</p>
<p><code>mv mailscanner /var/www/mailwatch<br />
</code></p>
<p>11. Make the temp and cache directories writeable</p>
<p><code>chmod 777 /var/www/mailwatch/temp<br />
chmod 777 /var/www/mailwatch/images/cache<br />
</code></p>
<p>12. Copy the example config file</p>
<p><code>mv /var/www/mailwatch/conf.php.example /var/www/mailwatch/conf.php<br />
</code></p>
<p>13. Configure the web interface (pico /var/www/mailwatch/conf.php)</p>
<p><code>define('DB_USER', '{username}');<br />
define('DB_PASS', '{password}');<br />
define('MAILWATCH_HOME', '/var/www/mailscanner');<br />
</code></p>
<p><em>Type the MySql username and password created in step 5</em></p>
<p>14. Install PEAR PHP framework</p>
<p><code>apt-get install php-pear<br />
</code></p>
<p>15. Install required PEAR packages</p>
<p><code>pear install DB<br />
pear install DB_Pager<br />
pear install Mail_mimeDecode-1.5.1<br />
</code></p>
<p>16. On line 37, add /usr/share/php to the mailwatch include path (pico /var/www/mailwatch/functions.php)</p>
<p><code>ini_set('include_path','.:'.MAILWATCH_HOME.'/pear:'.MAILWATCH_HOME.'/fpdf:'.MAILWATCH_HOME.'/xmlrpc:/usr/share/php');<br />
</code></p>
<p>17. Restart Apache and MailScanner</p>
<p><code>/etc/init.d/apache2 restart<br />
/etc/init.d/mailscanner restart<br />
</code></p>
<p>18. You're all set. Enter the web interface at this location http://yourserver/mailwatch</p>
]]></content:encoded>
			<wfw:commentRss>http://www.debiantutorials.com/install-and-configure-mailwatch-monitoring-tool-for-mailscanner/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tuning MySql with MySqlTuner to increase efficiency and performance</title>
		<link>http://www.debiantutorials.com/tuning-mysql-with-mysqltuner-to-increase-efficiency-and-performance/</link>
		<comments>http://www.debiantutorials.com/tuning-mysql-with-mysqltuner-to-increase-efficiency-and-performance/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 08:52:24 +0000</pubDate>
		<dc:creator>aip</dc:creator>
				<category><![CDATA[Lenny]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[mysqltuner]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.debiantutorials.net/?p=319</guid>
		<description><![CDATA[mysqltuner is a high-performance MySQL tuning script written in perl that will provide you with a snapshot of a MySQL server's health. Based on the statistics gathered, specific recommendations will be provided that will increase a MySQL server's efficiency and performance.
1. Install MySqlTuner
apt-get install mysqltuner

2. Run MySqlTuner
mysqltuner

Input your MySql administrative login and password
Please enter your [...]]]></description>
			<content:encoded><![CDATA[<p>mysqltuner is a high-performance MySQL tuning script written in perl that will provide you with a snapshot of a MySQL server's health. Based on the statistics gathered, specific recommendations will be provided that will increase a MySQL server's efficiency and performance.</p>
<p>1. Install MySqlTuner</p>
<p><code>apt-get install mysqltuner<br />
</code><span id="more-319"></span></p>
<p>2. Run MySqlTuner</p>
<p><code>mysqltuner<br />
</code></p>
<p>Input your MySql administrative login and password</p>
<p><code>Please enter your MySQL administrative login:<br />
Please enter your MySQL administrative password:<br />
</code></p>
<p>Here are sample results:</p>
<p><code>-------- General Statistics --------------------------------------------------<br />
[!!] There is a new version of MySQLTuner available<br />
[OK] Currently running supported MySQL version 5.0.51a-24+lenny2-log<br />
[OK] Operating on 32-bit architecture with less than 2GB RAM<br />
&nbsp;<br />
-------- Storage Engine Statistics -------------------------------------------<br />
[--] Status: +Archive -BDB -Federated +InnoDB -ISAM -NDBCluster<br />
[--] Data in MyISAM tables: 98M (Tables: 81)<br />
[!!] InnoDB is enabled but isn't being used<br />
&nbsp;<br />
-------- Performance Metrics -------------------------------------------------<br />
[--] Up for: 56d 10h 58m 7s (137M q [28.243 qps], 3M conn, TX: 2B, RX: 1B)<br />
[--] Reads / Writes: 90% / 10%<br />
[--] Total buffers: 2.6M per thread and 106.0M global<br />
[OK] Maximum possible memory usage: 368.5M (18% of installed RAM)<br />
[OK] Slow queries: 0% (75K/137M)<br />
[!!] Highest connection usage: 100%  (101/100)<br />
[OK] Key buffer size / total MyISAM indexes: 64.0M/79.3M<br />
[OK] Key buffer hit rate: 100.0%<br />
[OK] Query cache efficiency: 78.4%<br />
[!!] Query cache prunes per day: 269788<br />
[OK] Sorts requiring temporary tables: 0%<br />
[!!] Temporary tables created on disk: 99%<br />
[OK] Thread cache hit rate: 99%<br />
[!!] Table cache hit rate: 1%<br />
[OK] Open file limit used: 27%<br />
[OK] Table locks acquired immediately: 99%<br />
&nbsp;<br />
-------- Recommendations -----------------------------------------------------<br />
General recommendations:<br />
    Add skip-innodb to MySQL configuration to disable InnoDB<br />
    Reduce or eliminate persistent connections to reduce connection usage<br />
    When making adjustments, make tmp_table_size/max_heap_table_size equal<br />
    Reduce your SELECT DISTINCT queries without LIMIT clauses<br />
    Increase table_cache gradually to avoid file descriptor limits<br />
Variables to adjust:<br />
    max_connections (> 100)<br />
    wait_timeout (< 28800)<br />
    interactive_timeout (< 28800)<br />
    query_cache_size (> 16M)<br />
    tmp_table_size (> 32M)<br />
    max_heap_table_size (> 16M)<br />
    table_cache (> 200)<br />
</code></p>
<p>3. Adjust your MySql config file (/etc/mysql/my.cnf) according to the recommendations. Don't increase or decrease the values too much because it may have negative impact on the server. If this is a production server, just make minor changes each time and test again a few hours/days later and adjust the values again if needed. It may take a few days to figure out the best values for your server.</p>
<p>4. Restart MySql after you have made changes to the config file</p>
<p><code>/etc/init.d/mysql restart<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.debiantutorials.com/tuning-mysql-with-mysqltuner-to-increase-efficiency-and-performance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing EHCP (Easy Hosting Control Panel)</title>
		<link>http://www.debiantutorials.com/installing-ehcp-easy-hosting-control-panel/</link>
		<comments>http://www.debiantutorials.com/installing-ehcp-easy-hosting-control-panel/#comments</comments>
		<pubDate>Sun, 02 May 2010 22:26:40 +0000</pubDate>
		<dc:creator>aip</dc:creator>
				<category><![CDATA[Control Panel]]></category>
		<category><![CDATA[Lenny]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[ehcp]]></category>
		<category><![CDATA[postfix]]></category>

		<guid isPermaLink="false">http://www.debiantutorials.net/?p=263</guid>
		<description><![CDATA[EHCP is a powerful, yet easy to install control panel that allows the user to manage services such as Web, FTP, Database and DNS servers.
The install script handles the installation and configuration of the required services. I recommend starting with a clean Debian system to avoid conflicts.
1. Download required EHCP files
wget http://www.ehcp.net/download

2. Uncompress the files
tar [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.debiantutorials.net/wp-content/uploads/2010/05/ehcp.jpg" alt="ehcp" title="ehcp" width="175" height="74" class="alignright size-full wp-image-265" />EHCP is a powerful, yet easy to install control panel that allows the user to manage services such as Web, FTP, Database and DNS servers.</p>
<p>The install script handles the installation and configuration of the required services. I recommend starting with a clean Debian system to avoid conflicts.</p>
<p>1. Download required EHCP files</p>
<p><code>wget http://www.ehcp.net/download<br />
</code><span id="more-263"></span></p>
<p>2. Uncompress the files</p>
<p><code>tar zxvf ehcp_latest.tgz<br />
</code></p>
<p>3. Move into the install directory and run the install script</p>
<p><code>cd ehcp<br />
./install.sh<br />
</code></p>
<p><em>Read the instructions carefully, your server will send statistical information to the EHCP developers. If you choose to move on, the install script will install all required packages including Apache, MySql and Postfix. You will need to provide some information to configure the services and set the admin passwords.</em></p>
<p>4. When the installer is finished, enter the control panel using: http://yourserver.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.debiantutorials.com/installing-ehcp-easy-hosting-control-panel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Courier POP3 and IMAP daemon with MySql backend</title>
		<link>http://www.debiantutorials.com/installing-courier-pop3-and-imap-daemon-with-mysql-backend-install-courier/</link>
		<comments>http://www.debiantutorials.com/installing-courier-pop3-and-imap-daemon-with-mysql-backend-install-courier/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 11:02:31 +0000</pubDate>
		<dc:creator>aip</dc:creator>
				<category><![CDATA[Lenny]]></category>
		<category><![CDATA[Mail]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[courier]]></category>
		<category><![CDATA[etch]]></category>
		<category><![CDATA[imap]]></category>
		<category><![CDATA[lenny]]></category>
		<category><![CDATA[pop3]]></category>

		<guid isPermaLink="false">http://www.debiantutorials.net/?p=191</guid>
		<description><![CDATA[The Courier mail transfer agent (MTA) is an integrated mail/groupware server based on open commodity protocols, such as ESMTP, IMAP, POP3, LDAP, SSL, and HTTP. Courier provides ESMTP, IMAP, POP3, webmail, and mailing list services within a single, consistent, framework. In this tutorial we'll only use the Courier POP3 and IMAP services.
It's assumed that you [...]]]></description>
			<content:encoded><![CDATA[<p>The Courier mail transfer agent (MTA) is an integrated mail/groupware server based on open commodity protocols, such as ESMTP, IMAP, POP3, LDAP, SSL, and HTTP. Courier provides ESMTP, IMAP, POP3, webmail, and mailing list services within a single, consistent, framework. In this tutorial we'll only use the Courier POP3 and IMAP services.</p>
<p>It's assumed that you have already installed and configured Postfix according to this tutorial: <a href="http://www.debiantutorials.net/installing-postfix-with-mysql-backend-and-sasl-for-smtp-authentication/">Installing Postfix with MySql backend and SASL for SMTP authentication</a></p>
<p>1. Install required packages</p>
<p><code>apt-get install courier-authdaemon courier-authlib-mysql courier-pop courier-pop-ssl courier-imap courier-imap-ssl<br />
</code><span id="more-191"></span></p>
<p>2. Make Courier use MySql backend (pico /etc/courier/authdaemonrc)</p>
<p><code>authmodulelist="authmysql"<br />
</code></p>
<p>3. Configure the MySql connector (pico /etc/courier/authmysqlrc)</p>
<p><code>MYSQL_SERVER 127.0.0.1<br />
MYSQL_USERNAME {username}<br />
MYSQL_PASSWORD {password}<br />
MYSQL_PORT 0<br />
MYSQL_DATABASE {database}<br />
MYSQL_USER_TABLE users<br />
MYSQL_CRYPT_PWFIELD password<br />
MYSQL_UID_FIELD 5000<br />
MYSQL_GID_FIELD 5000<br />
MYSQL_LOGIN_FIELD email<br />
MYSQL_HOME_FIELD "/home/vmail"<br />
MYSQL_MAILDIR_FIELD CONCAT(SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1),'/')<br />
MYSQL_QUOTA_FIELD quota<br />
</code></p>
<p><em>{database} = MySql database name<br />
MySql username<br />
MySql password</em></p>
<p>4. Restart Courier daemons</p>
<p><code>/etc/init.d/courier-authdaemon restart<br />
/etc/init.d/courier-imap restart<br />
/etc/init.d/courier-imap-ssl restart<br />
/etc/init.d/courier-pop restart<br />
/etc/init.d/courier-pop-ssl restart<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.debiantutorials.com/installing-courier-pop3-and-imap-daemon-with-mysql-backend-install-courier/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Postfix with MySql backend and SASL for SMTP authentication</title>
		<link>http://www.debiantutorials.com/installing-postfix-with-mysql-backend-and-sasl-for-smtp-authentication/</link>
		<comments>http://www.debiantutorials.com/installing-postfix-with-mysql-backend-and-sasl-for-smtp-authentication/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 10:45:13 +0000</pubDate>
		<dc:creator>aip</dc:creator>
				<category><![CDATA[Lenny]]></category>
		<category><![CDATA[Mail]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[lenny]]></category>
		<category><![CDATA[postfix]]></category>
		<category><![CDATA[sasl]]></category>
		<category><![CDATA[smtp]]></category>
		<category><![CDATA[tls]]></category>

		<guid isPermaLink="false">http://www.debiantutorials.net/?p=186</guid>
		<description><![CDATA[Postfix is a free and open source mail transfer agent (MTA). It is intended as a fast, easy-to-administer, and secure alternative to the widely-used Sendmail MTA.
Install and configure Postfix
1. Install Postfix and SASL
apt-get install postfix postfix-mysql libsasl2-modules-sql sasl2-bin libsasl2-2 postfix-tls libpam-mysql
> Internet Site
> host.domain.com

2. Create database and tables (mysql -u root -p)
# Create the database
CREATE [...]]]></description>
			<content:encoded><![CDATA[<p>Postfix is a free and open source mail transfer agent (MTA). It is intended as a fast, easy-to-administer, and secure alternative to the widely-used Sendmail MTA.</p>
<p><strong>Install and configure Postfix</strong></p>
<p>1. Install Postfix and SASL</p>
<p><code>apt-get install postfix postfix-mysql libsasl2-modules-sql sasl2-bin libsasl2-2 postfix-tls libpam-mysql<br />
> Internet Site<br />
> host.domain.com<br />
</code><span id="more-186"></span></p>
<p>2. Create database and tables (mysql -u root -p)</p>
<p><code># Create the database<br />
CREATE DATABASE mail;<br />
&nbsp;<br />
# Create user and allow him to read from the mail database<br />
GRANT SELECT ON mail.* TO '{username}'@'localhost' IDENTIFIED BY '{password}';<br />
FLUSH PRIVILEGES;<br />
&nbsp;<br />
# Select the mail database<br />
USE mail;<br />
&nbsp;<br />
# Create table containing domains handled by this mail server<br />
CREATE TABLE domains (<br />
	domain varchar(255) NOT NULL,<br />
	PRIMARY KEY (domain)<br />
) TYPE=MyISAM;<br />
&nbsp;<br />
# Create table for e-mail address forwardings<br />
CREATE TABLE forwardings (<br />
	source varchar(255) NOT NULL,<br />
	destination varchar(255) NOT NULL,<br />
	PRIMARY KEY (source)<br />
) TYPE=MyISAM;<br />
&nbsp;<br />
# Create table for e-mail accounts / users<br />
CREATE TABLE users (<br />
	email varchar(255) NOT NULL,<br />
	password varchar(255) NOT NULL,<br />
	quota int(10) DEFAULT '104857600',<br />
	PRIMARY KEY (email)<br />
) TYPE=MyISAM;<br />
&nbsp;<br />
# Create table for transports<br />
CREATE TABLE transport (<br />
	domain varchar(255) NOT NULL,<br />
	transport varchar(255) NOT NULL,<br />
	UNIQUE KEY domain (domain)<br />
) TYPE=MyISAM;<br />
</code></p>
<p><em>{username} = A new MySql user used by Postfix to access the MySql data<br />
{password} = A password for the new MySql user</em></p>
<p>3. Create Postfix to MySql mappings</p>
<p>Domains (pico /etc/postfix/mysql-virtual_domains.cf)</p>
<p><code>user = {username}<br />
password = {password}<br />
dbname = mail<br />
table = domains<br />
select_field = 'virtual'<br />
where_field = domain<br />
hosts = 127.0.0.1<br />
</code></p>
<p>Forwards (pico /etc/postfix/mysql-virtual_forwardings.cf)</p>
<p><code>user = {username}<br />
password = {password}<br />
dbname = mail<br />
table = forwardings<br />
select_field = destination<br />
where_field = source<br />
hosts = 127.0.0.1<br />
</code></p>
<p>Mailboxes / Users (pico /etc/postfix/mysql-virtual_mailboxes.cf)</p>
<p><code>user = {username}<br />
password = {password}<br />
dbname = mail<br />
table = users<br />
select_field = CONCAT(SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1),'/')<br />
where_field = email<br />
hosts = 127.0.0.1<br />
</code></p>
<p>E-mail to E-mail (pico /etc/postfix/mysql-virtual_email2email.cf)</p>
<p><code>user = {username}<br />
password = {password}<br />
dbname = mail<br />
table = users<br />
select_field = email<br />
where_field = email<br />
hosts = 127.0.0.1<br />
</code></p>
<p>Transports (pico /etc/postfix/mysql-virtual_transports.cf)</p>
<p><code>user = {username}<br />
password = {password}<br />
dbname = mail<br />
table = transport<br />
select_field = transport<br />
where_field = domain<br />
hosts = 127.0.0.1<br />
</code></p>
<p>Quota (pico /etc/postfix/mysql-virtual_mailbox_limit_maps.cf)</p>
<p><code>user = {username}<br />
password = {password}<br />
dbname = mail<br />
table = users<br />
select_field = quota<br />
where_field = email<br />
hosts = 127.0.0.1<br />
</code></p>
<p>Destinations (pico /etc/postfix/mysql-mydestination.cf)</p>
<p><code>user = {username}<br />
password = {password}<br />
dbname = mail<br />
table = transport<br />
select_field = domain<br />
where_field = domain<br />
hosts = 127.0.0.1<br />
</code></p>
<p><em>{username} = The username you selected for the new MySql user<br />
{password} = The password you selected for the new MySql user</em></p>
<p>4. Change permissions on the new files</p>
<p><code>chmod 640 /etc/postfix/mysql-*.cf<br />
chgrp postfix /etc/postfix/mysql-*.cf<br />
</code></p>
<p><em>Make sure they aren't readable by any user because the password is included</em></p>
<p>5. Create a local user and group for the virtual users</p>
<p><code>groupadd -g 5000 vmail<br />
useradd -g vmail -u 5000 vmail -d /home/vmail -m<br />
</code></p>
<p>6. Create certificates for TLS</p>
<p><code>openssl req -new -outform PEM -out /etc/postfix/smtpd.cert -newkey rsa:2048 -nodes -keyout /etc/postfix/smtpd.key -keyform PEM -days 3650 -x509<br />
chmod 640 /etc/postfix/smtpd.key<br />
</code></p>
<p>7. Configure Postfix</p>
<p><code>postconf -e 'mydestination = localhost, proxy:mysql:/etc/postfix/mysql-mydestination.cf'<br />
postconf -e 'virtual_alias_maps = proxy:mysql:/etc/postfix/mysql-virtual_forwardings.cf, mysql:/etc/postfix/mysql-virtual_email2email.cf'<br />
postconf -e 'virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql-virtual_domains.cf'<br />
postconf -e 'virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailboxes.cf'<br />
postconf -e 'virtual_mailbox_base = /home/vmail'<br />
postconf -e 'virtual_uid_maps = static:5000'<br />
postconf -e 'virtual_gid_maps = static:5000'<br />
postconf -e 'smtpd_sasl_auth_enable = yes'<br />
postconf -e 'smtpd_helo_required = yes'<br />
postconf -e 'broken_sasl_auth_clients = yes'<br />
postconf -e 'smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination'<br />
postconf -e 'smtpd_use_tls = yes'<br />
postconf -e 'smtpd_tls_cert_file = /etc/postfix/smtpd.cert'<br />
postconf -e 'smtpd_tls_key_file = /etc/postfix/smtpd.key'<br />
postconf -e 'strict_rfc821_envelopes = yes'<br />
postconf -e 'disable_vrfy_command = yes'<br />
postconf -e 'transport_maps = proxy:mysql:/etc/postfix/mysql-virtual_transports.cf'<br />
postconf -e 'virtual_create_maildirsize = yes'<br />
postconf -e 'virtual_mailbox_extended = yes'<br />
postconf -e 'virtual_mailbox_limit_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailbox_limit_maps.cf'<br />
postconf -e 'virtual_mailbox_limit_override = yes'<br />
postconf -e 'virtual_maildir_limit_message = "Account is over quota"'<br />
postconf -e 'virtual_overquota_bounce = yes'<br />
postconf -e 'proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps    $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps'<br />
</code></p>
<p>8. Enable secure ports: 465 and 587 (pico /etc/postfix/master.cf)</p>
<p><code>smtps     inet  n       -       -       -       -       smtpd<br />
  -o smtpd_tls_wrappermode=yes<br />
  -o smtpd_sasl_auth_enable=yes<br />
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject<br />
  -o milter_macro_daemon_name=ORIGINATING<br />
&nbsp;<br />
587      inet  n       -       -       -       -       smtpd<br />
</code></p>
<p><strong>Configure SASL for SMTP authentication</strong></p>
<p>9. Create a folder for the SASL PID file</p>
<p><code>mkdir -p /var/spool/postfix/var/run/saslauthd<br />
</code></p>
<p>10. Enable SASL (pico /etc/default/saslauthd)</p>
<p><code>START=yes<br />
OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd -r"<br />
</code></p>
<p>11. Configure SASL to use the new PID file location (pico /etc/init.d/saslauthd)</p>
<p><code>PIDFILE="/var/spool/postfix/var/run/${NAME}/saslauthd.pid"<br />
</code></p>
<p><em>Make sure you replace all PIDFILE definations in the file. This is set on a few places.</em></p>
<p>12. Configure PAM to use MySql backend for authentication (pico /etc/pam.d/smtp)</p>
<p><code>auth    required   pam_mysql.so user={username} passwd={password} host=127.0.0.1 db=mail table=users usercolumn=email passwdcolumn=password crypt=1<br />
account sufficient pam_mysql.so user={username} passwd={password} host=127.0.0.1 db=mail table=users usercolumn=email passwdcolumn=password crypt=1<br />
</code></p>
<p><em>{username} = The username you selected for the new MySql user<br />
{password} = The password you selected for the new MySql user</em></p>
<p>13. Configure Postfix to use SASl for SMTP authentication (pico /etc/postfix/sasl/smtpd.conf)</p>
<p><code>pwcheck_method: saslauthd<br />
mech_list: plain login<br />
allow_plaintext: true<br />
auxprop_plugin: mysql<br />
sql_hostnames: 127.0.0.1<br />
sql_user: {username}<br />
sql_passwd: {password}<br />
sql_database: mail<br />
sql_select: select password from users where email = '%u'<br />
</code></p>
<p><em>{username} = The username you selected for the new MySql user<br />
{password} = The password you selected for the new MySql user</em></p>
<p>14. Restart Postfix and SASL</p>
<p><code>/etc/init.d/saslauthd restart<br />
/etc/init.d/postfix restart<br />
</code></p>
<p><strong>Test MySql data</strong></p>
<p>1. Handle mail for a domain. This must be done if you will create mailboxes or forwards handled on this server.</p>
<p><code>INSERT INTO domains VALUES ('domain.com');<br />
</code></p>
<p>2. Create user/mailbox. Users will be able to receive mail and send mails using this server</p>
<p><code>INSERT INTO users VALUES ('user@domain.com', ENCRYPT('password'), 104857600);<br />
</code></p>
<p>3. Create forward. A e-mail address used to forward to another e-mail address or multiple e-mail addresses</p>
<p><code>INSERT INTO forwardings VALUES ('user2@domain.com', 'user@domain.com');<br />
</code></p>
<p>Forward to multiple e-mail addresses using a comma to seperate</p>
<p><code>INSERT INTO forwardings VALUES ('user3@domain.com', 'user@domain.com,user@gmail.com');<br />
</code></p>
<p>4. Forward all mails for a domain to another mail server</p>
<p><code>INSERT INTO transport VALUES ('domain.com', 'smtp:server2.domain.com');<br />
</code></p>
<p>Next step is to set up services to support POP3 and IMAP:<br />
<a href="http://www.debiantutorials.net/installing-courier-pop3-and-imap-daemon-with-mysql-backend-install-courier/">Installing Courier POP3 and IMAP daemon with MySql backend / Install Courier</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.debiantutorials.com/installing-postfix-with-mysql-backend-and-sasl-for-smtp-authentication/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>MySql database replication (master/slave)</title>
		<link>http://www.debiantutorials.com/mysql-database-replication-masterslave/</link>
		<comments>http://www.debiantutorials.com/mysql-database-replication-masterslave/#comments</comments>
		<pubDate>Sun, 04 Oct 2009 23:14:27 +0000</pubDate>
		<dc:creator>aip</dc:creator>
				<category><![CDATA[Lenny]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[etch]]></category>
		<category><![CDATA[lenny]]></category>
		<category><![CDATA[replication]]></category>

		<guid isPermaLink="false">http://www.debiantutorials.net/?p=125</guid>
		<description><![CDATA[In this tutorial we'll create a simple one-way master/slave database replication. You must have at least one master and one slave but you can use multiple slaves.
Master
1. Configure master to listen on all ip addresses (pico /etc/mysql/my.cnf)
#bind-address            = 127.0.0.1

Comment out this line or remove [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial we'll create a simple one-way master/slave database replication. You must have at least one master and one slave but you can use multiple slaves.</p>
<p><strong>Master</strong></p>
<p>1. Configure master to listen on all ip addresses (pico /etc/mysql/my.cnf)</p>
<p><code>#bind-address            = 127.0.0.1<br />
</code><span id="more-125"></span></p>
<p><em>Comment out this line or remove it</em></p>
<p>2. Configure server id, log file location and which databases are allowed to be replicated (pico /etc/mysql/my.cnf)</p>
<p><code>server-id               = 1<br />
log_bin                 = /var/log/mysql/mysql-bin.log<br />
binlog_do_db            = {database}<br />
</code></p>
<p><em>Replace {database} with the one you would like to replicate</em></p>
<p>3. Restart MySql</p>
<p><code>/etc/init.d/mysql restart<br />
</code></p>
<p>4. Create a user and allow it to act as slave for this server (mysql -u root -p)</p>
<p><code>GRANT REPLICATION SLAVE ON *.* TO {username}@'{ip}' IDENTIFIED BY '{password}';<br />
FLUSH PRIVILEGES;<br />
</code></p>
<p><em>{username} = Your preferred username<br />
{password} = Your password<br />
{ip} = IP address of the slave system or % to allow all ip addresses</em></p>
<p>5. Show current log file and position (mysql -u root -p)</p>
<p><code>SHOW MASTER STATUS;<br />
</code></p>
<p>This will return something like this:</p>
<p><code>+------------------+----------+--------------+------------------+<br />
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |<br />
+------------------+----------+--------------+------------------+<br />
| mysql-bin.000004 |     2751 | {database}   |                  |<br />
+------------------+----------+--------------+------------------+<br />
</code></p>
<p><em>Keep the file name and position. It will be used later on the slave</em></p>
<p>6. Transfer data from the master to the slave</p>
<p>You can do this using various methods including exporting and importing using phpMyAdmin, creating a database dump from the master and import to the slave and "LOAD DATA FROM MASTER".</p>
<p><strong>Slave</strong></p>
<p>1. Configure this server to be a slave for the master MySql server (pico /etc/mysql/my.cnf)</p>
<p><code>server-id               = 2<br />
master-host             = {master_ip}<br />
master-user             = {username}<br />
master-password         = {password}<br />
master-connect-retry    = 60<br />
replicate-do-db         = {database}<br />
</code></p>
<p><em>{master_ip} = The ip of the master server<br />
{username} = The username you provided earlier on the master server<br />
{password} = The password you provided earlier on the master server<br />
{database} = The database you want to replicate</em></p>
<p>2. Restart MySql</p>
<p><code>/etc/init.d/mysql restart<br />
</code></p>
<p>3. Final configurations to make the slave replicate with the master (mysql -u root -p)</p>
<p><code>SLAVE STOP;<br />
CHANGE MASTER TO MASTER_HOST='{master_ip}', MASTER_USER='{username}', MASTER_PASSWORD='{password}', MASTER_LOG_FILE='{log_file}', MASTER_LOG_POS={log_position};<br />
SLAVE START;<br />
</code></p>
<p><em>{master_ip} = The ip of the master server<br />
{username} = The username you provided earlier on the master server<br />
{password} = The password you provided earlier on the master server<br />
{log_file} = Log file name from the master (ex. mysql-bin.000004)<br />
{log_position} = Log position from the master (ex. 2751)</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.debiantutorials.com/mysql-database-replication-masterslave/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moving databases from one MySql server to another</title>
		<link>http://www.debiantutorials.com/moving-databases-from-one-mysql-server-to-another/</link>
		<comments>http://www.debiantutorials.com/moving-databases-from-one-mysql-server-to-another/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 20:12:23 +0000</pubDate>
		<dc:creator>aip</dc:creator>
				<category><![CDATA[Lenny]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[database]]></category>

		<guid isPermaLink="false">http://www.debiantutorials.net/?p=106</guid>
		<description><![CDATA[1. On the source database server run the following command to export all databases:
mysqldump -h localhost -u {username} -p --all-databases > database_dump.sql

Replace {username} with your MySql username.
You can also export a single database using this command:
mysqldump -h localhost -u {username} -p {database} > database_dump.sql

Replace {username} with your MySql username and {database} with the database you [...]]]></description>
			<content:encoded><![CDATA[<p>1. On the source database server run the following command to export all databases:</p>
<p><code>mysqldump -h localhost -u {username} -p --all-databases > database_dump.sql<br />
</code></p>
<p><em>Replace {username} with your MySql username.</em><span id="more-106"></span></p>
<p>You can also export a single database using this command:</p>
<p><code>mysqldump -h localhost -u {username} -p {database} > database_dump.sql<br />
</code></p>
<p><em>Replace {username} with your MySql username and {database} with the database you are going to export.</em></p>
<p>2. Move the database_dump.sql file to your destination server. You could grab it from FTP server or put it on a public web location and use wget on the destination server to receive the file. This process it outside the scope of this tutorial.</p>
<p>3. Import the dump to the destination MySql server by running the following command:</p>
<p><code>mysql -h localhost -u {username} -p < database_dump.sql<br />
</code></p>
<p><em>Replace {username} with your MySql username.</em></p>
<p>If you are only exporting a single database, use this command instead:</p>
<p><code>mysql -h localhost -u {username} -p {database} < database_dump.sql<br />
</code></p>
<p><em>Replace {username} with your MySql username and {database} with the database you are going to export.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.debiantutorials.com/moving-databases-from-one-mysql-server-to-another/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing vsftpd with MySql backend</title>
		<link>http://www.debiantutorials.com/installing-vsftpd-with-mysql-backend/</link>
		<comments>http://www.debiantutorials.com/installing-vsftpd-with-mysql-backend/#comments</comments>
		<pubDate>Sat, 12 Sep 2009 21:31:47 +0000</pubDate>
		<dc:creator>aip</dc:creator>
				<category><![CDATA[FTP]]></category>
		<category><![CDATA[Lenny]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[lenny]]></category>
		<category><![CDATA[vsftpd]]></category>

		<guid isPermaLink="false">http://www.debiantutorials.net/?p=100</guid>
		<description><![CDATA[vsftpd is a secure, fast and stable FTP server. In this tutorial we'll install the server and make create a user database in MySql for virtual users.
1. Install required packages (make sure you have installed MySql)
apt-get install vsftpd libpam-mysql

2. Create database and insert the first user (mysql -u root -p)
CREATE DATABASE ftpd;
USE ftpd;
CREATE TABLE users [...]]]></description>
			<content:encoded><![CDATA[<p>vsftpd is a secure, fast and stable FTP server. In this tutorial we'll install the server and make create a user database in MySql for virtual users.</p>
<p>1. Install required packages (make sure you have installed MySql)</p>
<p><code>apt-get install vsftpd libpam-mysql<br />
</code><span id="more-100"></span></p>
<p>2. Create database and insert the first user (mysql -u root -p)</p>
<p><code>CREATE DATABASE ftpd;<br />
USE ftpd;<br />
CREATE TABLE users (username varchar (30) NOT NULL, password varchar(50) NOT NULL, PRIMARY KEY (username)) TYPE=MyISAM;<br />
INSERT INTO users (username, password) VALUES ('user1', PASSWORD('password1'));<br />
GRANT SELECT ON ftpd.users to vsftpd@localhost identified by 'yourpassword';<br />
exit;</code></p>
<p><em>Replace yourpassword with a strong password used later by vsftpd to authenticate</em></p>
<p>3. Configure vsftpd (pico /etc/vsftpd.conf)</p>
<p>Edit or add these variables in the config file and leave everything else with the default values.</p>
<p><code>anonymous_enable=NO<br />
local_enable=YES<br />
write_enable=YES<br />
local_umask=022<br />
nopriv_user=vsftpd<br />
virtual_use_local_privs=YES<br />
guest_enable=YES<br />
user_sub_token=$USER<br />
local_root=/var/www/$USER<br />
chroot_local_user=YES<br />
hide_ids=YES<br />
guest_username=vsftpd<br />
</code></p>
<p><em>Set the local_root to the parent directory where the user's home directories are located</em></p>
<p>4. Configure PAM to check the MySql database for users (pico /etc/pam.d/vsftpd)</p>
<p><code>auth required pam_mysql.so user=vsftpd passwd=yourpassword host=localhost db=ftpd table=users usercolumn=username passwdcolumn=password crypt=2<br />
account required pam_mysql.so user=vsftpd passwd=yourpassword host=localhost db=ftpd table=users usercolumn=username passwdcolumn=password crypt=2<br />
</code></p>
<p><em>Make sure you remove everything else from the file</em></p>
<p>5. Create a local user that's used by the virtual users to authenticate</p>
<p><code>useradd --home /home/vsftpd --gid nogroup -m --shell /bin/false vsftpd<br />
</code></p>
<p>6. Restart vsftpd</p>
<p><code>/etc/init.d/vsftpd restart<br />
</code></p>
<p>7. Create user's home directory since vsftpd doesn't do it automatically</p>
<p><code>mkdir /var/www/user1<br />
chown vsftpd:nogroup /var/www/user1<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.debiantutorials.com/installing-vsftpd-with-mysql-backend/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Installing Courier POP3 and IMAP services with MySql backend</title>
		<link>http://www.debiantutorials.com/installing-courier-pop3-and-imap-services-with-mysql-backend/</link>
		<comments>http://www.debiantutorials.com/installing-courier-pop3-and-imap-services-with-mysql-backend/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 23:55:46 +0000</pubDate>
		<dc:creator>aip</dc:creator>
				<category><![CDATA[Lenny]]></category>
		<category><![CDATA[Mail]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[courier]]></category>
		<category><![CDATA[imap]]></category>
		<category><![CDATA[lenny]]></category>
		<category><![CDATA[pop3]]></category>
		<category><![CDATA[postfix]]></category>

		<guid isPermaLink="false">http://www.debiantutorials.net/?p=64</guid>
		<description><![CDATA[This tutorial assumes you already have Postfix installed with MySql backend as described in this tutorial: Installing Postfix with MySql backend and TLS
1. Install required packages
apt-get install courier-authdaemon courier-authlib-mysql courier-pop courier-pop-ssl courier-imap courier-imap-ssl

2. Make the auth daemon support MySql virtual users (pico /etc/courier/authdaemonrc)
authmodulelist="authmysql"

3. Configure courier to use MySql backend (pico /etc/courier/authmysqlrc)
MYSQL_SERVER {mysql_host}
MYSQL_USERNAME {mysql_username}
MYSQL_PASSWORD {mysql_password}
MYSQL_PORT 0
MYSQL_DATABASE [...]]]></description>
			<content:encoded><![CDATA[<p>This tutorial assumes you already have Postfix installed with MySql backend as described in this tutorial: <a href="http://www.debiantutorials.net/installing-postfix-with-mysql-backend-and-tls/">Installing Postfix with MySql backend and TLS</a></p>
<p>1. Install required packages</p>
<p><code>apt-get install courier-authdaemon courier-authlib-mysql courier-pop courier-pop-ssl courier-imap courier-imap-ssl<br />
</code><span id="more-64"></span></p>
<p>2. Make the auth daemon support MySql virtual users (pico /etc/courier/authdaemonrc)</p>
<p><code>authmodulelist="authmysql"<br />
</code></p>
<p>3. Configure courier to use MySql backend (pico /etc/courier/authmysqlrc)</p>
<p><code>MYSQL_SERVER {mysql_host}<br />
MYSQL_USERNAME {mysql_username}<br />
MYSQL_PASSWORD {mysql_password}<br />
MYSQL_PORT 0<br />
MYSQL_DATABASE {mysql_database}<br />
MYSQL_USER_TABLE users<br />
MYSQL_CRYPT_PWFIELD password<br />
MYSQL_UID_FIELD 5000<br />
MYSQL_GID_FIELD 5000<br />
MYSQL_LOGIN_FIELD email<br />
MYSQL_HOME_FIELD "/home/vmail"<br />
MYSQL_MAILDIR_FIELD CONCAT(SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1),'/')<br />
MYSQL_QUOTA_FIELD quota<br />
</code></p>
<p>4. Restart affected daemons</p>
<p><code>/etc/init.d/courier-authdaemon restart<br />
/etc/init.d/courier-imap restart<br />
/etc/init.d/courier-imap-ssl restart<br />
/etc/init.d/courier-pop restart<br />
/etc/init.d/courier-pop-ssl restart<br />
</code></p>
<p>You can now connect to your server on port 110 for pop3, 995 for pop3s, 143 for imap and 993 for imaps.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.debiantutorials.com/installing-courier-pop3-and-imap-services-with-mysql-backend/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Postfix with MySql backend and TLS</title>
		<link>http://www.debiantutorials.com/installing-postfix-with-mysql-backend-and-tls/</link>
		<comments>http://www.debiantutorials.com/installing-postfix-with-mysql-backend-and-tls/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 22:57:36 +0000</pubDate>
		<dc:creator>aip</dc:creator>
				<category><![CDATA[Lenny]]></category>
		<category><![CDATA[Mail]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[lenny]]></category>
		<category><![CDATA[postfix]]></category>
		<category><![CDATA[sasl]]></category>
		<category><![CDATA[tls]]></category>

		<guid isPermaLink="false">http://www.debiantutorials.net/?p=61</guid>
		<description><![CDATA[In this tutorial we'll install a ready to use Postfix mail server with MySql backend for virtual users. Notice that this tutorial only covers installing the SMTP server (not POP3 and IMAP). Click here for a tutorial on installing Courier POP3 and IMAp services.
Once installed and configured, you can easily create your own admin system [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial we'll install a ready to use Postfix mail server with MySql backend for virtual users. Notice that this tutorial only covers installing the SMTP server (not POP3 and IMAP). <a href="http://www.debiantutorials.net/installing-courier-pop3-and-imap-services-with-mysql-backend/">Click here for a tutorial on installing Courier POP3 and IMAp services</a>.</p>
<p>Once installed and configured, you can easily create your own admin system to modifiy the domains and users because the table structure is very simple.</p>
<p>This tutorial has been tested on Debian etch and lenny</p>
<p>1. Install the Postfix mail server, MySql server and other required packages</p>
<p><code>apt-get install postfix postfix-mysql sasl2-bin libsasl2-modules mysql-client mysql-server libpam-mysql<br />
</code><span id="more-61"></span>	</p>
<p>In the configuration wizzard for Postfix select and input the following</p>
<p><code>General type of mail configuration<br />
 -> Internet Site<br />
&nbsp;<br />
System mail name<br />
 -> server.domain.com (your server host name)<br />
</code></p>
<p>2. Create a MySql database that will contain domains and mappings and create a user that has read privileges on it. Execute the following SQL queries to create the table structure:</p>
<p><code>CREATE TABLE domains (<br />
  domain varchar(63) NOT NULL,<br />
  PRIMARY KEY (domain)<br />
) ENGINE=MyISAM;<br />
&nbsp;<br />
CREATE TABLE forwardings (<br />
  email varchar(255) NOT NULL,<br />
  destination text NOT NULL,<br />
  PRIMARY KEY (email)<br />
) ENGINE=MyISAM;<br />
&nbsp;<br />
CREATE TABLE transport (<br />
  domain varchar(255) NOT NULL,<br />
  transport varchar(255) NOT NULL,<br />
  PRIMARY KEY (domain)<br />
) ENGINE=MyISAM;<br />
&nbsp;<br />
CREATE TABLE users (<br />
  email varchar(255) NOT NULL,<br />
  password varchar(255) NOT NULL,<br />
  quota int(10) unsigned NOT NULL default '102400',<br />
  PRIMARY KEY (email)<br />
) ENGINE=MyISAM;<br />
</code></p>
<p>3. Populate tables with some test data</p>
<p><code>INSERT INTO domains (domain) VALUES (mydomain.com);<br />
INSERT INTO users (email, password) VALUES ('address@mydomain.com', ENCRYPT('mypassword'));<br />
INESRT INTO forwardings (email, desination) VALUES ('myforward@mydomain.com', 'address@mydomain.com, otheraddress@mydomain.com');<br />
INSERT INTO transport (domain, transport) VALUES ('transport.com', 'smtp:mail.transport.com');<br />
</code></p>
<p><em>If you want to create a user or forwarding for a domain, you must add it to the domains table. Using the transport table you can forward all mail received to another mail server, when using the transport table you don't have to add the domain to the domains table.</em></p>
<p>4. Create MySql mappings for Postfix. Replace {mysql_*} with your MySql credentials.</p>
<p><code>pico /etc/postfix/mysql-virtual_domains.cf<br />
	hosts = {mysql_host}<br />
	user = {mysql_username}<br />
	password = {mysql_password}<br />
	dbname = {mysql_database}<br />
	table = domains<br />
	select_field = 'virtual'<br />
	where_field = domain<br />
&nbsp;<br />
pico /etc/postfix/mysql-virtual_forwardings.cf<br />
	hosts = {mysql_host}<br />
	user = {mysql_username}<br />
	password = {mysql_password}<br />
	dbname = {mysql_database}<br />
	table = forwardings<br />
	select_field = destination<br />
	where_field = email<br />
&nbsp;<br />
pico /etc/postfix/mysql-virtual_mailboxes.cf<br />
	hosts = {mysql_host}<br />
	user = {mysql_username}<br />
	password = {mysql_password}<br />
	dbname = {mysql_database}<br />
	table = users<br />
	select_field = CONCAT(SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1),'/')<br />
	where_field = email<br />
&nbsp;<br />
pico /etc/postfix/mysql-virtual_email2email.cf<br />
	hosts = {mysql_host}<br />
	user = {mysql_username}<br />
	password = {mysql_password}<br />
	dbname = {mysql_database}<br />
	table = users<br />
	select_field = email<br />
	where_field = email<br />
&nbsp;<br />
pico /etc/postfix/mysql-virtual_transports.cf<br />
	hosts = {mysql_host}<br />
	user = {mysql_username}<br />
	password = {mysql_password}<br />
	dbname = {mysql_database}<br />
	table = transport<br />
	select_field = transport<br />
	where_field = domain<br />
&nbsp;<br />
pico /etc/postfix/mysql-virtual_mailbox_limit_maps.cf<br />
	hosts = {mysql_host}<br />
	user = {mysql_username}<br />
	password = {mysql_password}<br />
	dbname = {mysql_database}<br />
	table = users<br />
	select_field = quota<br />
	where_field = email<br />
</code></p>
<p>5. Set correct permissions on the newly created files and allow Postfix to read the files</p>
<p><code>chmod 640 /etc/postfix/mysql-virtual_*<br />
chgrp postfix /etc/postfix/mysql-virtual_*<br />
</code></p>
<p>6. Create a new user and group named vmail. All incoming mail will be stored in this users home directory</p>
<p><code>groupadd -g 5000 vmail<br />
useradd -g vmail -u 5000 vmail -d /home/vmail -m<br />
</code></p>
<p>7. Configure Postfix to use SASL for user authentication and TLS for encryption</p>
<p><code>postconf -e 'smtpd_sasl_auth_enable = yes'<br />
postconf -e 'broken_sasl_auth_clients = yes'<br />
postconf -e 'smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination'<br />
postconf -e 'smtpd_use_tls = yes'<br />
postconf -e 'smtpd_tls_cert_file = /etc/postfix/smtpd.cert'<br />
postconf -e 'smtpd_tls_key_file = /etc/postfix/smtpd.key'<br />
postconf -e 'smtpd_sasl_local_domain = $myhostname'<br />
postconf -e 'smtpd_sasl_security_options = noanonymous'<br />
</code></p>
<p>8. Configure Postfix to use the MySql database to find virtual users, where to store mail and what to do for users over quota</p>
<p><code>postconf -e 'virtual_alias_domains ='<br />
postconf -e 'virtual_alias_maps = proxy:mysql:/etc/postfix/mysql-virtual_forwardings.cf, mysql:/etc/postfix/mysql-virtual_email2email.cf'<br />
postconf -e 'virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql-virtual_domains.cf'<br />
postconf -e 'virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailboxes.cf'<br />
postconf -e 'virtual_mailbox_base = /home/vmail'<br />
postconf -e 'virtual_uid_maps = static:5000'<br />
postconf -e 'virtual_gid_maps = static:5000'<br />
postconf -e 'transport_maps = proxy:mysql:/etc/postfix/mysql-virtual_transports.cf'<br />
postconf -e 'virtual_create_maildirsize = yes'<br />
postconf -e 'virtual_mailbox_extended = yes'<br />
postconf -e 'virtual_mailbox_limit_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailbox_limit_maps.cf'<br />
postconf -e 'virtual_mailbox_limit_override = yes'<br />
postconf -e 'virtual_maildir_limit_message = "The user you are trying to reach is over quota."'<br />
postconf -e 'virtual_overquota_bounce = yes'<br />
postconf -e 'proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps    $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps'<br />
</code></p>
<p>9. Create a self signed certificate to encrypt connections</p>
<p><code>openssl req -new -outform PEM -out /etc/postfix/smtpd.cert -newkey rsa:2048 -nodes -keyout /etc/postfix/smtpd.key -keyform PEM -days 3650 -x509<br />
chmod 640 /etc/postfix/smtpd.key<br />
</code></p>
<p>10. Make Postfix listen on port 465 for secure smtp connections (pico /etc/postfix/master.cf)</p>
<p><code>smtps     inet  n       -       -       -       -       smtpd<br />
 -o smtpd_tls_wrappermode=yes<br />
 -o smtpd_sasl_auth_enable=yes<br />
 -o smtpd_client_restrictions=permit_sasl_authenticated,reject<br />
</code></p>
<p>11. Force SASL to store the PID files in a location where Postfix can read them</p>
<p><code>mkdir -p /var/spool/postfix/var/run/saslauthd<br />
</code></p>
<p>Edit SASL config to enable the daemon and make it use the new PID file location (pico /etc/default/saslauthd)</p>
<p><code>START=yes<br />
OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd -r"<br />
</code></p>
<p>Edit the init file for SASL (pico /etc/init.d/saslauthd)</p>
<p><code>PIDFILE="/var/spool/postfix/var/run/${NAME}/saslauthd.pid"<br />
</code></p>
<p>12. Insert MySql credentials for PAM (pico /etc/pam.d/smtp)</p>
<p><code>auth    required   pam_mysql.so user={mysql_username} passwd={mysql_password} host={mysql_host} db={mysql_database} table=users usercolumn=email passwdcolumn=password crypt=1<br />
account sufficient pam_mysql.so user={mysql_username} passwd={mysql_password} host={mysql_host} db={mysql_database} table=users usercolumn=email passwdcolumn=password crypt=1<br />
</code></p>
<p>13. Config SASL for Postfix and specify MySql credentials (pico /etc/postfix/sasl/smtpd.conf)</p>
<p><code>pwcheck_method: saslauthd<br />
mech_list: plain login<br />
allow_plaintext: true<br />
auxprop_plugin: mysql<br />
sql_hostnames: {mysql_host}<br />
sql_user: {mysql_username}<br />
sql_passwd: {mysql_password}<br />
sql_database: {mysql_database}<br />
sql_select: select password from users where email = '%u'<br />
</code></p>
<p>14. Add the Postfix user to the SASL group allowing Postfix to communicate with SASL</p>
<p><code>adduser postfix sasl<br />
</code></p>
<p>15. Restart Postfix and SASL</p>
<p><code>/etc/init.d/postfix restart<br />
/etc/init.d/saslauthd restart<br />
</code></p>
<p>You're all done. Now you can connect to ports 25 and 465 to sent mails to your virtual users specified in the MySql database. When authenticating with your e-mail client, use the full e-mail address as the username.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.debiantutorials.com/installing-postfix-with-mysql-backend-and-tls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
