Quantcast
Channel: テックラボ 来夢多゛
Viewing all 14 articles
Browse latest View live

AIPO V8を試しにビルドしてみる

$
0
0

GitHubのAIPOを取得してビルドしてみると「Embedded error: 1.8 は無効な VM バージョンです。」
001
というメッセージでエラー終了してしまった。

hack AIPOのmvn installの際に「1.7は無効なVMバージョンです」と表示される時の対応 | Hackを見てみる。

あれれ、でもなんで??
pom.xmlをのぞいてみると

<properties>
<aipo.version>8.0.0</aipo.version>
<tomcat.version>7.0.57</tomcat.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

となっており、AIPOのメジャーバージョンが8.0.0に上がっていた。

Maven ビルド時の Java バージョンの変更 | Hackによるとpom.xml内のmaven-compilerでJavaのバージョンを指定しているらしいので、見てみる

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<failOnError>true</failOnError>
<encoding>UTF-8</encoding>
</configuration>
</plugin>

おー確かに1.8になっています。

以前ビルド環境を構築した時にはjdk1.6.0_45だったので1.8に変更し再トライだ。
Java SE Development Kit 8 – DownloadsのページでWindows X64の「jdk-8u31-windows-x64.exe」をダウンロードしてインストール。

インストール後、バージョン確認
002

も一度ビルドしてみる。
003
ぉぉおー、通った。

さて、Version8、起動してみますかぁ。

次へ続く


AIPO V8.0.0を起動してみる(失敗)

$
0
0

AIPO V8.0.0のWindows環境でのビルドはできたようなので、引き続き起動させてみる。

JDKのインストール

JDKは既に、ビルドの段階でWindows X64の「jdk-8u31-windows-x64.exe」を「C:\home\aipo\jdk1.8.0_31」にインストール済み。
環境変数のJAVA_HOMEを変更を変更する。
004

Tomcat

TomcatをVersion6からVersion7に変更する。
http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.59/bin/apache-tomcat-7.0.59-windows-x64.zipをダウンロードし、c:\home\aipo以下に下記のように解凍する。
005
指定の「 JDBC 3(8.X-XXX JDBC 3) 」JDBCドライバの配置を行う
http://jdbc.postgresql.org/download/postgresql-8.1-415.jdbc3.jar
からダウンロード。
ページの指定通りに配置。
006

Eclipseの設定変更

eclips10
eclipse -celanコマンドでEclipseを起動する。
eclips7
「ウィンドウ」->「設定」->「Tomcat」を開き、”Tomcatバージョン”と”Tomcatホーム”を適用させる。
007

プロジェクトの作成

「ファイル」->「新規」->「Javaプロジェクト」と選択し、ビルド済みのフォルダを選択して[次へ]をクリック
008
次の画面で、そのまま[完了]をクリック
009

Tomcatの設定

Eclipseのプロジェクト(パッケージ)エクスプローラーより、プロジェクトフォルダを右クリック
appbuild30
「 Tomcatプロジェクト 」->「 コンテキスト定義を更新 」を選択して、Tomcat のコンテキストを設定します。
appbuild28
appbuild31

起動してみる

Eclipse の Tomcat Launcher より、「 Tomcat 起動 」を実行します。
・・・?はて・???
googleで調べる。
[ウィンドウ][パースペクティブのカスタマイズ]メニューを選択
exec01
[コマンド]タブを選択し、[Tomcat]のチェックボックスにチェックを入れる
exec02
なんか増えた。
exec03

ではTomcat起動してみる。
exec04
セキュリティ警告がでるが、全部許可する。
exec05
うーむ。なんかダメっぽい。
010

EclipseのJava8対応

Eclipseのインストールと日本語化とJDK8(Java8)対応[Eclipse4.4とEclipse4.3]のページに従って、Java8対応をしてみる。
Eclipseのメニューの[Help]>[Eclipse Marketplace…]をクリックします。
011
表示された画面の「Find:」にJava 8 Keplerと入力し検索する。
012
先頭の3つをインストール。インストール保留にしたら、[すぐにインストール(I)>]をクリック
013
[確認(c)>]をクリック
014
「 “m2e – Eclipse 用 Maven 統合” はすでにインストールされているため、代わりに更新が実行されます。」とか表示されたので、そのまま[確認(c)>]をクリック
015
ライセンスに同意して[完了(F)]をクリック
016
インストールが完了すると、Eclipse再起動を求められるので、再起動する。
017

Java8対応の確認

「ウィンドウ」->「設定」と選択し、表示されたウィンドウのレフトメニュー「Java」-「コンパイラー」をクリックする。
コンパイラー準拠レベルのドロップダウンに”1.8″が増えているいればOK
018

Java8用のプラグインのインストール

「ヘルプ」->「新規ソフトウェアのインストール」をクリック
019
作業対象の処はドロップダウンから”http://download.eclipse.org/eclipse/updates/4.3-P-builds/”を選択する。
すると、”Eclipse Java 8 Support(for Kepler SR2)”が表示されるので、それをチェックして、[次へ]
020
そのまま「次へ」をクリック
021
ライセンスに同意し、[完了]をクリック
022
インストールが完了すると、Eclipse再起動を求められるので、再起動する。
017

JVM設定

「ウィンドウ」->「設定」と選択し、表示されたウィンドウのレフトメニュー「Java」-「インストール済みのJRE」をクリックする。
そして、右側の[追加]ボタンをクリック
023
JREの型は、”標準VM”で[次へ]
024
[ディレクトリー]ボタンを押して、jre1.8がインストールされたディレクトリーを選択する。そして[完了]をクリック
025
jre1.8.0_31を選択し、[OK]をクリック
026
再び「ウィンドウ」->「設定」と選択し、表示されたウィンドウのレフトメニュー「Tomcat」-「JVM設定」をクリックする。
027
JREのところのドロップダウンから”jre1.8.0_31″を選択し、[OK]をクリック

もう一度AIPO起動してみる

JVMもちゃんとjre1.8.0_31になっているようで、前よりは進んだようだが、やっぱりダメだった。
028

なんか、cayenneのところがダメだと言っているようだ。
また、今度。

つづく

「承認」を見える化、そしてアドラー的強いチームの作り方

$
0
0

2月23日(月)、掲題の通りなにやらおもしろいセミナーに参加しました。
時間は15:00から17:30で、内容は2部構成。

第一部は、株式会社シンクスマイルさんの内容で、
【「承認」の文化を定着させることで見えてくるメンバーの個性とつながり】
というタイトルで、会社の経営理念を見える化し、メンバーに落とし込む
というもの。

具体的には、会社のバリューをアイコンで可視化し、社内SNSを使って
社員同士が褒め認め合う仕組みにしてある。相手の欠点を見るのではなく、
「良いところを褒める」というのがポイントのようです。

この仕組みのすごいところは、このアイコンにクレドを反映しているところです。
行動志向(まず実践し、やりながら考え…)と言ったことを、アクティブな
絵に置換え、アイコン化している。このアイコンがクレドの数だけ存在する、
という面白いもの。

そこにゲーム的要素を加え、社内で遊び感覚で導入し、縦ではなく横のつなが
りからバッジをもらう。バッジが集まると、その種類ごとに分類され他者から
見た自分の姿がグラフに現れ、自分の強みと弱みが分かるシステム。
なかなか面白い仕組みです。なにより参加している方々の笑顔が素敵でした。
株式会社シンクスマイル

第二部は、ビジネス書作家で株式会社小倉広事務所の代表、小倉さんによる
【アドラー心理学に基づく強いチームの作り方】でした。
キーワードは「勇気づけ」
勇気とは、困難を克服する活力のことを指し、「づけ」ることで勇気を支える
行動のことを指します。ですので、チームにとって大切なことは、勇気づけ合
う風土を持つことが大切です。

具体的には?
①正の注目、出来ているところに目を向ける
 100点満点中70点だったとした場合、70点を認め残り30点の対策をとる。
 つい、出来ていない30点部分に目が行き、そこを注意してしまうことありま
 せんか?先に叱るべきだろうか?と悩んだ時は、70点の行動の動機が善なの
 か悪なのかで判断します。悪の場合は、悪を正してあげてください。

②感謝を伝える
 ありがとう、を伝える。○○してくれてありがとう、助かった。
 褒める、よりも自分の気持ちを「ありがとう」を伝える。
 注)褒めすぎるとコントロールにつながり、褒めないとやらない、が起きる。
 
③貢献感
 「人は自分に価値がある」と思える時にだけ勇気をもつことができる。
 明確な目的をもち、その行為の先に何かの誰かの役に立つことが分かっている
 時、自分に価値を感じ勇気をもった行動が取れる。

④課題の分離
 それは誰の問題ですか?
 その課題の結末を引き受けるのは誰ですか?
 相手の課題に踏み込み、支配しようとしない。また、相手のいいなりにならない。
 
⑤Youメッセージ、Iメッセージ
 You:あなたは○○出来てえらいね。(上から目線)
  I :私は嬉しい。感動した。ありがとう。(横から目線)
 
人を勇気づけるポイントは、アイメッセージを使えるように練習するところにあるようです。
株式会社小倉広事務所

JenkinsのSlaveでGitコミットログとコンソール出力(MSBUILD出力)が文字化け

$
0
0

既にセットアップ済みのJenkins(on Ubuntu)をmasterとして、jenkins slave(on Windows7)を追加した際のお話。

Gitコミットログが文字化ける

「jenkins 文字化け」キーワードでgoogleすると、起動オプションに「-Dfile.encoding=utf-8」を追加して再起動すれば文字化けが治りまっせ!
という情報をすぐに見つけることができるが、残念ながらJenkis Slave on windows環境下には効果がなかった。
更にgoogleし続けると

という素晴らしいページたちを発見。
このページに従いjenkins slaveサービスが実行されているWindows7に下記のシステム環境変数をセットする。
JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8
slave-encoding3
反映されているかどうかコマンドプロンプトで確認
slave-encoding4
windows上のjenkis slaveサービスを再起動する。
slave-encoding5
jenkins master側からslaveのシステム情報を確認。
「Jenkinsの管理」>> 「ノードの管理」で表示されたノードの一覧で、確認したノードのメニューを開き「システム情報」を選択する。
slave-encoding8
file.encodingとsun.jnu.encodingが”UTF-8″になっているかを確認する。MS932の場合はダメ。
slave-encoding6
slave-encoding7

コンソール出力が文字化ける

Gitコミットログが解決したぜ!!!
と安堵していたら、今度はコンソール出力が文字化けするようになってしまった。
MSBUILD.exeの出力がsjisになっていたのが原因だったので、

のページを参考にして、jenkins masterのプロジェクトのビルドを下記のように変更。
slave-encoding9
このようにmsbuildを実施する前に”chcp 65001″を実施すると、文字化けしないようになった。

無理やりのような気がするが、OKとする。
めでたしめでたし。

Jenkinsのリモートビルド

$
0
0

Jenkinsビルドで、既存のgitプラグインでは期待するようなHookを設定できずに途方に暮れていたところ、設定のビルドトリガの所に”リモートからビルド(例:スクリプトから)”というものがあるではないか!
remo01
認証トークンには、適当な文字列を設定してやれば良いのかな・・・

試にlinuxサーバーのプロンプトから叩いてみる

$ wget 'https://JENKINS_URL/job/ジョブ名/buildWithParameters?token=トークン'
--2015-xx-xx 11:01:37--  https://JENKINS_URL/job/ジョブ名/buildWithParameters?token=トークン
ERROR: cannot verify xxxxxxxxx certificate, issued by `/C=xx/ST=xxxxx/L=xxxx/O=dept/OU=xxxxx /CN=xxxxxxx':
  Self-signed certificate encountered.
    ERROR: certificate common name `xxxxxxx' doesn't match requested host name `xxxxxxxxxxxxxxxxxx'.
To connect to xxxxxxxxxxxxx insecurely, use `--no-check-certificate'.

中途半端なオレオレ証明書のチェックで失敗してしまいました。
提案通りに「–no-check-certificate」オプションを付加してみる。

