개발노트
목록
[Linux] Sendmail 삭제 후 재설치
phpsendmaillinuxcentos
Server 2024.03.26 237 회 읽음
Server 24.03.26 237


서버 이전 후에 PHP에서 메일을 발송해보니 오류가 있어 상태를 확인해 보니 아래와 같은 에러 코드가 표시되고 있습니다.

원인을 찾는 것도 좋지만 일단은 삭제하고 재 설치하려고 합니다.


# service sendmail status

Redirecting to /bin/systemctl status sendmail.service
● sendmail.service - Sendmail Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/sendmail.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2024-03-26 10:46:13 KST; 41s ago
  Process: 543 ExecStart=/usr/sbin/sendmail -bd $SENDMAIL_OPTS $SENDMAIL_OPTARG (code=exited, status=0/SUCCESS)
  Process: 536 ExecStartPre=/etc/mail/make aliases (code=exited, status=0/SUCCESS)
  Process: 534 ExecStartPre=/etc/mail/make (code=exited, status=0/SUCCESS)
 Main PID: 545 (sendmail)
    Tasks: 1
   CGroup: /system.slice/sendmail.service
           └─545 /usr/sbin/sendmail -bd -q1h
Mar 26 10:46:33 gtfun.net sendmail[545]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
Mar 26 10:46:33 gtfun.net sendmail[545]: daemon MTA: problem creating SMTP socket
Mar 26 10:46:38 gtfun.net sendmail[545]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
Mar 26 10:46:38 gtfun.net sendmail[545]: daemon MTA: problem creating SMTP socket
Mar 26 10:46:43 gtfun.net sendmail[545]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
Mar 26 10:46:43 gtfun.net sendmail[545]: daemon MTA: problem creating SMTP socket
Mar 26 10:46:48 gtfun.net sendmail[545]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
Mar 26 10:46:48 gtfun.net sendmail[545]: daemon MTA: problem creating SMTP socket
Mar 26 10:46:53 gtfun.net sendmail[545]: NOQUEUE: SYSERR(root): opendaemonsocket: daemon MTA: cannot bind: Address already in use
Mar 26 10:46:53 gtfun.net sendmail[545]: daemon MTA: problem creating SMTP socket


서비스를 종료 합니다.

# service sendmail stop


먼저 설치 여부를 확인합니다.

# rpm -qa | grep sendmail
sendmail-cf-8.14.7-6.el7.noarch
sendmail-8.14.7-6.el7.x86_64


yum erase sendmail 명령어를 이용하여 삭제 해 봅니다.

# yum erase sendmail
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package sendmail.x86_64 0:8.14.7-6.el7 will be erased
--> Processing Dependency: sendmail = 8.14.7-6.el7 for package: sendmail-cf-8.14.7-6.el7.noarch
--> Running transaction check
---> Package sendmail-cf.noarch 0:8.14.7-6.el7 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================================================================================================
 Package                                 Arch                               Version                                    Repository                         Size
===============================================================================================================================================================
Removing:
 sendmail                                x86_64                             8.14.7-6.el7                               @base                             1.7 M
Removing for dependencies:
 sendmail-cf                             noarch                             8.14.7-6.el7                               @base                             938 k
Transaction Summary
===============================================================================================================================================================
Remove  1 Package (+1 Dependent package)
Installed size: 2.6 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : sendmail-cf-8.14.7-6.el7.noarch                                                                                                             1/2 
  Erasing    : sendmail-8.14.7-6.el7.x86_64                                                                                                                2/2 
warning: /etc/mail/trusted-users saved as /etc/mail/trusted-users.rpmsave
warning: /etc/mail/sendmail.mc saved as /etc/mail/sendmail.mc.rpmsave
warning: /etc/mail/sendmail.cf saved as /etc/mail/sendmail.cf.rpmsave
warning: /etc/mail/local-host-names saved as /etc/mail/local-host-names.rpmsave
warning: /etc/mail/access saved as /etc/mail/access.rpmsave
  Verifying  : sendmail-cf-8.14.7-6.el7.noarch                                                                                                             1/2 
  Verifying  : sendmail-8.14.7-6.el7.x86_64                                                                                                                2/2 
