Install Postfix dovecot with mysql background - postfix-mta

I have spent about 3 days to install the Postfix, dovecot and mysql on my VPS server. It has been a very frustrating process. I have googled painfully for 3 days and collected the information piece by piece and eventually made this combination work.
Just want to list steps and all configuration files together, hopefully useful for who is also undergoing the painful process.
make mysql ready, and create database postfix (or whatever the name you want), create mysql user postfix and grant all privilege to postfix database.
Create the following tables:
CREATE TABLE virtual_domains (
id int(11) NOT NULL auto_increment,
name varchar(50) NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE virtual_aliases (
id int(11) NOT NULL auto_increment,
domain_id int(11) NOT NULL,
source varchar(100) NOT NULL,
destination varchar(100) NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (domain_id) REFERENCES virtual_domains(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE virtual_users (
id int(11) NOT NULL auto_increment,
domain_id int(11) NOT NULL,
password varchar(32) NOT NULL,
email varchar(100) NOT NULL,
maildir varchar(255) NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY email (email),
FOREIGN KEY (domain_id) REFERENCES virtual_domains(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Compile Postfix with mysql support, you should see the bunch of postfix configuration files:
main.cf
[root#mail postfix]#postconf -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /var/postfix/usr/sbin
compatibility_level = 2
daemon_directory = /var/postfix/usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6 /binddd
$daemon_directory/$process_name $process_id & sleep 5
home_mailbox = Maildir/
html_directory = no
inet_interfaces = all
inet_protocols = ipv4
mail_owner = postfix
mail_spool_directory = /home
mailq_path = /var/postfix/usr/bin/mailq
manpage_directory = /usr/local/man
meta_directory = /etc/postfix
mydomain = myspeedshow.com
myhostname = mail.yourdoamin.com
mynetworks_style = host
myorigin = $mydomain
newaliases_path = /var/postfix/usr/bin/newaliases
postscreen_greet_banner = "before smtp banner"
postscreen_greet_wait = 2s
postscreen_non_smtp_command_enable = no
postscreen_pipelining_enable = no
queue_directory = /var/spool/postfix
readme_directory = no
recipient_delimiter = +
sample_directory = /etc/postfix
sendmail_path = /var/postfix/usr/sbin/sendmail
setgid_group = postdrop
shlib_directory = no
smtpd_banner = $myhostname ESMTP $mail_name
smtpd_recipient_restrictions =
reject_invalid_hostname,<br>
reject_unknown_recipient_domain,
reject_unauth_pipelining,
permit_mynetworks,
reject_unauth_destination,
reject_rbl_client zen.spamhaus.org,
reject_rbl_client bl.spamcop.net,
reject_rbl_client dnsbl.sorbs.net,
reject_rbl_client cbl.abuseat.org,
reject_rbl_client b.barracudacentral.org,
reject_rbl_client dnsbl-1.uceprotect.net,
permit<br>
smtpd_sasl_auth_enable = yes
smtpd_sasl_path = private/auth
smtpd_sasl_type = dovecot
smtpd_tls_auth_only = yes
smtputf8_enable = no
unknown_local_recipient_reject_code = 550
virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-alias- maps.cf,mysql:/etc/postfix/mysql-email2email.cf
virtual_gid_maps = static:5000
virtual_mailbox_base = /var/vmail
virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-mailbox-domains.cf
virtual_mailbox_limit = 51200000
virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf
virtual_transport = virtual
virtual_uid_maps = static:5000
master.cf
relay unix - - n - - smtp
flush unix n - n 1000? 0 flush
trace unix - - n - 0 bounce
verify unix - - n - 1 verify
rewrite unix - - - - - trivial-rewrite
proxymap unix - - n - - proxymap
anvil unix - - n - 1 anvil
scache unix - - n - 1 scache
discard unix - - n - - discard
tlsmgr unix - - n 1000? 1 tlsmgr
retry unix - - n - - error
proxywrite unix - - n - 1 proxymap
smtp unix - - n - - smtp
smtp inet n - n - 1 postscreen
smtpd pass - - n - - smtpd
lmtp unix - - n - - lmtp
cleanup unix n - n - 0 cleanup
qmgr fifo n - n 300 1 qmgr
virtual unix - n n - - virtual
dovecot unix - n n - - pipe
flags=DRhu user=vmail:vmail argv=/usr/local/libexec/dovecot /dovecot-lda -f ${sender} -d ${recipient}
mysql-virtual-mailbox-domains.cf
user=postfix
password=yourpassword
host=127.0.0.1
dbname=postfix
query=select name from virtual_domains where name='%s'
mysql-virtual-mailbox-maps.cf
user=postfix
password=yourpassword
dbname=postfix
query=select maildir from virtual_users where email='%s'
mysql-virtual-alias-maps.cf
user=postfix
password=yourpassword
host=127.0.0.1
dbname=postfix
query=select destination from virtual_aliases where source='%s'
The next step is to configure the Dovecot.
10-auth.conf
disable_plaintext_auth = yes
auth_mechanisms = plain login
!include auth-sql.conf.ext
comments out all other !include
auth-sql.conf.ext
passdb {
driver = sql
args = /etc/dovecot/dovecot-sql.conf.ext
}
userdb {
driver = static
args = uid=vmail gid=vmail home=/var/vmail/%d/%n
}
10-mail.conf
comments out all mail_location
Here we use Maildir format to store the email in:
/var/vmail/domain/user/Maildir/ folder, in virtual_users table, the column maildir should be in the following format 'yourdomain.com/user/Maildir/'
If you have not populated the virtual_users.maildir column correctly, the postfix will use mailbox format, which store all mail belong to a domain to a file /var/vmail/1.

Related

mariadb cluster synced but one node shows size=0

I use mariadb 10.5 with galera 4. I have a 3 node cluster which worked perfectly for the past 6 months. Lately I have been having problems with very cpu intensive query and had to kill that process. One of the nodes (n1) went out of sync so I recreated it. Everything synced perfectly but since that day n1 shows wsrep_cluster_size=0 and the rest of them show wsrep_cluster_size=3.
After a couple of days I decided to stop n2 and n3 to recreate it from n1. Again everything went smoothly but now n3 shows wsrep_cluster_size=0 and n1,n2 show wsrep_cluster_size=3.
I have no idea what's going on. I've checked all the logs and manually checked all the tables and everything seems ok. Data is synced and database is working just fine.
Heres is my configuration
[mysqld]
binlog_format = ROW
bind-address = 0.0.0.0
# Galera Provider Configuration
wsrep_on = ON
wsrep_provider = /usr/lib/galera/libgalera_smm.so
# Galera Cluster Configuration
wsrep_cluster_name = cluser
wsrep_cluster_address = gcomm://10.0.0.2,10.0.0.3,10.0.0.4
wsrep_node_address = 10.0.0.2
wsrep_node_name = n1
# Galera Synchronization Configuration
wsrep_sst_method = rsync
log_error = /var/lib/mysql/node.log
default_storage_engine = InnoDB
innodb_autoinc_lock_mode = 2
innodb_locks_unsafe_for_binlog = 1
innodb_file_per_table = 1
#innodb_thread_concurrency = 0
innodb_buffer_pool_size = 10G
#innodb_log_buffer_size = 64M
innodb_flush_method = O_DIRECT
innodb_log_file_size = 2G
innodb_log_files_in_group = 2
wsrep_slave_threads = 5
innodb_locks_unsafe_for_binlog = 1
innodb_autoinc_lock_mode = 2
skip-name-resolve
lc-messages-dir = /usr/share/mysql
skip-external-locking
key_buffer_size = 16M
max_connections = 300
wait_timeout = 20
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
# * Query Cache Configuration
#
query_cache_limit = 1M
query_cache_size = 16M
expire_logs_days = 10
max_binlog_size = 100M
Here is my SHOW STATUS LIKE 'wsrep%' for 3 nodes
https://pastebin.com/GXj0c38R
And logs
https://pastebin.com/YxJBcguK
This is definitely a bug. Please report it on MariaDB JIRA.
In addition to the wsrep_cluster_size=0 on n3, wsrep_cluster_conf_id is uninitialised (and not the 23 like other nodes) and wsrep_cluster_state_uuid is blank.
For a synced node I'd expect these to have consistent values on all nodes.

Slow Query in Big Database

I have slow queries with a mysql request. But the request is not difficult:
SELECT * FROM emailarchiv WHERE typ='MAIL' AND benutzer = '542' ORDER BY datum DESC LIMIT 0,50;
# User#Host: XXX[XXX] # localhost []
# Thread_id: 13245239 Schema: usr_XXX_1 QC_hit: No
# Query_time: 20.919740 Lock_time: 0.000066 Rows_sent: 50 Rows_examined: 79212
Ok, in the database are 79212 entrys...but 20seconds???
My System: Centos7 MariaDB 5.5, 10GB RAM, 10 CPUs
Here my my.conf:
[mysqld]
local-infile = 0
datadir = /var/lib/mysql
socket = /var/lib/mysql/mysql.sock
user = mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
# Forced OLD_PASSWORD format is turned OFF by Plesk
#old_passwords = 1
# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links = 0
max_connections = 100
#port = 3306 #Port nicht aendern
key_buffer_size = 512M
max_allowed_packet = 256M
table_open_cache = 4096
sort_buffer_size = 64M
net_buffer_length = 128K
read_buffer_size = 1512K
read_rnd_buffer_size = 4096K
myisam_sort_buffer_size = 64M
max_heap_table_size = 512M
tmp_table_size = 1024M
key_cache_block_size = 4096
query_cache_size = 512M
query_cache_limit = 512M
thread_cache_size = 20
table_cache = 16384
#open_files_limit = 9212 #nicht aktivieren!! Verursacht Probleme...
#wait_timeout = 10 #nicht aktivieren !!
join_buffer_size = 32M
#bind-address = 127.0.0.1
#Aenderungen ab 23.07.2021
innodb_buffer_pool_size = 512M
max_heap_table_size= 1024M
skip-name-resolve
slow-query-log = 1
slow-query-log-file = /srv/slow-query.log
long_query_time = 5
ssl-ca=/etc/mysql-ssl/ca-cert.pem
ssl-cert=/etc/mysql-ssl/server-cert.pem
ssl-key=/etc/mysql-ssl/server-key.pem
[mysqld_safe]
#log-error = /var/log/mysqld.log
What goes here wrong?
I solved the problem by myself ;-)
I don't use indexes for the rows "typ" and "benutzer" that was the problem. Now the Query_time is 2 seconds 👍

Postfix spf - delivers spoofing emails. Not fail

I started receiving spoofing emails. So I set up my server and domain but I still receive emails. SPF is not rejecting emails.
Can anyone help?
dns records
myserver.com. IN TXT "v=spf1 a mx a:myserver.com ip4:50.111.111.111 -all"
_dmarc.myserver.com. IN TXT "v=DMARC1; p=reject; fo=1; ri=3600; pct=100; rua=mailto:info#myserver.com; ruf=mailto:info#myserver.com
/etc/postfix-policyd-spf-python/policyd-spf.conf
debugLevel = 1
HELO_reject = Fail
Mail_From_reject = Fail
PermError_reject = False
TempError_Defer = False
skip_addresses = 127.0.0.0/8,::ffff:127.0.0.0/104,::1
postfix - main.cnf
smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination unix check_policy_service: private / policyd-SPF reject_unauth_pipelining, reject_invalid_helo_hostname, reject_non_fqdn_helo_hostname, reject_unknown_recipient_domain, reject_rbl_client zen.spamhaus.org, bl.spamcop.net reject_rbl_client, check_policy_service inet: 127.0.0.1: 10023
postfix - master.cf
policyd-spf unix - n n - 0 spawn
user = policyd-spf argv = /usr/bin/policyd-spf
mail.log
Oct 12 21:13:36 myserver policyd-spf [26371]: None; identity = helo; client-ip = 72,167,234,237; helo = p3nlsmtp12.shr.prod.phx3.secureserver.net; envelope-from=test#baddkim.com; receiver=mymail#myserver.com
Oct 12 21:13:36 myserver policyd-spf [26371]: None; identity = mailfrom; client-ip = 72,167,234,237; helo = p3nlsmtp12.shr.prod.phx3.secureserver.net; envelope-from=test#baddkim.com; receiver=mymail#myserver.com
Oct 12 21:13:36 myserver policyd-spf [26369]: Pass; identity = mailfrom; client-ip = 72,167,234,237; helo = p3nlsmtp12.shr.prod.phx3.secureserver.net; envelope-from=test#emailspooftest.com; receiver=mymail#myserver.com
Oct 12 21:13:36 myserver postfix / smtpd [22955]: BFA1981347: client = p3nlsmtp12.shr.prod.phx3.secureserver.net [72.167.234.237]
Oct 12 21:13:36 myserver postgrey [2322]: action = pass, reason = triplet found, client_name = p3nlsmtp12.shr.prod.phx3.secureserver.net, client_address = 72.167.234.237, sender=test#baddkim.com, recipient=mymail#myserver.com
Oct 12 21:13:36 myserver postfix / smtpd [26363]: C1ADE814FA: client = p3nlsmtp12.shr.prod.phx3.secureserver.net [72.167.234.237]
Oct 12 21:13:36 myserver postgrey [2322]: action = pass, reason = triplet found, client_name = p3nlsmtp12.shr.prod.phx3.secureserver.net, client_address = 72.167.234.237, sender=test#emailspooftest.com, recipient=mymail#myserver.com

Query filesystems and DB utilization using vi editor

I am currently monitoring multiple systems' OS (Unix) filesystem utilization and DB (Sybase) utilization. I would like to query those in one file using the vi editor. My script goes like this:
df -h
su - sybpg1
isql -Usapsa -SPG1 -PMaster4SID -w999 -X
declare #pagesize numeric(19,0)
select #pagesize=(select ##maxpagesize)
SELECT "Database Name" = CONVERT(char(30), db_name(D.dbid)),
"Data Size MB" = STR(SUM(CASE WHEN U.segmap != 4 THEN U.size*#pagesize/1048576 END),10,1),
"Used Data MB" = STR(SUM(CASE WHEN U.segmap != 4 THEN size - curunreservedpgs(U.dbid, U.lstart, U.unreservedpgs)END)*#pagesize/1048576,10,1),
"Data Full%" = STR(100 * (1 - 1.0 * SUM(CASE WHEN U.segmap != 4 THEN curunreservedpgs(U.dbid, U.lstart, U.unreservedpgs) END)/SUM(CASE WHEN U.segmap != 4 THEN U.size END)),9,1) ,
"Log Size MB" = STR(SUM(CASE WHEN U.segmap = 4 THEN U.size*#pagesize/1048576 END),10,1),
"Free Log MB" = STR(lct_admin("logsegment_freepages",D.dbid)*#pagesize/1048576,10,1),
"Log Full%" = STR(100 * (1 - 1.0 * lct_admin("logsegment_freepages",D.dbid) /
SUM(CASE WHEN U.segmap = 4 THEN U.size END)),8,1)
FROM master..sysdatabases D,
master..sysusages U
WHERE U.dbid = D.dbid
AND ((D.dbid != 2))
GROUP BY D.dbid
ORDER BY db_name(D.dbid)
go
but whenever i execute:
sh filename
It was able to enter sybase, however couldn't get pass through the isql line.
It goes something like this:
sybsid.sh: line 6: isql: command not found
Hope you could help me out.
Thanks!

how to configure Postfix to send more emails per hour than the default [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
My postfix only let me send only 3600 email in an hour ( from which i conclude that there is 1s delay between each email ) while I want to send double that number .. I looked in the postfix configuration .Is there any parameters that i can change to send more than 3600 email in an hour ?
this is the output of postconf -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
bounce_queue_lifetime = 1d
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
default_destination_concurrency_limit = 5
default_destination_rate_delay = 0s
html_directory = no
inet_interfaces = all
inet_protocols = ipv4
initial_destination_concurrency = 2
lmtp_destination_rate_delay = 0s
local_destination_rate_delay = 0s
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
maximal_queue_lifetime = 1d
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mydomain = example.com
myhostname = server01.example.com
myorigin = $mydomain
newaliases_path = /usr/bin/newaliases.postfix
qmgr_message_recipient_limit = 10000
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.5.6/README_FILES
relay_destination_rate_delay = 0s
sample_directory = /usr/share/doc/postfix-2.5.6/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
smtp_bind_address = xxx.xxx.xxx.xxx
smtp_destination_rate_delay = 0s
smtp_generic_maps = hash:/etc/postfix/generic
smtpd_banner = $myhostname ESMTP $mail_name
smtpd_client_restrictions = check_client_access hash:/etc/postfix/access
unknown_local_recipient_reject_code = 550
virtual_alias_maps = hash:/etc/postfix/virtual
virtual_destination_rate_delay = 0s
see this,
you can play around with
default_recipient_limit
qmgr_message_recipient_limit
default_destination_rate_delay
The default amount of delay that is inserted between individual deliveries to the same destination; with per-destination recipient limit > 1, a destination is a domain, otherwise it is a recipient.
To enable the delay, specify a non-zero time value (an integral value plus an optional one-letter suffix that specifies the time unit).
Time units: s (seconds), m (minutes), h (hours), d (days), w (weeks). The default time unit is s (seconds).
NOTE: the delay is enforced by the queue manager. The delay timer state does not survive "postfix reload" or "postfix stop".
Use transport_destination_rate_delay to specify a transport-specific override, where transport is the master.cf name of the message delivery transport.
This feature is available in Postfix 2.5 and later.
http://www.postfix.org/postconf.5.html

Resources