さくらのVPS導入手順 10.postfixの利用準備

さくらのVPSのお試し期間のメール送信制限

さくらのVPSには2週間のお試し期間があるので、それを利用されている方が多いと思いますが、その間はいくつかの制限事項があります
その中のひとつに、外向きメール送信用のポート番号25が閉じた状態であるということがあります
よって、その期間内はメール送信ができません
なお、受信だけはできますので、メールマガジンなどを受け取るだけなら特に問題なく使用できます
お試し期間が終了するか、途中で自ら本登録すると、その数日後にお知らせ番号が郵送されてくるので、それを入力すればすべての機能が利用できるようになります

メールサーバーの構築方針

ここでは、最も簡単に、標準で動作しているpostfixにdovecotを組み合わせ、スタンダードなSMTP認証で送信時認証を行なう形式で設置します
さらにセキュリティを高めた設置方法についてはまた改めて記載します

postfixのインストール

さくらのVPSでは初期状態でpostfixがインストールされています
よって、インストール作業は必要ありません

postfix設定ファイルの編集

では、こちらも同じようにまずは設定ファイルのバックアップを取った後で編集を行います

$ sudo cp /etc/postfix/main.cf /etc/postfix/main.cf.original
$ sudo vi /etc/postfix/main.cf

まずはドメインの設定です
以前にドメインの設定を行なった際の情報をもとに、メールサーバーのホスト名とメールのドメイン名を記入します

# INTERNET HOST AND DOMAIN NAMES
#
# The myhostname parameter specifies the internet hostname of this
# mail system. The default is to use the fully-qualified domain name
# from gethostname(). $myhostname is used as a default value for many
# other configuration parameters.
#
#myhostname = host.domain.tld
#myhostname = virtual.domain.tld
myhostname = mail.talisnet.info (←あなたのメールサーバー用のホスト名に変更)

# The mydomain parameter specifies the local internet domain name.
# The default is to use $myhostname minus the first component.
# $mydomain is used as a default value for many other configuration
# parameters.
#
#mydomain = domain.tld
mydomain = talisnet.info (←あなたのメールのドメイン名に変更)

次に、myorigininet_interfacesの項で、15行目と29行目のコメントマークをはずし、32行目を逆にコメントにします
なお、ここまでに説明はしていませんが、IPv6を無効にする方は35~36行目の修正を入れておくとログにIPv6関連の警告が出なくなります

# SENDING MAIL
#
# The myorigin parameter specifies the domain that locally-posted
# mail appears to come from. The default is to append $myhostname,
# which is fine for small sites.  If you run a domain with multiple
# machines, you should (1) change this to $mydomain and (2) set up
# a domain-wide alias database that aliases each user to
# user@that.users.mailhost.
#
# For the sake of consistency between sender and recipient addresses,
# myorigin also specifies the default domain name that is appended
# to recipient addresses that have no @domain part.
#
#myorigin = $myhostname
myorigin = $mydomain

# RECEIVING MAIL

# The inet_interfaces parameter specifies the network interface
# addresses that this mail system receives mail on.  By default,
# the software claims all active interfaces on the machine. The
# parameter also controls delivery of mail to user@[ip.address].
#
# See also the proxy_interfaces parameter, for network addresses that
# are forwarded to us via a proxy or network address translator.
#
# Note: you need to stop/start Postfix when this parameter changes.
#
inet_interfaces = all
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
#inet_interfaces = localhost

# Enable IPv4, and IPv6 if supported
#inet_protocols = all
inet_protocols = ipv4

次に32行目と33行目のコメントを入れ替える

# The mydestination parameter specifies the list of domains that this
# machine considers itself the final destination for.
#
# These domains are routed to the delivery agent specified with the
# local_transport parameter setting. By default, that is the UNIX
# compatible delivery agent that lookups all recipients in /etc/passwd
# and /etc/aliases or their equivalent.
#
# The default is $myhostname + localhost.$mydomain.  On a mail domain
# gateway, you should also include $mydomain.
#
# Do not specify the names of virtual domains - those domains are
# specified elsewhere (see VIRTUAL_README).
#
# Do not specify the names of domains that this machine is backup MX
# host for. Specify those names via the relay_domains settings for
# the SMTP server, or use permit_mx_backup if you are lazy (see
# STANDARD_CONFIGURATION_README).
#
# The local machine is always the final destination for mail addressed
# to user@[the.net.work.address] of an interface that the mail system
# receives mail on (see the inet_interfaces parameter).
#
# Specify a list of host or domain names, /file/name or type:table
# patterns, separated by commas and/or whitespace. A /file/name
# pattern is replaced by its contents; a type:table is matched when
# a name matches a lookup key (the right-hand side is ignored).
# Continue long lines by starting the next line with whitespace.
#
# See also below, section "REJECTING MAIL FOR UNKNOWN LOCAL USERS".
#
#mydestination = $myhostname, localhost.$mydomain, localhost
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
#       mail.$mydomain, www.$mydomain, ftp.$mydomain

