Postfix - Virtual Domains
Z wiki linux-user
| Linia 221: | Linia 221: | ||
Tworzymy certyfikaty dla dovecot | Tworzymy certyfikaty dla dovecot | ||
| − | Jak to zrobić opisane jest | + | Jak to zrobić opisane jest [http://linux-user.eu/wiki/index.php/Postfix#Certyfikaty_TLS postfix#TLS] |
Przenosząc certyfikaty w odpowiednie miejsca | Przenosząc certyfikaty w odpowiednie miejsca | ||
| − | ssl_cert_file = /etc/pki/dovecot/certs/myserver.example.com.crt | + | ''ssl_cert_file = /etc/pki/dovecot/certs/myserver.example.com.crt''<br /> |
| − | ssl_key_file = /etc/pki/dovecot/private/myserver.example.com.key | + | ''ssl_key_file = /etc/pki/dovecot/private/myserver.example.com.key''<br /> |
| − | ssl_ca_file = /etc/pki/dovecot/certs/ca-bundle.crt | + | ''ssl_ca_file = /etc/pki/dovecot/certs/ca-bundle.crt''<br /> |
| − | Tworzymy plik /etc/dovecot/sql.conf i edytujemy go, aby wyglądał w następujący sposób: | + | Tworzymy plik ''/etc/dovecot/sql.conf'' i edytujemy go, aby wyglądał w następujący sposób: |
| − | driver = mysql | + | driver = mysql |
| − | default_pass_scheme = md5 | + | default_pass_scheme = md5 |
| − | connect = host=localhost dbname=postfix user=dovecot password=dovecot | + | connect = host=localhost dbname=postfix user=dovecot password=dovecot |
| − | user_query = SELECT concat('/var/vmail/', maildir) as home, concat('maildir:/var/vmail/', maildir) as mail, 101 AS uid, 12 AS gid, / | + | user_query = SELECT concat('/var/vmail/', maildir) as home, concat('maildir:/var/vmail/', maildir) as mail, 101 AS uid, 12 AS gid, / |
| − | concat('maildir:storage=', quota) AS quota FROM mailbox WHERE username = '%u' AND active = '1' | + | concat('maildir:storage=', quota) AS quota FROM mailbox WHERE username = '%u' AND active = '1' |
| − | # fast but now so nice:-) | + | # fast but now so nice:-) |
| − | #user_query = SELECT '/var/vmail/%d/%n' as home, 'maildir:/var/vmail/%d/%n' as mail, 101 AS uid, 12 AS gid, / | + | #user_query = SELECT '/var/vmail/%d/%n' as home, 'maildir:/var/vmail/%d/%n' as mail, 101 AS uid, 12 AS gid, / |
| − | concat('dirsize:storage=', quota) AS quota FROM mailbox WHERE username = '%u' AND active = '1' | + | concat('dirsize:storage=', quota) AS quota FROM mailbox WHERE username = '%u' AND active = '1' |
| − | # Just in case you are using postfix the delimiter char "+", the above query will probably fail for the username / | + | # Just in case you are using postfix the delimiter char "+", the above query will probably fail for the username / |
| − | '%n' or '%u' and result in a "5.5.1 user unknown" error | + | '%n' or '%u' and result in a "5.5.1 user unknown" error |
| − | #in this case, you will probalby want to use a separate user and domain part, whilst searching only / | + | #in this case, you will probalby want to use a separate user and domain part, whilst searching only / |
| − | for the destination user part (user_query only): | + | for the destination user part (user_query only): |
| − | # SELECT ... WHERE username = substring_index('%n','+',1) AND userrealm = '%d' | + | # SELECT ... WHERE username = substring_index('%n','+',1) AND userrealm = '%d' |
| − | password_query = SELECT username as user, password, concat('/var/vmail/', maildir) as userdb_home, / | + | password_query = SELECT username as user, password, concat('/var/vmail/', maildir) as userdb_home, / |
| − | concat('maildir:/var/vmail/', maildir) as userdb_mail, 101 as userdb_uid, 12 as userdb_gid FROM mailbox / | + | concat('maildir:/var/vmail/', maildir) as userdb_mail, 101 as userdb_uid, 12 as userdb_gid FROM mailbox / |
| − | WHERE username = '%u' AND active = '1' | + | WHERE username = '%u' AND active = '1' |
| − | # fast but now so nice:-) | + | # fast but now so nice:-) |
| − | #password_query = SELECT username as user, password, '/var/vmail/%d/%n' as userdb_home, / | + | #password_query = SELECT username as user, password, '/var/vmail/%d/%n' as userdb_home, / |
'maildir:/var/vmail/%d/%n' as userdb_mail, 101 as userdb_uid, 12 as userdb_gid FROM mailbox / | 'maildir:/var/vmail/%d/%n' as userdb_mail, 101 as userdb_uid, 12 as userdb_gid FROM mailbox / | ||
| − | WHERE username = '%u' AND active = '1' | + | WHERE username = '%u' AND active = '1' |
| − | UWAGA !! linie ze znakiem / są przełamane jeśli będziesz robił kopiuj wklej pamiętaj o połączeniu tych lini | + | '''UWAGA!!''' linie ze znakiem ''/'' są przełamane jeśli będziesz robił kopiuj wklej pamiętaj o połączeniu tych lini |
Jeśli zachodzi potrzeba to dostrajamy go do swoich potrzeb. | Jeśli zachodzi potrzeba to dostrajamy go do swoich potrzeb. | ||
| − | Kolejny plik który tworzymy to /etc/dovecot/trash.conf i dodajemy do niego | + | Kolejny plik który tworzymy to ''/etc/dovecot/trash.conf'' i dodajemy do niego |
| − | 1 Spam | + | 1 Spam |
| − | 2 Trash | + | 2 Trash |
| + | |||
| + | == Edycja postfixa == | ||
| + | |||
| + | |||
| + | Dodajemy do pliku ''master.cf'' następujące linijki | ||
| + | # Dovecot LDA | ||
| + | dovecot unix - n n - - pipe | ||
| + | flags=DRhu user=vmail:mail argv=/usr/libexec/dovecot/deliver -d ${recipient} | ||
| + | |||
| + | Następnie zmieniamy plik ''main.cf'' tak aby wyglądał następująco: | ||
| + | myhostname = my-domain.pl | ||
| + | inet_interfaces = all | ||
| + | myorigin = $myhostname | ||
| + | mynetworks = $config_directory/mynetworks | ||
| + | mydestination = localhost.$mydomain, localhost, #$myhostname | ||
| + | relay_domains = $mydestination | ||
| + | # ---------------------- VIRTUAL DOMAINS START ---------------------- | ||
| + | virtual_mailbox_domains = proxy:mysql:$config_directory/mysql_virtual_domains_maps.cf | ||
| + | virtual_mailbox_base = /var/vmail | ||
| + | virtual_mailbox_maps = proxy:mysql:$config_directory/mysql_virtual_mailbox_maps.cf | ||
| + | #virtual_alias_maps = proxy:mysql:$config_directory/mysql_virtual_alias_maps.cf | ||
| + | alias_maps = hash:/etc/aliases | ||
| + | virtual_mailbox_limit_maps = proxy:mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf | ||
| + | virtual_minimum_uid = 101 | ||
| + | virtual_uid_maps = static:101 | ||
| + | virtual_gid_maps = static:12 | ||
| + | virtual_transport = dovecot | ||
| + | dovecot_destination_recipient_limit = 1 | ||
| + | # ---------------------- VIRTUAL DOMAINS KONIEC ---------------------- | ||
| + | # ---------------------- SASL START ---------------------- | ||
| + | smtpd_sasl_auth_enable = yes | ||
| + | #smtpd_sasl_local_domain = $myhostname | ||
| + | smtpd_sasl_exceptions_networks = $mynetworks | ||
| + | smtpd_sasl_security_options = noanonymous | ||
| + | broken_sasl_auth_clients = yes | ||
| + | smtpd_sasl_type = dovecot | ||
| + | smtpd_sasl_path = private/auth | ||
| + | # ---------------------- SASL KONIEC ---------------------- | ||
| + | # ---------------------- TLS START ------------------------ | ||
| + | smtp_tls_CAfile = /etc/postfix/ssl/cacert.pem | ||
| + | smtp_tls_cert_file = /etc/postfix/ssl/smtpd.crt | ||
| + | smtp_tls_key_file = /etc/postfix/ssl/smtpd.key | ||
| + | #Postfix 2.5 albo wyzszy musi uzywac: | ||
| + | #smtp_tls_session_cache_database = btree:$data_directory/smtp_tls_session_cache | ||
| + | smtp_tls_session_cache_database = btree:/var/spool/postfix/smtp_tls_session_cache | ||
| + | smtp_tls_security_level = may | ||
| + | smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem | ||
| + | smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt | ||
| + | smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key | ||
| + | #Postfix 2.5 albo wyzszy musi uzywac: | ||
| + | #smtpd_tls_session_cache_database = btree:$data_directory/smtpd_tls_session_cache | ||
| + | smtpd_tls_session_cache_database = btree:/var/spool/postfix/smtpd_tls_session_cache | ||
| + | smtpd_tls_dh1024_param_file = $config_directory/dh_1024.pem | ||
| + | smtpd_tls_dh512_param_file = $config_directory/dh_512.pem | ||
| + | smtpd_tls_security_level = may | ||
| + | smtpd_tls_received_header = yes | ||
| + | smtpd_tls_ask_ccert = yes | ||
| + | smtpd_tls_loglevel = 1 | ||
| + | tls_random_source = dev:/dev/urandom | ||
| + | # ---------------------- TLS KONIEC ---------------------- | ||
| + | smtpd_helo_required = yes | ||
| + | disable_vrfy_command = yes | ||
| + | non_fqdn_reject_code = 450 | ||
| + | invalid_hostname_reject_code = 450 | ||
| + | maps_rbl_reject_code = 450 | ||
| + | #unverified_sender_reject_code = 550 | ||
| + | #header_checks = pcre:$config_directory/header_checks | ||
| + | #body_checks = pcre:$config_directory/body_checks | ||
| + | #warning: the restrictions reject_unknown_(sender|recipient)_domain | ||
| + | smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination, reject_rbl_client, | ||
| + | reject_non_fqdn_sender, reject_non_fqdn_recipient, reject_unlisted_recipient, reject_invalid_hostname | ||
| + | local_transport = virtual | ||
| + | readme_directory = /usr/share/doc/postfix-2.3.3/README_FILES | ||
| + | sample_directory = /usr/share/doc/postfix-2.3.3/samples | ||
| + | sendmail_path = /usr/sbin/sendmail | ||
| + | html_directory = no | ||
| + | setgid_group = postdrop | ||
| + | command_directory = /usr/sbin | ||
| + | manpage_directory = /usr/share/man | ||
| + | daemon_directory = /usr/libexec/postfix | ||
| + | newaliases_path = /usr/bin/newaliases | ||
| + | mailq_path = /usr/bin/mailq | ||
| + | queue_directory = /var/spool/postfix | ||
| + | mail_owner = postfix | ||
| + | unknown_local_recipient_reject_code = 450 | ||
| + | alias_database = | ||
| + | Tworzymy certyfikaty dla '''smtpd''' | ||
| + | Czyli znane nam już komendy | ||
| + | mkdir -P /etc/postfix/ssl | ||
| + | cd /etc/postfix/ssl | ||
| + | openssl genrsa -des3 -rand /etc/hosts -out smtpd.key 1024 | ||
| + | chmod 600 smtpd.key | ||
| + | openssl req -new -key smtpd.key -out smtpd.csr | ||
| + | openssl x509 -req -days 3650 -in smtpd.csr -signkey smtpd.key -out smtpd.crt | ||
| + | openssl rsa -in smtpd.key -out smtpd.key.unencrypted | ||
| + | mv -f smtpd.key.unencrypted smtpd.key | ||
| + | openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 365 | ||
| + | Tworzymy klucze ''dh'' używając biblioteki [[openssl]] | ||
| + | cd /etc/postfix | ||
| + | openssl dhparam -out dh_1024.pem 1024 | ||
| + | openssl dhparam -out dh_512.pem 512 | ||
| + | Następnie tworzymy pliki baz danych dla '''postfixa''' | ||
| + | |||
| + | Dodajemy kolejno pliki ''/etc/postfix/mysql_virtual_alias_maps.cf'' : | ||
| + | user = postfix | ||
| + | password = postfix | ||
| + | hosts = localhost | ||
| + | dbname = postfix | ||
| + | query = SELECT goto FROM alias WHERE address='%s' AND active = '1' | ||
| + | ''/etc/postfix/mysql_virtual_domains_maps.cf'': | ||
| + | |||
| + | user = postfix | ||
| + | password = postfix | ||
| + | hosts = localhost | ||
| + | dbname = postfix | ||
| + | #query = SELECT domain FROM domain WHERE domain='%s' | ||
| + | #optional query to use when relaying for backup MX | ||
| + | query = SELECT domain FROM domain WHERE domain='%s' AND backupmx = '0' AND active = '1'''/etc/postfix/mysql_relay_domains_maps.cf'': | ||
| + | user = postfix | ||
| + | password = postfix | ||
| + | hosts = localhost | ||
| + | dbname = postfix | ||
| + | query = SELECT domain FROM domain WHERE domain='%s' and backupmx = '1' | ||
| + | ''/etc/postfix/mysql_virtual_mailbox_limit_maps.cf'': | ||
| + | user = postfix | ||
| + | password = postfix | ||
| + | hosts = localhost | ||
| + | dbname = postfix | ||
| + | query = SELECT quota FROM mailbox WHERE username='%s' AND active = '1' | ||
| + | ''/etc/postfix/mysql_virtual_mailbox_maps.cf'': | ||
| + | user = postfix | ||
| + | password = postfix | ||
| + | hosts = localhost | ||
| + | dbname = postfix | ||
| + | query = SELECT CONCAT(domain,'/',maildir) FROM mailbox WHERE username='%s' AND active = '1' | ||
| + | Pamiętaj, aby zmienić liniki z hasłem, użytkownikiem lub z nazwą bazy danych jeśli masz inaczej. | ||
| + | Teraz edytujemy plik ''/etc/postfix/mynetworks'' i dodajemy do niego odpowiednie opcje | ||
| + | 192.168.2.0/24 moja.domena.pl | ||
| + | 127.0.0.0/8 | ||
| + | |||
| + | Oczywiście w pliku powyżej musisz podać swoje dane | ||
| + | |||
| + | |||
| + | == Konfiguracja Postfix.Admin == | ||
| + | |||
| + | Przechodzimy do katalogu głównego naszego serwera www i ściągamy pakiet '''postfix.admin''' na dzień dzisiejszy najnowszą wersją jest '''2.3.3''' | ||
| + | |||
| + | cd /var/www/html | ||
| + | wget http://sourceforge.net/projects/postfixadmin/files/postfixadmin/postfixadmin-2.3.3/postfixadmin-2.3.3.tar.gz/download | ||
| + | tar xvf postfixadmin-2.3.3.tar.gz | ||
| + | mv postfixadmin-2.3.3 postfixadmin | ||
| + | chown -R apache:apache postfixadmin | ||
| + | cd postfixadmin | ||
| + | vim config.sample.inc.php | ||
| + | |||
| + | Dostosowywujemy plik konfiguracyjny do naszych potrzeb, głównie chodzi o opcje związane z bazą danych i zmiane linijki | ||
| + | |||
| + | $CONF['configured'] = false; | ||
| + | |||
| + | na | ||
| + | |||
| + | $CONF['configured'] = true; | ||
| + | |||
| + | Poza tym opcje związane z połączeniem się do bazy danych | ||
| + | |||
| + | $CONF['database_type'] = 'mysql'; | ||
| + | $CONF['database_host'] = 'localhost'; | ||
| + | $CONF['database_user'] = 'postfixadmin'; | ||
| + | $CONF['database_password'] = 'postfixadmin'; | ||
| + | $CONF['database_name'] = 'postfix'; | ||
| + | |||
| + | Warto też edytować i przystosować do swoich potrzeb opcję | ||
| + | |||
| + | $CONF['postfix_admin_url'] = 'http://moja.domena.pl/postfixadmin'; | ||
| + | |||
| + | Po skończeniu i zapisaniu zmian zmieniamy nazwę pliku konfiguracyjnego | ||
| + | |||
| + | mv config.sample.inc.php config.inc.php | ||
| + | |||
| + | Wchodzimy do przegladarki i wpisujemy adres http://moja.domena.pl/postfixadmin/setup.php i postępujemy zgodnie z instrukcjami. | ||
| + | |||
| + | Na koniec, aby się zalogować do panelu administracyjnego wchodzimy na adres http://moja.domena.pl/postfixadmin/ | ||
| + | |||
| + | Pamiętajmy również o poprawnym skonfigurowaniu oprogramowania www do odbierania poczty np [[squirrelmail|squirrelmaila]] lub [[RoundCube|roundcube]] | ||
| + | |||
| + | Powyższą instalację możemy również wzbogacić o opcje typu filtrowanie treści czy doinstalowanie antywirusa i programu antyspamowego wszystkie te informacje zawarte są [[Postfix|tutaj]]. | ||
| + | |||
| + | <br /><google1 style="4"></google1> | ||
