awscliをインストールする
AWS Autoscaling環境を想定した、deploy時にS3にパッケージをアップロードするCapistranoプラグイン(IAMロール対応) - Qiita
これをやりたいのでawscliをインストールしようとしたが苦戦した。のでmemo
$ sudo gem install aws-cli
ERROR: Could not find a valid gem 'aws-cli' (>= 0) in any repository
ERROR: Possible alternatives: aws-cli
[tlab-app@purp-ci ~]$ sudo gem install awscli
Fetching: thor-0.19.1.gem (100%)
Successfully installed thor-0.19.1
Fetching: builder-3.2.2.gem (100%)
Successfully installed builder-3.2.2
Fetching: excon-0.45.4.gem (100%)
Successfully installed excon-0.45.4
Fetching: formatador-0.2.5.gem (100%)
Successfully installed formatador-0.2.5
Fetching: mime-types-2.6.1.gem (100%)
Successfully installed mime-types-2.6.1
Fetching: fog-core-1.32.1.gem (100%)
Successfully installed fog-core-1.32.1
Fetching: multi_json-1.11.2.gem (100%)
Successfully installed multi_json-1.11.2
Fetching: fog-json-1.0.2.gem (100%)
Successfully installed fog-json-1.0.2
Fetching: mini_portile-0.6.2.gem (100%)
Successfully installed mini_portile-0.6.2
Fetching: nokogiri-1.6.6.2.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing awscli:
ERROR: Failed to build gem native extension.[520/1881]
/usr/bin/ruby2.0 extconf.rb
checking if the C compiler accepts ... yes
Building nokogiri using packaged libraries.
checking for gzdopen() in -lz... no
zlib is missing; necessary for building libxml2extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib64
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/bin/ruby2.0
--help
--clean
--use-system-libraries
--enable-static
--disable-static
--with-zlib-dir
--without-zlib-dir
--with-zlib-include
--without-zlib-include=${zlib-dir}/include
--with-zlib-lib
--without-zlib-lib=${zlib-dir}/lib
--enable-cross-build
--disable-cross-buildGem files will remain installed in /usr/local/share/ruby/gems/2.0/gems/nokogiri-1.6.6.2 for inspection.
Results logged to /usr/local/share/ruby/gems/2.0/gems/nokogiri-1.6.6.2/ext/nokogiri/gem_make.outzlib is missing; necessary for building libxml2 と言われているのでzlibがあるか調べる。
zlibはあるので、恐らく zlib-develが必要なのかな。
$ rpm -qa | grep zlib
zlib-1.2.8-7.18.amzn1.x86_64
$ sudo yum install zlib-devel
Loaded plugins: priorities, update-motd, upgrade-helper
amzn-main/latest | 2.1 kB 00:00
amzn-updates/latest | 2.3 kB 00:00
amzn-updates/latest/updateinfo | 258 kB 00:00
amzn-updates/latest/primary_db | 1.0 MB 00:00
jenkins | 951 B 00:00
Resolving Dependencies
- > Running transaction check
- > Package zlib-devel.x86_64 0:1.2.8-7.18.amzn1 will be installed
- > Finished Dependency Resolution
Dependencies Resolved
============================================================================================================================================
Package Arch Version Repository Size
============================================================================================================================================
Installing:
zlib-devel x86_64 1.2.8-7.18.amzn1 amzn-main 53 kTransaction Summary
============================================================================================================================================
Install 1 Package
Total download size: 53 k
Installed size: 134 k
Is this ok [y/d/N]: y
Downloading packages:
zlib-devel-1.2.8-7.18.amzn1.x86_64.rpm | 53 kB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : zlib-devel-1.2.8-7.18.amzn1.x86_64 1/1
Verifying : zlib-devel-1.2.8-7.18.amzn1.x86_64 1/1Installed:
zlib-devel.x86_64 0:1.2.8-7.18.amzn1Complete!
再度実行
$ sudo gem install awscli
Building native extensions. This could take a while...
ERROR: Error installing awscli:
ERROR: Failed to build gem native extension./usr/bin/ruby2.0 extconf.rb
checking if the C compiler accepts ... yes
Building nokogiri using packaged libraries.
checking for gzdopen() in -lz... yes
checking for iconv... yes
************************************************************************
IMPORTANT NOTICE:Building Nokogiri with a packaged version of libxml2-2.9.2
with the following patches applied:
- 0001-Revert-Missing-initialization-for-the-catalog-module.patch
- 0002-Fix-missing-entities-after-CVE-2014-3660-fix.patchTeam Nokogiri will keep on doing their best to provide security
updates in a timely manner, but if this is a concern for you and want
to use the system library instead; abort this installation process and
reinstall nokogiri as follows:gem install nokogiri -- --use-system-libraries
[--with-xml2-config=/path/to/xml2-config]
[--with-xslt-config=/path/to/xslt-config]If you are using Bundler, tell it to use the option:
bundle config build.nokogiri --use-system-libraries
bundle installNote, however, that nokogiri is not fully compatible with arbitrary
versions of libxml2 provided by OS/package vendors.
************************************************************************
Extracting libxml2-2.9.2.tar.gz into tmp/x86_64-redhat-linux-gnu/ports/libxml2/2.9.2... OK
Running patch with /usr/local/share/ruby/gems/2.0/gems/nokogiri-1.6.6.2/ports/patches/libxml2/0001-Revert-Missing-initialization-for-the-cat
alog-module.patch...
Running 'patch' for libxml2 2.9.2... ERROR, review '/usr/local/share/ruby/gems/2.0/gems/nokogiri-1.6.6.2/ext/nokogiri/tmp/x86_64-redhat-linu
x-gnu/ports/libxml2/2.9.2/patch.log' to see what happened.extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
:
:nokogiriというやつのインストールに失敗しているっぽい。nokogiri単体でどうなるかを試す。
$ sudo gem install nokogiri
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension./usr/bin/ruby2.0 extconf.rb
checking if the C compiler accepts ... yes
Building nokogiri using packaged libraries.
checking for gzdopen() in -lz... yes
checking for iconv... yes
************************************************************************
IMPORTANT NOTICE:Building Nokogiri with a packaged version of libxml2-2.9.2
with the following patches applied:
- 0001-Revert-Missing-initialization-for-the-catalog-module.patch
- 0002-Fix-missing-entities-after-CVE-2014-3660-fix.patchTeam Nokogiri will keep on doing their best to provide security
updates in a timely manner, but if this is a concern for you and want
to use the system library instead; abort this installation process and
reinstall nokogiri as follows:gem install nokogiri -- --use-system-libraries
[--with-xml2-config=/path/to/xml2-config]
[--with-xslt-config=/path/to/xslt-config]If you are using Bundler, tell it to use the option:
bundle config build.nokogiri --use-system-libraries
bundle installNote, however, that nokogiri is not fully compatible with arbitrary
versions of libxml2 provided by OS/package vendors.
:
:
できないので調べたらいい感じのが出てきた。
nokogiriをビルドできずにrailsのインストールが失敗する。 - Qiitaこれの通りにインストールする。
$ sudo yum install libxml2 libxslt libxml2-devel libxslt-devel再度、nokogiriのインストールを試す
$ sudo gem install nokogiri -- --use-system-libraries
Building native extensions with: '--use-system-libraries'
This could take a while...
Successfully installed nokogiri-1.6.6.2
Parsing documentation for nokogiri-1.6.6.2
Installing ri documentation for nokogiri-1.6.6.2
Done installing documentation for nokogiri after 4 seconds
1 gem installedできた。
awscliを再度インストールする
$ sudo gem install awscli
Fetching: fog-xml-0.1.2.gem (100%)
Successfully installed fog-xml-0.1.2
Fetching: ipaddress-0.8.0.gem (100%)
Successfully installed ipaddress-0.8.0
Fetching: fog-atmos-0.1.0.gem (100%)
Successfully installed fog-atmos-0.1.0
Fetching: fog-aws-0.7.6.gem (100%)
Successfully installed fog-aws-0.7.6
Fetching: inflecto-0.0.2.gem (100%)
Successfully installed inflecto-0.0.2
Fetching: fog-brightbox-0.9.0.gem (100%)
:
:
:
Installing ri documentation for fog-voxel-0.1.0
Parsing documentation for fog-1.34.0
Installing ri documentation for fog-1.34.0
Parsing documentation for highline-1.7.3
Installing ri documentation for highline-1.7.3
Parsing documentation for awscli-0.2.8
Installing ri documentation for awscli-0.2.8
Done installing documentation for fog-xml, ipaddress, fog-atmos, fog-aws, inflecto, fog-brightbox, fog-dynect, fog-ecloud, fog-google, fog-local, fog-powerdns, fog-profitbricks, fog-radosgw, fog-riakcs, fog-sakuracloud, fog-serverlove, fog-softlayer, fog-storm_on_demand, fog-terremark, CFPropertyList, fission, fog-vmfusion, fog-voxel, fog, highline, awscli after 209 seconds
26 gems installed結構はまったけどようやく次にいける
awscliをインストールする
AWS Autoscaling環境を想定した、deploy時にS3にパッケージをアップロードするCapistranoプラグイン(IAMロール対応) - Qiita
これをやりたいのでawscliをインストールしようとしたが苦戦した。のでmemo
$ sudo gem install aws-cli
ERROR: Could not find a valid gem 'aws-cli' (>= 0) in any repository
ERROR: Possible alternatives: aws-cli
[tlab-app@purp-ci ~]$ sudo gem install awscli
Fetching: thor-0.19.1.gem (100%)
Successfully installed thor-0.19.1
Fetching: builder-3.2.2.gem (100%)
Successfully installed builder-3.2.2
Fetching: excon-0.45.4.gem (100%)
Successfully installed excon-0.45.4
Fetching: formatador-0.2.5.gem (100%)
Successfully installed formatador-0.2.5
Fetching: mime-types-2.6.1.gem (100%)
Successfully installed mime-types-2.6.1
Fetching: fog-core-1.32.1.gem (100%)
Successfully installed fog-core-1.32.1
Fetching: multi_json-1.11.2.gem (100%)
Successfully installed multi_json-1.11.2
Fetching: fog-json-1.0.2.gem (100%)
Successfully installed fog-json-1.0.2
Fetching: mini_portile-0.6.2.gem (100%)
Successfully installed mini_portile-0.6.2
Fetching: nokogiri-1.6.6.2.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing awscli:
ERROR: Failed to build gem native extension.[520/1881]
/usr/bin/ruby2.0 extconf.rb
checking if the C compiler accepts ... yes
Building nokogiri using packaged libraries.
checking for gzdopen() in -lz... no
zlib is missing; necessary for building libxml2extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib64
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/bin/ruby2.0
--help
--clean
--use-system-libraries
--enable-static
--disable-static
--with-zlib-dir
--without-zlib-dir
--with-zlib-include
--without-zlib-include=${zlib-dir}/include
--with-zlib-lib
--without-zlib-lib=${zlib-dir}/lib
--enable-cross-build
--disable-cross-buildGem files will remain installed in /usr/local/share/ruby/gems/2.0/gems/nokogiri-1.6.6.2 for inspection.
Results logged to /usr/local/share/ruby/gems/2.0/gems/nokogiri-1.6.6.2/ext/nokogiri/gem_make.outzlib is missing; necessary for building libxml2 と言われているのでzlibがあるか調べる。
zlibはあるので、恐らく zlib-develが必要なのかな。
$ rpm -qa | grep zlib
zlib-1.2.8-7.18.amzn1.x86_64
$ sudo yum install zlib-devel
Loaded plugins: priorities, update-motd, upgrade-helper
amzn-main/latest | 2.1 kB 00:00
amzn-updates/latest | 2.3 kB 00:00
amzn-updates/latest/updateinfo | 258 kB 00:00
amzn-updates/latest/primary_db | 1.0 MB 00:00
jenkins | 951 B 00:00
Resolving Dependencies
- > Running transaction check
- > Package zlib-devel.x86_64 0:1.2.8-7.18.amzn1 will be installed
- > Finished Dependency Resolution
Dependencies Resolved
============================================================================================================================================
Package Arch Version Repository Size
============================================================================================================================================
Installing:
zlib-devel x86_64 1.2.8-7.18.amzn1 amzn-main 53 kTransaction Summary
============================================================================================================================================
Install 1 Package
Total download size: 53 k
Installed size: 134 k
Is this ok [y/d/N]: y
Downloading packages:
zlib-devel-1.2.8-7.18.amzn1.x86_64.rpm | 53 kB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : zlib-devel-1.2.8-7.18.amzn1.x86_64 1/1
Verifying : zlib-devel-1.2.8-7.18.amzn1.x86_64 1/1Installed:
zlib-devel.x86_64 0:1.2.8-7.18.amzn1Complete!
再度実行
$ sudo gem install awscli
Building native extensions. This could take a while...
ERROR: Error installing awscli:
ERROR: Failed to build gem native extension./usr/bin/ruby2.0 extconf.rb
checking if the C compiler accepts ... yes
Building nokogiri using packaged libraries.
checking for gzdopen() in -lz... yes
checking for iconv... yes***********************************************************************
IMPORTANT NOTICE:
Building Nokogiri with a packaged version of libxml2-2.9.2
with the following patches applied:
- 0001-Revert-Missing-initialization-for-the-catalog-module.patch
- 0002-Fix-missing-entities-after-CVE-2014-3660-fix.patchTeam Nokogiri will keep on doing their best to provide security
updates in a timely manner, but if this is a concern for you and want
to use the system library instead; abort this installation process and
reinstall nokogiri as follows:gem install nokogiri -- --use-system-libraries
[--with-xml2-config=/path/to/xml2-config]
[--with-xslt-config=/path/to/xslt-config]If you are using Bundler, tell it to use the option:
bundle config build.nokogiri --use-system-libraries
bundle installNote, however, that nokogiri is not fully compatible with arbitrary
versions of libxml2 provided by OS/package vendors.***********************************************************************
Extracting libxml2-2.9.2.tar.gz into tmp/x86_64-redhat-linux-gnu/ports/libxml2/2.9.2... OK
Running patch with /usr/local/share/ruby/gems/2.0/gems/nokogiri-1.6.6.2/ports/patches/libxml2/0001-Revert-Missing-initialization-for-the-cat
alog-module.patch...
Running 'patch' for libxml2 2.9.2... ERROR, review '/usr/local/share/ruby/gems/2.0/gems/nokogiri-1.6.6.2/ext/nokogiri/tmp/x86_64-redhat-linu
x-gnu/ports/libxml2/2.9.2/patch.log' to see what happened.extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
:
:
Capistrano3でのjava webアプリのデプロイをいい感じにする
社内の有識者に聞いたらいい感じにできそうなのでいい感じにする。
あと、chefとも連携してサーバの構築周りも含めてやっていけるようにがんばる
Capistrano3でデプロイを試してみる。
java + tomcatのwarファイルの配布に現状はbash + perlなどを駆使してjenkinsからデプロイはできているが、いい加減苦しい
capistranoを触ってみる。
全く分からない状態からなのでここいらあたりを参考に
入門 Capistrano 3 ~ 全ての手作業を生まれる前に消し去りたい | エンジニアブログ | GREE Engineering
Capistrano3を最後にもう一度だけ懇切丁寧にまとめてみる - そのねこが学ぶとき
ざっと読んでもよく分からないのでとりあえず動かすことにしよう。
$ sudo gem install capistrano
$ sudo gem install capistrano-ext
$ sudo yum install -y ruby-devel
$ sudo yum install ruby20-devel gcc-c++
$ sudo gem install io-console
・ひな形を作る
$ mkdir test-projectなんかできたぞっと
$ cd test-project
$ cap install
Capfile構成から察するに、config/deploy ディレクトリが環境差異ごと、deploy.rb がデプロイの本体かな
lib/capistrano/tasks
config/
┝ deploy.rb
└ deploy/
┝ production.rb
└ staging.rb
deployで実現したいことをまとめる
1は既にできているので、2からが必要。
deploy.rb に
set :scm, :gitとあってgitがデフォルトっぽいが、今回はビルドは完了しているのでscmは使わない
どっかのブログに
set :scm, :noneとあったのでとりあえずこれで。
$ cap staging deploy:checkをするといい感じにnone が見つからないエラー。capistrano3だとnoneは使えないのか。
Capistrano3でSCMを使わずにdeployする - Qiita
ここでnoneを自分で作っている。なるほど、これならと思って書いてみるが、
$: << File.expand_path('../lib',__FILE__)
load 'capistrano/none.rb'
:
:ここの読み込む箇所でつっかえる…rubyの構文やお作法分からない…というか覚えるつもりがない。
scmを使わずにwarファイルを取得する方法を先に考える。
Capistrano 3 で Java Webアプリケーションをデプロイする - bati11 の 日記
capistranoの中身で何しているか全く読んでないけど、ここでやっていることをやればできそう
wgetでファイルを取得というのが何ともあれだけど…
そのまま真似する。
# deploy.rb
namespace :deploy do
Rake::Task["deploy:check"].clear_actions
task :check do
#invoke "#{scm}:check" gitを使わないので不要
invoke 'deploy:check:directories'
invoke 'deploy:check:linked_dirs'
invoke 'deploy:check:make_linked_dirs'
invoke 'deploy:check:linked_files'
end
end
次に
deploy:updatingを上書き
# deploy.rb
set :application, 'myapp'
set :job_url, 'http://jenkins.exsample.com/job/my_job/lastSuccessfulBuild/artifact/target/'namespace :deploy do
Rake::Task["deploy:updating"].clear_actions
task :updating => :new_release_path do
# invoke "deploy:set_current_revision" gitを使わないので不要
# warファイルを取得する。
on release_roles :all do
execute :mkdir, '-p', release_path
# wget でwarファイルを取得
execute :wget, "#{fetch(:job_url)}/#{fetch(:application)}.war -P #{release_path}"
#
execute :unzip, "#{release_path}/#{fetch(:application)}.war", '-d', "#{release_path}/#{fetch(:application)}"
end
end
end
再起動タスクも作る(再起動しないけど)
# deploy.rb
namespace :deploy do
task :restart do
on roles(:app), in: :sequence, wait: 5 do |host|
info("restart on #{host}")
# LBからサーバーを切り離して、アプリケーションサーバーを再起動したりする処理をここに書く
end
endafter :publishing, :restart
end
あとはサブタスクとしてtomcatの起動、停止も作る
# deploy.rb
namespace :deploy do
task :start_tomcat do
on roles(:app), in: :sequence, wait: 5 do |host|
info("start tomcat on #{host}")
execute :sudo, "#{fetch(:tomcat)} start"
end
endtask :stop_tomcat do
on roles(:app), in: :sequence, wait: 5 do |host|
info("stop tomcat on #{host}")
execute :sudo, "#{fetch(:tomcat)} stop"
end
end
end
これでひとまずは設定完了
cap staging deploy
したら一応は動いたので一旦はここまで。あとは
・ビルドの成果物をs3にアップロード
・リビジョン or ビルド番号の指定
・ロードバランサーの切り替え処理
・s3からwarファイルを取得
・デプロイ完了、失敗時に社内のslackへ通知
というあたりを対応していきたい。
mavenで環境ごとに使うjarを変える
参画しているプロジェクトで、サーバによって使うローカルリポジトリのjarを変える必要がでてきたのでメモ
そんなjarを使うなよ、という声が聞こえてきそうだが、会社間の関係上致し方なし…
まずは環境ごとのjarファイルを用意(サンプルとしてguava.jarを使う)
PROJECT_ROOT/lib/maven/guava/13.0.1/
┠ dev
┃ ┗ guava-13.0.1.jar
┃
┠ staging
┃ ┗ guava-13.0.1.jar
┃
┠ web01
┃ ┗ guava-13.0.1.jar
┃
┠ web02
┃ ┗ guava-13.0.1.jar
:
pom.xml に以下の設定を追加する。
dev
dev <!-- プロファイル名をプロパティーとして設定 -->
staging
staging
web01
web01
web02
web02
各種プロファイルに、maven -P dev 等と指定するとそのプロフィールが使えるように設定
次に、成果物の名前を決める。
これでプロフィール毎に成果物が作成されるようになる。
ROOT-${profile}-${env.BUILD_NUMBER}-${env.SVN_REVISION}
:
:
次に、dependency の設定
profileで設定した、propertiesの値を使うことによって動的に違うディレクトリのjarを参照させる。
com.google.guava
guava
13.0.1
system
${basedir}/lib/maven/guava/13.0.1/${profile}/guava-13.0.1.jar
あとはこれを
等と呼び出してやれば、サーバ毎に違うjarを参照するwarやjarが作られるようになる。
maven -P staging clean package -Dmaven.test.skip=true
これで作成されたwarをデプロイしてみところ、何やらクラスが見つからないエラーが出る。
ローカルリポジトリを参照しているjarは自動的にはコピーされないのか
同じようなことで躓いた人がいたのでこれを参考にしながら、
Mavenでローカルに存在するjarをパッケージしてみる
:
:
今回は欲しいのはローカルリポジトリのjarだけなので、スコープを system とした。
ここは必要に応じて変えられるのね。
これでビルドしたところ、無事環境ごとにjarを切り替えることができた。
物凄くバッドノウハウな気もするけれど、他にいい方法が思い浮かばなかったので…
mavenは便利だけど、覚えることがたくさんあって辛い…
postfixの設定
よく設定忘れてメール送れないとかに陥るので現状動いているサーバの設定ファイル
インスコとかは面倒くさいので割愛
1.ローカルホストからのみ送信
WEB+APP構成のAPP側でよくやる。ユーザ、パスワード必要ないので便利
vi /etc/postfix/main.cf
myhostname = homuhomu.com
mydomain = homuhomu.com
mynetworks = 127.0.0.0/8
mynetworks_style = host
myorigin = $mydomain
notify_classes = resource,software,policy
allow_percent_hack = yes
swap_bangpath = yes
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
mail_owner = postfix
inet_interfaces = all
mydestination = $mynetworks, $myhostname, localhost.$mydomain, localhost, $mydomain
unknown_local_recipient_reject_code = 550
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
home_mailbox = Maildir/
smtpd_banner = $myhostname ESMTP unknown
debug_peer_level = 2
debugger_command =
PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
xxgdb $daemon_directory/$process_name $process_id & sleep 5
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.3.3/samples
readme_directory = /usr/share/doc/postfix-2.3.3/README_FILES
2.SMTP認証形式
おそらく最も基本的な設定。SMTP認証にはlinuxユーザを使う
vi /etc/postfix/main.cf
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
mail_owner = postfix
myhostname = mail.homuhomu.com
mydomain = homuhomu.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
unknown_local_recipient_reject_code = 550
mynetworks = 192.168.1.0/24, 127.0.0.0/8, xxx.xxx.xx.xxx
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
home_mailbox = Maildir/smtpd_banner = $myhostname ESMTP unknown
debug_peer_level = 2
debugger_command =
PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
xxgdb $daemon_directory/$process_name $process_id & sleep 5
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.3.3/samples
readme_directory = /usr/share/doc/postfix-2.3.3/README_FILES
broken_sasl_auth_clients = yes
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
3.SMTP認証、リレーサーバ経由形式
借りたサーバが軒並みスパム認定のIPだった場合等に便利
vi /etc/postfix/main.cf
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
mail_owner = postfix
myhostname = mail.homuhomu.com
mydomain = homuhomu.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
unknown_local_recipient_reject_code = 550
mynetworks = 192.168.1.0/24, 127.0.0.0/8, xxx.xxx.xx.xxx
relay_domains = $mydestination
relayhost = relayhost.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
home_mailbox = Maildir/
smtpd_banner = $myhostname ESMTP unknown
debug_peer_level = 2
debugger_command =
PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
xxgdb $daemon_directory/$process_name $process_id & sleep 5sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.3.3/samples
readme_directory = /usr/share/doc/postfix-2.3.3/README_FILESallow_min_user = yes
broken_sasl_auth_clients = yes
smtpd_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions =
permit_mynetworks
permit_sasl_authenticated
reject_unauth_destinationmessage_size_limit = 10485760
4.複数バーチャルドメイン、mysql、postfixadmin
複数ドメイン分構築する時とかに便利。phpとかmysqlの入れ方はググるといいんじゃないかな
メールサーバ構築のまとめ(複数のバーチャルドメイン+Postfix+MySQL+Dovecot+procmail+Clam AntiVirus+spamassassin+postfixadmin) と中身ほぼ一緒だからこっち見た方がいいね
vi /etc/postfix/main.cf
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
mail_owner = postfix
myhostname = mail.homuhomu.com
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost
unknown_local_recipient_reject_code = 550
mynetworks = 192.168.1.0/24, 127.0.0.0/8, xxx.xxx.xx.xxx, yyy.yyy.yy.yyy
alias_maps = hash:/etc/aliases
home_mailbox = Maildir/
smtpd_banner = $myhostname ESMTP unknown
debug_peer_level = 2
debugger_command =
PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
xxgdb $daemon_directory/$process_name $process_id & sleep 5sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.3.3/samples
readme_directory = /usr/share/doc/postfix-2.3.3/README_FILES
allow_min_user = yes
owner_request_special = no
recipient_delimiter = +# sasl
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_local_domain = homuhomu.jp,homuhomu.com
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination# virtual
local_transport = local
virtual_transport = virtual
virtual_mailbox_base = /home/virtual
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_alias_domains = $virtual_alias_maps
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_uid_maps = static:1001
virtual_gid_maps = static:1001virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
virtual_mailbox_limit_override = yes
virtual_overquota_bounce = yes
virtual_mailbox_limit_inbox = yes# message size
message_size_limit = 102000000
mailbox_size_limit = 102400000
virtual_mailbox_limit = 102400000
5.セカンダリメールサーバ(キャッシュ保持のみ)
プライマリ側に行かなかったメールを10日キャッシュし、プライマリメールサーバに転送し続ける
冗長化と言えるのかな。用途は微妙ですね
・main.cf
vi /etc/postfix/main.cf・transport
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
mail_owner = postfix
myhostname = mail2.homuhomu.com
mydestination = localhost.$mydomain, localhost
mynetworks = 192.168.1.0/24, 127.0.0.0/8, xxx.xxx.xx.xx
trasnport_maps = hash:/etc/postfix/transport
relay_domains = $mydestination, homuhomu.jp
smtpd_banner = mail2.homuhomu.com ESMTP unknown
debug_peer_level = 2
debugger_command =
PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
xxgdb $daemon_directory/$process_name $process_id & sleep 5sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.3.3/samples
readme_directory = /usr/share/doc/postfix-2.3.3/README_FILESallow_min_user = yes
bounce_queue_lifetime = 10d
maximal_queue_lifetime = 10d
minimal_backoff_time = 120s
queue_run_delay = 120smessage_size_limit = 10485760
vi transporttransport編集後に下記コマンド実行
homuhomu.com smtp:[mail.homuhomu.com]
postmap /etc/postfix/transport
TLSは少し設定追加すれば使えるので割愛
mailmanとの連携もちょろっと書き足すだけですね
オススメはpostfixadminかな、WEB上でユーザ管理とか転送設定ができるのは便利
Facebook Graph API links で任意のサムネイルを表示する
facebookのGraph API links を使っていて軽くはまったのでメモ
公式ドキュメントをみるとフォームデータで
・access_token
・link (シェアするURL)
・message (メッセージ)
・picture (表示するサムネイル)
・name (サイト名タイトル)
・caption (キャプション)
・description (説明文)
を指定してやればいいらしい。
今回は picture の部分に任意のものを表示させたかったので、
URLに付与するパラメータによって og:image の内容が変わるようにしてやった。
http://hogehoge/sample/
と
http://hogehoge/sample/?id=10
でog:image が変わることまでは確認したが、シェアされるサムネイルが変わらず…
しかも、name,caption,description もすべて無視されてしまっている。
まあ、name,caption,description に関してはサイトのそのままのものを出せればいいけれど
picture の部分は任意のものが表示できないと非常に困る。
試行錯誤したものの分からなかったので社内の人に聞いてみたら、
公式のデバッガー くらい使えってから聞けよカスが!!!
と優しく教えてくれたのでさっそく使ってみる
Input URL or Access Tokenにhttp://hogehoge/sample/?id=10 を入れてみてデバッグを押してみる。
Object Properties のあたり
og:url: http://hogehoge/sample/
og:type: website
og:title: ほげほげ
og:image: http://hogehoge/sample/images/xxxxx.jpg
og:description: hogehoge
ふむー、og:url をちゃんと指定しないとパラメータ取り除かれちゃうのか
というわけで og:url を適切に設定したところ表示されたっぽい。
og:type
og:title
og:image
og:url
og:description
og:site
あたりは毎回設定したほうが無難かな。
面倒なら og:url と og:image だけでもいい気はするけど