Debian 11에서 PostfixAdmin으로 메일 서버를 설정하는 방법

Debian 11에서 PostfixAdmin으로 메일 서버를 설정하는 방법

2022-10-18 last update

8 minutes reading server linux email postfix debian
PostfixAdmin은 웹 브라우저에서 Postfix 메일 서버를 관리하는 데 사용되는 무료 오픈 소스 웹 기반 인터페이스입니다. 사용자, 별칭을 추가하고 디스크 할당량을 설정하고 웹 기반 인터페이스에서 도메인을 추가 및 제거할 수 있습니다. PostgreSQL, MySQL, MariaDB 및 SQLite를 포함한 여러 데이터베이스 백엔드를 지원합니다. 플러그인을 통해 Squirrelmail 및 Roundcube와 통합할 수 있습니다.
이 기사에서는 Debian 11에 PostfixAdmin을 설치하는 방법을 설명합니다.

전제 조건


  • postfix가 설치된 Debian 11을 실행하는 서버.
  • 유효한 도메인 이름은 서버 IP 주소를 가리킵니다.
  • 유효한 MX 레코드는 서버 IP 주소를 가리킵니다.
  • 시작하기


    먼저 다음 명령을 사용하여 시스템 패키지를 최신 버전으로 업데이트합니다.

    apt-get update -y
    시스템이 업데이트되면 서버의 정규화된 호스트 이름을 설정하십시오.
    hostnamectl set-hostname mail.domain.com
    그런 다음 다음 명령을 실행하여 변경 사항을 적용합니다.
    hostname -f
    완료되면 다음 단계로 진행할 수 있습니다.(adsbygoogle=window.adsbygoogle||[]).push({});

    Nginx, MariaDB 및 PHP 설치


    다음으로 Nginx 웹 서버, MariaDB, PHP 및 기타 필수 PHP 확장을 서버에 설치해야 합니다. 다음 명령으로 모두 설치할 수 있습니다.
    apt-get install nginx mariadb-server php-fpm php-cli php-imap php-json php-mysql php-opcache php-mbstring php-readline unzip sudo -y
    모든 패키지가 설치되면 다음 단계로 진행할 수 있습니다.

    PostfixAdmin 데이터베이스 생성


    다음으로 PostfixAdmin에 대한 데이터베이스와 사용자를 생성해야 합니다. 먼저 다음 명령을 사용하여 MariaDB 콘솔에 로그인합니다.
    mysql
    연결되면 다음 명령을 사용하여 데이터베이스와 사용자를 생성합니다.
    MariaDB [(none)]> CREATE DATABASE postfixadmin;
    MariaDB [(none)]> GRANT ALL ON postfixadmin.* TO 'postfixadmin'@'localhost' IDENTIFIED BY 'securepassword';
    다음으로 다음 명령을 사용하여 권한을 플러시하고 MariaDB 셸을 종료합니다.
    MariaDB [(none)]> FLUSH PRIVILEGES;
    MariaDB [(none)]> EXIT;
    이 시점에서 PostfixAdmin용 MariaDB 데이터베이스가 생성됩니다. 이제 다음 단계로 진행할 수 있습니다.

    PostfixAdmin 설치


    먼저 Sourceforge 웹사이트에서 최신 버전의 PostfixAdmin을 다운로드해야 합니다. 다음 명령으로 다운로드할 수 있습니다.
    wget https://webwerks.dl.sourceforge.net/project/postfixadmin/postfixadmin-3.3.8/PostfixAdmin%203.3.8.tar.gz
    다운로드가 완료되면 다음 명령으로 다운로드한 파일의 압축을 풉니다.
    tar -xvzf PostfixAdmin\ 3.3.8.tar.gz
    다음으로 압축을 푼 디렉터리를 Nginx 웹 루트 디렉터리로 이동합니다.
    mv postfixadmin-postfixadmin-7d04685 /var/www/html/postfixadmin
    다음으로 PostfixAdmin을 설치하는 데 필요한 디렉터리를 만듭니다.
    mkdir /var/www/html/postfixadmin/templates_c
    다음으로 PostfixAdmin 디렉토리에 적절한 소유권을 설정합니다.
    chown -R www-data: /var/www/html/postfixadmin/
    다음으로 config.local.php 파일을 만듭니다.
    nano /var/www/html/postfixadmin/config.local.php
    다음 줄을 추가합니다.
    <?php
    $CONF['configured'] = true;
     
    $CONF['database_type'] = 'mysqli';
    $CONF['database_host'] = 'localhost';
    $CONF['database_user'] = 'postfixadmin';
    $CONF['database_password'] = 'securepassword';
    $CONF['database_name'] = 'postfixadmin';
     
    $CONF['default_aliases'] = array (
     'abuse' => '[email protected]',
     'hostmaster' => '[email protected]',
     'postmaster' => '[email protected]',
     'webmaster' => '[email protected]'
    );
     
    $CONF['fetchmail'] = 'NO';
    $CONF['show_footer_text'] = 'NO';
     
    $CONF['quota'] = 'YES';
    $CONF['domain_quota'] = 'YES';
    $CONF['quota_multiplier'] = '1024000';
    $CONF['used_quotas'] = 'YES';
    $CONF['new_quota_table'] = 'YES';
     
    $CONF['aliases'] = '0';
    $CONF['mailboxes'] = '0';
    $CONF['maxquota'] = '0';
    $CONF['domain_quota_default'] = '0';
    ?>
    

    Save and close the file then create the schema for the PostfixAdmin database with the following command:

    sudo -u www-data php /var/www/html/postfixadmin/public/upgrade.php
    다음으로 PostfixAdmin에 대한 최고 관리자 계정을 만들어야 합니다. 다음 명령으로 생성할 수 있습니다.
    bash /var/www/html/postfixadmin/scripts/postfixadmin-cli admin add
    아래와 같이 관리자 사용자 이름, 암호 및 도메인을 제공합니다.
    Welcome to Postfixadmin-CLI v0.3
    ---------------------------------------------------------------
    
    Admin:  
    > [email protected]
    
    Password:  
    > [email protected]
    
    Password (again):  
    > [email protected]
    
    Super admin:
    (Super admins have access to all domains, can manage domains and admin accounts.) (y/n) 
    > y
    
    Domain:  
    > domain.com
    
    Active: (y/n) 
    > y
    
    The admin [email protected] has been added!
    
    ---------------------------------------------------------------
    

    PostfixAdmin용 Nginx 구성

    Next, you will need to create an Nginx virtual host configuration file for PostfixAdmin. You can create it with the following command:

    nano /etc/nginx/conf.d/domain.com.conf
    다음 줄을 추가합니다.
    server {
            listen 80;
            root /var/www/html/postfixadmin/public;
            index index.html index.htm index.php;
            server_name mail.domain.com;
    
            location ~ \.php$ {
              fastcgi_split_path_info ^(.+\.php)(/.+)$;
              fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
              fastcgi_index index.php;
              include fastcgi_params;
              fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
              fastcgi_intercept_errors off;
              fastcgi_buffer_size 16k;
              fastcgi_buffers 4 16k;
              fastcgi_connect_timeout 600;
              fastcgi_send_timeout 600;
              fastcgi_read_timeout 600;
            }
    
    
       location / {
           try_files $uri $uri/ =404;
       }
    
    }
    

    Save and close the file then restart the Nginx service to apply the changes:

    systemctl restart nginx
    다음 명령을 사용하여 Nginx의 상태를 확인할 수도 있습니다.
    systemctl status nginx
    다음과 같은 결과가 나와야 합니다.
    ? nginx.service - A high performance web server and a reverse proxy server
         Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
         Active: active (running) since Sat 2021-08-28 08:13:22 UTC; 7s ago
           Docs: man:nginx(8)
        Process: 74644 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
        Process: 74645 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
       Main PID: 74646 (nginx)
          Tasks: 2 (limit: 2341)
         Memory: 3.2M
            CPU: 57ms
         CGroup: /system.slice/nginx.service
                 ??74646 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
                 ??74647 nginx: worker process
    
    Aug 28 08:13:22 mail.domain.com systemd[1]: Starting A high performance web server and a reverse proxy server...
    Aug 28 08:13:22 mail.domain.com systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
    Aug 28 08:13:22 mail.domain.com systemd[1]: Started A high performance web server and a reverse proxy server.
    

    PostfixAdmin에 액세스


    이 시점에서 PostfixAdmin이 설치 및 구성됩니다. 이제 URL http://mail.domain.com을 사용하여 액세스할 수 있습니다. PostfixAdmin 로그인 페이지로 리디렉션됩니다.

    관리자 이메일, 비밀번호를 입력하고 로그인 버튼을 클릭합니다. 다음 화면에 PostfixAdmin 대시보드가 ​​표시되어야 합니다.

    결론


    축하합니다! Debian 11에 PostfixAdmin을 성공적으로 설치했습니다. 이제 웹 브라우저에서 Postfix 메일 서버를 쉽게 관리할 수 있습니다. 궁금한 점이 있으면 언제든지 문의해 주세요.