Removed:
  sendmail.x86_64 0:8.14.7-6.el7                                                                                                                               
Dependency Removed:
  sendmail-cf.noarch 0:8.14.7-6.el7                                                                                                                            
Complete!



Sendmail 설치


1. 설치하기

yum install sendmail sendmail-cf 명령어를 이용하여 설치 합니다.

# yum install sendmail sendmail-cf
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.kakao.com
 * epel: mirror-nrt.yuki.net.uk
 * extras: mirror.kakao.com
 * remi-php74: cdn.centos.no
 * remi-safe: cdn.centos.no
 * updates: mirror.kakao.com
Resolving Dependencies
--> Running transaction check
---> Package sendmail.x86_64 0:8.14.7-6.el7 will be installed
---> Package sendmail-cf.noarch 0:8.14.7-6.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================================================================================================
 Package                                 Arch                               Version                                     Repository                        Size
===============================================================================================================================================================
Installing:
 sendmail                                x86_64                             8.14.7-6.el7                                base                             737 k
 sendmail-cf                             noarch                             8.14.7-6.el7                                base                             186 k
Transaction Summary
===============================================================================================================================================================
Install  2 Packages
Total download size: 923 k
Installed size: 2.6 M
Is this ok [y/d/N]: y
Downloading packages:
(1/2): sendmail-cf-8.14.7-6.el7.noarch.rpm                                                                                              | 186 kB  00:00:00     
(2/2): sendmail-8.14.7-6.el7.x86_64.rpm                                                                                                 | 737 kB  00:00:00     
---------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                          2.9 MB/s | 923 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : sendmail-8.14.7-6.el7.x86_64                                                                                                                1/2 
  Installing : sendmail-cf-8.14.7-6.el7.noarch                                                                                                             2/2 
  Verifying  : sendmail-cf-8.14.7-6.el7.noarch                                                                                                             1/2 
  Verifying  : sendmail-8.14.7-6.el7.x86_64                                                                                                                2/2 
Installed:
  sendmail.x86_64 0:8.14.7-6.el7                                               sendmail-cf.noarch 0:8.14.7-6.el7                                              
Complete!


서비스를 활성화 해 줍니다.

systemctl enable sendmail



2. 환경 값 수정하기

/etc/mail/sendmail.mc 파일을 수정하기 위해 해당 파일을 열고 아래 52,53 라인과 116 라인 부분의 주석을 해제하고 동일하게 수정 해 줍니다.

#52 TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl

#53 define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl

# 116 DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA')dnl


# vi /etc/mail/sendmail.mc
# 52 line
TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
# 53 line
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
# 116
DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA')dnl
# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf


/etc/mail/access 파일으 열어서 허용할 도메인을 입력합니다.

#  vi /etc/mail/access
# Check the /usr/share/doc/sendmail/README.cf file for a description
# of the format of this file. (search for access_db in that file)
# The /usr/share/doc/sendmail/README.cf is part of the sendmail-doc
# package.
#
# If you want to use AuthInfo with "M:PLAIN LOGIN", make sure to have the
# cyrus-sasl-plain package installed.
#
# By default we allow relaying from localhost...
Connect:localhost.localdomain           RELAY
Connect:localhost                       RELAY
Connect:127.0.0.1                       RELAY Connect:gtfun.com RELAY Connect:gtfun.net RELAY Connect:mininam.com RELAY


설정한 정보를 저장 해줍니다.

 makemap hash /etc/mail/access < /etc/mail/access


이메일 서비스를 시작 해 줍니다.

# systemctl start sendmail


메일이 발송되지 않을 때에는 포트가 열려있는지 확인합니다.

# netstat -nltp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      6939/sendmail: acce 
tcp        0      0 0.0.0.0:4049            0.0.0.0:*               LISTEN      624/perl            
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1033/sshd           
tcp6       0      0 :::443                  :::*                    LISTEN      1680/httpd          
tcp6       0      0 :::3306                 :::*                    LISTEN      7351/mariadbd       
tcp6       0      0 :::80                   :::*                    LISTEN      1680/httpd  


목록