$ wget --no-check-certificate 'https://JENKINS_URL/job/ジョブ名/buildWithParameters?token=トークン'
--2015-xx-xx 11:15:09--  https://JENKINS_URL/job/ジョブ名/buildWithParameters?token=トークン
WARNING: cannot verify xxxxxxxxxx certificate, issued by `/C=xx/ST=xxxxx/L=xxxxx/O=xxxx/OU=xxxxxxxx/CN=xxxxxxx':
  Self-signed certificate encountered.
    WARNING: certificate common name `xxxxxxxxx' doesn't match requested host name `xxxxxxxxxxxxxxxxxx'.
Proxy request sent, awaiting response... 403 Forbidden
2015-xx-xx 11:15:09 ERROR 403: Forbidden.

証明書チェックはスルー出来たのだが、認証で失敗

googleで調査。
認証必須環境におけるJenkinsのスクリプトトリガーによるビルドの実行 | そんなこと覚えてないによると、認証付きjenkinsの場合、User IDとAPI トークンが必要らしい

Jenkinsのログインアカウント名で表示されるプルダウンメニューから”設定”をクリックする。
remo02
APIトークンの所に所望の物が表示されている。
remo03
では、もう一度チャレンジ

$ wget --no-check-certificate --auth-no-challenge --http-user=kitada --http-password=xxxxxxxxxxxxxxxx 'https://JENKINS_URL/job/ジョブ名/buildWithParameters?token=トークン'
--2015-xx-xx 11:48:26--  https://JENKINS_URL/job/ジョブ名/buildWithParameters?token=トークン
WARNING: cannot verify xxxxxxxxxx certificate, issued by `/C=xx/ST=xxxxx/L=xxxxx/O=xxxx/OU=xxxxxxxx/CN=xxxxxxx':
  Self-signed certificate encountered.
    WARNING: certificate common name `xxxxxxxxx' doesn't match requested host name `xxxxxxxxxxxxxxxxxx'.
Proxy request sent, awaiting response... 201 Created
Length: 0
Saving to: `buildWithParameters?token=トークン'

    [ <=>                                                                                                            ] 0           --.-K/s   in 0s      

2015-xx-xx 11:48:26 (0.00 B/s) - `buildWithParameters?token=トークン' saved [0/0]

