postfix dovecot roundcube 를 이용한 mail server 구축 내용 입니다.
LAMP Stack 설치는 아래 링크를 참고해 주세요.
NAVER,GOOGLE 등으로 메일을 발송 하기 위해서는 SPF 설정이 필요 합니다.
http://dev.crois.net/2019/10/03/ubuntu-lamp-stack-%ec%84%a4%ec%b9%98/
사전작업
root@mail:~# apt upgrade -y root@mail:~# vi /etc/hosts 192.168.0.20 mail.test.com root@mail:~# init 6
LAMP Stack 설치는 생략합니다.
hostname 변경
root@mail:~# vi /etc/cloud/cloud.cfg preserve_hostname: true root@mail:~# hostnamectl set-hostname mail.test01.com root@mail:~# systemctl restart systemd-logind
apache rewrite module 활성화
root@mail:~# a2enmod rewrite root@mail:~# systemctl restart apache2
php 추가 패키지 설치 및 postfix 패키지 설치
root@mail:~# apt -y install php libapache2-mod-php php-mysql php-intl php-ldap php-imagick php-dom php-xml php-mbstring php-gd root@mail:~# apt install -y postfix
dpkg-reconfigure postfix 실행
root@mail:~# dpkg-reconfigure postfix
OK 를 눌러 설정을 진행 합니다.
Internet Site 를 선택합니다.
mail 도메인 이름을 지정합니다.
리다이렉트 설정 sanjuk user 는 sudo user 입니다.
메일큐 동기업데이트 설정 No 로 설정 합니다.
편지함 크기지정 Default 0 으로 설정 합니다.
postfix.cf 파일 수정
root@mail:~# cp /etc/postfix/main.cf /etc/postfix/main.cf.org root@mail:~# vi /etc/postfix/main.cf # See /usr/share/postfix/main.cf.dist for a commented, more complete version # Debian specific: Specifying a file name will cause the first # line of that file to be used as the name. The Debian default # is /etc/mailname. #myorigin = /etc/mailname ~ 중략 ## postfix settings home_mailbox = Maildir/ smtpd_sasl_type = dovecot smtpd_sasl_path = private/auth smtpd_sasl_local_domain = smtpd_sasl_security_options = noanonymous broken_sasl_auth_clients = yes smtpd_sasl_auth_enable = yes smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination smtp_tls_security_level = may smtpd_tls_security_level = may smtp_tls_note_starttls_offer = yes smtpd_tls_loglevel = 1 smtpd_tls_received_header = yes
single sign 인증서 생성 및 인증서 복사
root@mail:~# openssl genrsa -des3 -out server.key 2048 root@mail:~# openssl rsa -in server.key -out server.key.insecure root@mail:~# mv server.key server.key.secure root@mail:~# mv server.key.insecure server.key root@mail:~# openssl req -new -key server.key -out server.csr root@mail:~# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt root@mail:~# cp server.crt /etc/ssl/certs root@mail:~# cp server.key /etc/ssl/private
postconf 를 실행 하여 인증서 위치를 등록 합니다.
root@mail:~# postconf -e 'smtpd_tls_key_file = /etc/ssl/private/server.key' root@mail:~# postconf -e 'smtpd_tls_cert_file = /etc/ssl/certs/server.crt'
main.cf 파일수정
root@mail:~# vi /etc/postfix/master.cf ~중략 최하단에 설정 합니다. submission inet n - - - - smtpd -o syslog_name=postfix/submission -o smtpd_tls_security_level=encrypt -o smtpd_sasl_auth_enable=yes -o smtpd_relay_restrictions=permit_sasl_authenticated,reject -o milter_macro_daemon_name=ORIGINATING smtps inet n - n - - smtpd -o syslog_name=postfix/smtps -o smtpd_tls_wrappermode=yes -o smtpd_sasl_auth_enable=yes -o smtpd_relay_restrictions=permit_sasl_authenticated,reject -o milter_macro_daemon_name=ORIGINATING
dovecot SASL 설치 및 설정
root@mail:~# apt -y install dovecot-common root@mail:~# vi /etc/dovecot/conf.d/10-master.conf ~중략 # Postfix smtp-auth unix_listener /var/spool/postfix/private/auth { mode = 0660 user = postfix group = postfix } root@mail:~# vi /etc/dovecot/conf.d/10-auth.conf ~중략 auth_mechanisms = plain login
postfix / dovecot Daemon 활성화 및 실행
root@mail:~# systemctl enable dovecot root@mail:~# systemctl enable postfix root@mail:~# systemctl restart postfix root@mail:~# systemctl restart dovecot
메일 수신을 위하여 dovecot-imapd dovecot-pop3d 를 설치 합니다.
root@mail:~# apt -y install dovecot-imapd dovecot-pop3d root@mail:~# vi /etc/dovecot/conf.d/10-mail.conf #기존 30번 라인을 주석 처리 하고 24 번 라인의 주석을 삭제 합니다. 24 mail_location = maildir:~/Maildir 25 # mail_location = mbox:~/mail:INBOX=/var/mail/%u 26 # mail_location = mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%n 27 # 28 # <doc/wiki/MailLocation.txt> 29 # 30 #mail_location = mbox:~/mail:INBOX=/var/mail/%u root@mail:~# vi /etc/dovecot/conf.d/20-pop3.conf 50 pop3_uidl_format = %08Xu%08Xv
dovecot 데몬을 재시작 합니다.
root@mail:~# systemctl restart dovecot
메일 에서 사용하는 포트를 확인 합니다.
root@mail:~# netstat -nl4 Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:993 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:995 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:587 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:143 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:465 0.0.0.0:* LISTEN udp 0 0 127.0.0.53:53 0.0.0.0:* root@mail:~# 만약 25 port 가 없을 경우 postfix 가 정상적으로 설정 문제일수 있습니다. postfix check 명령어로 설정을 검증 할수 있습니다. root@mail:~# postfix chkeck postfix: fatal: /etc/postfix/main.cf, line 62: missing '=' after attribute name: "@mail:~#" root@mail:~#
php.ini 설정
php-fpm 을 사용하지 않을 경우 /etc/php/7.2/apache2/php.ini 파일을 설정 하시면 됩니다.
root@mail:~# vi /etc/php/7.2/fpm/php.ini date.timezone =Asia/Seoul root@mail:~# systemctl restart php7.2-fpm
Roundcube 설치
root@mail:~# cd /var/www/html/ root@mail:/var/www/html# wget https://github.com/roundcube/roundcubemail/releases/download/1.3.10/roundcubemail-1.3.10-complete.tar.gz root@mail:/var/www/html# tar xvf roundcubemail-1.3.10-complete.tar.gz root@mail:/var/www/html# mv roundcubemail-1.3.10 mail root@mail:/var/www/html# chown -R www-data:www-data mail/
roundcube db 생성
root@mail:~# mysql -uroot -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 49 Server version: 10.1.41-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04 Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> CREATE DATABASE roundcube; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> GRANT ALL PRIVILEGES ON roundcube.* TO 'roundcube'@'localhost' IDENTIFIED BY 'password'; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> quit; Bye root@mail:~#
Roundcube 설정
http://mail.test.com/mail/installer/
최하단의 NEXT 를 클릭합니다.
roundcube database 정보를 입력 합니다.
최하단의 CREATE CONFIG 를 클릭합니다.
CONTINUE 버튼을 클릭 하여 roundcube 설치를 완료 합니다.
Initialize database 를 클릭 합니다.
roundcube login 용 계정을 생성합니다.
root@mail:~# useradd -m test root@mail:~# passwd test
roundcube 에 로그인 합니다.
Test 가상 도메인 으로 사용하였기 때문에 일반적인 메일로 테스트는 불가 합니다.
일부 mail 서비스로는 테스트메일을 보낼수 있습니다. 🙂
Comments