次はhome_mailboxの項について、下の9行目のコメントを解除します

# DELIVERY TO MAILBOX
#
# The home_mailbox parameter specifies the optional pathname of a
# mailbox file relative to a user's home directory. The default
# mailbox file is /var/spool/mail/user or /var/mail/user.  Specify
# "Maildir/" for qmail-style delivery (the / is required).
#
#home_mailbox = Mailbox
home_mailbox = Maildir/

次はsmtpd_bannerの項について、12行目の内容を追加します

# SHOW SOFTWARE VERSION OR NOT
#
# The smtpd_banner parameter specifies the text that follows the 220
# code in the SMTP server's greeting banner. Some people like to see
# the mail version advertised. By default, Postfix shows no version.
#
# You MUST specify $myhostname at the start of the text. That is an
# RFC requirement. Postfix itself does not care.
#
#smtpd_banner = $myhostname ESMTP $mail_name
#smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)
smtpd_banner = $myhostname ESMTP unknown

最後に、設定ファイルの末尾に以下の内容をすべて追記します

smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions =
    permit_mynetworks,
    permit_sasl_authenticated,
    reject_unauth_destination

message_size_limit = 10485760

SMTP-Auth設定ファイルの編集

もうひとつ、メール送信時の認証用サービスがありますので、そちらの設定ファイルも編集します
こちらも同じようにまずは設定ファイルのバックアップを取った後で編集を行います

$ sudo cp /etc/sasl2/smtpd.conf /etc/sasl2/smtpd.conf.original
$ sudo vi /etc/sasl2/smtpd.conf

ここでは認証用のユーザー名とパスワードをシステムとは別々にする形を想定します
1行目の内容を3行目の形に書き換えてください

pwcheck_method: saslauthd
  ↓ 変更
pwcheck_method: auxprop
mech_list: plain login

新規ユーザー用メールボックス作成

新規ユーザ作成時に自動でホームディレクトリにMaildir形式のメールボックスが作成されるようにしておきます

$ sudo mkdir -p /etc/skel/Maildir/{new,cur,tmp}
$ sudo chmod -R 700 /etc/skel/Maildir/

サービスの起動と登録

では、postfixとsaslauthを起動し、自動起動の登録をしておきましょう
まずはsaslauthdからです
1行目で起動し、3行目のコマンドで自動起動登録、4行目でその確認です

$ sudo service saslauthd start
saslauthd を起動中:                                        [  OK  ]
$ sudo chkconfig saslauthd on
$ chkconfig --list saslauthd
saslauthd       0:off   1:off   2:on    3:on    4:on    5:on    6:off

次にpostfixです
こちらは初期状態で起動していて、また自動起動設定も行なわれているはずなので、1行目で再起動を行い、4行目で自動起動の確認を行ないます

$ sudo service postfix restart
postfix を停止中:                                          [  OK  ]
postfix を起動中:                                          [  OK  ]
$ chkconfig --list postfix
postfix         0:off   1:off   2:on    3:on    4:on    5:on    6:off

ここまでで、メール送信用サーバーの設定は完了しましたが、メールの受信用サーバーが設置できていません
というわけで、続きは次の記事で

次は さくらのVPS導入手順 11.dovecotの利用準備

はじめに戻る さくらのVPS導入手順 0.はじめに

さくらのVPS導入手順 9.WordPressの利用準備

はじめに

ここではWordPressのインストールを行っていきます
WordPress自体はブログを書くツールとして有名ですが、実際にはこれがあれば会社のコーポレートサイトや製品紹介のサイト、ニュース配信サイトなど、いろんなサイトを作れます
また、その為に役に立つデザインテンプレートやプラグインなども豊富に用意されていますので、非常に簡単にサイトを製作することができます

なお、WordPressは一切使うつもりはないという方は、ここは飛ばしてもらってかまいません
逆に、後でいつでもこの作業を行うことで使えるようになります

PHPのインストール

まずはWordPressを動かすために必要になる、PHPのパッケージをインストールします
モジュールが多いので、途中長々とログが流れて、たくさんダウンロードしたりインストールしたりしますが、最後、Complete!と表示されればインストール完了です