よし、うまく行ったみたい。
ただし、毎回`buildWithParameters?token=トークン’みたいなゴミファイルができあがってしまうので、下記のように変更する。

$ wget -q -O - --no-check-certificate --auth-no-challenge --http-user=kitada --http-password=xxxxxxxxxxxxxxxx 'https://JENKINS_URL/job/ジョブ名/buildWithParameters?token=トークン' > /dev/null

これをBashスクリプトで実行すれば、なんとかなりそうだ。

「ネットワーク管理者」が表示されない

$
0
0

マルチサイト化すると管理ページのメニューに「サイトネットワーク管理者」が表示され、このメニューからプラグインのインストールや設定変更ができるようになるのだが、いつの間にか非表示になっていた。

なぜなのかはわからないが、このメニューが非表示になっているとプラグインが動作しなくなる。
「SEO対策」「https化」「スパムコメント対策」「wp-login.phpへのセキュリティー対策」・・・・などなど、色々とプラグインに頼っている関係上、早急に対処しなければならない。

一通り、マルチサイト化の設定は完了しており、設定は変更していないので、何らかのエラーだろうか。。。。さて、どうしょうか?

困った時のエラーログ

基本に返って(これしか知らない)、apacheのエラーログを調べてみる。

[Sat Jul 11 21:39:19 2015] [error] [client ***.***.***.***] WordPress \xe3\x83\x87\xe3\x83\xbc\xe3\x82\xbf\xe3\x83\x99\xe3\x83\xbc\xe3\x82\xb9\xe3\x82\xa8\xe3\x83\xa9\xe3\x83\xbc: Table './***/wp_sitemeta' is marked as crashed and should be repaired for query SELECT meta_value FROM wp_sitemeta WHERE site_id = 1 AND meta_key = 'site_name' made by require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), require('wp-includes/ms-settings.php'), get_current_site_name, referer: http://www.ramuda.co.jp/techlabo/archives/2109

むむ、” Table ‘./***/wp_sitemeta’ is marked as crashed and should be repaired for query SELECT meta_value FROM wp_sitemeta “などという不吉なエラーが大量に吐き出されているではないか!

テーブル補修

googleで調べてみると、テーブルがぶっ壊れた | 好奇心~気の向くままに~がヒット。
このサイトに従って、テーブルを補修してみる。
pic01
wp_sitemetaというテーブルが

  • warning : Table is marked as crashed
  • warning : 5 clients are usning or haven’t closed the table properly
  • error : Record at pos: 59420 is not remove-marked
  • error : record delete-link-chain corrupted
  • error : Corrupt

となっているらしい。・・・なんか深刻そうだが、直るのだろうか?
pic02
Bravo!!!!
なんかよくわからんけど、無事に修復したようです。

ネットワーク管理者メニュー復活

サーバー上で、”[root]# tail -f error_log”として、ページにアクセスしてみるとcrashedエラーは出力されなくなっていた。
次にwp-loing.phpで管理者ページにアクセスしてみる。
pic03
「サイトネットワーク管理者」が復活しています。
・・・なんで、だろうか。
まぁ、結果オーライということで。
良かった。

wp_sitemetaって何者

よくわからんが、「ネットワーク管理者」メニューには、データベースのwp_sitemetaテーブルが関係していて、このテーブルがクラッシュ状態で読み込みに失敗しているのが原因という事のようだ。
“wp_sitemeta”のキーワードでgoogleしてみると、確かにそれらしい記事がヒットしているので、ほぼ正しいと思われる。

今回は無事に修復できたからよかったが、やはりデータベースのバックアップを定期的に取っておこう!
と思った。

JenkinsスレーブとしてMacを追加

$
0
0

まだまだ、使いこなせていませんがJenkinsは非常に便利ですね。
豊富なプラグインや、皆様のknowledgeを見れば、大抵の事は実現できます。
今後もお世話になりそうです。

Macをスレーブとして追加

既に、Window7マシンをスレーブとして追加済みですが、今回は新たにMacをスレーブとして追加することになりました。
という訳で、そのセットアップ手順をここに残しておきます。

Jenkinsマスターでノードを追加

Jenkinsマスターにおいて、「Jenkinsの管理」->「ノードの管理」->「新規ノード作成」とクリックします。
fig01
fig15
ノード名を入力し、”ダムスレーブ”をチェック後、[OK]をクリック
fig03
リモートFSルートにMacマシンでのJenkinsのワークディレクトリーのPathを設定して、[保存]をクリックします。(適当入力し、後からMac側でパスが決定してから変更すれば良い)
fig14
無事にノードが追加されました。
fig05
まだMac側でのSlave設定が完了していないので、接続に失敗します。

Mac側での設定

Mac側では、下記の作業を実施する。

  • jenkinsユーザーを追加
  • slave.jarをダウンロードして、適当な場所に設置
  • Launchdに登録

jenkinsユーザー作成

jenkinsユーザーを作成すると、”/Users/jenkins”というディレクトリーできる。私は、その配下に”slave”というディレクトリーを新たに作成し、これをリモートFSルートにすることにしました。ここら辺は、各自で自由にしてよいところだと思います。

slave.jarをダウンロード

Macのブラウザにて、Jenkinsマスターサーバーへアクセスして、「Jenkinsの管理」->「ノードの管理」->とクリックする。ノード一覧が表示されているので、先ほど追加したMac用のノードをクリックする。
fig06
ページに表示されている”slave.jar”リンクから、slave.jarをダウンロードし、これを”/Users/jenkins/slave/”以下に配置する。そして、jnlpUrlやsecretは、あとでlaunchctl登録のplist内へ記述するのでメモっておく。

Launchdに登録

Mac起動時に自動的にslave.jarを実行させる為には、下記のようなplistと呼ばれる設定ファイル(?)を作成して、Launchdに登録しなければならない。(すいません。Mac、よく理解してません。。。)

/Library/LaunchDeamons/mac.slave.plist

<!--?xml version="1.0" encoding="UTF-8"?-->

        UserName
        jenkins
        Label
        [ラベル名]
        ProgramArguments

                /usr/bin/java
                -jar
                /Users/jenkins/slave/slave.jar
                -jnlpUrl
                [jnlpUrl]
                -secret
                [secret]
                -noCertificateCheck

        KeepAlive

        RunAtLoad

[jnlpUrl]や[secret]は先ほどメモっておいたものを記述。また、jenkinsマスターサーバーをhttps化しているような方は、”-noCertificateCheck”を追加して証明書のチェックを無効化する必要がある。

出来上がったplistファイルを下記コマンドで登録する。

 launchctl load /Library/LaunchDeamons/mac.slave.plist

Macを再起動後、Jenkinsのノード一覧を表示してみると、無事に接続されていた。
fig08

・・・「空きスワップ容量」が0Bなのは、後で調べてみます。

wp-login.phpへの攻撃に対して自動的にiptablesルールで対策する

$
0
0

WordPressの代表的なアタックの「WordPressのログインファイル(wp-login.php)にアクセスし、ログインを繰り返し狙う悪質な攻撃のブルートフォースアタック」。当サイトにも定期的に行われているようです。

実は先日、この攻撃が元でapacheのプロセスがメモリーを食いつぶしてしまい、サービス不能な状態になってしまいました。
ログを解析すると約4時間に渡って1~2秒周期でPOSTが繰り返えされ、最終的には「oom-killer」というLinuxの仕組みによりサービス不能の状態に陥っていたようです。この場合、ログインよりもサービスを不能にすることが目的のようで、いわゆる「Slow POST」という攻撃のようです。

ちょっとログを見てみる

試しにapacheのアクセスログを見てみましょう。

[root ~]# grep -o "^.*\"POST /wp-login\.php HTTP/1\.1" /var/log/httpd/access_log
122.25.184.151 - - [16/Jul/2015:01:28:03 +0900] "POST /wp-login.php HTTP/1.1
46.118.123.96 - - [16/Jul/2015:01:49:21 +0900] "POST /wp-login.php HTTP/1.1
46.118.123.96 - - [16/Jul/2015:05:01:58 +0900] "POST /wp-login.php HTTP/1.1
91.200.12.18 - - [16/Jul/2015:11:34:52 +0900] "POST /wp-login.php HTTP/1.1
91.200.12.18 - - [16/Jul/2015:11:34:56 +0900] "POST /wp-login.php HTTP/1.1
91.200.12.18 - - [16/Jul/2015:11:34:59 +0900] "POST /wp-login.php HTTP/1.1
91.200.12.18 - - [16/Jul/2015:11:35:02 +0900] "POST /wp-login.php HTTP/1.1
91.200.12.18 - - [16/Jul/2015:11:35:14 +0900] "POST /wp-login.php HTTP/1.1
91.200.12.18 - - [16/Jul/2015:11:35:25 +0900] "POST /wp-login.php HTTP/1.1
91.200.12.18 - - [16/Jul/2015:11:35:35 +0900] "POST /wp-login.php HTTP/1.1
91.200.12.18 - - [16/Jul/2015:11:35:41 +0900] "POST /wp-login.php HTTP/1.1
91.200.12.18 - - [16/Jul/2015:11:35:48 +0900] "POST /wp-login.php HTTP/1.1
91.200.12.18 - - [16/Jul/2015:11:35:54 +0900] "POST /wp-login.php HTTP/1.1
91.200.12.18 - - [16/Jul/2015:11:35:59 +0900] "POST /wp-login.php HTTP/1.1
91.200.12.18 - - [16/Jul/2015:11:36:04 +0900] "POST /wp-login.php HTTP/1.1
91.200.12.18 - - [16/Jul/2015:11:36:10 +0900] "POST /wp-login.php HTTP/1.1
91.200.12.18 - - [16/Jul/2015:11:36:15 +0900] "POST /wp-login.php HTTP/1.1
91.200.12.18 - - [16/Jul/2015:11:36:24 +0900] "POST /wp-login.php HTTP/1.1
91.200.12.18 - - [16/Jul/2015:11:36:31 +0900] "POST /wp-login.php HTTP/1.1
91.200.12.18 - - [16/Jul/2015:11:36:39 +0900] "POST /wp-login.php HTTP/1.1
91.200.12.18 - - [16/Jul/2015:11:36:44 +0900] "POST /wp-login.php HTTP/1.1
91.200.12.18 - - [16/Jul/2015:11:36:48 +0900] "POST /wp-login.php HTTP/1.1
91.200.12.18 - - [16/Jul/2015:11:36:52 +0900] "POST /wp-login.php HTTP/1.1
91.200.12.18 - - [16/Jul/2015:11:36:56 +0900] "POST /wp-login.php HTTP/1.1
91.200.12.18 - - [16/Jul/2015:11:37:01 +0900] "POST /wp-login.php HTTP/1.1

身に覚えのないIPアドレスの場合、おそらく不正ログインの試行です。そして、91.200.12.18からは明らかに意図したような攻撃後が残っています。おおよそ5秒周期でのPOSTなので、プログラムによる攻撃でしょう。

この短期間のアクセスをなんとか締め出したいもんですね。
では、1分間当たりのアクセス数を集計してみましょう。

[root ~]# grep -o "^.*\"POST /wp-login\.php HTTP/1\.1" /var/log/httpd/access_log | grep -o "^.*[0-9]\{2\}/.../[0-9]\{4\}:[0-9]\{2\}:[0-9]\{2\}" | uniq -c | sort
      1 117.104.134.135 - - [17/Jul/2015:10:11
      1 117.104.134.135 - - [17/Jul/2015:16:48
      1 122.216.28.206 - - [15/Jul/2015:19:16
      1 122.216.28.206 - - [17/Jul/2015:17:00
      1 122.25.184.151 - - [15/Jul/2015:02:40
      1 122.25.184.151 - - [16/Jul/2015:01:28
      1 122.25.184.151 - - [17/Jul/2015:00:27
      1 122.25.184.151 - - [17/Jul/2015:00:57
      1 122.25.184.151 - - [17/Jul/2015:02:18
      1 122.25.184.151 - - [17/Jul/2015:02:35
      1 122.25.184.151 - - [17/Jul/2015:02:36
      1 122.25.184.151 - - [17/Jul/2015:02:37
      1 122.25.184.151 - - [17/Jul/2015:02:50
      1 178.137.160.226 - - [18/Jul/2015:03:40
      1 178.137.160.226 - - [18/Jul/2015:11:39
      1 178.137.160.226 - - [18/Jul/2015:20:09
      1 46.118.123.96 - - [14/Jul/2015:09:41
      1 46.118.123.96 - - [16/Jul/2015:01:49
      1 46.118.123.96 - - [16/Jul/2015:05:01
      1 46.118.123.96 - - [16/Jul/2015:13:00
      1 46.118.123.96 - - [16/Jul/2015:22:26
      1 46.118.123.96 - - [16/Jul/2015:23:04
      2 122.25.184.151 - - [15/Jul/2015:01:48
      2 46.118.123.96 - - [17/Jul/2015:14:57
      3 91.200.12.18 - - [16/Jul/2015:11:34
      7 91.200.12.55 - - [15/Jul/2015:18:41
      8 91.200.12.18 - - [16/Jul/2015:11:35
      8 91.200.12.55 - - [15/Jul/2015:18:37
      9 91.200.12.18 - - [16/Jul/2015:11:39
      9 91.200.12.55 - - [15/Jul/2015:18:35
     10 91.200.12.18 - - [16/Jul/2015:11:36
     10 91.200.12.18 - - [16/Jul/2015:11:37
     10 91.200.12.18 - - [16/Jul/2015:11:38
     10 91.200.12.55 - - [15/Jul/2015:18:34
     10 91.200.12.55 - - [15/Jul/2015:18:36
     10 91.200.12.55 - - [15/Jul/2015:18:39
     11 91.200.12.55 - - [15/Jul/2015:18:33
     11 91.200.12.55 - - [15/Jul/2015:18:40
     14 91.200.12.55 - - [15/Jul/2015:18:38

同一IPからの1分間当たりのアクセス数が10回を超えるのは、明らかに攻撃ですね。
91.200.12.18、91.200.12.55とかがこれに該当します。

攻撃元のアクセスを制限する

黙って見ているのもなんなんで、この方々を締め出しましょう。

というわけで、下記のようなシェルスクリプトを作成しました。

#!/bin/bash

IPTABLES=/sbin/iptables
IFS=$'\n';
# 監視するapacheのログ
APACHE_LOG=/var/log/httpd/access_log
# 1分間当たりのログイン試行回数の許容
NOF_ATTEMPT=8
# 不正アクセス者のIPリスト
ATTACKER_LIST=/var/log/wp_attacker/iplist

for LINE in `grep -o "^.*\"POST .*/wp-login\.php HTTP/1\.1" $APACHE_LOG | grep -o "^.*\"POST " | grep -o "^.*[0-9]\{2\}/.../[0-9]\{4\}:[0-9]\{2\}:[0-9]\{2\}" | uniq -c`
do
  NN=`echo $LINE | sed 's/[\t ]\+/\t/g' | cut -f2`
  ATTACKER=`echo $LINE | sed 's/[\t ]\+/\t/g' | cut -f3`
  #echo $ATTACKER

  if [ $NN -ge $NOF_ATTEMPT ]; then
    # 1分間当たりの試行回数が許容以上のアクセスを検出
    if [ -e $ATTACKER_LIST ]; then
      # 既にリスト内に存在していないかどうかをチェック
      ENTRY=`grep $ATTACKER $ATTACKER_LIST | wc -l`
      if [ $ENTRY -eq 0 ]; then
        # 新参者発見
        echo $ATTACKER >> $ATTACKER_LIST
        echo "${ATTACKER} put into the attcker-list."
        # 該当IPアドレスからのアクセスを拒否するルールを挿入
        $IPTABLES -I INPUT -s $ATTACKER -j DROP
        # 上記ルールを48時間後に削除するスケジュールを登録
        echo "${IPTABLES} -D INPUT -s $ATTACKER -j DROP > /dev/null 2>&1; sed -i '/${ATTACKER}/d' $ATTACKER_LIST > /dev/null 2>&1" | at now+48hour > /dev/null 2>&1
      fi
    else
      # まだ不正アクセス者のIPリストが存在していない場合
      echo $ATTACKER > $ATTACKER_LIST
      echo "${ATTACKER} put into the attcker-list."
      # 該当IPアドレスからのアクセスを拒否するルールを挿入
      $IPTABLES -I INPUT -s $ATTACKER -j DROP
      # 上記ルールを48時間後に削除するスケジュールを登録
      echo "${IPTABLES} -D INPUT -s $ATTACKER -j DROP > /dev/null 2>&1; sed -i '/${ATTACKER}/d' $ATTACKER_LIST > /dev/null 2>&1" | at now+48hour > /dev/null 2>&1
    fi
  fi

done

このスクリプトを利用する場合、下記を設定してください。

  • APACHE_LOGへ監視するアパッチのログをフルパスで記述
  • NOF_ATTEMPTへwp-login.phpに対する一分間当たりのアクセス数での許容回数
  • ATTACKER_LISTには、不正アクセス者のIPリストを記録しておくためのファイルをフルパスで記述

不正アクセス者を検出した際には、iptablesのDROPルールにより48時間アクセスが禁止されます。
禁止する時間を変更したい場合は、
“echo “iptables -D INPUT -s $ATTACKER -j DROP > /dev/null 2>&1; sed -i ‘/${ATTACKER}/d’ $ATTACKER_LIST > /dev/null 2>&1″ | at now+48hour”
の48hourを所望の期間に書き換えてください。

上記スクリプトのダウンロードはこちらから

cronで10分毎に実施

上記のスクリプトを「wplogin_protect.sh」としてセーブし、実行権限を与える

[root ~]# chmod +x wplogin_protect.sh
[root ~]# ls -l wplogin_protect.sh
-rwxr-xr-x 1 root root 1907  7月 18 20:48 2015 wplogin_protect.sh

cronにより10分毎に実施するようにセットアップ

[root ~]# crontab -e
MAILTO=""
*/10  *  *  *  * /root/wplogin_protect.sh

素晴らしいプラグイン「Limit Login Attempts」

こんな面倒なスクリプトではなく、「Limit Login Attempts」を利用すれば、ブルートフォースアタックは十分に防げます。
(攻撃者からのPOSTアクセス自体は防げないようです。十分に理解してませんでした。よってDoS攻撃が目的の場合は、このプラグインでは防げないですね。 大変失礼いたしました。)
Limit Login Attempts – ログイン画面のログイン試行回数を制限できるWordPressプラグイン – ネタワン

素晴らしい・・・!?、あれれ

素晴らしいと思っていたのですが、数日後再びアパッチのアクセスログを見てみると

27.153.234.214 - - [22/Jul/2015:15:35:16 +0900] "POST /techlabo/archives/357/wp-login.php HTTP/1.1
27.153.234.214 - - [22/Jul/2015:15:35:17 +0900] "POST /techlabo/archives/672/wp-login.php HTTP/1.1
27.153.234.214 - - [22/Jul/2015:15:35:17 +0900] "POST /techlabo/archives/2595/wp-login.php HTTP/1.1
27.153.234.214 - - [22/Jul/2015:15:35:18 +0900] "POST /techlabo/archives/1586/wp-login.php HTTP/1.1
27.153.234.214 - - [22/Jul/2015:15:35:19 +0900] "POST /techlabo/archives/2216/wp-login.php HTTP/1.1
27.153.234.214 - - [22/Jul/2015:15:35:19 +0900] "POST /techlabo/archives/597/wp-login.php HTTP/1.1
27.153.234.214 - - [22/Jul/2015:15:35:19 +0900] "POST /techlabo/archives/37/wp-login.php HTTP/1.1
27.153.234.214 - - [22/Jul/2015:15:35:20 +0900] "POST /techlabo/archives/379/wp-login.php HTTP/1.1
27.153.234.214 - - [22/Jul/2015:15:35:20 +0900] "POST /techlabo/archives/392/wp-login.php HTTP/1.1
27.153.234.214 - - [22/Jul/2015:15:35:21 +0900] "POST /techlabo/archives/644/wp-login.php HTTP/1.1
27.153.234.214 - - [22/Jul/2015:15:35:21 +0900] "POST /techlabo/archives/357/wp-login.php HTTP/1.1
27.153.234.214 - - [22/Jul/2015:15:35:21 +0900] "POST /techlabo/archives/672/wp-login.php HTTP/1.1
27.153.234.214 - - [22/Jul/2015:15:35:22 +0900] "POST /techlabo/archives/2595/wp-login.php HTTP/1.1
27.153.234.214 - - [22/Jul/2015:15:35:23 +0900] "POST /techlabo/archives/1586/wp-login.php HTTP/1.1
27.153.234.214 - - [22/Jul/2015:15:35:23 +0900] "POST /techlabo/archives/2216/wp-login.php HTTP/1.1
27.153.234.214 - - [22/Jul/2015:15:35:24 +0900] "POST /techlabo/archives/37/wp-login.php HTTP/1.1
27.153.234.214 - - [22/Jul/2015:15:35:24 +0900] "POST /techlabo/archives/597/wp-login.php HTTP/1.1
27.153.234.214 - - [22/Jul/2015:15:35:25 +0900] "POST /techlabo/archives/392/wp-login.php HTTP/1.1
27.153.234.214 - - [22/Jul/2015:15:35:26 +0900] "POST /techlabo/archives/379/wp-login.php HTTP/1.1
27.153.234.214 - - [22/Jul/2015:15:35:27 +0900] "POST /techlabo/archives/672/wp-login.php HTTP/1.1
27.153.234.214 - - [22/Jul/2015:15:35:27 +0900] "POST /techlabo/archives/2595/wp-login.php HTTP/1.1
27.153.234.214 - - [22/Jul/2015:15:35:28 +0900] "POST /techlabo/archives/1586/wp-login.php HTTP/1.1
27.153.234.214 - - [22/Jul/2015:15:35:28 +0900] "POST /techlabo/archives/2216/wp-login.php HTTP/1.1
27.153.234.214 - - [22/Jul/2015:15:35:28 +0900] "POST /techlabo/archives/37/wp-login.php HTTP/1.1
27.153.234.214 - - [22/Jul/2015:15:35:29 +0900] "POST /techlabo/archives/379/wp-login.php HTTP/1.1
27.153.234.214 - - [22/Jul/2015:15:35:30 +0900] "POST /techlabo/archives/672/wp-login.php HTTP/1.1
27.153.234.214 - - [22/Jul/2015:15:35:30 +0900] "POST /techlabo/archives/2595/wp-login.php HTTP/1.1
27.153.234.214 - - [22/Jul/2015:15:35:31 +0900] "POST /techlabo/archives/2216/wp-login.php HTTP/1.1
27.153.234.214 - - [22/Jul/2015:15:35:32 +0900] "POST /techlabo/archives/672/wp-login.php HTTP/1.1
27.153.234.214 - - [22/Jul/2015:15:35:34 +0900] "POST /techlabo/archives/672/wp-login.php HTTP/1.1

がズラーっと。。。ノーガードで撃たれまくりですね。
なんかプラグインがうまく効いていないみたい。(うーむ、設定が悪いのかなぁ・・・・)

よくよく考えてみると、Limit Login Attemptのプラグインがiptablesルールまでセットしてくれる訳はないのでした。 m(_ _)m スンマセン。愚か者でした。

兎に角、この方々にもご退場頂くことにしました。

grep -o "^.*\"POST /wp-login\.php HTTP/1\.1" $APACHE_LOG
を訂正して、
grep -o "^.*\"POST .*/wp-login\.php HTTP/1\.1" $APACHE_LOG
に変更

AIPO7でオレオレ(自己)認証局とサーバ証明書を使う

$
0
0

どうやら最新版バージョン 44.0.2403.89 mのChromeブラウザで、オレオレ証明書を利用したサイトにアクセスすると「この接続ではプライバシーが保護されません」という警告が、頻繁にでるようになり、まともに操作できなくなるらしい。
jjj
jjj2

IEでは、毎回、下記のような警告がでるが、それほど気にすることはなかった。
jjj3

「とりあえずIEか、Firefoxを使ってよ!」と言い放ち、軽く流してしまいたい所だけど、潔く対応することにしましょう。

下記のサイトを参考に作業を進める。

(大変わかりやすいサイトで助かりました。)
Linux – 独自SSLサーバ認証局(CA)作成とサーバ証明書発行 – Qiita
そして、「 Windowsでは2017年1月1日以降、SHA1証明書サイトへのSSL通信が接続拒否される」らしいので、どうせならSHA-2証明書で行うことにしょう。
httpd – CentOS6などで俺俺CAとSHA2証明書を作るときのメモ – Qiita
SHA-1 証明書の受付終了と SHA-2 証明書への移行について|サイバートラスト

認証局構築

openssl.cnfを修正する。

[root]# vi /etc/pki/tls/openssl.cnf
    (中略)
####################################################################
[ CA_default ]

#dir             = /etc/pki/CA           # Where everything is kept  (コメントアウト)
dir             = /etc/ssl/ramudaCA               #                   (変更)
certs           = $dir/certs            # Where the issued certs are kept
crl_dir         = $dir/crl              # Where the issued crl are kept
database        = $dir/index.txt        # database index file.
    (中略)

CA用に下記のディレクトリーをそれぞれ作成し、秘密鍵が置かれるprivateディレクトリーは権限を0×700とします。

[root]# mkdir -p /etc/ssl/ramudaCA/certs
[root]# mkdir -p /etc/ssl/ramudaCA/private
[root]# mkdir -p /etc/ssl/ramudaCA/crl
[root]# mkdir -p /etc/ssl/ramudaCA/newcerts
[root]# chmod 700 /etc/ssl/ramudaCA/private/

シリアルを初期化

[root]# echo "01" > /etc/ssl/ramudaCA/serial

証明書データベースを初期化します。

[root]# touch /etc/ssl/ramudaCA/index.txt

ここまでの作業で下記のようになりました。

[root]# ls -l /etc/ssl/ramudaCA/
total 20
drwxr-xr-x 2 root root 4096 Jul 24 14:21 certs
drwxr-xr-x 2 root root 4096 Jul 24 14:22 crl
-rw-r--r-- 1 root root    0 Jul 24 14:26 index.txt
drwxr-xr-x 2 root root 4096 Jul 24 14:22 newcerts
drwx------ 2 root root 4096 Jul 24 14:21 private
-rw-r--r-- 1 root root    3 Jul 24 14:25 serial

CA証明書/秘密鍵作成

自己署名済みの証明書と秘密鍵を作成します。/etc/pki/tls/openssl.cnf のdafault_mdの指定がCentOS6まではsha1なので、
-sha256のオプションを明示します。

[root]# cd /etc/ssl/ramudaCA/
[root ramudaCA]# openssl req -new -x509 -newkey rsa:2048 -out cacert.pem -keyout private/cakey.pem -days 1825 -sha256
Generating a 2048 bit RSA private key
..................................................................................................................................+++
.........................+++
writing new private key to 'private/cakey.pem'
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:JP
State or Province Name (full name) []:Tokyo
Locality Name (eg, city) [Default City]:Chiyoda-ku
Organization Name (eg, company) [Default Company Ltd]:Ramuda Co.,Ltd
Organizational Unit Name (eg, section) []:Network Dept.
Common Name (eg, your name or your server's hostname) []:ramuda.co.jp
Email Address []:webmaster@ramuda.co.jp

下記のファイルが作成される。

/etc/ssl/ramudaCA/cacert.pem : 自己署名済みCA証明書
/etc/ssl/ramudaCA/private/cakey.pem : CA証明書の秘密鍵

CA証明書の秘密鍵は他人にみられると困るので、こうします。

[root ramudaCA]# chown root:root /etc/ssl/ramudaCA/private/cakey.pem
[root ramudaCA]# chmod 600 /etc/ssl/ramudaCA/private/cakey.pem

証明書が正しく出来たか確認

[root ramudaCA]# openssl x509 -in /etc/ssl/ramudaCA/cacert.pem -text
Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number: 13491930018308904667 (0xbb3cf6de4bbb56db)
    Signature Algorithm: sha256WithRSAEncryption
        Issuer: C=JP, ST=Tokyo, L=Chiyoda-ku, O=Ramuda Co.,Ltd, OU=Network Dept., CN=ramuda.co.jp/emailAddress=webmaster@ramuda.co.jp
        Validity
            Not Before: Jul 24 05:51:39 2015 GMT
            Not After : Jul 22 05:51:39 2020 GMT
        Subject: C=JP, ST=Tokyo, L=Chiyoda-ku, O=Ramuda Co.,Ltd, OU=Network Dept., CN=ramuda.co.jp/emailAddress=webmaster@ramuda.co.jp
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                Public-Key: (2048 bit)
                Modulus:
                    00:eb:c2:fd:31:88:4e:b3:f9:04:d0:3a:12:e9:db:
                    95:b7:a0:96:c2:5c:5c:2b:71:45:19:cb:fa:c8:0a:
(中略)
                    99:6c:ab:85:1c:82:36:1b:7b:8c:a9:c5:10:19:e8:
                    14:11
                Exponent: 65537 (0x10001)
        X509v3 extensions:
            X509v3 Subject Key Identifier:
                02:CE:E4:52:CF:67:46:B6:20:8D:56:E1:D8:92:A0:33:46:2D:86:01
            X509v3 Authority Key Identifier:
                keyid:02:CE:E4:52:CF:67:46:B6:20:8D:56:E1:D8:92:A0:33:46:2D:86:01

            X509v3 Basic Constraints:
                CA:TRUE
    Signature Algorithm: sha256WithRSAEncryption
         1b:3e:b4:48:2d:a7:85:e5:bd:7c:d0:5b:7e:8a:9f:1e:23:07:
         f4:d9:b7:ae:69:57:4e:d8:d8:b8:e7:17:6d:03:04:07:ff:3c:
           (中略)
         fe:b9:ff:c7:78:b4:8a:28:30:e6:4c:68:13:2e:1e:6e:8d:94:
         01:06:6f:22
-----BEGIN CERTIFICATE-----
MIIEITCCAwmgAwIBAgIJALs89t5Lu1bbMA0GCSqGSIb3DQEBCwUAMIGmMQswCQYD
VQQGEwJKUDEOMAwGA1UECAwFVG9reW8xEzARBgNVBAcMCkNoaXlvZGEta3UxFzAV
   (中略)
AHSvIK2uI8NZyhYv6BJYyRqBH7Y3LOByM6EPZKDlgpgx5ftkrUiIMq48wyic+SUb
qa9+gzmgZiNWCMObpK98itDJngyhytQjoyzl2hm7tf65/8d4tIooMOZMaBMuHm6N
lAEGbyI=
-----END CERTIFICATE-----

ブラウザにCA証明書を組み込む

ブラウザに取り込めるDER形式にエンコードします。

[root ramudaCA]# openssl x509 -inform PEM -outform DER -in /etc/ssl/ramudaCA/cacert.pem -out /etc/ssl/ramudaCA/ramudaCAcert.der

作成されたramudaCAcert.derは、利用するPCにダウンロードして「ルート証明書ストア」などにインストールする必要があります。

サーバ証明書

作成した自己認証CA局を使って目的のサイト自体の証明書を発行します。
以下のようなディレクトリを作成しました。

 [root]# mkdir -p /etc/ssl/ramuda.co.jp

鍵ペアと証明書要求(CSR)ファイルを作成します。

[root@IPD-0185 ~]# openssl req -new -sha256 -keyout /etc/ssl/ramuda.co.jp/aipo_server_key.pem -out /etc/ssl/ramuda.co.jp/aipo_server_csr.pem
Generating a 2048 bit RSA private key
................................................................................................+++
....................................................................................+++
writing new private key to '/etc/ssl/ramuda.co.jp/aipo_server_key.pem'
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:JP
State or Province Name (full name) []:Tokyo
Locality Name (eg, city) [Default City]:Chiyoda-ku
Organization Name (eg, company) [Default Company Ltd]:Ramuda Co.,Ltd
Organizational Unit Name (eg, section) []:Network Dept.
Common Name (eg, your name or your server's hostname) []:ramuda.co.jp
Email Address []:webmaster@ramuda.co.jp

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

作成が終わると以下のファイルができあがります。

/etc/ssl/ramudua.co.jp/aipo_server_csr.pem : サーバ証明書要求(CSR)
/etc/ssl/ramuda.co.jp/aipo_server_key.pem : サーバ秘密鍵

自己認証CA局で署名(CA管理者)

サーバ証明書要求(CSR)を先ほど作成した自己認証CA局で署名します。

[root@IPD-0185 ~]# openssl ca -md sha256 -out /etc/ssl/ramuda.co.jp/aipo_server_cert.pem -infiles /etc/ssl/ramuda.co.jp/aipo_server_csr.pem
Using configuration from /etc/pki/tls/openssl.cnf
Enter pass phrase for /etc/ssl/ramudaCA/private/cakey.pem:
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 2 (0x2)
        Validity
            Not Before: Jul 24 07:01:27 2015 GMT
            Not After : Jul 23 07:01:27 2016 GMT
        Subject:
            countryName               = JP
            stateOrProvinceName       = Tokyo
            organizationName          = Ramuda Co.,Ltd
            organizationalUnitName    = Network Dept.
            commonName                = ramuda.co.jp
            emailAddress              = webmaster@ramuda.co.jp
        X509v3 extensions:
            X509v3 Basic Constraints:
                CA:FALSE
            Netscape Comment:
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier:
                38:7D:05:4A:BA:4D:1F:30:E0:35:17:0F:72:EF:4B:DA:DC:2B:40:88
            X509v3 Authority Key Identifier:
                keyid:02:CE:E4:52:CF:67:46:B6:20:8D:56:E1:D8:92:A0:33:46:2D:86:01

Certificate is to be certified until Jul 23 07:01:27 2016 GMT (365 days)
Sign the certificate? [y/n]:y

1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

証明書が正しく出来たかを確認する

[root]# openssl x509 -in /etc/ssl/ramuda.co.jp/aipo_server_cert.pem -text
Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number: 2 (0x2)
    Signature Algorithm: sha256WithRSAEncryption
        Issuer: C=JP, ST=Tokyo, L=Chiyoda-ku, O=Ramuda Co.,Ltd, OU=Network Dept., CN=ramuda.co.jp/emailAddress=webmaster@ramuda.co.jp
        Validity
            Not Before: Jul 24 07:01:27 2015 GMT
            Not After : Jul 23 07:01:27 2016 GMT
        Subject: C=JP, ST=Tokyo, O=Ramuda Co.,Ltd, OU=Network Dept., CN=ramuda.co.jp/emailAddress=webmaster@ramuda.co.jp
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                Public-Key: (2048 bit)
                Modulus:
                    00:ea:55:dc:db:6b:d6:8a:f3:f1:71:a2:91:4c:58:
                    e8:04:f5:9e:1c:24:6b:fb:10:1c:4b:96:8e:02:0a:
                        (中略)
                    0a:05:db:ee:1e:7f:54:22:58:90:1e:f4:e1:c5:8e:
                    2c:6a:92:47:33:97:a5:69:b3:b2:b4:71:c0:a3:cf:
                    de:17
                Exponent: 65537 (0x10001)
        X509v3 extensions:
            X509v3 Basic Constraints:
                CA:FALSE
            Netscape Comment:
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier:
                38:7D:05:4A:BA:4D:1F:30:E0:35:17:0F:72:EF:4B:DA:DC:2B:40:88
            X509v3 Authority Key Identifier:
                keyid:02:CE:E4:52:CF:67:46:B6:20:8D:56:E1:D8:92:A0:33:46:2D:86:01

    Signature Algorithm: sha256WithRSAEncryption
         98:5f:6a:02:0a:4f:68:8e:64:4f:df:05:78:4e:26:ca:4a:b4:
         bd:d8:b3:d8:c7:05:a2:da:1e:a0:d6:04:6b:c3:cd:4e:92:93:
           (中略)
         a4:63:23:7b:a9:c5:c6:ea:b7:b7:4e:3c:9a:11:da:aa:2d:7a:
         0e:7c:71:ba
-----BEGIN CERTIFICATE-----
MIIELzCCAxegAwIBAgIBAjANBgkqhkiG9w0BAQsFADCBpjELMAkGA1UEBhMCSlAx
DjAMBgNVBAgMBVRva3lvMRMwEQYDVQQHDApDaGl5b2RhLWt1MRcwFQYDVQQKDA5S
(中略)
SfyENOswi5jnTc5xW5WPIA8sACIrXJ4ZGFPC96w+myJDS1wsuXKxXPrV0bDopGMj
e6nFxuq3t048mhHaqi16Dnxxug==
-----END CERTIFICATE-----

出来上がったファイルはこんな感じとなります。

[root]# ls -l /etc/ssl/ramuda.co.jp/
total 16
-rw-r--r-- 1 root root 4735 Jul 24 15:37 aipo_server_cert.pem  サーバ証明書(署名済み)
-rw-r--r-- 1 root root 1090 Jul 24 15:30 aipo_server_csr.pem   サーバ証明書要求(CSR) ←もういらない!?
-rw-r--r-- 1 root root 1834 Jul 24 15:30 aipo_server_key.pem   サーバ秘密鍵

パスフレーズをキャンセルする

サーバ再起動時にいちいちパスフレーズを入力するのが面倒です。 パスフレーズは、サーバ秘密鍵に書かれているのでこんな感じでRSAキーを書き込みます。

[root]# openssl rsa -in /etc/ssl/ramuda.co.jp/aipo_server_key.pem -out /etc/ssl/ramuda.co.jp/aipo_server_key.pem.nopass
Enter pass phrase for /etc/ssl/ramuda.co.jp/aipo_server_key.pem:
writing RSA key
[root]# ls -l /etc/ssl/ramuda.co.jp/
total 20
-rw-r--r-- 1 root root 4735 Jul 24 15:37 aipo_server_cert.pem
-rw-r--r-- 1 root root 1090 Jul 24 15:30 aipo_server_csr.pem
-rw-r--r-- 1 root root 1834 Jul 24 15:30 aipo_server_key.pem
-rw-r--r-- 1 root root 1679 Jul 24 15:46 aipo_server_key.pem.nopass  パスフレーズが書き込まれている秘密鍵

証明書と秘密鍵をサーバーへ組み込む

AIPOのSSL対応は、SSLへの対応|無料グループウェア「アイポ」に記載されています。が、しかし、結局正当な方式がないので、リバースプロキシを使用して簡単にAipoを既存のApacheと連携させる+SSL対応+自動起動|成長の果実の方式を利用しています。

出来上がった証明書と(パスフレーズ書き込み済みの)秘密鍵を下記のように組み込み、apahceを再起動する。

[root]# vi /etc/httpd/conf.d/ssl.conf
  (省略)
#   SSL Protocol support:
# List the enable protocol levels with which clients will be able to
# connect.  Disable SSLv2 access by default:
SSLProtocol All -SSLv2 -SSLv3

#   SSL Cipher Suite:
# List the ciphers that the client is permitted to negotiate.
# See the mod_ssl documentation for a complete list.
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW

#   Server Certificate:
# Point SSLCertificateFile at a PEM encoded certificate.  If
# the certificate is encrypted, then you will be prompted for a
# pass phrase.  Note that a kill -HUP will prompt again.  A new
# certificate can be generated using the genkey(1) command.
#SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateFile /etc/ssl/ramuda.co.jp/aipo_server_cert.pem

#   Server Private Key:
#   If the key is not combined with the certificate, use this
#   directive to point at the key file.  Keep in mind that if
#   you've both a RSA and a DSA private key you can configure
#   both in parallel (to also allow the use of DSA ciphers, etc.)
#SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
SSLCertificateKeyFile /etc/ssl/ramuda.co.jp/aipo_server_key.pem.nopass

正しく整合性が取れると

ルート証明書をアクセスするPCにインストールし、ルート署名付きのサーバー証明書との整合性がとれると、Chormeの場合下記のような表示となる。
206
鍵マークが黄緑色になる。

また、SHA256を利用したので、鍵マークをクリックして証明書の詳細を表示した際に
205
「××××への接続は新しい暗号スィートにより暗号化されています」の表示になっているはずである。

ルート証明書をインストールする

$
0
0

自己(CA)認証局を作り、そのルート証明書を発行した場合のインストール手順である。
(ちなみに下記は全てWindows 8.1での例です。)

InternetExplorerの場合

ルート証明書のダウンロードリンクをクリックすると
111
「xxxxxxから(ルート証明書名)を開くか、または保存しますか?」と聞かれるので、[ファイルを開く]ボタンをクリックする。

下記の”セキュリティの警告”ダイアログが表示されるので、[開く]ボタンをクリックする。
002

下記の”証明書”ダイアログが表示されるので、[証明書のインストール(I)..]ボタンをクリックする。
004

証明書のインポートウィザードの開始となる。
保存場所に表示されているラジオボタンを適宜選択して[次へ]ボタンをクリックする。(画像ではローカルコンピューターが選択されている)
005

“証明書をすべて次のストアに配置する”を選択し、[参照(R)]ボタンをクリックする。
006

下記の”証明書ストアの選択”ダイアログが表示されるので、「信頼されたルート証明機関」を選択状態としてから、[OK]ボタンをクリックする。
007
証明書ストア: のテキストボックスに”信頼されたルート証明機関”と入力されているはずなので、そのまま[次へ]ボタンをクリックする。
008

[完了]ボタンをクリックする。
009
正しくインポートされました。と表示されるので[OK]ボタンをクリックする。
010

ルート証明書とサーバー証明書の整合性が取れるとIE10では下記のように、鍵マークが金色になるはず。
204
EV SSLなどの正式な証明書ではないのでURLの背景は白いままである。

Google Chromeの場合

ルート証明書のダウンロードリンクをクリックすると
111
そのままダウンロードされるので、ダウロードされた証明書をクリックする。

下記の”セキュリティの警告”ダイアログが表示されるので、[開く]ボタンをクリックする。
002

下記の”証明書”ダイアログが表示されるので、[証明書のインストール(I)..]ボタンをクリックする。
004

証明書のインポートウィザードの開始となる。
保存場所に表示されているラジオボタンを適宜選択して[次へ]ボタンをクリックする。(画像ではローカルコンピューターが選択されている)
005

“証明書をすべて次のストアに配置する”を選択し、[参照(R)]ボタンをクリックする。
006

下記の”証明書ストアの選択”ダイアログが表示されるので、「信頼されたルート証明機関」を選択状態としてから、[OK]ボタンをクリックする。
007
証明書ストア: のテキストボックスに”信頼されたルート証明機関”と入力されているはずなので、そのまま[次へ]ボタンをクリックする。
008

[完了]ボタンをクリックする。
009
正しくインポートされました。と表示されるので[OK]ボタンをクリックする。
010

ルート証明書とサーバー証明書の整合性が取れるとIE10では下記のように、鍵マークが黄緑色になるはず。
206

Firefoxの場合

ルート証明書のダウンロードリンクをクリックすると
112
“証明書のインポート”のダイアログが表示されるので、「この認証局によるWebサイトの識別を信頼する」をチェックして、[OK]をクリックする。

ちなみにFirefoxでは証明書を独自で管理しており、今、取り込んだ証明書を見る為には、
画面右端のボタンをクリックし、「オプション」を選択する。
200
レフトメニューの「詳細」をクリックし、その後「証明書」をクリックする
201
[証明書を表示(C)...]ボタンをクリックする。
200
“証明書マネージャ”のダイアログが表示され、「認証局証明書」タブをクリックすると一覧に表示されているはずである。
203

社内イントラからプライベートIPでアクセスしなければないらない時

せっかく、自己(CA)認証局のルート証明書をインストールして、ルート署名付きサーバー証明書をWebサーバーにセットアップしても、イントラでの社内アクセスの場合、プライベート(192.168.1.xxxなどの)IPで接続しなければならない。

アクセスするPCがWindowsマシンの場合は、hostsファイルへCommon NameとプレイベートIPを記述し、名前解決させるようにすればセキュリティー警告を回避することができる。

hostsファイルの書き換えは、下記の親切なページを参照してくだされ。

ubuntu 12.04LTSへredmine+nginx+unicornでインストール

$
0
0

Ubuntu 12.04LTSで稼働中のnginxとunicornにredmineをセットアップします。

githubからclone

root@IPD-0197:/home# cd /var
root@IPD-0197:/var# git clone https://github.com/redmine/redmine.git
Cloning into 'redmine'...
remote: Counting objects: 123923, done.
remote: Compressing objects: 100% (434/434), done.
remote: Total 123923 (delta 245), reused 0 (delta 0), pack-reused 123481
Receiving objects: 100% (123923/123923), 41.71 MiB | 3.42 MiB/s, done.
Resolving deltas: 100% (94044/94044), done.
Checking connectivity... done.
root@IPD-0197:/var# cd redmine/
root@IPD-0197:/var/redmine# ls
app  config     CONTRIBUTING.md  doc    files    lib  plugins  Rakefile     script  tmp
bin  config.ru  db               extra  Gemfile  log  public   README.rdoc  test
root@IPD-0197:/var/redmine#

最新のstableブランチに切り替える

root@IPD-0197:/var/redmine# git branch -a
* master
  remotes/origin/0.6-stable
  remotes/origin/0.7-stable
  remotes/origin/0.8-stable
  remotes/origin/0.9-stable
  remotes/origin/1.0-stable
  remotes/origin/1.1-stable
  remotes/origin/1.2-stable
  remotes/origin/1.3-stable
  remotes/origin/1.4-stable
  remotes/origin/2.0-stable
  remotes/origin/2.1-stable
  remotes/origin/2.2-stable
  remotes/origin/2.3-stable
  remotes/origin/2.4-stable
  remotes/origin/2.5-stable
  remotes/origin/2.6-stable
  remotes/origin/3.0-stable
  remotes/origin/3.1-stable
  remotes/origin/HEAD -> origin/master
  remotes/origin/integration-to-svn-stable-1.0
  remotes/origin/integration-to-svn-trunk
  remotes/origin/master
  remotes/origin/nbc
  remotes/origin/plugin-hooks
  remotes/origin/swistak
  remotes/origin/work
root@IPD-0197:/var/redmine# git checkout -b 3.1-stable remotes/origin/3.1-stable
Branch 3.1-stable set up to track remote branch 3.1-stable from origin.
Switched to a new branch '3.1-stable'
root@IPD-0197:/var/redmine# git branch
* 3.1-stable
  master
root@IPD-0197:/var/redmine#

mysqlにredmine用のデータベースとユーザーを作成します。(passwordは独自に設定)

root@IPD-0197:/var/redmine# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 64
Server version: 5.5.44-0ubuntu0.12.04.1 (Ubuntu)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database redmine character set utf8;
Query OK, 1 row affected (0.00 sec)

mysql> create user 'redmine'@'localhost' identified by '**********';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on redmine.* to 'redmine'@'localhost';
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
root@IPD-0197:/var/redmine#

データベースのコンフィグレーション

root@IPD-0197:/var/redmine# ls config
additional_environment.rb.example  boot.rb                    database.yml.example  environments  locales    settings.yml
application.rb                     configuration.yml.example  environment.rb        initializers  routes.rb
root@IPD-0197:/var/redmine# cp config/database.yml{.example,}
root@IPD-0197:/var/redmine# ls config
additional_environment.rb.example  boot.rb                    database.yml          environment.rb  initializers  routes.rb
application.rb                     configuration.yml.example  database.yml.example  environments    locales       settings.yml

root@IPD-0197:/var/redmine# vi config/database.yml
# Default setup is given for MySQL with ruby1.9.
# Examples for PostgreSQL, SQLite3 and SQL Server can be found at the end.
# Line indentation must be 2 spaces (no tabs).

production:
  adapter: mysql2
  database: redmine
  host: localhost
  username: redmine   <== 変更
  password: "**********" <== 変更
  encoding: utf8

development:
  adapter: mysql2
  database: redmine_development
  host: localhost
  username: root
  password: ""
  encoding: utf8

  (以下省略)

セッションストア秘密鍵を生成する

root@IPD-0197:/var/redmine# rake generate_secret_token
Could not find gem 'rails (= 4.2.4) ruby' in the gems available on this machine.
Run `bundle install` to install missing gems.

なんかエラーになった。
指示通りに”bundle install”やってみる。

root@IPD-0197:/var/redmine# bundle install
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this application for all
non-root users on this machine.
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Installing rake 10.4.2
Installing i18n 0.7.0
Installing json 1.8.3
Installing minitest 5.8.1
Installing thread_safe 0.3.5
Installing tzinfo 1.2.2
Installing activesupport 4.2.4
Installing builder 3.2.2
Installing erubis 2.7.0
Installing mini_portile 0.6.2
Installing nokogiri 1.6.6.2
Installing rails-deprecated_sanitizer 1.0.3
Installing rails-dom-testing 1.0.7
Installing loofah 2.0.3
Installing rails-html-sanitizer 1.0.2
Installing actionview 4.2.4
Installing rack 1.6.4
Installing rack-test 0.6.3
Installing actionpack 4.2.4
Installing globalid 0.3.6
Installing activejob 4.2.4
Installing mime-types 2.6.2
Installing mail 2.6.3
Installing actionmailer 4.2.4
Installing actionpack-action_caching 1.1.1
Installing actionpack-xml_parser 1.0.2
Installing activemodel 4.2.4
Installing arel 6.0.3
Installing activerecord 4.2.4
Using bundler 1.6.2
Installing xpath 2.0.0
Installing capybara 2.5.0
Installing ffi 1.9.10
Installing childprocess 0.5.6
Installing coderay 1.1.0
Installing docile 1.1.5
Installing thor 0.19.1
Installing railties 4.2.4
Installing jquery-rails 3.1.4
Installing metaclass 0.0.4
Installing mocha 1.1.0
Installing multi_json 1.11.2
Installing mysql2 0.3.20
Installing net-ldap 0.3.1
Installing protected_attributes 1.1.3
Installing ruby-openid 2.3.0
Installing rack-openid 1.4.2
Installing sprockets 3.4.0
Installing sprockets-rails 2.3.3
Installing rails 4.2.4
Installing rbpdf 1.18.6
Installing rdoc 4.2.0
Installing redcarpet 3.3.3
Installing request_store 1.0.5

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /usr/local/bin/ruby extconf.rb
checking for gcc... yes
checking for Magick-config... no
checking for pkg-config... yes
Package MagickCore was not found in the pkg-config search path.
Perhaps you should add the directory containing `MagickCore.pc'
to the PKG_CONFIG_PATH environment variable
No package 'MagickCore' found
checking for outdated ImageMagick version (<= 6.4.9)... *** 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.

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}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/usr/local/bin/ruby

