메일 서버 · 18 min read · Sep 25, 2025
Postfix, Courier, MySQL 및 SquirrelMail을 이용한 가상 사용자 및 도메인 (Ubuntu 13.10)
이 튜토리얼은 2014년 Falko Timme & Srijan Kishore의 저작권이 있습니다. 이 튜토리얼은 http://workaround.org에서 찾을 수 있는 Christoph Haas의 튜토리얼을 기반으로 합니다. 이 튜토리얼은 Creative Commons 라이선스 2.5 또는 이후 버전 하에 자유롭게 사용할 수 있습니다.
이 문서는 MySQL 데이터베이스에 있는 가상 사용자 및 도메인을 기반으로 하는 Postfix 메일 서버를 설치하는 방법을 설명합니다. 또한 Courier(Courier-POP3, Courier-IMAP)의 설치 및 구성을 시연하여 Courier가 Postfix가 사용하는 동일한 MySQL 데이터베이스에 대해 인증할 수 있도록 합니다.
결과적으로 생성된 Postfix 서버는 SMTP-AUTH 및 TLS 및 쿼터를 지원합니다(쿼터는 기본적으로 Postfix에 내장되어 있지 않으며, Postfix를 적절하게 패치하는 방법을 보여드리겠습니다). 비밀번호는 데이터베이스에 암호화된 형태로 저장됩니다(내가 찾은 대부분의 문서는 보안 위험이 있는 일반 텍스트 비밀번호를 다루고 있었습니다). 이 튜토리얼은 또한 이메일이 스팸 및 바이러스를 검사할 수 있도록 Amavisd, SpamAssassin 및 ClamAV의 설치를 다룹니다. 또한 사용자가 이메일을 읽고 보내고 비밀번호를 변경할 수 있도록 웹메일 인터페이스로 SquirrelMail을 설치하는 방법도 보여드리겠습니다.
이러한 “가상” 설정(가상 사용자 및 도메인이 MySQL 데이터베이스에 있음)의 장점은 “실제” 시스템 사용자 기반의 설정보다 훨씬 더 성능이 뛰어나다는 것입니다. 이 가상 설정을 통해 메일 서버는 수천 개의 도메인과 사용자를 처리할 수 있습니다. 또한 새로운 사용자/도메인을 추가하거나 기존의 것을 편집할 때 MySQL 데이터베이스만 다루면 되므로 관리가 더 쉽습니다. 더 이상 db 파일을 생성하기 위한 postmap 명령이나 Postfix를 다시 로드할 필요가 없습니다. MySQL 데이터베이스 관리를 위해 phpMyAdmin과 같은 웹 기반 도구를 사용할 수 있으며, 이 방법에서도 설치됩니다. 세 번째 장점은 사용자가 사용자 이름으로 이메일 주소를 가지므로(사용자 이름 + 이메일 주소 대신) 이해하고 기억하기가 더 쉽다는 것입니다.
이 방법은 실용적인 가이드를 의미하며, 이론적 배경은 다루지 않습니다. 이론적 배경은 웹의 많은 다른 문서에서 다루어집니다.
이 문서는 어떤 종류의 보증 없이 제공됩니다! 이러한 시스템을 설정하는 유일한 방법이 아니라는 점을 말씀드리고 싶습니다. 이 목표를 달성하는 방법은 여러 가지가 있지만, 이것이 제가 선택한 방법입니다. 이것이 귀하에게 작동할 것이라는 보증을 제공하지 않습니다!
1 사전 참고
이 튜토리얼은 Ubuntu 13.10 Server(Saucy Salamander)를 기반으로 하므로, 이 튜토리얼을 계속 진행하기 전에 기본 Ubuntu 13.10 서버 설치를 설정해야 합니다. 시스템은 정적 IP 주소를 가져야 합니다. 이 튜토리얼에서는 192.168.0.100을 IP 주소로 사용하고 server1.example.com을 호스트 이름으로 사용합니다.
루트로 로그인했는지 확인하십시오(루트가 되려면
sudo su를 입력하십시오). 이 튜토리얼의 모든 단계를 루트 사용자로 실행해야 합니다.
/bin/sh를 /bin/bash에 대한 심볼릭 링크로 만드는 것이 매우 중요합니다…
dpkg-reconfigure dashdash를 기본 시스템 셸(/bin/sh)로 사용하시겠습니까? <– 아니요
… 그리고 AppArmor를 비활성화해야 합니다:
/etc/init.d/apparmor stop
update-rc.d -f apparmor remove
apt-get remove apparmor apparmor-utils2 Postfix, Courier, Saslauthd, MySQL, phpMyAdmin 설치
Postfix, Courier, Saslauthd, MySQL 및 phpMyAdmin을 설치하려면 다음 명령을 실행합니다.
apt-get install postfix postfix-mysql postfix-doc mysql-client mysql-server courier-authdaemon courier-authlib-mysql courier-pop courier-pop-ssl courier-imap courier-imap-ssl libsasl2-2 libsasl2-modules libsasl2-modules-sql sasl2-bin libpam-mysql openssl phpmyadmin apache2 libapache2-mod-php5 php5 php5-mysql libpam-smbpass몇 가지 질문을 받을 것입니다:
MySQL “root” 사용자에 대한 새 비밀번호: <– yourrootsqlpassword
MySQL “root” 사용자에 대한 비밀번호 반복: <– yourrootsqlpassword
웹 기반 관리용 디렉토리 생성? <– 아니요
메일 구성의 일반 유형: <– 인터넷 사이트
시스템 메일 이름: <– server1.example.com
SSL 인증서 필요 <– 확인
자동으로 재구성할 웹 서버: <– apache2
phpmyadmin의 데이터베이스를 dbconfig-common으로 구성하시겠습니까? <– 아니요
3 Postfix에 쿼타 패치 적용
Postfix 소스를 가져오고, 쿼타 패치로 패치한 후, 새로운 Postfix.deb 패키지를 빌드하고 설치해야 합니다:
apt-get build-dep postfixcd /usr/src
apt-get source postfix(다음 명령에서 올바른 Postfix 버전을 사용하고 있는지 확인하십시오. 저는 Postfix 2.10.2를 설치했습니다. 다음 명령을 실행하여 Postfix 버전을 확인할 수 있습니다.
postconf -d | grep mail_version출력은 다음과 같아야 합니다:
root@server1:/usr/src# postconf -d | grep mail_version
mail_version = 2.10.2
milter_macro_v = $mail_name $mail_version
root@server1:/usr/src#wget http://vda.sourceforge.net/VDA/postfix-vda-v13-2.10.0.patch
cd postfix-2.10.2
patch -p1 < ../postfix-vda-v13-2.10.0.patch다음으로 debian/rules를 열고 DEB_BUILD_HARDENING을 1에서 0으로 변경합니다:
vi debian/rules| [...] export DEB_BUILD_HARDENING=0 [...] |
이 작업을 수행하지 않으면 다음과 같은 오류 메시지와 함께 빌드가 실패합니다:
maildir.c: In function âdeliver_maildirâ:
maildir.c:974:17: error: format not a string literal and no format arguments [-Werror=format-security]
maildir.c:977:17: error: format not a string literal and no format arguments [-Werror=format-security]
maildir.c:983:17: error: format not a string literal and no format arguments [-Werror=format-security]
maildir.c:986:17: error: format not a string literal and no format arguments [-Werror=format-security]
maildir.c: In function âsql2fileâ:
maildir.c:404:25: warning: ignoring return value of âreadâ, declared with attribute warn_unused_result [-Wunused-result]
maildir.c:417:26: warning: ignoring return value of âwriteâ, declared with attribute warn_unused_result [-Wunused-result]
cc1: some warnings being treated as errors
make: * [maildir.o] Error 1
make: Leaving directory `/usr/src/postfix-2.10.2/src/virtual'
make[1]: * [update] Error 1
make[1]: Leaving directory `/usr/src/postfix-2.10.2'
make: *** [build] Error 2
dpkg-buildpackage: error: debian/rules build gave error exit status 2
root@server1:/usr/src/postfix-2.10.2#이제 새로운 Postfix.deb 패키지를 빌드할 수 있습니다:
dpkg-buildpackage이제 한 디렉토리 위로 이동합니다. 새로운 .deb 패키지가 생성된 곳입니다:
cd ..명령
ls -l은 사용 가능한 패키지를 보여줍니다:
root@server1:/usr/src# ls -l
total 7124
drwxr-xr-x 18 root root 4096 Apr 16 04:29 postfix-2.10.2
-rw-r--r-- 1 root root 48594 Apr 16 04:29 postfix-cdb_2.10.2-1_amd64.deb
-rw-r--r-- 1 root root 161974 Apr 16 04:29 postfix-dev_2.10.2-1_all.deb
-rw-r--r-- 1 root root 1094344 Apr 16 04:29 postfix-doc_2.10.2-1_all.deb
-rw-r--r-- 1 root root 57342 Apr 16 04:29 postfix-ldap_2.10.2-1_amd64.deb
-rw-r--r-- 1 root root 50554 Apr 16 04:29 postfix-mysql_2.10.2-1_amd64.deb
-rw-r--r-- 1 root root 50804 Apr 16 04:29 postfix-pcre_2.10.2-1_amd64.deb
-rw-r--r-- 1 root root 50756 Apr 16 04:29 postfix-pgsql_2.10.2-1_amd64.deb
-rw-r--r-- 1 root root 55701 Jun 7 2013 postfix-vda-v13-2.10.0.patch
-rw-r--r-- 1 root root 282175 Apr 16 04:28 postfix_2.10.2-1.diff.gz
-rw-r--r-- 1 root root 1522 Apr 16 04:28 postfix_2.10.2-1.dsc
-rw-r--r-- 1 root root 3899 Apr 16 04:29 postfix_2.10.2-1_amd64.changes
-rw-r--r-- 1 root root 1542368 Apr 16 04:29 postfix_2.10.2-1_amd64.deb
-rw-r--r-- 1 root root 3828326 Sep 12 2013 postfix_2.10.2.orig.tar.gzpostfix 및 postfix-mysql 패키지를 선택하고 다음과 같이 설치합니다:
dpkg -i postfix_2.10.2-1_amd64.deb postfix-mysql_2.10.2-1_amd64.deb4 Postfix/Courier용 MySQL 데이터베이스 생성
이제 mail이라는 데이터베이스를 생성합니다:
mysqladmin -u root -p create mail이 질문을 받을 것입니다:
비밀번호 입력: <– yourrootsqlpassword
다음으로 MySQL 셸로 이동합니다:
mysql -u root -pMySQL 셸에서 mail 데이터베이스에 대해 SELECT, INSERT, UPDATE, DELETE 권한을 가진 mail_admin 사용자(자신의 비밀번호로 교체)를 생성합니다. 이 사용자는 Postfix와 Courier가 메일 데이터베이스에 연결하는 데 사용됩니다:
GRANT SELECT, INSERT, UPDATE, DELETE ON mail.* TO 'mail_admin'@'localhost' IDENTIFIED BY 'mail_admin_password';
GRANT SELECT, INSERT, UPDATE, DELETE ON mail.* TO 'mail_admin'@'localhost.localdomain' IDENTIFIED BY 'mail_admin_password';
FLUSH PRIVILEGES;여전히 MySQL 셸에서 Postfix와 Courier에 필요한 테이블을 생성합니다:
USE mail;CREATE TABLE domains (
domain varchar(50) NOT NULL,
PRIMARY KEY (domain) )
ENGINE=MyISAM;CREATE TABLE forwardings (
source varchar(80) NOT NULL,
destination TEXT NOT NULL,
PRIMARY KEY (source) )
ENGINE=MyISAM;CREATE TABLE users (
email varchar(80) NOT NULL,
password varchar(20) NOT NULL,
quota INT(10) DEFAULT '10485760',
PRIMARY KEY (email)
) ENGINE=MyISAM;CREATE TABLE transport (
domain varchar(128) NOT NULL default '',
transport varchar(128) NOT NULL default '',
UNIQUE KEY domain (domain)
) ENGINE=MyISAM;quit;보시다시피 quit; 명령으로 MySQL 셸을 종료하고 리눅스 셸로 돌아왔습니다.
domains 테이블은 Postfix가 이메일을 수신해야 하는 각 가상 도메인을 저장합니다(예: example.com).
| domain |
| example.com |
forwardings 테이블은 하나의 이메일 주소를 다른 이메일 주소로 별칭하는 데 사용됩니다. 예를 들어 [email protected]의 이메일을 [email protected]로 전달합니다.
| source | destination |
| [email protected] | [email protected] |
users 테이블은 모든 가상 사용자(즉, 이메일 주소, 이메일 주소와 사용자 이름이 동일함)와 비밀번호( 암호화된 형태!) 및 각 메일 박스의 쿼타 값을 저장합니다(이 예제에서는 기본값이 10485760 바이트, 즉 10MB입니다).
| password | quota | |
| [email protected] | No9.E4skNvGa. (암호화된 형태의 “비밀“) | 10485760 |
transport 테이블은 선택 사항이며, 고급 사용자용입니다. 특정 사용자, 전체 도메인 또는 모든 메일을 다른 서버로 전달할 수 있습니다. 예를 들어,
| domain | transport |
| example.com | smtp:[1.2.3.4] |
는 example.com의 모든 이메일을 SMTP 프로토콜을 통해 IP 주소 1.2.3.4의 서버로 전달합니다(대괄호 []는 “MX DNS 레코드를 조회하지 마십시오”를 의미합니다(이는 IP 주소에 대해 의미가 있습니다…). 완전한 도메인 이름(FQDN)을 대신 사용할 경우 대괄호를 사용하지 않습니다.).
참고로(귀하의 메일 서버 시스템의 IP 주소가 192.168.0.100이라고 가정합니다), 브라우저에서 http://192.168.0.100/phpmyadmin/를 통해 phpMyAdmin에 액세스하고 mail_admin으로 로그인할 수 있습니다. 그런 다음 데이터베이스를 살펴볼 수 있습니다. 나중에 phpMyAdmin을 사용하여 메일 서버를 관리할 수 있습니다.
5 Postfix 구성
이제 Postfix에 데이터베이스에서 모든 정보를 찾을 수 있는 위치를 알려야 합니다. 따라서 여섯 개의 텍스트 파일을 생성해야 합니다. Postfix가 localhost 대신 IP 주소 127.0.0.1에 대해 MySQL에 연결하도록 지시하는 것을 알 수 있습니다. 이는 Postfix가 chroot 감옥에서 실행되고 MySQL 소켓에 접근할 수 없기 때문입니다. localhost를 사용하라고 지시하면 Postfix는 연결을 시도할 MySQL 소켓에 접근하려고 합니다. 127.0.0.1을 사용하면 Postfix는 TCP 네트워킹을 사용하여 MySQL에 연결하므로 chroot 감옥에서도 문제가 없습니다(대안은 MySQL 소켓을 chroot 감옥으로 이동하는 것이며, 이는 다른 문제를 일으킵니다).
/etc/mysql/my.cnf에 다음 줄이 포함되어 있는지 확인하십시오:
vi /etc/mysql/my.cnf| [...] # Instead of skip-networking the default is now to listen only on # localhost which is more compatible and is not less secure. bind-address = 127.0.0.1 [...] |
/etc/mysql/my.cnf를 수정해야 했다면 지금 MySQL을 재시작하십시오:
/etc/init.d/mysql restart다음 명령을 실행하여 MySQL이 127.0.0.1( localhost.localdomain)에서 수신 대기 중인지 확인하십시오:
netstat -tap | grep mysqlroot@server1:~# netstat -tap | grep mysql
tcp 0 0 localhost.localdo:mysql *:* LISTEN 24970/mysqld
root@server1:~#이제 여섯 개의 텍스트 파일을 생성합시다.
vi /etc/postfix/mysql-virtual_domains.cf| user = mail_admin password = mail_admin_password dbname = mail query = SELECT domain AS virtual FROM domains WHERE domain='%s' hosts = 127.0.0.1 |
vi /etc/postfix/mysql-virtual_forwardings.cf| user = mail_admin password = mail_admin_password dbname = mail query = SELECT destination FROM forwardings WHERE source='%s' hosts = 127.0.0.1 |
vi /etc/postfix/mysql-virtual_mailboxes.cf| user = mail_admin password = mail_admin_password dbname = mail query = SELECT CONCAT(SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1),'/') FROM users WHERE email='%s' hosts = 127.0.0.1 |
vi /etc/postfix/mysql-virtual_email2email.cf| user = mail_admin password = mail_admin_password dbname = mail query = SELECT email FROM users WHERE email='%s' hosts = 127.0.0.1 |
vi /etc/postfix/mysql-virtual_transports.cf| user = mail_admin password = mail_admin_password dbname = mail query = SELECT transport FROM transport WHERE domain='%s' hosts = 127.0.0.1 |
vi /etc/postfix/mysql-virtual_mailbox_limit_maps.cf| user = mail_admin password = mail_admin_password dbname = mail query = SELECT quota FROM users WHERE email='%s' hosts = 127.0.0.1 |
그런 다음 이러한 파일의 권한과 그룹을 변경합니다:
chmod o= /etc/postfix/mysql-virtual_*.cf
chgrp postfix /etc/postfix/mysql-virtual_*.cf이제 /home/vmail에 홈 디렉토리를 두고 vmail이라는 사용자 및 그룹을 생성합니다. 여기에서 모든 메일 박스가 저장됩니다.
groupadd -g 5000 vmail
useradd -g vmail -u 5000 vmail -d /home/vmail -m다음으로 Postfix 구성을 진행합니다. server1.example.com을 유효한 FQDN으로 교체해야 Postfix가 제대로 작동합니다!
postconf -e 'myhostname = server1.example.com'
postconf -e 'mydestination = server1.example.com, localhost, localhost.localdomain'
postconf -e 'mynetworks = 127.0.0.0/8'
postconf -e 'virtual_alias_domains ='
postconf -e 'virtual_alias_maps = proxy:mysql:/etc/postfix/mysql-virtual_forwardings.cf, mysql:/etc/postfix/mysql-virtual_email2email.cf'
postconf -e 'virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql-virtual_domains.cf'
postconf -e 'virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailboxes.cf'
postconf -e 'virtual_mailbox_base = /home/vmail'
postconf -e 'virtual_uid_maps = static:5000'
postconf -e 'virtual_gid_maps = static:5000'
postconf -e 'smtpd_sasl_auth_enable = yes'
postconf -e 'broken_sasl_auth_clients = yes'
postconf -e 'smtpd_sasl_authenticated_header = yes'
postconf -e 'smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination'
postconf -e 'smtpd_use_tls = yes'
postconf -e 'smtpd_tls_cert_file = /etc/postfix/smtpd.cert'
postconf -e 'smtpd_tls_key_file = /etc/postfix/smtpd.key'
postconf -e 'transport_maps = proxy:mysql:/etc/postfix/mysql-virtual_transports.cf'
postconf -e 'virtual_maildir_extended = yes'
postconf -e 'virtual_mailbox_limit_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailbox_limit_maps.cf'
postconf -e 'virtual_mailbox_limit_override = yes'
postconf -e 'virtual_maildir_limit_message = "The user you are trying to reach is over quota."'
postconf -e 'virtual_overquota_bounce = yes'
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'그 후 TLS에 필요한 SSL 인증서를 생성합니다:
cd /etc/postfix
openssl req -new -outform PEM -out smtpd.cert -newkey rsa:2048 -nodes -keyout smtpd.key -keyform PEM -days 365 -x509국가 이름(2자리 코드) [AU]: <– 귀하의 국가 이름 입력(예: “DE”).
주 또는 지방 이름(전체 이름) [Some-State]: <– 귀하의 주 또는 지방 이름 입력.
지역 이름(예: 도시) []: <– 귀하의 도시 입력.
조직 이름(예: 회사) [Internet Widgits Pty Ltd]: <– 귀하의 조직 이름 입력(예: 귀하의 회사 이름).
조직 단위 이름(예: 섹션) []: <– 귀하의 조직 단위 이름 입력(예: “IT 부서”).
공통 이름(예: 귀하의 이름) []: <– 시스템의 완전한 도메인 이름 입력(예: “server1.example.com”).
이메일 주소 []: <– 귀하의 이메일 주소 입력.
그런 다음 smtpd.key의 권한을 변경합니다:
chmod o= /etc/postfix/smtpd.key6 Saslauthd 구성
먼저 실행합니다.
mkdir -p /var/spool/postfix/var/run/saslauthd그런 다음 /etc/default/saslauthd를 편집합니다. START를 yes로 설정하고 OPTIONS=”-c -m /var/run/saslauthd” 줄을 OPTIONS=”-c -m /var/spool/postfix/var/run/saslauthd -r”로 변경합니다:
vi /etc/default/saslauthd| # # Settings for saslauthd daemon # Please read /usr/share/doc/sasl2-bin/README.Debian for details. # # Should saslauthd run automatically on startup? (default: no) START=yes # Description of this saslauthd instance. Recommended. # (suggestion: SASL Authentication Daemon) DESC="SASL Authentication Daemon" # Short name of this saslauthd instance. Strongly recommended. # (suggestion: saslauthd) NAME="saslauthd" # Which authentication mechanisms should saslauthd use? (default: pam) # # Available options in this Debian package: # getpwent -- use the getpwent() library function # kerberos5 -- use Kerberos 5 # pam -- use PAM # rimap -- use a remote IMAP server # shadow -- use the local shadow password file # sasldb -- use the local sasldb database file # ldap -- use LDAP (configuration is in /etc/saslauthd.conf) # # Only one option may be used at a time. See the saslauthd man page # for more information. # # Example: MECHANISMS="pam" MECHANISMS="pam" # Additional options for this mechanism. (default: none) # See the saslauthd man page for information about mech-specific options. MECH_OPTIONS="" # How many saslauthd processes should we run? (default: 5) # A value of 0 will fork a new process for each connection. THREADS=5 # Other options (default: -c -m /var/run/saslauthd) # Note: You MUST specify the -m option or saslauthd won't run! # # WARNING: DO NOT SPECIFY THE -d OPTION. # The -d option will cause saslauthd to run in the foreground instead of as # a daemon. This will PREVENT YOUR SYSTEM FROM BOOTING PROPERLY. If you wish # to run saslauthd in debug mode, please run it by hand to be safe. # # See /usr/share/doc/sasl2-bin/README.Debian for Debian-specific information. # See the saslauthd man page and the output of 'saslauthd -h' for general # information about these options. # # Example for chroot Postfix users: "-c -m /var/spool/postfix/var/run/saslauthd" # Example for non-chroot Postfix users: "-c -m /var/run/saslauthd" # # To know if your Postfix is running chroot, check /etc/postfix/master.cf. # If it has the line "smtp inet n - y - - smtpd" or "smtp inet n - - - - smtpd" # then your Postfix is running in a chroot. # If it has the line "smtp inet n - n - - smtpd" then your Postfix is NOT # running in a chroot. #OPTIONS="-c -m /var/run/saslauthd" OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd -r" |
그런 다음 /etc/pam.d/smtp 파일을 생성합니다. 이 파일에는 다음 두 줄만 포함되어야 합니다(정확한 데이터베이스 세부정보를 입력해야 합니다):
vi /etc/pam.d/smtp| auth required pam_mysql.so user=mail_admin passwd=mail_admin_password host=127.0.0.1 db=mail table=users usercolumn=email passwdcolumn=password crypt=1 account sufficient pam_mysql.so user=mail_admin passwd=mail_admin_password host=127.0.0.1 db=mail table=users usercolumn=email passwdcolumn=password crypt=1 |
그런 다음 /etc/postfix/sasl/smtpd.conf 파일을 생성합니다. 이 파일은 다음과 같아야 합니다:
vi /etc/postfix/sasl/smtpd.conf| pwcheck_method: saslauthd mech_list: plain login allow_plaintext: true auxprop_plugin: sql sql_engine: mysql sql_hostnames: 127.0.0.1 sql_user: mail_admin sql_passwd: mail_admin_password sql_database: mail sql_select: select password from users where email = '%u@%r' |
그런 다음 postfix 사용자를 sasl 그룹에 추가합니다(이렇게 하면 Postfix가 saslauthd에 접근할 수 있는 권한을 갖게 됩니다):
adduser postfix sasl그런 다음 Postfix와 Saslauthd를 재시작합니다:
/etc/init.d/postfix restart
/etc/init.d/saslauthd restart7 Courier 구성
이제 Courier가 MySQL 데이터베이스에 대해 인증하도록 지시해야 합니다. 먼저 /etc/courier/authdaemonrc를 편집하고 authmodulelist의 값을 다음과 같이 변경합니다:
vi /etc/courier/authdaemonrc| [...] authmodulelist="authmysql" [...] |
그런 다음 /etc/courier/authmysqlrc의 백업을 만들고 이전 파일을 비웁니다:
cp /etc/courier/authmysqlrc /etc/courier/authmysqlrc_orig
cat /dev/null > /etc/courier/authmysqlrc그런 다음 /etc/courier/authmysqlrc를 열고 다음 줄을 추가합니다:
vi /etc/courier/authmysqlrc| MYSQL_SERVER localhost MYSQL_USERNAME mail_admin MYSQL_PASSWORD mail_admin_password MYSQL_PORT 0 MYSQL_DATABASE mail MYSQL_USER_TABLE users MYSQL_CRYPT_PWFIELD password #MYSQL_CLEAR_PWFIELD password MYSQL_UID_FIELD 5000 MYSQL_GID_FIELD 5000 MYSQL_LOGIN_FIELD email MYSQL_HOME_FIELD "/home/vmail" MYSQL_MAILDIR_FIELD CONCAT(SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1),'/') #MYSQL_NAME_FIELD MYSQL_QUOTA_FIELD quota |
설치 중에 IMAP-SSL 및 POP3-SSL에 대한 SSL 인증서가 localhost라는 호스트 이름으로 생성됩니다. 이를 올바른 호스트 이름(server1.example.com으로 변경)으로 변경하려면 인증서를 삭제합니다…
cd /etc/courier
rm -f /etc/courier/imapd.pem
rm -f /etc/courier/pop3d.pem… 그리고 다음 두 파일을 수정합니다. CN=localhost를 CN=server1.example.com으로 바꿉니다(필요한 경우 다른 값도 수정할 수 있습니다):
vi /etc/courier/imapd.cnf| [...] CN=server1.example.com [...] |
vi /etc/courier/pop3d.cnf| [...] CN=server1.example.com [...] |
그런 다음 인증서를 다시 생성합니다…
mkimapdcert
mkpop3dcert… 그리고 Courier를 재시작합니다:
/etc/init.d/courier-authdaemon restart
/etc/init.d/courier-imap restart
/etc/init.d/courier-imap-ssl restart
/etc/init.d/courier-pop restart
/etc/init.d/courier-pop-ssl restarttelnet localhost pop3를 실행하여 POP3 서버가 제대로 작동하는지 확인할 수 있습니다. +OK Hello there.를 반환해야 합니다. (quit를 입력하여 리눅스 셸로 돌아갑니다.)
root@server1:/etc/courier# telnet localhost pop3
Trying ::1...
Connected to localhost.localdomain.
Escape character is '^]'.
+OK Hello there.
<-- quit
+OK Better luck next time.
Connection closed by foreign host.
root@server1:/etc/courier#8 /etc/aliases 수정
이제 /etc/aliases를 열어야 합니다. postmaster가 root를 가리키고 root가 자신의 사용자 이름이나 이메일 주소를 가리키도록 확인하십시오. 예를 들어 다음과 같이:
vi /etc/aliases| [...] postmaster: root root: [email protected] [...] |
또는 다음과 같이(관리자가 자신의 사용자 이름인 경우):
| [...] postmaster: root root: administrator [...] |
/etc/aliases를 수정할 때마다 다음과 같이 실행해야 합니다:
newaliases그런 다음 Postfix를 재시작합니다:
/etc/init.d/postfix restart9 amavisd-new, SpamAssassin 및 ClamAV 설치
amavisd-new, spamassassin 및 clamav를 설치하려면 다음 명령을 실행합니다:
apt-get install amavisd-new spamassassin clamav clamav-daemon zoo unzip bzip2 libnet-ph-perl libnet-snpp-perl libnet-telnet-perl nomarch lzop pax그런 다음 amavisd-new를 구성해야 합니다. 구성은 /etc/amavis/conf.d 디렉토리에 있는 여러 파일로 나뉘어 있습니다. 각 파일을 살펴보아 구성에 익숙해지십시오. 대부분의 설정은 괜찮지만 세 가지 파일을 수정해야 합니다:
먼저 /etc/amavis/conf.d/15-content_filter_mode에서 @bypass_virus_checks_maps 및 @bypass_spam_checks_maps 줄의 주석을 제거하여 ClamAV 및 SpamAssassin을 활성화해야 합니다:
vi /etc/amavis/conf.d/15-content_filter_mode파일은 다음과 같아야 합니다:
| use strict; # You can modify this file to re-enable SPAM checking through spamassassin # and to re-enable antivirus checking. # # Default antivirus checking mode # Please note, that anti-virus checking is DISABLED by # default. # If You wish to enable it, please uncomment the following lines: @bypass_virus_checks_maps = ( \ bypass_virus_checks, \ @bypass_virus_checks_acl, \ $bypass_virus_checks_re); # # Default SPAM checking mode # Please note, that anti-spam checking is DISABLED by # default. # If You wish to enable it, please uncomment the following lines: @bypass_spam_checks_maps = ( \ bypass_spam_checks, \ @bypass_spam_checks_acl, \ $bypass_spam_checks_re); 1; # ensure a defined return |
그런 다음 /etc/amavis/conf.d/20-debian_defaults에서 스팸 설정 및 스팸/바이러스 메일에 대한 작업을 살펴보십시오. 기본 설정이 괜찮다면 아무것도 변경할 필요가 없습니다. 이 파일에는 많은 설명이 포함되어 있으므로 여기에서 설정을 설명할 필요는 없습니다:
vi /etc/amavis/conf.d/20-debian_defaults| [...] $QUARANTINEDIR = "$MYHOME/virusmails"; $quarantine_subdir_levels = 1; # enable quarantine dir hashing $log_recip_templ = undef; # disable by-recipient level-0 log entries $DO_SYSLOG = 1; # log via syslogd (preferred) $syslog_ident = 'amavis'; # syslog ident tag, prepended to all messages $syslog_facility = 'mail'; $syslog_priority = 'debug'; # switch to info to drop debug output, etc $enable_db = 1; # enable use of BerkeleyDB/libdb (SNMP and nanny) $enable_global_cache = 1; # enable use of libdb-based cache if $enable_db=1 $inet_socket_port = 10024; # default listening socket $sa_spam_subject_tag = '*SPAM* '; $sa_tag_level_deflt = 2.0; # add spam info headers if at, or above that level $sa_tag2_level_deflt = 6.31; # add 'spam detected' headers at that level $sa_kill_level_deflt = 6.31; # triggers spam evasive actions $sa_dsn_cutoff_level = 10; # spam level beyond which a DSN is not sent [...] $final_virus_destiny = D_DISCARD; # (data not lost, see virus quarantine) $final_banned_destiny = D_BOUNCE; # D_REJECT when front-end MTA $final_spam_destiny = D_BOUNCE; $final_bad_header_destiny = D_PASS; # False-positive prone (for spam) [...] |
마지막으로 /etc/amavis/conf.d/50-user를 편집하고 중간에 $pax=’pax’; 줄을 추가합니다:
vi /etc/amavis/conf.d/50-user| use strict; # # Place your configuration directives here. They will override those in # earlier files. # # See /usr/share/doc/amavisd-new/ for documentation and examples of # the directives you can use in this file # $pax='pax'; #------------ Do not modify anything below this line ------------- 1; # ensure a defined return |
그런 다음 clamav 사용자를 amavis 그룹에 추가하고 amavisd-new 및 ClamAV를 재시작하는 명령을 실행합니다:
adduser clamav amavis
/etc/init.d/amavis restart
/etc/init.d/clamav-freshclam restart
/etc/init.d/clamav-daemon restart이제 Postfix가 수신 이메일을 amavisd-new를 통해 파이프하도록 구성해야 합니다:
postconf -e 'content_filter = amavis:[127.0.0.1]:10024'
postconf -e 'receive_override_options = no_address_mappings'그런 다음 /etc/postfix/master.cf에 다음 줄을 추가합니다:
vi /etc/postfix/master.cf| [...] amavis unix - - - - 2 smtp -o smtp_data_done_timeout=1200 -o smtp_send_xforward_command=yes 127.0.0.1:10025 inet n - - - - smtpd -o content_filter= -o local_recipient_maps= -o relay_recipient_maps= -o smtpd_restriction_classes= -o smtpd_client_restrictions= -o smtpd_helo_restrictions= -o smtpd_sender_restrictions= -o smtpd_recipient_restrictions=permit_mynetworks,reject -o mynetworks=127.0.0.0/8 -o strict_rfc821_envelopes=yes -o receive_override_options=no_unknown_recipient_checks,no_header_body_checks |
그런 다음 Postfix를 재시작합니다:
/etc/init.d/postfix restart이제 다음 명령을 실행합니다:
netstat -tapPostfix( master)가 포트 25( smtp) 및 10025에서 수신 대기 중이며 amavisd-new가 포트 10024에서 수신 대기 중인 것을 확인할 수 있습니다:
root@server1:/etc/courier# netstat -tap
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 *:http *:* LISTEN 6134/apache2
tcp 0 0 *:ssh *:* LISTEN 610/sshd
tcp 0 0 *:smtp *:* LISTEN 23128/master
tcp 0 0 localhost.localdo:10024 *:* LISTEN 21937/amavisd-new (
tcp 0 0 localhost.localdo:10025 *:* LISTEN 23128/master
tcp 0 0 localhost.localdo:mysql *:* LISTEN 4308/mysqld
tcp 0 52 server1.example.com:ssh 192.168.0.206:57597 ESTABLISHED 976/0
tcp6 0 0 [::]:ssh [::]:* LISTEN 610/sshd
tcp6 0 0 [::]:smtp [::]:* LISTEN 23128/master
tcp6 0 0 [::]:imaps [::]:* LISTEN 18191/couriertcpd
tcp6 0 0 [::]:pop3s [::]:* LISTEN 18259/couriertcpd
tcp6 0 0 [::]:pop3 [::]:* LISTEN 18222/couriertcpd
tcp6 0 0 [::]:imap2 [::]:* LISTEN 18154/couriertcpd
root@server1:/etc/courier#10 Razor, Pyzor 및 DCC 설치 및 SpamAssassin 구성
Razor, Pyzor 및 DCC는 협업 필터링 네트워크를 사용하는 스팸 필터입니다. Razor 및 Pyzor를 설치하려면 다음 명령을 실행합니다:
apt-get install razor pyzorDCC는 Ubuntu 13.10 리포지토리에서 사용할 수 없으므로 다음과 같이 설치합니다:
cd /tmp
wget http://www.dcc-servers.net/dcc/source/dcc-dccproc.tar.Z
tar xzvf dcc-dccproc.tar.Z
cd dcc-dccproc-1.3.1.154
./configure --with-uid=amavis
make
make install
chown -R amavis:amavis /var/dcc
ln -s /var/dcc/libexec/dccifd /usr/local/bin/dccifd이제 SpamAssassin에 이 세 가지 프로그램을 사용하도록 지시해야 합니다. /etc/spamassassin/local.cf를 편집하고 다음 줄을 추가합니다:
vi /etc/spamassassin/local.cf| [...] #dcc use_dcc 1 dcc_path /usr/local/bin/dccproc #pyzor use_pyzor 1 pyzor_path /usr/bin/pyzor #razor use_razor2 1 razor_config /etc/razor/razor-agent.conf #bayes use_bayes 1 use_bayes_rules 1 bayes_auto_learn 1 |
그런 다음 SpamAssassin에서 DCC 플러그인을 활성화해야 합니다. /etc/spamassassin/v310.pre를 열고 loadplugin Mail::SpamAssassin::Plugin::DCC 줄의 주석을 제거합니다:
vi /etc/spamassassin/v310.pre| [...] # DCC - perform DCC message checks. # # DCC is disabled here because it is not open source. See the DCC # license for more details. # loadplugin Mail::SpamAssassin::Plugin::DCC [...] |
SpamAssassin 구성을 확인하려면 다음을 실행합니다:
spamassassin --lint오류가 표시되지 않아야 합니다.
그런 다음 amavisd-new를 재시작합니다:
/etc/init.d/amavis restart이제 다음과 같이 SpamAssassin 규칙 세트를 업데이트합니다:
sa-update --no-gpg규칙 세트를 정기적으로 업데이트하기 위해 cron 작업을 생성합니다. 다음을 실행하여 cron 작업 편집기를 엽니다:
crontab -e다음 cron 작업을 생성합니다:
| 23 4 */2 * * /usr/bin/sa-update --no-gpg &> /dev/null |
이렇게 하면 매 2일마다 4시 23분에 규칙 세트가 업데이트됩니다.
새 게시물을 받은 편지함에서 받기
스팸은 없습니다. 언제든지 구독 해지 가능합니다.