$ sudo yum -y install php php-mbstring php-mysql php-mcrypt php-gd php-devel php-pear php-pecl-apc
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile

~~~途中省略~~~

Complete!

データベースの準備

次にWordPressが使用するデータベースとユーザーを用意しておきます
まずはmysqlコマンドを実行します

$ mysql -u root -p

次にデータベースとユーザーの準備です
1行目はデータベースを作成しています。ここではwordpress_dataとしていますが、他の名前でもかまいません
4行目はそのデータベースにWordPressがアクセスするためのユーザーを作成して、権限を付与しています
最初にデータベース名を変更した方は、ここでもwordpress_dataを同じ名前に変更してください
最後の‘XXXXXXXX’はパスワードになりますので、これも任意のものに変更してください
ユーザー名はwordpressとしましたが、これも変更可能です
7行目は今変更した情報をMySQLの内部にまで反映させるコマンドです

mysql> CREATE DATABASE wordpress_data DEFAULT CHARACTER SET utf8;
Query OK, 1 row affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON wordpress_data.* TO wordpress@localhost IDENTIFIED BY 'XXXXXXXX';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

WordPressの取得

WordPressは今までのようにyumコマンドで半自動でインストールするのではなく、自分で設置しなくてはなりません
しかし手順はごく簡単です
まずは最新版のWordPressをダウンロードします
最後に保存完了と出ればダウンロード成功です

$ wget http://ja.wordpress.org/latest-ja.zip

では、これを実際に設置していきましょう
以下の手順でファイルを配置します

$ unzip latest-ja.zip
$ rm latest-ja.zip
$ sudo mv wordpress /var/www/html/wordpress
$ sudo chown -R apache:apache /var/www/html/wordpress

ここではwordpressという名前のフォルダーに配置しているため、実際にアクセスする際に、
http://(あなたのドメイン)/wordpress/
というURLでのアクセスになります
それを変更したい場合、上の太字になっているwordpressを任意の名前に変更してください
なお、http://(あなたのドメイン)/でアクセスした際にWordPressにアクセスできるようにする方法は別のページで説明します
設定辞退はこのまま進めても大丈夫です

WordPressの初期設定

では、WordPressの初期設定を行います
ブラウザを開いて、http://(あなたのドメイン)/wordpress/ にアクセスしてみてください
最初に、設定ファイルがまだ無いから作るかどうか聞かれますので、作成するをクリックして設定を開始します
sakura-vps-09-01
次に導入説明のページが表示されますが、先ほどまでに設定してきた情報があれば大丈夫です
始めましょうボタンをクリックして先に進めます
sakura-vps-09-02
すると、詳細情報の入力画面が表示されます
先ほどまでに設定してきた、WordPress用データベースの名前、WordPress用のMySQLのユーザー名とパスワードの3つを入力します
他の2つはそのままで大丈夫です
入力したら送信ボタンをクリックして先に進めます
sakura-vps-09-03
無事完了すると、このような画面が表示されます
インストールボタンをクリックして、データベースにWordPressのインストールを実行します
sakura-vps-09-04
成功すると、いよいよ実際に開設するサイトの情報を設定します
後で変更もできるので、サイトの名前は仮でも大丈夫です
但し、IDとパスワードは他の人に知られると記事を消したりなど、いろいろなことができてしまいますので、しっかり設定しておきましょう
sakura-vps-09-05
すべての情報を入力してインストールボタンをクリックすると、サイトのデータが作成され、次の画面が表示されます
では、ログインボタンをクリックしてWordPressにログインしてみましょう
sakura-vps-09-06
先ほど設定したWordPressの管理者ユーザーのユーザー名とパスワードを入力してログインボタンをクリックします
sakura-vps-09-07
ログインできると、下のような管理画面が表示されました
あとはそこにあるメニューを使って、デザインを変更したり、記事を書いたりしてみてください
(※管理画面はWordPressのバージョンアップによってデザインも変わることがあるので、写真とは異なっている可能性があります)
sakura-vps-09-08

これでWordPressを使ったサイト構築の作業は完了です
次からはメールサーバーの設置手順となりますので、メールサーバーを設置しない人はここまでで終わりです
http://mydomain/wordpress/ではなく、http://mydomain/でWordPressにアクセスする方法などは、別の記事にまとめますので、しばらくお待ちください

次は さくらのVPS導入手順 10.postfixの利用準備

はじめに戻る さくらのVPS導入手順 0.はじめに