Gem files will remain installed in /usr/local/lib/ruby/gems/2.0.0/gems/rmagick-2.15.4 for inspection.
Results logged to /usr/local/lib/ruby/gems/2.0.0/gems/rmagick-2.15.4/ext/RMagick/gem_make.out
An error occurred while installing rmagick (2.15.4), and Bundler cannot continue.
Make sure that `gem install rmagick -v '2.15.4'` succeeds before bundling.
root@IPD-0197:/var/redmine#

またまた、失敗した。

http://d.hatena.ne.jp/kitokitoki/20130714/p3

Ubuntu13.04 で gem install rmagick -v ’2.13.2′ に失敗したときの対処例 – わからん
のページを参照。

root@IPD-0197:/var/redmine# apt-get install imagemagick libmagickwand-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
imagemagick is already the newest version.
The following packages were automatically installed and are no longer required:
  git-man liberror-perl libjpeg62
Use 'apt-get autoremove' to remove them.
The following NEW packages will be installed:
  libmagickwand-dev
0 upgraded, 1 newly installed, 0 to remove and 3 not upgraded.
Need to get 449 kB of archives.
After this operation, 2,538 kB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://jp.archive.ubuntu.com/ubuntu/ precise-updates/main libmagickwand-dev amd64 8:6.6.9.7-5ubuntu3.3 [449 kB]
Fetched 449 kB in 0s (2,173 kB/s)
Selecting previously unselected package libmagickwand-dev.
(Reading database ... 111593 files and directories currently installed.)
Unpacking libmagickwand-dev (from .../libmagickwand-dev_8%3a6.6.9.7-5ubuntu3.3_amd64.deb) ...
Processing triggers for man-db ...
Setting up libmagickwand-dev (8:6.6.9.7-5ubuntu3.3) ...
root@IPD-0197:/var/redmine#
root@IPD-0197:/var/redmine# gem install rmagick -v '2.15.4'
Building native extensions.  This could take a while...
Successfully installed rmagick-2.15.4
Parsing documentation for rmagick-2.15.4
Installing ri documentation for rmagick-2.15.4
Done installing documentation for rmagick after 11 seconds
1 gem installed

