7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PHP mb_send_mail EC2 mail送れない。

Last updated at Posted at 2015-09-04

お急ぎのかたは、目次:1=>4.5.6.7へ
初歩的な事かもしれないですが、ハマって色々触ったのでメモ

構成 AWS利用

・ EC2インスタンスを2台立ている。
・ ELBを利用して振り分けている。

問題

片方のServerでMail送信時エラー発生している。

[000] [error] [client 00.0.0.00] exec exception:\n
sendmail: fatal: config variable inet_interfaces: host not found: localhost

問題確認

とりあえず設定ファイルを確認

1.grepでpostconf設定内容確認

 [000/root]$ postconf | grep size
berkeley_db_create_buffer_size = 16777216
berkeley_db_read_buffer_size = 131072
body_checks_size_limit = 51200
bounce_size_limit = 50000
header_size_limit = 102400
mailbox_size_limit = 51200000
message_size_limit = 10240000
tcp_windowsize = 0

[000 /root]$ postconf | grep size
berkeley_db_create_buffer_size = 16777216
berkeley_db_read_buffer_size = 131072
body_checks_size_limit = 51200
bounce_size_limit = 50000
header_size_limit = 102400
postconf: fatal: config variable inet_interfaces: host not found: localhost

設定値がおかしい!
とりあえず、

2.設定ファイルの差分とってみる。

[user@ip-00-0-0-000 ~]$ if diff <(ssh -i *****.pem root@00.0.0.00 cat /etc/postfix/main.cf) <(ssh -i *****.pem root@00.0.0.000 cat /etc/postfix/main.cf) ; then
> echo yes
> else
> echo no
> fi
yes

設定ファイル内容は同じ。
ちなみにPHP.iniも原因ではない。

[0000 /root]$ php -i | grep php.ini
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/php.ini

[user@ip-00-0-0-000 ~]$ if diff <(ssh -i *****.pem root@00.0.0.00 cat /etc/php.ini) <(ssh -i *****.pem root@00.0.0.000 cat /etc/php.ini) ; then
> echo no
> else
> echo yes
> fi
453c453
< error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE & ~E_WARNING
---
> error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_WARNING & ~E_NOTICE
yes

3.プロセスの確認

[000 /root]$ /etc/init.d/postfix status
-b dead but pid file exists
[000 /root]$ ps aux | grep postfix
root     18691  0.0  0.0 103240   868 pts/0    S+   14:44   0:00 grep postfix

プロセスが実行されて無い?

[000 /root]$ sudo /etc/init.d/postfix stop 
Shutting down postfix:                                     [  FIELD  ]
[000 /root]$ sudo /etc/init.d/postfix start
Starting postfix:                                          [  FIELD ]

???

4. ???

あれ結局エラーってなんだっけ?

sendmail: fatal: config variable inet_interfaces: host not found: localhost

localhostさんは誰ですか?

[000 /root]$ ping localhost
ping: unknown host localhost

5.localhostの設定確認

[000 /root]$ vi /etc/hosts
000.0.0.0               localhost.localdomain ap1
::1             localhost6.localdomain6 localhost6

00.0.0.000      db

localhost居ないじゃん!

6.localhostの設定

[000 /root]$ vi /etc/hosts
000.0.0.0               localhost.localdomain ap1 localhost
::1             localhost6.localdomain6 localhost6

00.0.0.000      db

7.postfix再起動

[000 /root]$ sudo /etc/init.d/postfix stop
Shutting down postfix:                                     [  OK  ]
[000 /root]$ sudo /etc/init.d/postfix start
Starting postfix:                                          [  OK  ]

直ったー!

8.おまけ

mail_log確認

[000 /root]$ tail /var/log/maillog

postfix_commondの内容確認

[000 /etc/init.d]$ cat postfix
----------
RETVAL=0
prog="postfix"
lockfile=/var/lock/subsys/$prog
pidfile=/var/spool/postfix/pid/master.pid

ALIASESDB_STAMP=/var/lib/misc/postfix.aliasesdb-stamp

# Script to update chroot environment
CHROOT_UPDATE=/etc/postfix/chroot-update

status -p $pidfile -l $(basename $lockfile) -b /usr/libexec/postfix/master master >/dev/null 2>&1
running=$?

conf_check() {
    [ -x /usr/sbin/postfix ] || exit 5
    [ -d /etc/postfix ] || exit 6
    [ -d /var/spool/postfix ] || exit 5
}

make_aliasesdb() {
	if [ "$(/usr/sbin/postconf -h alias_database)" == "hash:/etc/aliases" ]
	then
		# /etc/aliases.db may be used by other MTA, make sure nothing
		# has touched it since our last newaliases call
		[ /etc/aliases -nt /etc/aliases.db ] ||
			[ "$ALIASESDB_STAMP" -nt /etc/aliases.db ] ||
			[ "$ALIASESDB_STAMP" -ot /etc/aliases.db ] || return
		/usr/bin/newaliases
		touch -r /etc/aliases.db "$ALIASESDB_STAMP"
	else
		/usr/bin/newaliases
	fi
}

start() {
	[ "$EUID" != "0" ] && exit 4
	# Check that networking is up.
	[ ${NETWORKING} = "no" ] && exit 1
	conf_check
	# Start daemons.
	echo -n $"Starting postfix: "
	make_aliasesdb >/dev/null 2>&1
	[ -x $CHROOT_UPDATE ] && $CHROOT_UPDATE
	/usr/sbin/postfix start 2>/dev/null 1>&2 && success || failure $"$prog start"
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch $lockfile
        echo
	return $RETVAL
}

stop() {
	[ "$EUID" != "0" ] && exit 4
	conf_check
        # Stop daemons.
	echo -n $"Shutting down postfix: "
	/usr/sbin/postfix stop 2>/dev/null 1>&2 && success || failure $"$prog stop"
	RETVAL=$?
	[ $RETVAL -eq 0 ] && rm -f $lockfile $pidfile
	echo
	return $RETVAL
}

reload() {
	conf_check
	echo -n $"Reloading postfix: "
	[ -x $CHROOT_UPDATE ] && $CHROOT_UPDATE
	/usr/sbin/postfix reload 2>/dev/null 1>&2 && success || failure $"$prog reload"
	RETVAL=$?
	echo
	return $RETVAL
}

abort() {
	conf_check
	/usr/sbin/postfix abort 2>/dev/null 1>&2 && success || failure $"$prog abort"
	return $?
}

flush() {
	conf_check
	/usr/sbin/postfix flush 2>/dev/null 1>&2 && success || failure $"$prog flush"
	return $?
}

check() {
	conf_check
	/usr/sbin/postfix check 2>/dev/null 1>&2 && success || failure $"$prog check"
	return $?
}

# See how we were called.
case "$1" in
  start)
	[ $running -eq 0 ] && exit 0
	start
	;;
  stop)
	[ $running -eq 0 ] || exit 0
	stop
	;;
  restart|force-reload)
	stop
	start
	;;
  reload)
	[ $running -eq 0 ] || exit 7
	reload
	;;
  abort)
	abort
	;;
  flush)
	flush
	;;
  check)
	check
	;;
  status)
	status -p $pidfile -l $(basename $lockfile) -b /usr/libexec/postfix/master master
	;;
  condrestart)
	[ $running -eq 0 ] || exit 0
	stop
	start
	;;
  *)
	echo $"Usage: $0 {start|stop|restart|reload|abort|flush|check|status|condrestart}"
	exit 2
esac

exit $?

7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?