IRedMail/FAQ/Store.Realtime.Quota.In.MySQL

From iRedMail

(Difference between revisions)
Jump to: navigation, search
(Steps)
(Test)
 
(11 intermediate revisions not shown)
Line 2: Line 2:
= Requirements =
= Requirements =
-
* Dovecot 1.2.x
+
* Dovecot 1.2.x. If you're using dovecot-1.1.x, please [[iRedMail/FAQ/Upgrade.Dovecot.1.1.to.1.2 |Upgrade Dovecot 1.1.x to 1.2.x]] first.
= Steps =
= Steps =
Line 9: Line 9:
{{cfg|/etc/dovecot.conf|<pre>
{{cfg|/etc/dovecot.conf|<pre>
plugin {
plugin {
-
     #quota = maildir                       # <- Comment this line.
+
     #quota = maildir                         # <- Comment this line.
     quota = dict:user::proxy::quotadict      # <- Add this line.
     quota = dict:user::proxy::quotadict      # <- Add this line.
Line 19: Line 19:
{{cfg|/etc/dovecot.conf|<pre>
{{cfg|/etc/dovecot.conf|<pre>
dict {
dict {
-
     quotadict = mysql:/etc/dovecot-realtime-quota.conf
+
     quotadict = mysql:/etc/dovecot-used-quota.conf       # <- Add this line.
     # ... SKIP OTHER CONFIG HERE ...
     # ... SKIP OTHER CONFIG HERE ...
Line 25: Line 25:
</pre>}}
</pre>}}
-
* '''[For OpenLDAP backend]''' Create MySQL tables '''realtime_quota''' in database '''iredadmin''' used to store realtime quota info. (Of course you can use other database instead of '''iredadmin'''.)
+
* '''[For OpenLDAP backend]''' Create MySQL tables '''used_quota''' in database '''iredadmin''' used to store realtime quota info. (Of course you can use other database instead of '''iredadmin'''.)
{{cmd|<pre>
{{cmd|<pre>
$ mysql -uroot -p iredadmin
$ mysql -uroot -p iredadmin
-
mysql> CREATE TABLE IF NOT EXISTS realtime_quota (
+
mysql> CREATE TABLE IF NOT EXISTS `used_quota` (
     `username` VARCHAR(255) NOT NULL,
     `username` VARCHAR(255) NOT NULL,
     `bytes` BIGINT(20) NOT NULL DEFAULT 0,
     `bytes` BIGINT(20) NOT NULL DEFAULT 0,
Line 43: Line 43:
</pre>}}
</pre>}}
-
* Create file '''/etc/dovecot-realtime-quota.conf''' ('''Note''': Change '''dbname''', '''table''' if you're using MySQL backend):
+
'''Note''': Column '''"bytes"''' stores size of all mails in user's mailbox, column '''"messages"''' stores number of all mails in user's mailbox.
-
{{cfg|/etc/dovecot-realtime-quota.conf|<pre>
+
 
-
connect = host=localhost dbname=iredadmin user=root password=passwd
+
* Create file '''/etc/dovecot-used-quota.conf'''. Note:
 +
** If you're using iRedAdmin with OpenLDAP backend (either Open Source Edition or iRedAdmin-Pro), you can find database user and password in its config file '''settings.ini''', under iRedAdmin installation root directory, in section '''[iredadmin]'''.
 +
** Change '''dbname''', '''table''' if you're using MySQL backend.
 +
 
 +
{{cfg|/etc/dovecot-used-quota.conf|<pre>
 +
connect = host=localhost dbname=iredadmin user=iredadmin password=passwd
map {
map {
     pattern = priv/quota/storage
     pattern = priv/quota/storage
-
     table = realtime_quota
+
     table = used_quota
     username_field = username
     username_field = username
-
     value_field = currentbytes
+
     value_field = bytes
}
}
map {
map {
     pattern = priv/quota/messages
     pattern = priv/quota/messages
-
     table = realtime_quota
+
     table = used_quota
     username_field = username
     username_field = username
-
     value_field = currentmessages
+
     value_field = messages
}
}
</pre>}}
</pre>}}
 +
 +
Note: You can find
* Restart dovecot and it should work as expected now.
* Restart dovecot and it should work as expected now.
 +
 +
= Test =
 +
* Restart dovecot.
 +
* Restart postfix.
 +
* Log into webmail. Dovecot will update table 'used_quota' when mail arrived or removed.
 +
* Log into phpMyAdmin and check whether there's any records in table 'used_quota'. Sample data:
 +
{{cmd|<pre>
 +
mysql> select * from used_quota;
 +
+----------+-------+----------+
 +
| username | bytes | messages |
 +
+----------+-------+----------+
 +
| www@a.cn |  9907 |        2 |
 +
+----------+-------+----------+
 +
</pre>}}
= References =
= References =
* Dovecot dictionary quota: http://wiki.dovecot.org/Quota/Dict
* Dovecot dictionary quota: http://wiki.dovecot.org/Quota/Dict
* [http://www.iredmail.org/forum/topic1306-enh-mysqlbased-used-quota.html Article contributed by @maxie_ro, works with Dovecot-1.1.x]
* [http://www.iredmail.org/forum/topic1306-enh-mysqlbased-used-quota.html Article contributed by @maxie_ro, works with Dovecot-1.1.x]
 +
 +
 +
[[Category: iRedMail/FAQ]]
 +
[[Category: FAQ]]

Current revision as of 10:58, 27 May 2012

Contents


Requirements

Steps

  • Replace file based quota by quotadict in /etc/dovecot.conf:
File: /etc/dovecot.conf
plugin {
    #quota = maildir                          # <- Comment this line.
    quota = dict:user::proxy::quotadict       # <- Add this line.

    # ... SKIP OTHER CONFIG HERE ...
}
  • Add quotadict in dict section in /etc/dovecot.conf:
File: /etc/dovecot.conf
dict {
    quotadict = mysql:/etc/dovecot-used-quota.conf        # <- Add this line.

    # ... SKIP OTHER CONFIG HERE ...
}
  • [For OpenLDAP backend] Create MySQL tables used_quota in database iredadmin used to store realtime quota info. (Of course you can use other database instead of iredadmin.)
Terminal:
$ mysql -uroot -p iredadmin
mysql> CREATE TABLE IF NOT EXISTS `used_quota` (
    `username` VARCHAR(255) NOT NULL,
    `bytes` BIGINT(20) NOT NULL DEFAULT 0,
    `messages` BIGINT(20) NOT NULL DEFAULT 0,
    PRIMARY KEY (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  • [For MySQL backend] If you're using iRedMail-0.6.1 or order version, you can simply add two columns in table vmail.mailbox:
Terminal:
$ mysql -uroot -p vmail
mysql> ALTER TABLE mailbox ADD COLUMN `bytes` BIGINT(20) NOT NULL DEFAULT 0;
mysql> ALTER TABLE mailbox ADD COLUMN `messages` BIGINT(20) NOT NULL DEFAULT 0;

Note: Column "bytes" stores size of all mails in user's mailbox, column "messages" stores number of all mails in user's mailbox.

  • Create file /etc/dovecot-used-quota.conf. Note:
    • If you're using iRedAdmin with OpenLDAP backend (either Open Source Edition or iRedAdmin-Pro), you can find database user and password in its config file settings.ini, under iRedAdmin installation root directory, in section [iredadmin].
    • Change dbname, table if you're using MySQL backend.
File: /etc/dovecot-used-quota.conf
connect = host=localhost dbname=iredadmin user=iredadmin password=passwd
map {
    pattern = priv/quota/storage
    table = used_quota
    username_field = username
    value_field = bytes
}
map {
    pattern = priv/quota/messages
    table = used_quota
    username_field = username
    value_field = messages
}

Note: You can find

  • Restart dovecot and it should work as expected now.

Test

  • Restart dovecot.
  • Restart postfix.
  • Log into webmail. Dovecot will update table 'used_quota' when mail arrived or removed.
  • Log into phpMyAdmin and check whether there's any records in table 'used_quota'. Sample data:
Terminal:
mysql> select * from used_quota;
+----------+-------+----------+
| username | bytes | messages |
+----------+-------+----------+
| www@a.cn |  9907 |        2 | 
+----------+-------+----------+

References

Personal tools