再度チャレンジしてみると、成功

root@IPD-0197:/var/redmine# bundle install
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this application for all
non-root users on this machine.
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Using rake 10.4.2
Using i18n 0.7.0
Using json 1.8.3
Using minitest 5.8.1
Using thread_safe 0.3.5
Using tzinfo 1.2.2
Using activesupport 4.2.4
Using builder 3.2.2
Using erubis 2.7.0
Using mini_portile 0.6.2
Using nokogiri 1.6.6.2
Using rails-deprecated_sanitizer 1.0.3
Using rails-dom-testing 1.0.7
Using loofah 2.0.3
Using rails-html-sanitizer 1.0.2
Using actionview 4.2.4
Using rack 1.6.4
Using rack-test 0.6.3
Using actionpack 4.2.4
Using globalid 0.3.6
Using activejob 4.2.4
Using mime-types 2.6.2
Using mail 2.6.3
Using actionmailer 4.2.4
Using actionpack-action_caching 1.1.1
Using actionpack-xml_parser 1.0.2
Using activemodel 4.2.4
Using arel 6.0.3
Using activerecord 4.2.4
Using bundler 1.6.2
Using xpath 2.0.0
Using capybara 2.5.0
Using ffi 1.9.10
Installing childprocess 0.5.7
Using coderay 1.1.0
Using docile 1.1.5
Using thor 0.19.1
Using railties 4.2.4
Using jquery-rails 3.1.4
Using metaclass 0.0.4
Using mocha 1.1.0
Using multi_json 1.11.2
Using mysql2 0.3.20
Using net-ldap 0.3.1
Using protected_attributes 1.1.3
Using ruby-openid 2.3.0
Using rack-openid 1.4.2
Using sprockets 3.4.0
Using sprockets-rails 2.3.3
Using rails 4.2.4
Using rbpdf 1.18.6
Using rdoc 4.2.0
Using redcarpet 3.3.3
Using request_store 1.0.5
Using rmagick 2.15.4
Installing rubyzip 1.1.7
Installing websocket 1.2.2
Installing selenium-webdriver 2.48.1
Installing simplecov-html 0.9.0
Installing simplecov 0.9.2
Installing yard 0.8.7.6
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
root@IPD-0197:/var/redmine#

