(ヽ'ω`) < Mailmanをしっかり理解しながらインストール
(ヽ'ω`) < しっかり理解とは?
Mailmanのインストールから実際の運用まで、(可能な限り)コマンドの羅列ではなく、なぜこの設定が必要なのかというところを含めて解説していきたい。というより、忘れないように作業メモを清書しておく。
他のインストール解説ページと比べて冗長な部分が多々あるので、必要のない部分は読み飛ばしてくださいな。
(ヽ'ω`) < 想定環境
ザックリと以下の環境を想定。
対象 | 環境 |
---|---|
OS | CentOS 6.5(システムの文字コードEUC-JP) |
Python | python2.6 |
Mailman | 2.1.14+j7(tarball) |
HTTPd | Apache2.2 yumでインストール済 |
(ヽ'ω`) < EUC-JP? UTF-8じゃなくて?
Mailmanの日本語対応にあたって、内部で使用される文字コードはEUC-JPで固定されている。 UTF-8環境での運用も不可能ではないが、コマンドを実行した時など、ふとした時に悩まされることがあるので、Dedicatedなサーバならシステムの文字コードをEUC-JPにしておいたほうが楽
使ったことはないのだが、ハックのためのスクリプトが存在する模様。
python-nkf/mailman-ja-utf8ize.sh at master · fumiyas/python-nkf · GitHub
(ヽ´ω`) < なんでtarballなの? yumとかaptじゃだめなん?
Mailmanの日本語カスタム版がtarballの形式でしか配布されていないため。
素のMailmanでも日本語には対応しているが、以下のように細かなFixが行われている。
Mailman はそのままでも日本語で利用することができますが、それは文字コード 集合についての規則 (JIS) を守っている場合であって、機種依存文字の使用な どでエラーになったり不具合も残っています。このあたりは、日本人でも正確に 問題を把握している人は少なく、その事情を本家の開発者に伝えるのも結構大変です。
そこで、Mailman に少々手を加えて、日本語メールで機種依存文字を使われても、 文字コード集合の規則にかなったメールを配信できるようにしたものを +j バー ジョンとして作成しました。
(ヽ´ω`) < インストールの流れ
インストールは以下の流れで行っていく。
- Mailman本体のインストール
-
mailman
ユーザとグループの作成 - ディレクトリの準備
- パッケージのダウンロードと解凍
- ファイルのインストール
- アイコンファイルのコピー
-
- Postfix側での設定
- Postfixでaliasesファイルの場所を指定
- aliasesファイル内
forward
,include
でのコマンド実行許可を設定 -
mynetworks
へのIPv6ループバックアドレスの追加 - Postfix再起動
- ログやcronなどの周辺環境の設定
- ログローテーションの設定
- 定期処理をcrontabへ追加
- Apacheとの連携設定
-
AddDefautCharset
の変更 - Webインターフェースのための
ScriptAlias
設定 - Pipermailのための
Alias
設定 - アクセスコントロール
- Apache再起動
-
ここまでやって、ようやくMailmanの設定に入れる
- Mailmanの初期設定
- mm_cfg.pyの設定
- aliasesファイルの仮作成
- 管理ML(mailman)作成
- マスターパスワード設定
- 動作を確認
- 投稿確認
- Gmailからの投稿確認
(ヽ´ω`) < Mailman本体のインストール
まずはMailmanをインストールするためのユーザ・グループ、ディレクトリを作成。その後、Mailmanのパッケージを取得し、ファイルシステム上へ配置していく
mailman
ユーザとグループの作成
Mailmanで使用するユーザとグループを作成する。名前はそのものズバリのmailman
。
ログインシェルは必要ないので/sbin/nologin
にしておく。
# groupadd mailman # useradd -s /sbin/nologin -g mailman mailman
ディレクトリの準備
Mailmanをインストールするディレクトリを作成する。
ここで悩ましいのが、/usr/local
以下に配置するか、/opt
のようなそれ以外の場所に配置するか。
デフォルトのインストールでは/usr/local/mailman
への配置となるのだが、それにしてもmakeで自動的に作成されるわけではなく、./configure
より事前に作成しておく必要がある。作成されていない場合は./configure
が失敗する。
また、ディレクトリ構成も
[root@486497a9e830 mailman]# pwd /usr/local/mailman [root@486497a9e830 mailman]# tree -L 1 ./ ./ |-- Mailman |-- archives |-- bin |-- cgi-bin |-- cron |-- data |-- icons |-- lists |-- locks |-- logs |-- mail |-- messages |-- pythonlib |-- qfiles |-- scripts |-- spam |-- templates `-- tests 18 directories, 0 files
このように、bin
ディレクトリも含め、全てを自分のディレクトリの中に持つような形なので、ディレクトリの役割的には/usr/lib
や/opt
に配置するのが正しいかなと思う。
参考
というわけで、/opt
にディレクトリを作成。
# mkdir /opt/mailman
ディレクトリのグループをmailman
に設定して、パーミッションを02775
に設定する。
# chgrp /opt/mailman mailman # chmod 02775 /opt/mailman
パッケージのダウンロードと解凍
下記URLからMailmanの+jバージョンを取得し、展開したものを、適当なディレクトリ(/usr/local/src
)に置く。
2014/11/13現在で、最新のものは mailman-2.1.14+j7 となっている。
Mailman公式では2.1系の最新バージョンは mailman-2.1.18-1 になっており、どちらを使うか悩ましいところ。
1.14から1.18までのRelease notesとChangelogを見てみると、結構な数の新機能とバグフィックスが含まれている様子なので、可能であれば1.18-1を使用したほうが…と思いつつ、このメモを作成した時は1.14+j7が最新だったのでとりあえず今回の解説は1.14+j7をベースに行っていく。
2.1.15 : Series 2.1 : GNU Mailman 2.1.16 : Series 2.1 : GNU Mailman 2.1.17 : Series 2.1 : GNU Mailman 2.1.18 : Series 2.1 : GNU Mailman 2.1.18-1 : Series 2.1 : GNU Mailman
# cd /usr/local/src # wget http://docs.python.jp/contrib/mailman/_static/mailman-2.1.14+j7.tgz # tar xvzf mailman-2.1.14+j7.tgz
ファイルのインストール
解凍して作成されたディレクトリで./configure
, make
, make install
を行っていく。
まずは./configure
* prefix
オプションは、先ほど作成した/opt/mailman
を渡す
* with-cgi-gid
でApacheの実行グループ名を渡す
mailmanではWeb管理画面を提供しているため、Apacheとの連携のために、Apacheの実行グループ名を、with-cgi-gid
オプションで渡してやる必要がある。Apache以外のHTTPdサーバについては未調査(ヽ´ω`)
CentOS6のyumでインストールした場合のユーザ名はapache
となるが、Debianなんかだとwww-data
になるし、指定しないとnobody
が値として使われる。
その他のオプションは以下のページを参照
# cd /usr/local/src/mailman-2.1.14+j7 # ./configure --prefix=/opt/mailman --with-cgi-gid=apache
この時点で、mailman
, apache
ユーザが作成されていなかったり、インストール先ディレクトリが存在しない・パーミッションが適切でない場合はエラーが発生する。
問題なく終了したら、次はmake
とmake install
。これに関しては特に注意点は無いかと。
# make # make install
ファイルが配置されたら付属のbin/check_perm
スクリプトでパーミッションの確認を行う。問題がある場合はメッセージが表示されるので、適時修正して問題が出なくなるまでその作業を繰り返す。
このコマンドはカレントディレクトリをbin
に変更してから実行する。
# cd /opt/mailman/bin # ./check_perm -f
Dockerで実際に上記チェックスクリプトを実行したところ、下記のエラーが発生した。
[root@d09f4ab28203 bin]# ./check_perms -f directory permissions must be 02775: /opt/mailman/templates/gl (fixing) directory permissions must be 02775: /opt/mailman/templates/ru (fixing) directory permissions must be 02775: /opt/mailman/templates/fi (fixing) directory permissions must be 02775: /opt/mailman/templates/lt (fixing) directory permissions must be 02775: /opt/mailman/templates/da (fixing) directory permissions must be 02775: /opt/mailman/templates/it (fixing) directory permissions must be 02775: /opt/mailman/templates/pt (fixing) directory permissions must be 02775: /opt/mailman/templates/de (fixing) directory permissions must be 02775: /opt/mailman/templates/cs (fixing) directory permissions must be 02775: /opt/mailman/templates/pt_BR (fixing) directory permissions must be 02775: /opt/mailman/templates/zh_TW (fixing) directory permissions must be 02775: /opt/mailman/templates/pl (fixing) directory permissions must be 02775: /opt/mailman/templates/uk (fixing) directory permissions must be 02775: /opt/mailman/templates/sk (fixing) directory permissions must be 02775: /opt/mailman/templates/sr (fixing) directory permissions must be 02775: /opt/mailman/templates/el (fixing) directory permissions must be 02775: /opt/mailman/templates/zh_CN (fixing) directory permissions must be 02775: /opt/mailman/templates/fr (fixing) directory permissions must be 02775: /opt/mailman/templates/eu (fixing) directory permissions must be 02775: /opt/mailman/templates/en (fixing) directory permissions must be 02775: /opt/mailman/templates/hu (fixing) directory permissions must be 02775: /opt/mailman/templates/es (fixing) directory permissions must be 02775: /opt/mailman/templates/sl (fixing) directory permissions must be 02775: /opt/mailman/templates/ar (fixing) directory permissions must be 02775: /opt/mailman/templates/ro (fixing) directory permissions must be 02775: /opt/mailman/templates/ast (fixing) directory permissions must be 02775: /opt/mailman/templates/no (fixing) directory permissions must be 02775: /opt/mailman/templates/ko (fixing) directory permissions must be 02775: /opt/mailman/templates/ca (fixing) directory permissions must be 02775: /opt/mailman/templates/sv (fixing) directory permissions must be 02775: /opt/mailman/templates/vi (fixing) directory permissions must be 02775: /opt/mailman/templates/nl (fixing) directory permissions must be 02775: /opt/mailman/templates/tr (fixing) directory permissions must be 02775: /opt/mailman/templates/ja (fixing) directory permissions must be 02775: /opt/mailman/templates/he (fixing) directory permissions must be 02775: /opt/mailman/templates/et (fixing) directory permissions must be 02775: /opt/mailman/templates/hr (fixing) directory permissions must be 02775: /opt/mailman/templates/ia (fixing) directory permissions must be 02775: /opt/mailman/messages/gl (fixing) directory permissions must be 02775: /opt/mailman/messages/ja_JP.UTF8 (fixing) directory permissions must be 02775: /opt/mailman/messages/ru (fixing) directory permissions must be 02775: /opt/mailman/messages/fi (fixing) directory permissions must be 02775: /opt/mailman/messages/lt (fixing) directory permissions must be 02775: /opt/mailman/messages/da (fixing) directory permissions must be 02775: /opt/mailman/messages/it (fixing) directory permissions must be 02775: /opt/mailman/messages/pt (fixing) directory permissions must be 02775: /opt/mailman/messages/de (fixing) directory permissions must be 02775: /opt/mailman/messages/cs (fixing) directory permissions must be 02775: /opt/mailman/messages/pt_BR (fixing) directory permissions must be 02775: /opt/mailman/messages/zh_TW (fixing) directory permissions must be 02775: /opt/mailman/messages/pl (fixing) directory permissions must be 02775: /opt/mailman/messages/uk (fixing) directory permissions must be 02775: /opt/mailman/messages/sk (fixing) directory permissions must be 02775: /opt/mailman/messages/sr (fixing) directory permissions must be 02775: /opt/mailman/messages/el (fixing) directory permissions must be 02775: /opt/mailman/messages/zh_CN (fixing) directory permissions must be 02775: /opt/mailman/messages/fr (fixing) directory permissions must be 02775: /opt/mailman/messages/eu (fixing) directory permissions must be 02775: /opt/mailman/messages/hu (fixing) directory permissions must be 02775: /opt/mailman/messages/es (fixing) directory permissions must be 02775: /opt/mailman/messages/sl (fixing) directory permissions must be 02775: /opt/mailman/messages/ar (fixing) directory permissions must be 02775: /opt/mailman/messages/ro (fixing) directory permissions must be 02775: /opt/mailman/messages/ast (fixing) directory permissions must be 02775: /opt/mailman/messages/no (fixing) directory permissions must be 02775: /opt/mailman/messages/ko (fixing) directory permissions must be 02775: /opt/mailman/messages/ca (fixing) directory permissions must be 02775: /opt/mailman/messages/sv (fixing) directory permissions must be 02775: /opt/mailman/messages/vi (fixing) directory permissions must be 02775: /opt/mailman/messages/nl (fixing) directory permissions must be 02775: /opt/mailman/messages/tr (fixing) directory permissions must be 02775: /opt/mailman/messages/ja (fixing) directory permissions must be 02775: /opt/mailman/messages/he (fixing) directory permissions must be 02775: /opt/mailman/messages/et (fixing) directory permissions must be 02775: /opt/mailman/messages/hr (fixing) directory permissions must be 02775: /opt/mailman/messages/ia (fixing) Warning: Private archive directory is other-executable (o+x). This could allow other users on your system to read private archives. If you're on a shared multiuser system, you should consult the installation manual on how to fix this. Problems found: 76 Re-run as mailman (or root) with -f flag to fix [root@d09f4ab28203 bin]# ./check_perms -f Warning: Private archive directory is other-executable (o+x). This could allow other users on your system to read private archives. If you're on a shared multiuser system, you should consult the installation manual on how to fix this. No problems found
表示の通りfixing
と表示されていたので、もう一度実行するとエラーは自動で修正されていた。
Private archive directoryに関するWarningが出ているが、これはDedicated(専有)サーバでない(一般のユーザが自由にログイン可能)場合、そのユーザたちがPrivateなアーカイブを閲覧できてしまうという警告。専有サーバであっても、そのまま放置するのも気味が悪いので変更しておく。
# chmod o-x /opt/mailman/archives/private/ # ./check_perms -f No problems found
アイコンファイルのコピー
WebUIのためのアイコン画像が<インストール先ディレクトリ>/icons/
に入っている。このファイルをhttp://<ホスト名>/icons/
から参照できるようにコピーする。yum経由でhttpdをインストールした場合は、/var/www/icons/
になるので、
# cp /opt/mailman/icons/* /var/www/icons/
とする。
以上でファイルの配置は完了。次はMailman本体の設定、と行きたいところだが、その前に連携するMTA側の設定を行う。
(ヽ´ω`) < Postfixの設定
MTAとしてPostfixを例に設定を行っていく。
(ヽ´ω`) < というかsendmailが魔窟過ぎて…
aliasesファイルの場所を追加
Mailmanはメーリングリストのサーバではあるものの、実際にメールを受け取るのはMTA(Postfix)の仕事になる。Postfixは受け取ったメールが、メーリングリスト宛のメールであれば、Mailmanのプログラムにそのメールを転送する。
Postfixがメーリングリスト宛かどうかを判断するのが、aliasesファイルとなる。
Mailmanはメーリングリストの作成・削除を行う度にdata/aliases
というファイルを作成する。このファイルをPostfixがaliasesファイルとして読みこむように、以下の設定を追加する。
PostfixをCentOS6のyumでインストールした場合、編集するファイルは/etc/postfix/main.cf
となる。
# 以下の内容がPostfixのデフォルト値 #alias_maps = hash:/etc/aliases #alias_database = hash:/etc/aliases # 以下のように追記 alias_maps = hash:/etc/aliases, hash:/opt/mailman/data/aliases alias_database = hash:/etc/aliases, hash:/opt/mailman/data/aliases
aliasesファイル内include
でのコマンド実行許可を設定
Postfixのデフォルトでは、メールをコマンドに渡すのをaliasesとforwardでしか許可をしていない。
local(8) が外部コマンドへメールを配送するのを制限します。 デフォルトでは :include: ファイルでの "|command" への配送を認めません (この用例を定義している文章は aliases(5) を参照してください)。
:include:
でもコマンドを実行するのを許可するために、以下の設定を/etc/postfix/main.cf
に追加。
allow_mail_to_commands = alias,forward,include
ただ、これMailmanのインストール手順に書いてあるけど、Mailmanが作成するaliasesファイルに:include:
が含まれてないんですよね。なんなんだろう?(ヽ´ω`)
mynetworks
へのIPv6ループバックアドレスの追加
環境依存の問題なのかは不明だが、mynetworks
へIPv6のループバックアドレスを追加しないと、外部へのメール配送が上手くいかない。
/etc/postfix/main.cf
のmynetworks
に値を追加
mynetworks = [既存の値], [::1]/128
Postfix再起動
設定を書き換えたので再起動。
説明は端折ってあるが、そもそものPostfixの基本的な設定はしっかりできていることが大前提。再起動後に、Mailmanは置いておいて正常にメールの送受信ができるかを確認する。
(ヽ´ω`) < ログやcronなどの周辺環境の設定
ここまでやっても、未だMailman本体の設定には入らない。我慢していくスタイル。
続いてMailmanのログローテーションの設定と、定期処理のためのCron設定を行う。
ログローテーションの設定
ログのローテーションはlogrotate
コマンドに任せることになるが、syslog経由で吐き出されるログじゃないので、ローテーション実行時の再読み込み処理が独自のコマンドとなる。
4.07 How can I rotate my Mailman logs? - Documentation - Confluence
上記URLによると(また、コマンドのヘルプでも確認できたが)、以下のコマンドを実行することで、ログが再オープンされる。
# bin/mailmanctl reopen
ということで、/etc/logrotate.d/mailman
ファイルを新規に作成して、以下の内容を記述する。
/opt/mailman/logs/bounce /opt/mailman/logs/mischief /opt/mailman/logs/error /opt/mailman/logs/post /opt/mailman/logs/smtp /opt/mailman/logs/smtp-failure /opt/mailman/logs/qrunner /opt/mailman/logs/locks /opt/mailman/logs/fromusenet /opt/mailman/logs/subscribe /opt/mailman/logs/vette { sharedscripts postrotate /opt/mailman/bin/mailmanctl reopen > /dev/null 2>&1 || true endscript }
対象ファイルの指定で/opt/mailman/logs/*
じゃダメなの? と思うかも知れないが、
(ヽ´ω`) < マジで死ぬ。というか死んだ。
Mailmanは関係のない話になるが、ローテーション後のxxxxx.xのファイルもローテーションの対象になってエライことになる。
定期処理をcrontabに追加
Mailmanではメールの配送以外で、以下の様な処理をcronで定期実行している。
- 保留中の処理やパスワード変更に関する通知
- リストのメール書庫の圧縮
- その他、ユーザへの情報通知やキューの掃除など
これらの処理はcron/
ディレクトリにスクリプトとして用意されている。
この処理をシステムのcronへ登録するために、以下のコマンドを実行する。
# crontab -u mailman cron/crontab.in
上記のコマンドの-u
オプションからも分かる通り、これらの処理はmailman
ユーザの権限で実行される。
追加される内容はcron/crontab.in
に記載されている。実際に中身を見てもらえればわかるが、これ本当に必要か? と思う処理もいくつかある(コメントにも"必要ないならコメントアウトしてね"って書いてあるものもある)
この辺りの調整は、運用ポリシーなどの問題もあるのでここでは触れずに、別エントリで考える。
(ヽ´ω`) < Apacheとの連携設定
先述の通り、Mailmanでは各リストの管理にWebインターフェースを提供している。Webサーバ機能は内蔵していないため、ApacheのようなHTTPdサーバとの連携が必要となる。 また、Mailmanではやりとりされたメールをアーカイブ化して、Webから閲覧可能にするPipermailという機能を持っている。そこでも連携設定が必要となる。
とは言っても、そこまで面倒な設定が必要なわけではなく、Apache側でAliasを張るだけ。
下記2つの設定は、httpd.conf
の中に追加してもいいし、/etc/httpd/conf.d/mailman.conf
のようなファイルを新規に作成して、その中で記述するのもOK。Debianならmods-availableの中にmailman.confを作成して、mods-enabledにSymlinkを張るという形か。
AddDefaultCharset
のOff
Mailmanに限った話ではないが、ApacheではAddDefaultCharset
ディレクティブで、サーバがtext/plainやtext/htmlな種類のファイルを応答する際に、任意の文字コードを指定してHTTPヘッダに挿入することができる。
core - Apache HTTP ãµã¼ã ãã¼ã¸ã§ã³ 2.2
CentOS6のyumでインストールできるApacheでは、デフォルトでutf-8
が指定されている(2014/11/14)。のだが、Mailmanが生成する日本語のページのエンコーディングは、全てEUC-JPとなっている。
そのため、デフォルトのApacheのままでは日本語のページを表示させた時に、文字化けが発生する。
個々のHTMLページ内に記載されるmetaタグ内のContent-Typeは、優先順位の関係で無視される。
Javaの文字化け対策FAQ(1):Webブラウザが文字コードを判定する基準は? - @IT
まずは、Webにおける文字コードの扱いをおさらいしておこう。HTML 4.01仕様では、Webブラウザが以下の優先順位で文字コードを決定することを規定している。
- HTTPにおけるContent-Typeヘッダのcharsetパラメータ
- HTML文書内のMETA宣言およびhttp-equiv属性で設定された、Content-Typeヘッダのcharsetパラメータ
- HTML文書内の各要素のcharset属性
というわけで、Apacheの設定でhttpd.conf
内にAddDefaultCharset
というディレクティブがあるはずなので、それを探して値をEUC-JP
にする。
AddDefaultCharset EUC-JP
これで文字コードの判別は個々のHTMLファイルまたはレスポンスの中のmetaタグから行われる。もしもmetaタグでの定義がされていない場合は、ブラウザの文字コード判別アルゴリズムに則って決定される。
WebインターフェースのためのScriptAlias
設定
Mailmanが提供するWebインターフェースの機能はcgi-bin/
ディレクトリ内のCGIによって実装されている。
なので単純にApacheの設定に以下の内容を追加してやればいい。
Alias元の/mailman/
は任意の値が設定可能だが、とりあえずmailman
としておく。
ScriptAlias /mailman/ /opt/mailman/cgi-bin/
PipermailのためのAlias
設定
これも単純に、ファイルがarchives/public
ディレクトリに作成されるので、以下の内容を追加。/pipermail/
の部分の値は任意のもので。
Alias /pipermail/ /opt/mailman/archives/public/
リスト毎の設定で、アーカイブを公開(public)にするか否か(private)を設定できる。
archives/
ディレクトリにはpublic
とprivate
ディレクトリが作成されるため、公開する分はpublic
にAliasを張っておく。
アクセスコントロール
上記設定で、Webインターフェースでのエントリポイントが2つ作成された。
これらに対して、無条件でアクセスを許可するのは正直あまり好ましくない。というわけで、アクセスコントロールを設定することができるが、これは各自の環境と運用ポリシーに合わせて設定を行う。
具体的な記述に関しては、その他のセキュリティ対策と一緒に別エントリで。
Apache再起動
設定を書き終わったら、Apacheを再起動して起動に問題がないかを確認する。
(ヽ´ω`) < 長い…
ここまでで、ようやくファイルの配置と周辺環境の設定が完了。
いよいよMailman自身の設定を行っていくことになるが、長くなったので一旦ここで区切り。次のエントリでMailmanの設定について説明していく。