やっとできる

root@IPD-0197:/var/redmine# rake generate_secret_token
root@IPD-0197:/var/redmine#

データベース上にテーブルを作成

Redmineのインストールディレクトリで下記コマンドを実行します。

root@IPD-0197:/var/redmine# RAILS_ENV=production rake db:migrate
== 1 Setup: migrating =========================================================
-- create_table("attachments", {:force=>true})
   -> 0.0904s
-- create_table("auth_sources", {:force=>true})
   -> 0.0919s
-- create_table("custom_fields", {:force=>true})
   -> 0.0932s
-- create_table("custom_fields_projects", {:id=>false, :force=>true})
   -> 0.0920s
-- create_table("custom_fields_trackers", {:id=>false, :force=>true})
   -> 0.0920s
-- create_table("custom_values", {:force=>true})
   -> 0.0920s
-- create_table("documents", {:force=>true})
   -> 0.0920s
-- add_index("documents", ["project_id"], {:name=>"documents_project_id"})
   -> 0.1758s

 (中略)

== 20150525103953 ClearEstimatedHoursOnParentIssues: migrating ================
== 20150525103953 ClearEstimatedHoursOnParentIssues: migrated (0.0023s) =======

== 20150526183158 AddRolesTimeEntriesVisibility: migrating ====================
-- add_column(:roles, :time_entries_visibility, :string, {:limit=>30, :default=>"all", :null=>false})
   -> 0.3009s
== 20150526183158 AddRolesTimeEntriesVisibility: migrated (0.3010s) ===========

== 20150528084820 AddRolesAllRolesManaged: migrating ==========================
-- add_column(:roles, :all_roles_managed, :boolean, {:default=>true, :null=>false})
   -> 0.5031s
== 20150528084820 AddRolesAllRolesManaged: migrated (0.5033s) =================

== 20150528092912 CreateRolesManagedRoles: migrating ==========================
-- create_table(:roles_managed_roles, {:id=>false})
   -> 0.2423s
== 20150528092912 CreateRolesManagedRoles: migrated (0.2424s) =================

== 20150528093249 AddUniqueIndexOnRolesManagedRoles: migrating ================
-- add_index(:roles_managed_roles, [:role_id, :managed_role_id], {:unique=>true})
   -> 0.1922s
== 20150528093249 AddUniqueIndexOnRolesManagedRoles: migrated (0.1924s) =======

root@IPD-0197:/var/redmine#

デフォルトデータをデータベースに登録

root@IPD-0197:/var/redmine# RAILS_ENV=production rake redmine:load_default_data

Select language: ar, az, bg, bs, ca, cs, da, de, el, en, en-GB, es, es-PA, et, eu, fa, fi, fr, gl, he, hr, hu, id, it, ja, ko, lt, lv, mk, mn, nl, no, pl, pt, pt-BR, ro, ru, sk, sl, sq, sr, sr-YU, sv, th, tr, uk, vi, zh, zh-TW [en] ja
====================================
Default configuration data loaded.
root@IPD-0197:/var/redmine#

webrick で起動テスト

redmineとMySQLのインストールが問題なくできているかを確認する為にwebrickという
Ruby簡易HTTPサーバを利用してRedmineの起動テストを実施する。

root@IPD-0197:/var/redmine# ruby bin/rails server webrick -e production
=> Booting WEBrick
=> Rails 4.2.4 application starting in production on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2015-10-25 22:44:26] INFO  WEBrick 1.3.1
[2015-10-25 22:44:26] INFO  ruby 2.0.0 (2013-11-22) [x86_64-linux]
[2015-10-25 22:44:26] INFO  WEBrick::HTTPServer#start: pid=25718 port=3000

Webブラウザでアクセスしてみる。

http://localhost:3000

確認できたら、[CTRL]+Cで終了する。

^C[2015-10-25 22:45:12] INFO  going to shutdown ...
[2015-10-25 22:45:12] INFO  WEBrick::HTTPServer#start done.
Exiting

Redmineディレクトリー権限を変更

root@IPD-0197:/var/redmine# chown -R www-data:www-data files/ log/ tmp/ public/plugin_assets/
root@IPD-0197:/var/redmine# chmod -R 755 files/ log/ tmp/ public/plugin_assets/
root@IPD-0197:/var/redmine# ll
total 112
drwxr-xr-x 17 root     root     4096 Oct 25 16:06 ./
drwxr-xr-x 17 root     root     4096 Oct 25 16:00 ../
drwxr-xr-x  6 root     root     4096 Oct 23 01:01 app/
drwxr-xr-x  2 root     root     4096 Oct 23 01:01 bin/
drwxr-xr-x  5 root     root     4096 Oct 23 01:22 config/
-rw-r--r--  1 root     root      160 Oct 23 01:01 config.ru
-rw-r--r--  1 root     root      241 Oct 23 01:01 CONTRIBUTING.md
drwxr-xr-x  3 root     root     4096 Oct 25 16:11 db/
drwxr-xr-x  2 root     root     4096 Oct 23 01:11 doc/
drwxr-xr-x  5 root     root     4096 Oct 23 01:01 extra/
drwxr-xr-x  2 www-data www-data 4096 Oct 23 01:01 files/
-rw-r--r--  1 root     root     3475 Oct 23 01:11 Gemfile
-rw-r--r--  1 root     root     4298 Oct 25 16:06 Gemfile.lock
drwxr-xr-x  8 root     root     4096 Oct 23 01:11 .git/
-rw-r--r--  1 root     root      739 Oct 23 01:01 .gitignore
-rw-r--r--  1 root     root      615 Oct 23 01:01 .hgignore
drwxr-xr-x  7 root     root     4096 Oct 23 01:11 lib/
drwxr-xr-x  2 www-data www-data 4096 Oct 25 16:09 log/
drwxr-xr-x  2 root     root     4096 Oct 23 01:01 plugins/
drwxr-xr-x  8 root     root     4096 Oct 23 01:01 public/
-rw-r--r--  1 root     root      275 Oct 23 01:01 Rakefile
-rw-r--r--  1 root     root      205 Oct 23 01:01 README.rdoc
drwxr-xr-x  2 root     root     4096 Oct 23 01:01 script/
drwxr-xr-x 11 root     root     4096 Oct 23 01:11 test/
drwxr-xr-x  9 www-data www-data 4096 Oct 25 16:20 tmp/
-rw-r--r--  1 root     root     6631 Oct 23 01:11 .travis.yml

Unicornのインストールと設定

root@IPD-0197:/var/redmine# echo "gem 'unicorn'" >> Gemfile.local
root@IPD-0197:/var/redmine# bundle install
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this application for all
non-root users on this machine.
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Using rake 10.4.2
Using i18n 0.7.0
Using json 1.8.3
Using minitest 5.8.1
Using thread_safe 0.3.5
Using tzinfo 1.2.2
Using activesupport 4.2.4
Using builder 3.2.2
Using erubis 2.7.0
Using mini_portile 0.6.2
Using nokogiri 1.6.6.2
Using rails-deprecated_sanitizer 1.0.3
Using rails-dom-testing 1.0.7
Using loofah 2.0.3
Using rails-html-sanitizer 1.0.2
Using actionview 4.2.4
Using rack 1.6.4
Using rack-test 0.6.3
Using actionpack 4.2.4
Using globalid 0.3.6
Using activejob 4.2.4
Using mime-types 2.6.2
Using mail 2.6.3
Using actionmailer 4.2.4
Using actionpack-action_caching 1.1.1
Using actionpack-xml_parser 1.0.2
Using activemodel 4.2.4
Using arel 6.0.3
Using activerecord 4.2.4
Using bundler 1.6.2
Using xpath 2.0.0
Using capybara 2.5.0
Using ffi 1.9.10
Using childprocess 0.5.7
Using coderay 1.1.0
Using docile 1.1.5
Using thor 0.19.1
Using railties 4.2.4
Using jquery-rails 3.1.4
Installing kgio 2.10.0
Using metaclass 0.0.4
Using mocha 1.1.0
Using multi_json 1.11.2
Using mysql2 0.3.20
Using net-ldap 0.3.1
Using protected_attributes 1.1.3
Using ruby-openid 2.3.0
Using rack-openid 1.4.2
Using sprockets 3.4.0
Using sprockets-rails 2.3.3
Using rails 4.2.4
Installing raindrops 0.15.0
Using rbpdf 1.18.6
Using rdoc 4.2.0
Using redcarpet 3.3.3
Using request_store 1.0.5
Using rmagick 2.15.4
Using rubyzip 1.1.7
Using websocket 1.2.2
Using selenium-webdriver 2.48.1
Using simplecov-html 0.9.0
Using simplecov 0.9.2
Installing unicorn 4.9.0
Using yard 0.8.7.6
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
root@IPD-0197:/var/redmine#

インストールされたようだ。
サンプルファイルのありかを探して、redmineインストールディレクトリーにコピーする。

root@IPD-0197:/# find . -name "unicorn.conf*"
./usr/local/lib/ruby/gems/2.0.0/gems/unicorn-4.9.0/examples/unicorn.conf.minimal.rb
./usr/local/lib/ruby/gems/2.0.0/gems/unicorn-4.9.0/examples/unicorn.conf.rb
./home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/unicorn-4.6.3/examples/unicorn.conf.minimal.rb
./home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/unicorn-4.6.3/examples/unicorn.conf.rb
root@IPD-0197:/#
root@IPD-0197:/# cp /usr/local/lib/ruby/gems/2.0.0/gems/unicorn-4.9.0/examples/unicorn.conf.rb /var/redmine/config/unicorn.rb

編集する

# Sample verbose configuration file for Unicorn (not Rack)
#
# This configuration file documents many features of Unicorn
# that may not be needed for some applications. See
# http://unicorn.bogomips.org/examples/unicorn.conf.minimal.rb
# for a much simpler configuration file.
#
# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete
# documentation.

# Use at least one worker per core if you're on a dedicated server,
# more will usually help for _short_ waits on databases/caches.
worker_processes 4

# Since Unicorn is never exposed to outside clients, it does not need to
# run on the standard HTTP port (80), there is no reason to start Unicorn
# as root unless it's from system init scripts.
# If running the master process as root and the workers as an unprivileged
# user, do this to switch euid/egid in the workers (also chowns logs):
# user "unprivileged_user", "unprivileged_group"
user "www-data", "www-data"  <strong><span style="color: #ff0000;">追加</span></strong>

# Help ensure your application will always spawn in the symlinked
# "current" directory that Capistrano sets up.
#working_directory "/path/to/app/current" # available in 0.94.0+ <strong><span style="color: #ff0000;">コメントアウト</span></strong>
working_directory "/var/redmine" # available in 0.94.0+ <strong><span style="color: #ff0000;">追加</span></strong>

# listen on both a Unix domain socket and a TCP port,
# we use a shorter backlog for quicker failover when busy
#listen "/path/to/.unicorn.sock", :backlog => 64 <strong><span style="color: #ff0000;">コメントアウト</span></strong>
#listen 8080, :tcp_nopush => true  <strong><span style="color: #ff0000;">コメントアウト</span></strong>
listen "/tmp/redmine.sock", :backlog => 64   <strong><span style="color: #ff0000;">追加</span></strong>

# nuke workers after 30 seconds instead of 60 seconds (the default)
#timeout 30  <strong><span style="color: #ff0000;">コメントアウト</span></strong>

# feel free to point this anywhere accessible on the filesystem
#pid "/path/to/app/shared/pids/unicorn.pid"  <strong><span style="color: #ff0000;">コメントアウト</span></strong>
pid File.expand_path('tmp/pids/unicorn.pid', ENV['RAILS_ROOT'])  <strong><span style="color: #ff0000;">追加</span></strong>

# By default, the Unicorn logger will write to stderr.
# Additionally, ome applications/frameworks log to stderr or stdout,
# so prevent them from going to /dev/null when daemonized here:
#stderr_path "/path/to/app/shared/log/unicorn.stderr.log"  <strong><span style="color: #ff0000;">コメントアウト</span></strong>
#stdout_path "/path/to/app/shared/log/unicorn.stdout.log"  <strong><span style="color: #ff0000;">コメントアウト</span></strong>
stderr_path File.expand_path('log/unicorn.stderr.log', ENV['RAILS_ROOT']) <strong><span style="color: #ff0000;">追加</span></strong>
stdout_path File.expand_path('log/unicorn.stdout.log', ENV['RAILS_ROOT']) <strong><span style="color: #ff0000;">追加</span></strong>

# combine Ruby 2.0.0dev or REE with "preload_app true" for memory savings
# http://rubyenterpriseedition.com/faq.html#adapt_apps_for_cow
preload_app true
GC.respond_to?(:copy_on_write_friendly=) and
  GC.copy_on_write_friendly = true

# Enable this flag to have unicorn test client connections by writing the
# beginning of the HTTP headers before calling the application.  This
# prevents calling the application for connections that have disconnected
# while queued.  This is only guaranteed to detect clients on the same
# host unicorn runs on, and unlikely to detect disconnects even on a
# fast LAN.
check_client_connection false

# local variable to guard against running a hook multiple times
run_once = true

before_fork do |server, worker|
  # the following is highly recomended for Rails + "preload_app true"
  # as there's no need for the master process to hold a connection
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.connection.disconnect!

  # Occasionally, it may be necessary to run non-idempotent code in the
  # master before forking.  Keep in mind the above disconnect! example
  # is idempotent and does not need a guard.
  if run_once
    # do_something_once_here ...
    run_once = false # prevent from firing again
  end

  # The following is only recommended for memory/DB-constrained
  # installations.  It is not needed if your system can house
  # twice as many worker_processes as you have configured.
  #
  # # This allows a new master process to incrementally
  # # phase out the old master process with SIGTTOU to avoid a
  # # thundering herd (especially in the "preload_app false" case)
  # # when doing a transparent upgrade.  The last worker spawned
  # # will then kill off the old master process with a SIGQUIT.
   old_pid = "#{server.config[:pid]}.oldbin"     <strong><span style="color: #ff0000;">有効化</span></strong>
   if old_pid != server.pid               <strong><span style="color: #ff0000;">有効化</span></strong>
     begin                         <strong><span style="color: #ff0000;">有効化</span></strong>
       sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU  <strong><span style="color: #ff0000;">有効化</span></strong>
       Process.kill(sig, File.read(old_pid).to_i)   <strong><span style="color: #ff0000;">有効化</span></strong>
     rescue Errno::ENOENT, Errno::ESRCH         <strong><span style="color: #ff0000;">有効化</span></strong>
     end                          <strong><span style="color: #ff0000;">有効化</span></strong>
   end                            <strong><span style="color: #ff0000;">有効化</span></strong>
  #
  # Throttle the master from forking too quickly by sleeping.  Due
  # to the implementation of standard Unix signal handlers, this
  # helps (but does not completely) prevent identical, repeated signals
  # from being lost when the receiving process is busy.
   sleep 1
end

after_fork do |server, worker|
  # per-process listener ports for debugging/admin/migrations
  # addr = "127.0.0.1:#{9293 + worker.nr}"
  # server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true)

  # the following is *required* for Rails + "preload_app true",
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.establish_connection

  # if preload_app is true, then you may also want to check and
  # restart any other shared sockets/descriptors such as Memcached,
  # and Redis.  TokyoCabinet file handles are safe to reuse
  # between any number of forked children (assuming your kernel
  # correctly implements pread()/pwrite() system calls)
end

動作確認する。

root@IPD-0197:/var/redmine# bundle exec unicorn_rails -c config/unicorn.rb -E production -D
root@IPD-0197:/var/redmine# ps axu | grep unicorn
git       1809  0.0  1.7 516996 139408 ?       Sl   Oct13   0:16 unicorn_rails master -D -c /home/git/gitlab/config/unicorn.rb -E production
git       2197  0.0  1.7 521380 137836 ?       Sl   Oct13   0:09 unicorn_rails worker[0] -D -c /home/git/gitlab/config/unicorn.rb -E production
git       2201  0.0  1.7 526736 141992 ?       Sl   Oct13   0:09 unicorn_rails worker[1] -D -c /home/git/gitlab/config/unicorn.rb -E production
root     26364  7.3  1.3 333848 110276 ?       Sl   23:32   0:02 unicorn_rails master -c config/unicorn.rb -E production -D
www-data 26368  0.0  1.3 333848 106804 ?       Sl   23:32   0:00 unicorn_rails worker[0] -c config/unicorn.rb -E production -D
www-data 26371  0.0  1.3 333848 106824 ?       Sl   23:32   0:00 unicorn_rails worker[1] -c config/unicorn.rb -E production -D
www-data 26374  0.0  1.3 333848 106652 ?       Sl   23:32   0:00 unicorn_rails worker[2] -c config/unicorn.rb -E production -D
www-data 26377  0.0  1.3 333980 106880 ?       Sl   23:32   0:00 unicorn_rails worker[3] -c config/unicorn.rb -E production -D
root     26384  0.0  0.0   9388   940 pts/0    S+   23:32   0:00 grep --color=auto unicorn
root@IPD-0197:/var/redmine# kill -KILL 26364
root@IPD-0197:/var/redmine# ps axu | grep unicorn
git       1809  0.0  1.7 516996 139408 ?       Sl   Oct13   0:16 unicorn_rails master -D -c /home/git/gitlab/config/unicorn.rb -E production
git       2197  0.0  1.7 521380 137836 ?       Sl   Oct13   0:09 unicorn_rails worker[0] -D -c /home/git/gitlab/config/unicorn.rb -E production
git       2201  0.0  1.7 526736 141992 ?       Sl   Oct13   0:09 unicorn_rails worker[1] -D -c /home/git/gitlab/config/unicorn.rb -E production
root     26386  0.0  0.0   9384   940 pts/0    S+   23:35   0:00 grep --color=auto unicorn

Redmineの起動スクリプト

root@IPD-0197:/var/redmine# vi /etc/init.d/unicorn
#!/bin/sh

### BEGIN INIT INFO
# Provides:          unicorn
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start unicorn for redmine at boot time
# Description:       The Unicorn for redmine
### END INIT INFO
# <span style="color: #ff0000;">bundlerのバージョンはインストールされたものに合わせる</span>
export PATH="${PATH:+$PATH:}/usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.6.2/bin:/usr/local/bin"
#PATH=/bin:/usr/bin:/sbin:/usr/sbin

# move to project root directory
NAME=unicorn
ENVIROMENT=production

# SCRIPT_DIR=`dirname $0`
# ROOT_DIR=$(cd "${SCRIPT_DIR}/../../"; pwd)
ROOT_DIR="/var/redmine"

PID="${ROOT_DIR}/tmp/pids/unicorn.pid"
CONF="${ROOT_DIR}/config/unicorn.rb"
BUNDLE_BIN="/usr/local/bin/bundle"

start()
{
  if [ -e $PID ]; then
    echo "$NAME already started";
    exit 1;
  fi
  echo "start $NAME";
  cd $ROOT_DIR
  bundle exec unicorn_rails -c ${CONF} -E ${ENVIROMENT} -D
}

stop()
{
  if [ ! -e $PID ]; then
    echo "$NAME not started";
    exit 1;
  fi
  echo "stop $NAME";
  kill -QUIT `cat ${PID}`
  rm -f $PID
}

force_stop()
{
  if [ ! -e $PID ]; then
    echo "$NAME not started";
    exit 1;
  fi
  echo "stop $NAME";
  kill -TERM `cat ${PID}`
  rm -f $PID
}

reload()
{
  if [ ! -e $PID ]; then
    echo "$NAME not started";
    start
    exit 0;
  fi
  echo "reload $NAME";
  kill -HUP `cat ${PID}`
}

restart()
{
    stop
    start
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  force-stop)
    force_stop
    ;;
  reload)
    reload
    ;;
  restart)
    restart
    ;;
  *)
    echo "Syntax Error: release [start|stop|force-stop|reload|restart]"
    ;;
esac

root@IPD-0197:/var/redmine# chmod +x /etc/init.d/unicorn
root@IPD-0197:/var/redmine# sysv-rc-conf unicorn on
root@IPD-0197:/var/redmine# sysv-rc-conf --list | grep unicorn
unicorn      2:on       3:on    4:on    5:on
root@IPD-0197:/var/redmine#

システム停止・起動時の問題

root@IPD-0197:/var/redmine# sysv-rc-conf --list | grep unicorn
unicorn      2:on       3:on    4:on    5:on

システム停止時にちゃんと/etc/init.d/unicorn stopが呼ばれるように設定変更。

root@IPD-0197:/var/redmine# sysv-rc-conf --level 3 unicorn on
root@IPD-0197:/var/redmine# sysv-rc-conf --level 4 unicorn on
root@IPD-0197:/var/redmine# sysv-rc-conf --level 5 unicorn on
root@IPD-0197:/var/redmine# sysv-rc-conf --level 1 unicorn off
root@IPD-0197:/var/redmine# sysv-rc-conf --level 6 unicorn off

Redmineをサブディレクトリーで動作させる

root@IPD-0197:/var/redmine# vi config/environment.rb
# Load the rails application
require File.expand_path('../application', __FILE__)

# Make sure there's no plugin in vendor/plugin before starting
vendor_plugins_dir = File.join(Rails.root, "vendor", "plugins")
if Dir.glob(File.join(vendor_plugins_dir, "*")).any?
  $stderr.puts "Plugins in vendor/plugins (#{vendor_plugins_dir}) are no longer allowed. " +
    "Please, put your Redmine plugins in the `plugins` directory at the root of your " +
    "Redmine directory (#{File.join(Rails.root, "plugins")})"
  exit 1
end

# Initialize the rails application
RedmineApp::Application.initialize!

ActionController::Base.relative_url_root = "/redmine"   <=== 追加

root@IPD-0197:/var/redmine# vi config
config/    config.ru
root@IPD-0197:/var/redmine# vi config.ru
# This file is used by Rack-based servers to start the application.

require ::File.expand_path('../config/environment',  __FILE__)
#run RedmineApp::Application      <strong><span style="color: #ff0000;"><== コメントアウト</span></strong>
map ActionController::Base.relative_url_root || "/" do          <strong><span style="color: #ff0000;"><== 以降追加。</span></strong>
  run RedmineApp::Application
end

root@IPD-0197:/var/redmine#

nginxのconfを設定する

# Maintainer: @randx

# CHUNKED TRANSFER
# It is a known issue that Git-over-HTTP requires chunked transfer encoding [0] which is not
# supported by Nginx < 1.3.9 [1]. As a result, pushing a large object with Git (i.e. a single large file)
# can lead to a 411 error. In theory you can get around this by tweaking this configuration file and either
# - installing an old version of Nginx with the chunkin module [2] compiled in, or
# - using a newer version of Nginx.
#
# At the time of writing we do not know if either of these theoretical solutions works. As a workaround
# users can use Git over SSH to push large files.
#
# [0] https://git.kernel.org/cgit/git/git.git/tree/Documentation/technical/http-protocol.txt#n99
# [1] https://github.com/agentzh/chunkin-nginx-module#status
# [2] https://github.com/agentzh/chunkin-nginx-module

# this can be any application server, not just Unicorn/Rainbows!
upstream unicorn_redmine {
  # fail_timeout=0 means we always retry an upstream even if it failed
  # to return a good HTTP response (in case the Unicorn master nukes a
  # single worker for timing out).

  # for UNIX domain socket setups:
  # server unix:/tmp/.sock fail_timeout=0;
  server unix:/tmp/redmine.sock fail_timeout=0;

  # for TCP setups, point these to your backend servers
  # server 192.168.0.7:8080 fail_timeout=0;
  # server 192.168.0.8:8080 fail_timeout=0;
  # server 192.168.0.9:8080 fail_timeout=0;
}

server {
  listen 443 ssl;        # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea
  server_name xxxx.xxxx.co.jp;     # e.g., server_name source.example.com;
  server_tokens off;     # don't show the version number, a security best practice
  root /var/www/public;
  
  # Increase this if you want to upload large attachments
  # Or if you want to accept large git objects over http
  client_max_body_size 20m;

  # individual nginx logs for this gitlab vhost
  access_log  /var/log/nginx/access.log;
  error_log   /var/log/nginx/error.log;

  ssl  on;
  ssl_certificate      /etc/nginx/certs/host.crt;
  ssl_certificate_key  /etc/nginx/certs/host.key;
  ssl_protocols SSLv3 TLSv1 TLSv1.2;
  ssl_ciphers AES:HIGH:!ADH:!MD5; 
  ssl_prefer_server_ciphers on;

  location ^~ /redmine {
    root /var/redmine/public;
    try_files $uri/index.html $uri.html $uri @redmine;
  }

  location @redmine {
    proxy_set_header   X-Real-IP         $remote_addr;
    proxy_set_header   X-Forwarded-Proto $scheme;
    # an HTTP header important enough to have its own Wikipedia entry:
    # http://en.wikipedia.org/wiki/X-Forwarded-For
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;

    # enable this if you forward HTTPS traffic to unicorn,
    # this helps Rack set the proper URL scheme for doing redirects:
    # proxy_set_header X-Forwarded-Proto $scheme;

    # pass the Host: header from the client right along so redirects
    # can be set properly within the Rack application
    proxy_set_header   Host $http_host;

    # we don't want nginx trying to do something clever with
    # redirects, we set the Host: header above already.
    proxy_redirect off;

    # set "proxy_buffering off" *only* for Rainbows! when doing
    # Comet/long-poll/streaming. It's also safe to set if you're using
    # only serving fast clients with Unicorn + nginx, but not slow
    # clients. You normally want nginx to buffer responses to slow
    # clients, even with Rails 3.1 streaming because otherwise a slow
    # client can become a bottleneck of Unicorn.
    #
    # The Rack application may also set "X-Accel-Buffering (yes|no)"
    # in the response headers do disable/enable buffering on a
    # per-response basis.
    # proxy_buffering off;

    proxy_pass http://unicorn_redmine;

  }
  error_page 502 /502.html;
}

AIPOのDBテーブルにカラム追加

$
0
0

AipoはCayenne を通じてデータベースに接続して、必要なデータを取得したり、追加したりしています。
Cayenne を利用するためには、

  • 実際にデータベースにあるテーブル構造を、Cayenneにも設定しておく
  • テーブル構造ごとのJavaのクラスファイルを作成する

の2点必要があります。
この設定とクラスファイルの作成の両方を行うためのツールがCayenne Modeler です。

DBをカラムした場合は、変更後のCayenne Modelerでテーブル構造に合った「Cayenneの設定ファイル(xml)」および「オブジェクトモデルのJava クラス」を生成しなければなりません。

まずPostgreSQLでカラムを追加

AIPOのタイムカード情報は「EipTExtTimecard」というテーブルに記録されているので、ここにユーザーメモ用に「user_memo」というText型のカラムを追加します。

Windows開発環境にセットアップ済みのPostgreSQLのpsql.exeをコマンドプロンプトで
「psql.exe -U aipo_postgres -h localhost -d org001」
(gitからソースを取ってきた人は、-U postgresかな)
と入力し、パスワード+「enter」でDBに接続する。
100

カラム追加のクエリーを実行する。

ALTER TABLE eip_t_ext_timecard ADD user_memo text;

101
ちゃんと追加されているかを確認する。

\d eip_t_ext_timecard

102

CayenneModelerの起動

ドキュメント|無料グループウェア「アイポ」
に従って開発環境を構築していれば、下記で「Cayenne Modeler」が起動できる。
(cayenne_home)\bin\CayenneModeler.exe
01

JDBCを指定する

レフトメニューの「ClassPath」をクリックし、右側の[Add Jar/Zip]ボタンをクリックする。
300
AIPOビルド環境構築にて、セットアップしたJDBCドライバのJarファイルを指定する。

C:\home\aipo\apache-tomcat-6.0.37\common\lib\postgresql-8.1-415.jdbc3.jar

http://jdbc.postgresql.org/download/postgresql-8.1-415.jdbc3.jar
301
[Save]をクリック
302

PostgreSQLとつなげる

メニュー「Tools」->「Preferences」をクリック。
200
“Edit Preferences”ウィンドウが表示されるので、レフトメニューの「Local DataSources」をクリックする。
201
[New..]ボタンをクリック
202
Adapter:をPostgresのものを選択し、[Create]ボタンをクリック
203
DB URL:のdatabaseをorg001に変更。そしてUserNameとPasswordを入力して[Test..]ボタンをクリック
204
303
Successと表示されるはず。
304
[Save]をクリックする。

プロジェクトファイルを開く

[File]-[Open Project]で、プロジェクトファイルを開きます。

(プロジェクトルート)\oms\src\main\webapp\WEB-INF\cayenne.xml

02
03
プロジェクトファイルを開くと下記のような画面になる。
04
ちなみに、このcayenne.xmlは下記のようなファイル

<?xml version="1.0" encoding="utf-8"?>
<domains project-version="2.0">
<domain name="SharedDomain">
    <property name="cayenne.DataDomain.dataContextFactory" value="com.aimluck.eip.cayenne.access.IsolatedDataContextFactory"/>
    <property name="cayenne.DataRowStore.snapshot.size" value="50000"/>

    <map name="AccountSharedDomainMap" location="AccountSharedDomainMap.map.xml"/>
    <map name="SecuritySharedDomainMap" location="SecuritySharedDomainMap.map.xml"/>
    <map name="SharedDomainMap" location="SharedDomainMap.map.xml"/>
    <map name="SocialSharedDomainMap" location="SocialSharedDomainMap.map.xml"/>
</domain>
</domains>

PostgreSQLと同期

先ほど追加したカラムについて、AIPOのタイムカード情報「EipTExtTimecard」テーブルと同期してCayenee Modelerに反映させる。
ツリー表示の「SharedDomainMap」をクリックする。
308
Tools
–> Reengineer Databse Schema
とクリックする。
305
JDBC経由でDBに接続する。
306
Select Schema:をPublicに変更して、[Continue]をクリック
307
既にDbEntityが存在してますよ!と警告されるが、構わずに[Overwrite]をクリックする。
309
Progress..と表示され同期が行われる。
310

サーバー証明書の期限切れ

$
0
0

「忙しい時に限って、サーバーメンテナンス対応はやってくるものだ!」
これって、どこかの諺にありそうだが。。。。

深く理解せずに、google先生に頼りっぱなしのオレは、少しでも次回の手間を省くために、ここに備忘録を残す。

ちゃんとした証明書にしたいが、ちょっとそれも面倒。
という訳で、オレオレ証明書の期限を延長してやり過ごす。
以上

root@xxxxxx:/etc/nginx/certs/2016# openssl genrsa -aes128 -out server.key 2048
Generating RSA private key, 2048 bit long modulus
.................................................................................+++
.+++
e is 65537 (0x10001)
Enter pass phrase for server.key:
Verifying - Enter pass phrase for server.key:
root@xxxxxx:/etc/nginx/certs/2016# ls
server.key
root@xxxxxx:/etc/nginx/certs/2016# openssl rsa -in server.key -out server.key 
Enter pass phrase for server.key:
writing RSA key
root@xxxxxx:/etc/nginx/certs/2016# openssl req -new -days 3650 -key server.key -out server.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:JP
State or Province Name (full name) [Some-State]:Tokyo
Locality Name (eg, city) []:Chiyoda-ku
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Ramuda Co.,Ltd
Organizational Unit Name (eg, section) []:Network Dept.
Common Name (e.g. server FQDN or YOUR name) []:xxx.xxxx.co.jp
Email Address []:webmaster@ramuda.co.jp

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
root@xxxxxx:/etc/nginx/certs/2016# openssl x509 -in server.csr -out server.crt -req -signkey server.key -days 3650
Signature ok
subject=/C=JP/ST=Tokyo/L=Chiyoda-ku/O=Ramuda Co.,Ltd/OU=Network Dept./CN=xxx.xxxx.co.jp/emailAddress=webmaster@ramuda.co.jp
Getting Private key
root@xxxxxx:/etc/nginx/certs/2016# chmod 400 server.*
root@xxxxxx:/etc/nginx/certs/2016# ls -l
total 12
-r-------- 1 root root 1375 Dec 11 13:12 server.crt
-r-------- 1 root root 1090 Dec 11 12:51 server.csr
-r-------- 1 root root 1675 Dec 11 12:46 server.key
root@xxxxxx:/etc/nginx/certs/2016# 

Huawei P9 liteのUSBデバックモード

$
0
0

Huawei P9 liteの「USBデバックモード」のメニューを探すのに、日曜日をまるまるつぶしてしまった哀れな男のお話。

この情報(動画)を検索できなかった。
「p9 lite USB debug」
でgoogleすれば一発だったのに。orz

自分の無能さにあきれてしまう。
そもそも、「ビルド番号」を7回タップするなんて・・・・

「探し物はなんですかぁー
 見つけにくいものですかぁー
 カバンの中も机の中も探したけれど見つからないのに
 まだまだ探す気ですか?
 それより僕と踊りませんか・・・・・・・」

その日は諦めて、次の日にやるとサックリと解決するパターン

「夢の中へ、行ってみたいと思いませんか・・・」
できることなら、そうしたい!

Viewing all 14 articles
Browse latest View live