<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Real Beat &#187; server</title>
	<atom:link href="http://nobu666.com/category/server/feed" rel="self" type="application/rss+xml" />
	<link>http://nobu666.com</link>
	<description>Keep drinking, Keep listening to music, Go fuck yourself</description>
	<lastBuildDate>Thu, 19 Jan 2012 04:57:28 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>さくらのVPSでCentOSからUbuntuに鞍替えまとめ</title>
		<link>http://nobu666.com/2011/05/19/904.html</link>
		<comments>http://nobu666.com/2011/05/19/904.html#comments</comments>
		<pubDate>Thu, 19 May 2011 13:32:28 +0000</pubDate>
		<dc:creator>nobu</dc:creator>
				<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://nobu666.com/?p=904</guid>
		<description><![CDATA[@macchaからリクエストがあったので、適当にまとめました。タイトルの通りです。 OS再インストールの準備 リモートコンソールの起動にJDK必須なので、作業するマシンにJDKが入ってなければいれとく。あとはTightV &#8230;<p class="read-more"><a href="http://nobu666.com/2011/05/19/904.html">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://twitter.com/maccha">@maccha</a>からリクエストがあったので、適当にまとめました。タイトルの通りです。</p>
<h2>OS再インストールの準備</h2>
<p>リモートコンソールの起動にJDK必須なので、作業するマシンにJDKが入ってなければいれとく。あとはTightVNCとか、必要ならどうぞ。あとバックアップ忘れずに。とりあえずwordpressだけ動いてる状態だったので</p>
<pre class="brush: plain; pad-line-numbers: 2; title: ; notranslate">
$ mysqldump -uroot -p wp -Q -c --opt &gt; dumpfile
$ tar zcvf wordpress.tar.gz /var/www/wordpress
$ tar zcvf ssh.tar.gz ~/.ssh
</pre>
<p>みたいな感じでバックアップ取って作業マシンにscpなりlftpなりで持ってきておく。必要なら/etc/my.cnfとか/etc/php.iniとか、ホームのドットファイル類も。</p>
<h2>OS再インストール</h2>
<p>VPSコントロールパネルにログインして、OS再インストール→カスタムOSインストール→ubuntu 10.04 amd64を選択→<a href="http://support.sakura.ad.jp/support/vps/menu_oscustom_ubuntu.shtml">カスタムOSインストールガイド ： Ubuntu 10.04</a>の通り進める。10分くらいありゃ終わる。</p>
<h2>SSHの設定</h2>
<p>何はともあれrootのパスワードとSSHの設定をリモートコンソールからやる。scpなりで、バックアップファイルを転送しとくこと。</p>
<pre class="brush: plain; pad-line-numbers: 2; title: ; notranslate">
$ sudo passwd
$ tar zxf wordpress.tar.gz
$ tar zxf ssh.tar.gz
$ chmod 700 .ssh
$ chmod 600 .ssh/*
$ sudo vi /etc/ssh/sshd_config
- Port 22
+ Port 適当なポート

- PermitRootLogin yes
+ PermitRootLogin no

- #PasswordAuthentication yes
+ PasswordAuthentication no
</pre>
<p>ポートは変えなくてもいいけどお好みで。ポート変えたら/etc/servicesのSSHのとこを合わせて変更するのも忘れずに。</p>
<pre class="brush: plain; pad-line-numbers: 2; title: ; notranslate">
$ sudo sshd -t
</pre>
<p>でチェックして、エラーが出なければOKなので再起動</p>
<pre class="brush: plain; pad-line-numbers: 2; title: ; notranslate">
$ sudo service ssh restart
</pre>
<p>ここで、もう一個ターミナル開いて問題なく接続できることを必ず確認。以降は普通に端末からSSHでつないで作業</p>
<h2>諸々設定</h2>
<p>もうあとはお好みでどうぞなんだけど、最低やることだけ書いとく</p>
<pre class="brush: plain; pad-line-numbers: 2; title: ; notranslate">
$ sudo apt-get update
.
.
.
$ sudo apt-get upgrade
.
.
.
$ sudo ufw status
Status: inactive
$ sudo ufw default deny
Default incoming policy changed to 'deny'
(be sure to update your rules accordingly)
$ sudo ufw allow SSHのポート番号
Rules updated
$ sudo ufw allow 80
Rules updated
$ sudo ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
Firewall is active and enabled on system startup
$ sudo ufw status
Status: active
To                         Action      From
--                           ------      ----
SSHのポート番号   ALLOW       Anywhere
80                          ALLOW       Anywhere
$ sudo apt-get install denyhosts sysv-rc-conf build-essential zsh screen vim tmux curl wget git-core apache2 php5 libapache2-mod-php5 mysql-server php5-mysql #まぁこの辺は余計なのも入ってるのでお好きなように
$ sudo a2enmod rewrite # rewrite有効に
$ sudo vi /etc/apache2/sites-available/default #VirtualHostなりなんなり、お好きにどうぞ
$ sudo service apache2 restart
$ sudo sysv-rc-conf #自動起動したいやつを適当に選択
$ cp -a wordpress/* /var/www/wordpress #wordpressのバックアップ復元
$ mysql -uroot -p -e&quot;create database wp&quot; #とりあえずDBつくる
$ sudo cp my.cnf.backup /etc/my.cnf
$ sudo service mysql restart
$ mysql -uroot -p wp &lt; dumpfile #dumpファイルからデータ復元
</pre>
<p>ここまでやればwordpressはもう普通に動いてるはず。あとはchshするなり、ドットファイル復元するなり、好きにすればいいかと。</p>
]]></content:encoded>
			<wfw:commentRss>http://nobu666.com/2011/05/19/904.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PS3用にDLNAサーバMediatombを入れる</title>
		<link>http://nobu666.com/2009/06/15/776.html</link>
		<comments>http://nobu666.com/2009/06/15/776.html#comments</comments>
		<pubDate>Mon, 15 Jun 2009 04:24:05 +0000</pubDate>
		<dc:creator>nobu</dc:creator>
				<category><![CDATA[game]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://nobu666.com/?p=776</guid>
		<description><![CDATA[先日気がついたらPS3を買っており、バイオハザードで恐ろしい目にあったり、まいにちいっしょで和んだりしております。 PS3でもう少し便利に遊ぶため、mediatombでDLNAサーバをたてる。emerge mediato &#8230;<p class="read-more"><a href="http://nobu666.com/2009/06/15/776.html">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>先日気がついたらPS3を買っており、バイオハザードで恐ろしい目にあったり、まいにちいっしょで和んだりしております。</p>
<p>PS3でもう少し便利に遊ぶため、mediatombでDLNAサーバをたてる。emerge mediatombして依存関係諸々入れる。とりあえずこれだけでもいいのだが、これだと最新の0.12.0が入ってくれないので、一端emerge -C mediatombしてソースから入れる。</p>
<pre class="brush: bash; title: ; notranslate">
svn co https://svn.mediatomb.cc/svnroot/mediatomb/trunk/mediatomb mediatomb0.12.0
cd mediatomb0.12.0
autoreconf -i
./configure &amp;&amp; make &amp;&amp; sudo make install
mysql -uroot -p
mysql&gt; create database mediatomb;
mysql&gt; grant select,insert,update,delete,create,drop on mediatomb.* to mediatomb@localhost identified by 'mediatomb';
mysql&gt; flush privileges;
mysql&gt; exit;
</pre>
<p>下準備はこれでおしまい。あとは設定ファイルを少し弄る。と言ってもアカウント周りと、コメントで for PS3云々と書いてあるのでその通り書き換えればいいだけ。細かいことは<a href="http://kwmr.blogzine.jp/kanji/2009/01/ps3macyoutubeme_c28b.html">いい感じ: PS3+Macで超・超快適メディアプレイヤー：Youtube->Mediatomb on iMac ->PS3 ->BRAVIA</a>を参照。</p>
<p>これで一通りの音楽と動画が、PS3経由でTVで観られるようになった。でもPCに動画撮り溜めたりしてるわけじゃないから、あんまり出番はないな。YouTubeも別にDLNA経由しないでも、PS3でそのままブラウザから観れるしな。PCでテレビを録画したりしてる人には大変ありがたい機能なんだろうな。あ、でも写真をスライドショーにしてテレビで観るとかはするかも。あとテレビにしっかりしたスピーカーがあるなら、音楽もPCで聴くよりテレビで聴きたいとかいう需要はあるか。テレビ用のスピーカー買うかなー…安くていいのないかな。</p>
]]></content:encoded>
			<wfw:commentRss>http://nobu666.com/2009/06/15/776.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iTunesサーバーをたてて、LANで曲を共有するようにした</title>
		<link>http://nobu666.com/2008/09/24/637.html</link>
		<comments>http://nobu666.com/2008/09/24/637.html#comments</comments>
		<pubDate>Tue, 23 Sep 2008 16:02:22 +0000</pubDate>
		<dc:creator>nobu</dc:creator>
				<category><![CDATA[diary]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[memo]]></category>
		<category><![CDATA[music]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://nobu666.com/?p=637</guid>
		<description><![CDATA[前から使ってたけど今はあまり使ってないデスクトップ、最近主力のMacBook、たまに使うLet&#8217;s NoteとうちにはPCが3台ある。あとGentooサーバー。全部の環境からmp3を共有したかったので、Gen &#8230;<p class="read-more"><a href="http://nobu666.com/2008/09/24/637.html">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>前から使ってたけど今はあまり使ってないデスクトップ、最近主力のMacBook、たまに使うLet&#8217;s NoteとうちにはPCが3台ある。あとGentooサーバー。全部の環境からmp3を共有したかったので、GentooでiTunesサーバーをたてて共有することにした。</p>
<p>まずはデスクトップからごっそり外付けHDDにmp3をコピー。1万曲超、60GBくらいあった。これをGentooにぶっさして、とりあえず放置。Gentooで環境構築。</p>
<pre class="brush: bash; title: ; notranslate">
wget http://www.porchdogsoft.com/download/howl-1.0.0.tar.gz
tar zxf howl-1.0.0.tar.gz
cd howl-1.0.0
./configure &amp;&amp; make &amp;&amp; sudo make install &amp;&amp; cd
sudo emerge libogg
sudo emerge libvorbis
sudo emerge mt-daapd
sudo cp /etc/mt-daapd.conf.example /etc/mt-daapd.conf
</pre>
<p>confは適当にmp3の入った外付けHDDのmount先を指定したりweb_rootのパスワード指定したりする程度。これであっさり行くと思ったら、まずこのままではmt-daapdが起動しない。なぜか知らないが/etc/init.d/mt-daapdで、depend()部分が間違ってるのが原因。mDNSResponderをmDNSResponderPosixに修正、mDNSResponderPosixを起動してから再度動かすと動いた。</p>
<p>これでとりあえず動いたものの、MacのiTunes上からは文字化けの嵐。WindowsのiTunesでは問題ない。つまり文字コードの問題だな。ここは先人の知恵を借り、ググってみるとwindows上で変換しるとよいことが判明。HDDを一旦デスクトップにつないで、iTunesで曲を全部選択して「ID3タグを変換」→「Unicodeを元に戻す」。何故かうまく行かないで化けちゃうのがあるので、個々に探して同様に変換したら直った。とりあえずこれでタグは問題なくUnicodeになったので、再度Gentooにつないでmountしてmt-daapdのキャッシュをクリアしたらok。ちなみにmountするときには、mount -o noauto,users,umask=000,iocharset=utf8とか言ってやらないと正しくGentoo上で日本語が読めない。</p>
<p>これでokかと思いきや、やっぱり文字化けは解消せず。色々調べてみたら、<a href="http://www.kzsoft.to/~kazu/mt-daapd/">パッチ</a>を当てれば解決することが判明。</p>
<pre class="brush: bash; title: ; notranslate">
sudo emerge -C mt-daapd
wget http://nchc.dl.sourceforge.net/sourceforge/mt-daapd/mt-daapd-0.2.4.2.tar.gz
tar zxf mt-daapd-0.2.4.2.tar.gz
cd mt-daapd-0.2.4.2
wget http://www.kzsoft.to/~kazu/mt-daapd/patch/mt-daapd-0.2.4-cp932.patch
patch &lt; mt-daapd-0.2.4.2.tar.gz
</pre>
<p>parser.cのパッチでこけるので、手動でパッチした。とりあえずdiffを残しておく。</p>
<pre class="brush: diff; title: ; notranslate">
--- src/parser.c.orig   2008-04-20 04:44:54.000000000 +0900
+++ src/parser.c        2008-09-23 17:16:15.000000000 +0900
@@ -132,8 +132,18 @@
 #define AGO 287
 #define INTERVAL 288

+#define USE_CP932

-
+#ifdef USE_CP932
+  #define UNKNOWN_STR    &quot;UNKNOWN&quot;
+  #ifndef FILESYSTEM_CES
+    #define FILESYSTEM_CES &quot;CP932&quot;
+  /*
+    #define FILESYSTEM_CES &quot;UTF-8&quot;
+    #define FILESYSTEM_CES &quot;EUC-JP&quot;
+  */
+  #endif
+#endif

 /* Copy the first part of user declarations.  */
 #line 1 &quot;parser.y&quot;
@@ -167,6 +177,11 @@
 #include &lt;string.h&gt;
 #include &quot;playlist.h&quot;

+#ifdef USE_CP932
+ #include &lt;iconv.h&gt;
+ #include &lt;errno.h&gt;
+#endif
+
 #define YYERROR_VERBOSE 1

 extern int yyerror(char *msg);
@@ -1828,6 +1843,43 @@

 #line 174 &quot;parser.y&quot;
+#ifdef USE_CP932
+#define MAX_ICONV_BUF 1024
+
+typedef enum {
+  ICONV_OK,
+  ICONV_TRYNEXT,
+  ICONV_FATAL
+} iconv_result;
+
+static iconv_result do_convert(const char* to_ces, const char* from_ces,
+                              char *inbuf,  size_t inbytesleft,
+                              char *outbuf_orig, size_t outbytesleft_orig) {
+  size_t rc;
+  iconv_result ret = ICONV_OK;
+
+  size_t outbytesleft = outbytesleft_orig - 1;
+  char* outbuf = outbuf_orig;
+
+  iconv_t cd  = iconv_open(to_ces, from_ces);
+  if (cd == (iconv_t)-1) {
+    return ICONV_FATAL;
+  }
+  rc = iconv(cd, &amp;inbuf, &amp;inbytesleft, &amp;outbuf, &amp;outbytesleft);
+  if (rc == (size_t)-1) {
+    if (errno == E2BIG) {
+      ret = ICONV_FATAL;
+    } else {
+      ret = ICONV_TRYNEXT;
+      memset(outbuf_orig, '&#92;&#48;', outbytesleft_orig);
+    }
+  }
+  iconv_close(cd);
+
+  return ret;
+}
+#endif
+

 PL_NODE *pl_newintpredicate(int tag, int op, int value) {
     PL_NODE *pnew;
@@ -1867,7 +1919,25 @@
     pnew-&gt;op=op;
     pnew-&gt;type=T_STR;
     pnew-&gt;arg1.ival=tag;
+#ifdef USE_CP932
+    if (!strcasecmp(FILESYSTEM_CES, &quot;UTF-8&quot;)) {
     pnew-&gt;arg2.cval=value;
+      } else {
+       char* iconv_buf = (char*)calloc(MAX_ICONV_BUF, sizeof(char));
+       if (iconv_buf) {
+         iconv_result rc = do_convert(&quot;UTF-8&quot;, FILESYSTEM_CES, value, strlen(value),
+                                      iconv_buf, MAX_ICONV_BUF);
+         if(rc == ICONV_OK) {
+           pnew-&gt;arg2.cval = iconv_buf;
+         } else {
+           pnew-&gt;arg2.cval = strdup(UNKNOWN_STR);
+           free(iconv_buf);
+         }
+       }
+      } // if utf-8
+#else
+    pnew-&gt;arg2.cval=value;
+#endif
     return pnew;
 }
</pre>
<p>こけるのは#ifdef USE_CP932から#endifまでなので、まぁ手動で当てても特別問題はないだろう。あとは普通にconfigureしてmake &#038;&#038; make installなんだが。このままだと/etc/init.d/mt-daapdが使えないので、適当に以下のように編集する。</p>
<pre class="brush: bash; title: ; notranslate">
PIDFILE=&quot;/var/run/mt-daapd.pid&quot;
CONFFILE=&quot;/etc/mt-daapd.conf&quot;

depend() {
    need net
    need mDNSResponderPosix
}

start() {
    ebegin &quot;Starting mt-daapd DAAP server&quot;
    /usr/sbin/mt-daapd -c ${CONFFILE} &amp;
    eend $?
}

stop() {
    ebegin &quot;Stopping mt-daapd DAAP server&quot;
    kill `cat ${PIDFILE}`
    eend $?

    rm -f ${PIDFILE}
}
</pre>
<p>とりあえず今あるものを共有する、という意味ではこれで万事よいのだが、俺の環境ではまだ問題があった。実は外付けHDDは元々Windowsで使っていたものなので、当然フォーマットはNTFS。でもmountしてるのはGentooなわけなので、普通にmountしたのではどうがんばってもリードオンリーになってしまう。これでは新しく曲を追加したり出来ない訳で、これは困る。メインはMacBookなので、samba経由で書き込めないと困ってしまう訳だ。色々試行錯誤したんだけど、ntfs-3gとかいうのを使ったらすげーあっさりと書き込みできるようになった。</p>
<pre class="brush: bash; title: ; notranslate">
sudo emerge ntfs3g
sudo update-modules
sudo su -
echo &quot;/dev/sdb5   /mnt/usbhdd ntfs-3g    noauto,users,umask=000,iocharset=utf8 0 0&quot; &gt;&gt; /etc/fstab
logout
sudo mount  /dev/sdb5 /mnt/usbhdd
</pre>
<p>あとは/etc/mt-daapd.confで、rescan_intervalを適当な値に設定しておいてやればok。</p>
]]></content:encoded>
			<wfw:commentRss>http://nobu666.com/2008/09/24/637.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NICが認識しない件、解決</title>
		<link>http://nobu666.com/2008/02/20/557.html</link>
		<comments>http://nobu666.com/2008/02/20/557.html#comments</comments>
		<pubDate>Wed, 20 Feb 2008 06:35:31 +0000</pubDate>
		<dc:creator>nobu</dc:creator>
				<category><![CDATA[diary]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://nobu666.com/2008/02/20/000557.html</guid>
		<description><![CDATA[dmesg&#124;grep eth してみたら、eth0からeth1にrenameしたよとか書いてあったorz ので、単純に これだけでした。あとはルータ側でポート開けたり、スタティックルーティングしたりして、EM-ONE使っ &#8230;<p class="read-more"><a href="http://nobu666.com/2008/02/20/557.html">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>dmesg|grep eth してみたら、eth0からeth1にrenameしたよとか書いてあったorz ので、単純に</p>
<pre class="brush: bash; title: ; notranslate">
ln -sf /etc/init.d/net.lo /etc/init.d/net.eth1
sed -i 's/eth0/eth1/g' /etc/conf.d/net
/etc/init.d/net.eth1 start
</pre>
<p>これだけでした。あとはルータ側でポート開けたり、スタティックルーティングしたりして、EM-ONE使って外から繋がることを確認。が、今度はメールが送れなくてしばし嵌った。プロバイダが変わったから、単純に/etc/postfix/main.cfのrelayhostを書き換えて、smtp_sasl_password_mapsで指定したファイルにSMTPホスト名とユーザ名とパスワード書いて、そいつをpostmapして/etc/init.d/postfix restartで終了だと思っていたのだが。</p>
<p>色々見直してmain.cfのrelayhostと、postmapするファイルの書き方を example.com:587 やら、[example.com]:587 やら試すもダメ。master.cf見直したりしても結局わからず。しかたないのでmain.cfの smtp* を全部虱潰しに調べるも特に以上は見あたらず。半ば諦めつつWebを検索してたら<a href="http://aerith.mydns.jp/regrets/2006/07/vine32postfixsmtp.html">Vine3.2のPostfixでSMTP認証</a>ってエントリで</p>
<blockquote><p>→main.cf へ smtp_sasl の設定を追加。 smtpd_sasl じゃないので、要注意。</p></blockquote>
<p>……もしやと思って見てみたら、smtpd_sasl_auth_enable = yes という記述はあったけども、 smtp_sasl_auth_enable = yes がなかったのが原因でしたとさ…。疲れたわ。</p>
]]></content:encoded>
			<wfw:commentRss>http://nobu666.com/2008/02/20/557.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>サーバが2時間ほど死んで、復旧するまでのドキュメンタリー</title>
		<link>http://nobu666.com/2007/03/23/505.html</link>
		<comments>http://nobu666.com/2007/03/23/505.html#comments</comments>
		<pubDate>Thu, 22 Mar 2007 16:25:08 +0000</pubDate>
		<dc:creator>nobu</dc:creator>
				<category><![CDATA[diary]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://nobu666.com/2007/03/23/000505.html</guid>
		<description><![CDATA[22時頃、保守フェーズに入っているあるウェブアプリケーションの担当者から、アクセスできなくなっていると電話。サーバには職場からしか繋げないのだが、たまたま職場に後輩が残っていたため、電話して口頭で作業させた。そのウェブア &#8230;<p class="read-more"><a href="http://nobu666.com/2007/03/23/505.html">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>22時頃、保守フェーズに入っているあるウェブアプリケーションの担当者から、アクセスできなくなっていると電話。サーバには職場からしか繋げないのだが、たまたま職場に後輩が残っていたため、電話して口頭で作業させた。そのウェブアプリの構成は以下のようになっている。</p>
<pre>
              +---------------+
              | Load Balancer |
              +---------------+
                      |
             +--------+--------+
             |                 |
         +------+          +------+
         |apache|          |apache|
         +------+          +------+
             |     mod_jk      |
             +-----------------+
                     |
   +-------- +-------+--------+---------+
   |         |       |        |         |
+------+ +------+ +------+ +------+ +------+
|tomcat| |tomcat| |tomcat| |tomcat| |tomcat|
+------+ +------+ +------+ +------+ +------+
   |         |   hibernate    |         |
   |         |       |        |         |
   +-------- +-------+--------+---------+
                     |
+------------------------------------------+
|                                          |
|                 +-----+                  |
|                 |mysql|                  |
|                 +-----+                  |
|                    |                     |
|               replication                |
|                    |                     |
|            +-------+-------+             |
|            |       |       |             |
|         +-----+ +-----+ +-----+          |
|         |mysql| |mysql| |mysql|          |
|         +-----+ +-----+ +-----+          |
|                                          |
+------------------------------------------+
</pre>
<p>実際はもっとサーバの台数も多いのだが、まぁ主要なサーバはこんな感じだ。なんのことはない、割と一般的なJavaのウェブアプリといえる。とりあえずトラブルシューティングとしてやったことを列挙。ちなみにサーバはRHEL4、apacheは2.0、tomcatは5.0、mysqlは4.1、javaは1.5。</p>
<pre class="brush: bash; title: ; notranslate">
ps -ef|grep httpd|wc -l
/usr/local/apache2/bin/apachectl graceful
/etc/init.d/tomcat restart &amp;&amp; apache: /usr/local/apache2/bin/apachectl graceful
mysql: mysql -uroot -p -e'show processlist'|grep Locked
</pre>
<p>ここまでやって、とりあえずDBで詰まってるわけではないことが判明。単純なプロセス再起動で復旧しないことから、アクセスの異常増加かハードウェア異常じゃないかと疑ってみる。httpdのプロセス数はMaxClients 512に設定してあるが、2台ともFULL。全サーバでtop/sarを確認するも特に異常なし。そこで思い立って hdparm -t /dev/sda してみる。通常は50MB/sec?80MB/secくらい出るのだが、webの1台だけ1.5MB/secとかいうふざけた野郎がいるのを発見。とりあえず shutdown -r now したらIOの速度は復旧。デバイスドライバのbugっぽげ。</p>
<p>ここまでやって、自宅からVPNで接続できる担当者と連絡が付いたので、後輩はお役後免にする（なにをやらかすかわからない子なのでｗ）。リブートまでしたものの、状況は先ほどと変わらず。訳がわからないので、とりあえずもう1台のwebもリブートしてみよう、ということになり実施する。が、担当者がshutdownのオプションを間違えて（多分solarisと間違ってる…）リブートじゃなくてまともに電源断。サーバの置いてある現地とは連絡が付かないため状況はさらに悪化…</p>
<p>webが片肺になってしまったので、httpd.confでMaxClientsとServerLimitを倍に設定。だがプロセス数300前後で反応がなくなる。問題はapacheではなさそうなので、次に散々泣かされているmod_jkを疑ってみる。netstat -a|grep ESTABLISHED とかすると、tomcatサーバの1台がコネクションを捕まえっぱなしになっていることが判明。ブラウザからjkstatusの管理画面を見ると、1台はrecovering、1台okで残りはerrorになっている。原因究明は後で良いので復旧第一ということで、tomcatを全部再起動してその後apacheも再起動。そうするとあら不思議、今までの重さがウソのように完全に復旧しましたとさ。とりあえず10分ほど動作確認して、問題なさそうなので解散。電源は朝入れれば良いと言うことで…</p>
<p>実際はもう少し色々試行錯誤があったのだけど、ダイジェストにするとおおよそこんな感じ。22時だからまだ良かったよ…寝てても容赦なく電話くるから。しかし根本原因がよくわからない。IO性能が異常に劣化してたのはbugだとしても、1回目のtomcat全部再起動で復旧しなかったのが謎。なんかtomcatって、stop/startを素早くやりすぎるときちんと再起動しないことがあるような気がするのだが、それなのかなー。てか、もうmod_jkは止めたい。でもapache2.2はまだちょっと怖いし、sticky session使ってるし…代替案でいいのがない。</p>
]]></content:encoded>
			<wfw:commentRss>http://nobu666.com/2007/03/23/505.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>503が多すぎる</title>
		<link>http://nobu666.com/2007/01/25/492.html</link>
		<comments>http://nobu666.com/2007/01/25/492.html#comments</comments>
		<pubDate>Wed, 24 Jan 2007 15:49:00 +0000</pubDate>
		<dc:creator>nobu</dc:creator>
				<category><![CDATA[diary]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://nobu666.com/2007/01/25/000492.html</guid>
		<description><![CDATA[nobu666.comはさくらインターネットで共有のレンタルサーバなんだが、夜間帯の503が多すぎる。うんこ。負荷がある一定ラインを超えると503エラーを自動的に吐く仕様らしいのだが、その「ある一定ライン」は公表されてい &#8230;<p class="read-more"><a href="http://nobu666.com/2007/01/25/492.html">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>nobu666.comはさくらインターネットで共有のレンタルサーバなんだが、夜間帯の503が多すぎる。うんこ。負荷がある一定ラインを超えると503エラーを自動的に吐く仕様らしいのだが、その「ある一定ライン」は公表されていない。どうも同じサーバに負荷が高いサイトがある、とかいうのは関係ないらしいのだが。</p>
<p>このnobu666.comは、そんなに負荷が高いのは思えないのだが、やたらに503が出るのはなぜなんだ。PVだって200PV/dayとかいうショボイ感じだし、cronで回してるのも朝方にawstats動かしてるくらいだし。謎。そしてウンコ。</p>
]]></content:encoded>
			<wfw:commentRss>http://nobu666.com/2007/01/25/492.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>fish (friendly interactive shell)</title>
		<link>http://nobu666.com/2007/01/11/483.html</link>
		<comments>http://nobu666.com/2007/01/11/483.html#comments</comments>
		<pubDate>Thu, 11 Jan 2007 14:42:11 +0000</pubDate>
		<dc:creator>nobu</dc:creator>
				<category><![CDATA[diary]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://nobu666.com/2007/01/11/000483.html</guid>
		<description><![CDATA[どのくらいfriendlyなのかと試したら、えらくfriendlyでびびった。スクリーンショットのリンク張っておくので興味が有れば見てみて。まったくカスタマイズすることなく、ここまでインタラクティブなのは結構凄いことのよ &#8230;<p class="read-more"><a href="http://nobu666.com/2007/01/11/483.html">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>どのくらいfriendlyなのかと試したら、えらくfriendlyでびびった。<a href="http://farm1.static.flickr.com/134/353846084_dbbd92c7e3_o.png" target="_blank">スクリーンショットのリンク</a>張っておくので興味が有れば見てみて。まったくカスタマイズすることなく、ここまでインタラクティブなのは結構凄いことのような気もするが、zshをもりもりカスタマイズして使っている人からすると興味は薄いかも知れないな。「bashじゃないの使ってみようかな?、小学生までって言われたしな?」みないな人は試してみてはいかがか。</p>
<p>スクリプトの文法がちょっと違っていたりするが、<a href="http://ja.wikipedia.org/wiki/Friendly_interactive_shell" target="_blank">wikipediaの説明</a>や<a href="http://lwn.net/Articles/136232/" target="_blank">LWNの記事</a>に詳細が書かれているのでそっち参照。エラーメッセージが異常に親切なので、あんまり迷うことはない気がする。</p>
<p>ちょっと使ってみてるけど、fishdっていうdaemonが立ち上がるんだなコレ…面白い。もう今更zshから乗り換えるのは微妙だけど、しばらく併用してみようかと思う。</p>
]]></content:encoded>
			<wfw:commentRss>http://nobu666.com/2007/01/11/483.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[memo] 異なるアーキテクチャ間でクロスコンパイル</title>
		<link>http://nobu666.com/2006/11/19/449.html</link>
		<comments>http://nobu666.com/2006/11/19/449.html#comments</comments>
		<pubDate>Sun, 19 Nov 2006 14:27:30 +0000</pubDate>
		<dc:creator>nobu</dc:creator>
				<category><![CDATA[gentoo]]></category>
		<category><![CDATA[memo]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://nobu666.com/2006/11/19/000449.html</guid>
		<description><![CDATA[前提条件 基本的にはGentoo distcc ドキュメント・DistCC クロスコンパイルガイド、この2つのドキュメントの通り行う。気をつけなきゃいけないのは、「資源を借りる側」と「資源を貸す側」で若干設定が異なる点。 &#8230;<p class="read-more"><a href="http://nobu666.com/2006/11/19/449.html">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<h4>前提条件</h4>
<p>基本的には<a href="http://www.gentoo.org/doc/ja/distcc.xml" target="_blank">Gentoo distcc ドキュメント</a>・<a href="http://www.gentoo.org/doc/ja/cross-compiling-distcc.xml" target="_blank">DistCC クロスコンパイルガイド</a>、この2つのドキュメントの通り行う。気をつけなきゃいけないのは、「資源を借りる側」と「資源を貸す側」で若干設定が異なる点。ここでは借りる側はi686(192.168.0.4)、貸す側はamd64(192.168.0.3)とする。</p>
<p>貸す側と借りる側で、gccのバージョンは同じであること。3.3.x同時はOKだが、3.3.xと3.2.xは混ぜないこと。</p>
<p>また、資源を借りる側は一方的に借りるだけで、相互に助け合わない設定とした。これは、貸す側はサーバなので24時間稼働しているが、借りる側はノートなのでそうした。</p>
<h4>資源を貸す側の設定</h4>
<pre class="brush: bash; title: ; notranslate">
emerge distcc crossdev
vi /etc/make.conf
 MAKEOPTS=&quot;-j8&quot; #(CPUの数+1)*2 ここは全体じゃなくてサーバ単体で計算すべきなのかも。詳細不明…もしかしたら-j6が当たりなのかも?
 FEATURES=&quot;distcc&quot;
 DISTCC_DIR=&quot;/var/tmp/.distcc&quot;
 PORTDIR_OVERLAY=&quot;/usr/local/portage&quot;
distcc-config --set-hosts &quot;localhost 192.168.0.4&quot;
vi /etc/conf.d/distccd
 DISTCCD_OPTS=&quot;${DISTCCD_OPTS} --allow localhost --allow 192.168.0.4&quot; #--allow 192.168.0.0/24でも可
/etc/init.d/distcc start
rc-update add distcc default
crossdev -t i686
</pre>
<h4>資源を借りる側の設定</h4>
<pre class="brush: bash; title: ; notranslate">
emerge distcc
vi /etc/make.conf
 MAKEOPTS=&quot;-j8&quot; #(CPUの数+1)*2
 FEATURES=&quot;distcc&quot;
 DISTCC_DIR=&quot;/var/tmp/.distcc&quot;
vi /etc/conf.d/distccd
 DISTCCD_OPTS=&quot;${DISTCCD_OPTS} --allow localhost&quot; #相互に助け合いたい場合は--allow 192.168.0.3を足すか--allow 192.168.0.0/24にする
cd /usr/lib/distcc/bin
rm c++ g++ gcc cc
echo '#!/bin/bash' &amp;gt; i686-pc-linux-gnu-wrapper
echo 'exec /usr/lib/distcc/bin/sparc-unknown-linux-gnu-${0##*/} &quot;$@&quot;' &amp;gt;&amp;gt; i686-pc-linux-gnu-wrapper
chmod a+x i686-pc-linux-gnu-wrapper
ln -s i686-pc-linux-gnu-wrapper cc
ln -s i686-pc-linux-gnu-wrapper gcc
ln -s i686-pc-linux-gnu-wrapper g++
ln -s i686-pc-linux-gnu-wrapper c++
/etc/init.d/distcc start
rc-update add distcc default
export CC=&quot;i686-pc-linux-gnu-gcc&quot;
</pre>
<h4>実際に試す</h4>
<p>借りる側から何か(それなりに時間のかかりそうなものを)emergeし、貸す側でtopコマンドで見てみる。distccというUSERでdistccやcc1というプロセスが見えれば成功している。当たり前だがコンパイルは速くなるが、configureやアーカイブのunpackは速くならないのであしからず。また、貸す側ではデフォルトでnice -15で実行されている。これは /etc/conf.d/distccdのDISTCCD_NICEで設定されているので、貸す側が暇なマシンなら変更してもいい。</p>
]]></content:encoded>
			<wfw:commentRss>http://nobu666.com/2006/11/19/449.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[memo][Gentoo] SNMP+RRDtool+cactiでサーバ監視</title>
		<link>http://nobu666.com/2006/11/12/442.html</link>
		<comments>http://nobu666.com/2006/11/12/442.html#comments</comments>
		<pubDate>Sun, 12 Nov 2006 03:03:34 +0000</pubDate>
		<dc:creator>nobu</dc:creator>
				<category><![CDATA[gentoo]]></category>
		<category><![CDATA[memo]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://nobu666.com/2006/11/12/000442.html</guid>
		<description><![CDATA[インストールまでは上手くいったけど設定に嵌って酷い目にあった。 必要なものをインストールする 以下のものが必要。 net-snmp apache php mysql rrdtool cacti さくっとemergeするわ &#8230;<p class="read-more"><a href="http://nobu666.com/2006/11/12/442.html">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>インストールまでは上手くいったけど設定に嵌って酷い目にあった。</p>
<h4>必要なものをインストールする</h4>
<p>以下のものが必要。</p>
<ul>
<li>net-snmp</li>
<li>apache</li>
<li>php</li>
<li>mysql</li>
<li>rrdtool</li>
<li>cacti</li>
</ul>
<p>さくっとemergeするわけだが、USEフラグに注意。cactiにはapache2/snmp、phpにはapache2/snmp/sockets/mysqlあたりが必要(gdとかxmlも必須なのか?よくわらかんがこの辺は/etc/make.confでデフォルトで付けている)。</p>
<h4>初期設定</h4>
<p>cacti用のデータベースとユーザを作成し、付属のスクリプトでテーブルを作成する。</p>
<pre class="brush: bash; title: ; notranslate">
mysqladmin -u root create cacti -p
mysql cacti -u root -p &gt; /var/www/localhost/htdocs/cacti/cacti.sql
mysql -u root mysql -p -e&quot;GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'p4ssw0rd'&quot;
mysql -u root mysql -p -e&quot;flush privileges&quot;
</pre>
<p>次にphpのconfigファイルを、今設定したものに合わせて書き換える。</p>
<pre class="brush: bash; title: ; notranslate">
vi /var/www/localhost/htdocs/cacti/include/config.php
 $database_username = &quot;cactiuser&quot;;
 $database_password = &quot;p4ssw0rd&quot;;
</pre>
<h4>cron実行用のシステムアカウント作成とパーミッション変更</h4>
<pre class="brush: bash; title: ; notranslate">
useradd -g apache -d /dev/null -s /bin/false -c cacti cacti
</pre>
<p>ホームディレクトリを/dev/null、ログインシェルを/bin/falseにすることで、cactiというユーザでログインできないようにする。この辺は適当に手を抜いてrootでやったりすると怖いので忘れずに。次にcactiユーザでデータの読み書きするためにパーミションを変える。</p>
<pre class="brush: bash; title: ; notranslate">
chown -R cacti:apache /var/www/localhost/htdocs/cacti
</pre>
<p>全部変えちゃったけどrraとlogディレクトリだけでいいかも。未検証。</p>
<h4>cronの設定</h4>
<p>適当なタイミングでスクリプトをブン回す。とりあえず5分間隔に設定。</p>
<pre class="brush: bash; title: ; notranslate">
vi /etc/crontab
 */5 * * * * cacti   /usr/bin/php /var/www/localhost/htdocs/cacti/cmd.php &gt; /dev/null 2&gt;&amp;1
</pre>
<h4>cactiの設定</h4>
<p>ブラウザから http://hostname/cacti/ にアクセス。デフォルトのユーザとパスワードはadmin/admin。ウィザードが始まるがNext押していけばいい。adminのパスワードは適当なものに変更する。</p>
<p>色々設定するところがあるが、一番下にある参考URLらへんを参照。</p>
<p>ここでrrdtoolからACCESS DENIEDと言われてグラフが上手く表示されなかった。よくわからんがcactiでadminじゃなくてcactiというユーザを作り、User Management→cacti→Graph PermissionsでDenyをAllowにお変更してSave。Graph Managementからなんかグラフを選んで、右上の*Turn On Graph Debug Mode.をクリックするとログが見えるようになるので押してみる。今度は&#8217;rra/localhost_load_1min_5.rrd&#8217;: No such file or directoryとか怒られる。</p>
<p>見てみると確かにrraの下が空っぽなのでダメらしい。/var/www/localhost/htdocs/cacti/cmd.phpを実行してもエラーらしきものは出ておらず。しばらくココで嵌ったが、/var/www/localhost/htdocs/cacti/poller.phpを実行すればOKだった。1回目は前のデータがないので怒られるが、もう1度やると問題なく実行された。そのあとcactiからはちゃんと見えるようになった。</p>
<h4>参考URL</h4>
<ul>
<li><a href="http://www.boreas.dti.ne.jp/~mishiro/" target="_blank">Net-SNMPの設定方法</a></li>
<li><a href="http://net-snmp.sourceforge.net/" target="_blank">net-snmp</a></li>
<li><a href="http://www.photonway.net/AboutRrdtool.html" target="_blank">About Rrdtool</a></li>
<li><a href="http://www.boreas.dti.ne.jp/~mishiro/rrdtool/" target="_blank">RRDtoolのすすめ</a></li>
<li><a href="http://cacti.net/" target="_blank">cacti</a></li>
<li><a href="http://cacti.loaded.jp/" target="_blank">グラフツールcactiとは?</a></li>
<li><a href="http://www.stackasterisk.jp/tech/systemManagement/snmp01_01.jsp" target="_blank">【連載 】SNMPによるネットワークシステムの監視</a></li>
<li><a href="http://www.aconus.com/~oyaji/suse9.3/cacti_linux1.htm" target="_blank">RRDTool+Cactiによるサーバ監視(Linux編)</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://nobu666.com/2006/11/12/442.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[memo] GentooにPlaggerをインストール</title>
		<link>http://nobu666.com/2006/11/11/439.html</link>
		<comments>http://nobu666.com/2006/11/11/439.html#comments</comments>
		<pubDate>Fri, 10 Nov 2006 16:29:02 +0000</pubDate>
		<dc:creator>nobu</dc:creator>
				<category><![CDATA[gentoo]]></category>
		<category><![CDATA[memo]]></category>
		<category><![CDATA[plagger]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://nobu666.com/2006/11/11/000439.html</guid>
		<description><![CDATA[Gentooにはg-cpanという素晴らしいものがあるのだが、そこはあえて使わずにいく。というかなんか知らないけど上手くいかなかったので、仕方なく手動で入れたとも言う。とりあえず自宅サーバと言うことで、サックリrootに &#8230;<p class="read-more"><a href="http://nobu666.com/2006/11/11/439.html">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>Gentooにはg-cpanという素晴らしいものがあるのだが、そこはあえて使わずにいく。というかなんか知らないけど上手くいかなかったので、仕方なく手動で入れたとも言う。とりあえず自宅サーバと言うことで、サックリrootになって入れることにする。そのほうが簡単。以前レンタルサーバで悩んだのがウソのようだ。ちゃんとログを取ってないので曖昧な記憶でメモ。</p>
<h4>準備</h4>
<p>別段何もない。</p>
<pre class="brush: bash; title: ; notranslate">
perl -MCPAN -e shell
</pre>
<p>基本全部デフォルトのままENTER押してりゃよし。Gentooの場合、cpanでガンガン入れる前にまず</p>
<pre class="brush: bash; title: ; notranslate">
emerge expat
</pre>
<p>これをやっておく。次にCPANのConfigを弄る。</p>
<pre class="brush: perl; title: ; notranslate">
vi /usr/lib/perl5/5.8.8/CPAN/Config.pm
 $CPAN::Config = {
  'build_cache' =&gt; q[100],
  'build_dir' =&gt; q[/root/.cpan/build],
  'bzip2' =&gt; q[/bin/bzip2],
  'cache_metadata' =&gt; q[1],
  'check_sigs' =&gt; q[0],
  'colorize_output' =&gt; q[0],
  'commandnumber_in_prompt' =&gt; q[1],
  'cpan_home' =&gt; q[/root/.cpan],
  'curl' =&gt; q[/usr/bin/curl],
  'ftp' =&gt; q[/usr/bin/ftp],
  'ftp_passive' =&gt; q[1],
  'ftp_proxy' =&gt; q[],
  'getcwd' =&gt; q[cwd],
  'gpg' =&gt; q[],
  'gzip' =&gt; q[/bin/gzip],
  'histfile' =&gt; q[/root/.cpan/histfile],
  'histsize' =&gt; q[100],
  'http_proxy' =&gt; q[],
  'inactivity_timeout' =&gt; q[0],
  'index_expire' =&gt; q[1],
  'inhibit_startup_message' =&gt; q[0],
  'keep_source_where' =&gt; q[/root/.cpan/sources],
  'lynx' =&gt; q[],
  'make' =&gt; q[/usr/bin/make],
  'make_arg' =&gt; q[],
  'make_install_arg' =&gt; q[],
  'make_install_make_command' =&gt; q[/usr/bin/make],
  'makepl_arg' =&gt; q[],
  'mbuild_arg' =&gt; q[],
  'mbuild_install_arg' =&gt; q[],
  'mbuild_install_build_command' =&gt; q[./Build],
  'mbuildpl_arg' =&gt; q[],
  'ncftp' =&gt; q[],
  'ncftpget' =&gt; q[],
  'no_proxy' =&gt; q[],
  'pager' =&gt; q[lv -Ou8 -c],
  'prefer_installer' =&gt; q[EUMM],
  'prerequisites_policy' =&gt; q[ask],
  'scan_cache' =&gt; q[atstart],
  'shell' =&gt; q[/bin/zsh],
  'show_upload_date' =&gt; q[1],
  'tar' =&gt; q[/usr/bin/tar],
  'term_is_latin' =&gt; q[1],
  'term_ornaments' =&gt; q[1],
  'test_report' =&gt; q[0],
  'unzip' =&gt; q[/usr/bin/unzip],
  'urllist' =&gt; [q[ftp://ftp.kddilabs.jp/CPAN/]],
  'wget' =&gt; q[/usr/bin/wget],
 };
 1;
 __END__

cpan -i Bundle::CPAN
</pre>
<h4>CPANモジュールのインストール</h4>
<p><a href="http://subtech.g.hatena.ne.jp/otsune/20060816/PlaggerCPAN" target="_blank">Bundle::CPANとPlaggerに依存するモジュール（メモ）</a>に従って進める。書いてあるとおり、TemplateとEncode::Detectはまともには入らないっぽいので諦めてforce installで。別段不都合はないので。</p>
<p>なんかRDF::Coreが上手く入らなくて困った記憶がある。emerge expatしてないせいだった、という記憶もあるが…ちょっと覚えてない。でもコマンドの履歴に以下のものが残っていた。</p>
<pre class="brush: bash; title: ; notranslate">
wget http://ftp.yz.yamagata-u.ac.jp/pub/lang/cpan/modules/by-module/RDF/DPOKORNY/RDF-Core-0.50.tar.gz
tar -zxvf RDF-Core-0.50.tar.gz
cd RDF-Core-0.50
perl Makefile.PL
make
</pre>
<p>手動で入れたっぽい。若年アルツで覚えてない。まぁとりあえず頑張って入れて、cpanシェルでtest Plaggerが通るまで頑張る。通ったらinstall Plagger。</p>
<h4>リポジトリから最新取得</h4>
<p>subversionを使ってリポジトリから最新版を持ってきてmakeする。</p>
<pre class="brush: bash; title: ; notranslate">
svn co http://svn.bulknews.net/repos/plagger/trunk/plagger
cd plagger
perl Makefile.PL
make
</pre>
<p>ここまで行ったら出来たも同然。Plagger3大罠の1つである、assetsのコピーを忘れないうちにやっておく。svnで最新版を入れたディレクトリのassets以下に、　.cpan/build/Plagger-x.x.xx/assets/plugins/Publish-Gmail/gmail_notify.tt をコピっておく。yamlのglobalでassets_pathを指定するのも忘れずに。ちなみにyamlのサンプルは .cpan/build/Plagger-x.x.xx/examples 以下に入っているので、適当な場所にコピって編集すべし。</p>
<p>まぁ何が言いたいかって言うとレン鯖だと非常に苦労したインストールも、自宅鯖なら超簡単だぜってことです。gmailのメール送信量制限も、自宅鯖なら無関係。cacheもレン鯖だと、HDDが1Gくらいしかないので気にしなきゃいけないけど自宅鯖にはほぼ無関係。足りなくなったら増やせばイイだけだし。Plagger自体それなりに負荷があるので、レン鯖の場合は30分単位くらいで回さないと怒られそうなのだが、それを気にしなくていいのが一番でかい。もう5分とかで回してる。</p>
]]></content:encoded>
			<wfw:commentRss>http://nobu666.com/2006/11/11/439.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>[memo] rep2をSSL+Basic認証で使う</title>
		<link>http://nobu666.com/2006/11/04/429.html</link>
		<comments>http://nobu666.com/2006/11/04/429.html#comments</comments>
		<pubDate>Fri, 03 Nov 2006 17:24:07 +0000</pubDate>
		<dc:creator>nobu</dc:creator>
				<category><![CDATA[gentoo]]></category>
		<category><![CDATA[memo]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://nobu666.com/2006/11/04/000429.html</guid>
		<description><![CDATA[通勤時の電車の中では本を読んでいるか、暇つぶしに2ch見てるわけだが。どうせ携帯で見るなら自宅サーバのリソースも余ってることだし有効活用したい。そんなわけでrep2を使うことにした。 インストール とりあえずダウンロード &#8230;<p class="read-more"><a href="http://nobu666.com/2006/11/04/429.html">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>通勤時の電車の中では本を読んでいるか、暇つぶしに2ch見てるわけだが。どうせ携帯で見るなら自宅サーバのリソースも余ってることだし有効活用したい。そんなわけで<a href="http://akid.s17.xrea.com/" target="_blank">rep2</a>を使うことにした。</p>
<h4>インストール</h4>
<p>とりあえずダウンロードして、/var/www/localhost/rep2とかに置く。apacheは当然SSL有効でコンパイルしておくこと。phpはやたらに使用可能なフラグが多いのでメモっておく。</p>
<pre class="brush: bash; title: ; notranslate">
emerge -pv php

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R   ] dev-lang/php-5.1.6-r6  USE=&quot;apache2 bzip2 cjk cli crypt curl curlwrappers gd iconv mysql ncurses nls pcre readline sasl session spell ssl threads unicode xml xmlrpc zlib (-adabas) -apache -bcmath -berkdb (-birdstep) -calendar -cdb -cgi -concurrentmodphp -ctype -db2 -dbase (-dbmaker) -debug -discard-path -doc (-empress) (-empress-bcs) (-esoob) -exif -fastbuild (-fdftk) (-filepro) (-firebird) -flatfile -force-cgi-redirect (-frontbase) -ftp -gd-external -gdbm -gmp -hardenedphp -hash -hyperwave-api -imap (-informix) -inifile -interbase -iodbc -ipv6 -java-external -kerberos -ldap -libedit -mcve -memlimit -mhash -ming -msql -mssql -mysqli -oci8 (-oci8-instant-client) -odbc -pcntl -pdo -pdo-external -pic -posix -postgres -qdbm -recode -reflection -sapdb -sharedext -sharedmem -simplexml -snmp -soap -sockets (-solid) -spl -sqlite (-sybase) (-sybase-ct) -sysvipc -tidy -tokenizer -truetype -vm-goto -vm-switch -wddx -xmlreader -xmlwriter -xpm -xsl -yaz -zip&quot; 0 kB
</pre>
<p>rep2はPEARモジュールのいくつかが必須なので、PEARもと必須モジュールを入れる。eixで見つからなかったものはpearコマンドで入れ、見つかったものはemergeで入れた。</p>
<pre class="brush: bash; title: ; notranslate">
emerge PEAR-PEAR
pear install Net_UserAgent_Mobile-beta
pear install PHP_Compat
emerge PEAR-HTTP_Request
emerge PEAR-Pager
emerge PEAR-File
</pre>
<h4>phpの設定</h4>
<p>/etc/php/apache2-php5/php.iniの次のコメントアウトを外す。</p>
<pre class="brush: php; title: ; notranslate">
[mbstring]
mbstring.internal_encoding = EUC-JP
mbstring.http_input = auto
mbstring.http_output = EUC-JP
mbstring.detect_order = auto
mbstring.substitute_character = none;
</pre>
<h4>apacheの設定</h4>
<p>SSLを使うため、認証局と証明書が必要。<a href="http://nobu666.com/2006/10/29/000423.html">[修正版][memo] postfix + dovecotでSMTP AUTH &#038; IMAPなメールサーバを立ち上げる</a>で作成したものがあるのでそれを流用する。</p>
<pre class="brush: bash; title: ; notranslate">
cp -p /etc/ssl/postfix/server.crt /etc/apache2/ssl/
cp -p /etc/ssl/postfix/server.key /etc/apache2/ssl/
</pre>
<p>次にBasic認証に使う.htaccessをフォルダで上書きできるようにしておくため、/etc/apache2/modules.d/41_mod_ssl.default-vhost.confと/etc/apache2/vhosts.d/00_default_vhost.confの&lt;directory &#8220;/var/www/localhost/htdocs&#8221;&gt;部分を以下のように設定する。</p>
<pre class="brush: xml; title: ; notranslate">
&lt;directory &quot;/var/www/localhost/htdocs&quot;&gt;
    Options FollowSymLinks
    AllowOverride AuthConfig
&lt;/directory&gt;
</pre>
<h4>.htaccessの設定</h4>
<p>/var/www/localhost/htdocs/rep2に.htaccessを作成(サイト全体に認証をかけたいならhtdocsの下でも可)。</p>
<pre class="brush: bash; title: ; notranslate">
vi /var/www/localhost/htdocs/rep2/.htaccess
 AuthName &quot;User Authentication Required&quot;
 AuthType Basic
 Require valid-user
 AuthUserFile /etc/apache2/.htpasswd
htpasswd2 -c /etc/apache2/.htpasswd ユーザ名
</pre>
<h4>apacheの起動パラメータ</h4>
<p>gentooのapacheは、有効にしたいモジュールを明示しないといけないので、/etc/conf.d/apache2を修正。</p>
<pre class="brush: bash; title: ; notranslate">
vi /etc/conf.d/apache2
 APACHE2_OPTS=&quot;-D SSL -D PHP5 -D DEFAULT_VHOST -D SSL_DEFAULT_VHOST&quot;
/etc/init.d/apache2 restart
</pre>
<p>これで　https://ホスト名:443/rep2/　に行けばユーザ名とパスワードが聞かれるはず。念のため携帯からもアクセスして問題なく認証できれば万事OK。ただ携帯でパスワードを入力するのは面倒なので、どうにか携帯の固有IDでパスできないか調べ中。auだとHTTP_X_UP_SUBNOで取れるみたいなんだが…</p>
]]></content:encoded>
			<wfw:commentRss>http://nobu666.com/2006/11/04/429.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[memo] GentooでUPS(APC ES 500)を使う</title>
		<link>http://nobu666.com/2006/10/30/424.html</link>
		<comments>http://nobu666.com/2006/10/30/424.html#comments</comments>
		<pubDate>Sun, 29 Oct 2006 16:29:11 +0000</pubDate>
		<dc:creator>nobu</dc:creator>
				<category><![CDATA[gentoo]]></category>
		<category><![CDATA[memo]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://nobu666.com/2006/10/30/000424.html</guid>
		<description><![CDATA[Amazonで\7,000ちょっとという値段だったので、購入したのが届いた。流石に24時間稼働だとUPSがないと怖い。今年の雷で瞬断も多くあったので。付属のPowerCuteはWindowsとMacOS Xと商用Linu &#8230;<p class="read-more"><a href="http://nobu666.com/2006/10/30/424.html">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.amazon.co.jp/exec/obidos/ASIN/B0000AG7HB/realbeat-22/ref=nosim/" name="amazletlink" target="_blank"><img src="http://images-jp.amazon.com/images/P/B0000AG7HB.09.MZZZZZZZ.jpg" alt="APC ES 500" /></a></p>
<p>Amazonで\7,000ちょっとという値段だったので、購入したのが届いた。流石に24時間稼働だとUPSがないと怖い。今年の雷で瞬断も多くあったので。付属のPowerCuteはWindowsとMacOS Xと商用Linuxにしか対応していないので自力でどうにかする方法をメモ。</p>
<h4>準備と接続、認識確認</h4>
<pre class="brush: bash; title: ; notranslate">
emerge apcupsd
</pre>
<p>なにはなくともコレがないと始まらない。とりあえずインストールしたら一旦シャットダウンしてコンセントをUPSにつなぎ変え、付属のUSB通信ケーブルでUPSとサーバを接続して再起動。再起動したらdmesgを見てサーバがES500を認識しているか確認。</p>
<pre class="brush: plain; title: ; notranslate">
usbcore: registered new driver hiddev
hiddev0: USB HID v1.10 Device [APC APC ES 500 FW:803.p6.A USB FW:p6] on usb-0000:00:10.2-2
</pre>
<p>上記のようなメッセージがあれば問題ない。が、</p>
<pre class="brush: plain; title: ; notranslate">
es500 hid device not claimed
</pre>
<p>とか出てたら認識していない。俺の場合は思い切り認識していなかった。要するにまたカーネル再構築。だがもう手慣れたモンなのでサクサクと再構築する。こういうときはマシンパワーがあると非常に楽だ。お約束の以下の呪文を唱える。</p>
<pre class="brush: bash; title: ; notranslate">
cd /usr/src/linux
make menuconfig
</pre>
<p>そして今の設定をLOADして、以下のところにチェックを付けて保存。</p>
<pre class="brush: xml; title: ; notranslate">
Device Drivers ---&gt;
    USB Support ---&gt;
        /dev/hiddev raw HID device support
</pre>
<p>またお約束の呪文。</p>
<pre class="brush: bash; title: ; notranslate">
make &amp;&amp; make modules_install
cp arch/x86_64/boot/bzImage /boot/なんか適当な名前
</pre>
<p>そしたら/boot/grub/grub.confを編集して再起動すればいい。今度はちゃんと認識されているはず。念のためapcaccess statusとやってエラーが出ないことを確認する。</p>
<h4>設定と動作確認</h4>
<p>次はapcupsdの設定を行う。</p>
<pre class="brush: bash; title: ; notranslate">
cat /etc/apcupsd/apcupsd.conf
UPSCABLE usb
UPSTYPE usb
DEVICE
LOCKFILE /var/lock
ONBATTERYDELAY 6
BATTERYLEVEL 5
MINUTES 3
TIMEOUT 10
ANNOY 300
ANNOYDELAY 60
NOLOGON disable
KILLDELAY 0
NETSERVER on
NISIP 0.0.0.0
NISPORT 3551
EVENTSFILE /var/log/apcupsd.events
EVENTSFILEMAX 10
UPSCLASS standalone
UPSMODE disable
STATTIME 0
STATFILE /var/log/apcupsd.status
LOGSTATS off
DATATIME 0
</pre>
<p>殆どデフォルト。TIMEOUTに関しては動作確認のため10にした。これは10だと電源断から10秒でシャットダウンするということ。実際にapcupsdを動かして試してみる。</p>
<pre class="brush: bash; title: ; notranslate">
/etc/init.d/apcupsd start
rc-update add apcupsd default
</pre>
<p>思い切ってUPSのコンセントをぶっこ抜いてみる。ピーピーピーと警告音が鳴り、10秒後にシャットダウン処理が走れば成功。忘れないようにTIMEOUTは0にしておくこと。ここを0にしておくとUPS側のバッテリーで頑張ってくれるようになる。どのくらい頑張るかはBATTERYLEVELとMINUTESで決まる。BATTERYLEVELはバッテリ残量が残り何%になったらシャットダウンするかで、MINUTESは残り時間何分でシャットダウンするか。どちらかの条件を満たすとシャットダウンされる。お好みで変える。</p>
]]></content:encoded>
			<wfw:commentRss>http://nobu666.com/2006/10/30/424.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[修正版][memo] postfix + dovecotでSMTP AUTH &amp; IMAPなメールサーバを立ち上げる</title>
		<link>http://nobu666.com/2006/10/29/423.html</link>
		<comments>http://nobu666.com/2006/10/29/423.html#comments</comments>
		<pubDate>Sun, 29 Oct 2006 08:42:48 +0000</pubDate>
		<dc:creator>nobu</dc:creator>
				<category><![CDATA[gentoo]]></category>
		<category><![CDATA[memo]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://nobu666.com/2006/10/29/000423.html</guid>
		<description><![CDATA[[memo] postfix + dovecotでSMTP AUTH &#38; IMAPなメールサーバを立ち上げるがあまり正しくないので修正版。 ssmtpの削除 Gentooではいきなりpostfixを入れようとして &#8230;<p class="read-more"><a href="http://nobu666.com/2006/10/29/423.html">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://nobu666.com/2006/10/25/000420.html">[memo] postfix + dovecotでSMTP AUTH &amp; IMAPなメールサーバを立ち上げる</a>があまり正しくないので修正版。</p>
<h4>ssmtpの削除</h4>
<p>Gentooではいきなりpostfixを入れようとしても、デフォルトでssmtpが入っていてblockされるのでssmtpを消すのが先決。</p>
<pre class="brush: bash; title: ; notranslate">
emerge -C ssmtp
</pre>
<h4>postfixとdovecotのインストール</h4>
<p>Gentooの基本だけど、emergeするときはemerge -pvでどんなフラグが有効になるか必ず確認。必要ないならpackage.useで外す。あとsaslが必要なのでこれは付けておく。あとなんでかわからないけどpostfixにsaslを付けるとついてくるcyrus-saslで、gdbmやcryptをUSEするとコンパイルに失敗したので外した。</p>
<pre class="brush: bash; title: ; notranslate">
emerge -pv postfix dovecot
echo &quot;mmail-mta/postfix -mysql sasl&quot; &gt;&gt; /etc/portage/package.use
echo &quot;dev-libs/cyrus-sasl -mysql -java -gdbm -crypt&quot; &gt;&gt; /etc/portage/package.use
emerge postfix dovecot
</pre>
<h4>オレオレ認証局の作成</h4>
<p>Gentooでの方法なので他のディストリではパスが違うようなので注意。</p>
<pre class="brush: bash; title: ; notranslate">
mkdir /etc/certs
chmod 700 /etc/certs
cd /etc/certs
cp /etc/ssl/misc/CA.pl .
perl ./CA.pl -newca
CA certificate filename (or enter to create)
(ENTER)
Making CA certificate ...
Generating a 1024 bit RSA private key
..................................++++++
.......................++++++
writing new private key to './demoCA/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) [AU]:JP
State or Province Name (full name) [Some-State]:Kanagawa
Locality Name (eg, city) []:Yokohama
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Private
Organizational Unit Name (eg, section) []:Private
Common Name (eg, YOUR name) []:nobu666.fam.cx
Email Address []:root@nobu666.fam.cx

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:(ENTER)
An optional company name []:(ENTER)
Using configuration from /etc/ssl/openssl.cnf
Enter pass phrase for ./demoCA/private/cakey.pem:
Check that the request matches the signature
Signature ok
Certificate Details:
 (略)
Certificate is to be certified until Oct 28 06:15:58 2009 GMT (1095 days)

Write out database with 1 new entries
Data Base Updated
</pre>
<h4>クライアント用CA証明書とサーバ用CA証明書を作成</h4>
<pre class="brush: bash; title: ; notranslate">
cd /etc/certs/demoCA
openssl x509 -inform pem -in cacert.pem -outform der -out cacert.der
openssl x509 -in ./cacert.pem -out ./cacert.crt
</pre>
<h4>デジタル証明書のリクエストファイルを作成</h4>
<pre class="brush: bash; title: ; notranslate">
cd /etc/certs
perl ./CA.pl -newreq-nodes
Generating a 1024 bit RSA private key
...++++++
...............................................................................................................++++++
writing new private key to 'newkey.pem'
-----
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]:Kanagawa
Locality Name (eg, city) []:Yokohama
Organization Name (eg, company) [Internet Widgits Pty Ltd]:nobu666.fam.cx
Organizational Unit Name (eg, section) []:Admin
Common Name (eg, YOUR name) []:nobu666.fam.cx
Email Address []:root@nobu666.fam.cx

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:(ENTER)
An optional company name []:(ENTER)
Request is in newreq.pem, private key is in newkey.pem
</pre>
<h4>リクエストファイルからX.509サーバ証明書の作成と署名</h4>
<pre class="brush: bash; title: ; notranslate">
perl ./CA.pl -sign
Using configuration from /etc/ssl/openssl.cnf
Enter pass phrase for ./demoCA/private/cakey.pem:
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number:
            ce:db:05:2a:6a:dc:75:17
        Validity
            Not Before: Oct 29 06:51:11 2006 GMT
            Not After : Oct 29 06:51:11 2007 GMT
        Subject:
            countryName               = JP
            stateOrProvinceName       = Kanagawa
            localityName              = Yokohama
            organizationName          = nobu666.fam.cx
            organizationalUnitName    = Admin
            commonName                = nobu666.fam.cx
            emailAddress              = root@nobu666.fam.cx
        X509v3 extensions:
            X509v3 Basic Constraints:
                CA:FALSE
            Netscape Comment:
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier:
                7B:0E:46:62:02:FB:B6:A6:05:DC:DE:75:2E:2D:5A:29:5D:31:79:F8
            X509v3 Authority Key Identifier:
                keyid:A7:51:EC:0A:BD:B6:70:68:A5:01:ED:8E:76:1F:FE:0C:4D:B2:A0:19

Certificate is to be certified until Oct 29 06:51:11 2007 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
Signed certificate is in newcert.pem

openssl x509 -in newcert.pem -out server.crt
</pre>
<h4>postfix用にシンボリックリンクを張る</h4>
<pre class="brush: bash; title: ; notranslate">
ln -sf /etc/certs/server.crt /etc/ssl/postfix/server.crt
ln -sf /etc/certs/newkey.pem /etc/ssl/postfix/server.key
</pre>
<h4>postfixの設定</h4>
<pre class="brush: bash; title: ; notranslate">
vi /etc/postfix/main.cf

queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/lib/postfix
mail_owner = postfix
myhostname = nobu666.fam.cx
mydomain = nobu666.fam.cx
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, $mydomain, mail.$mydomain, localhost
unknown_local_recipient_reject_code = 550
mynetworks_style = subnet
mynetworks = 192.168.0.0/24, 127.0.0.0/8
relay_domains = $mydestination
alias_maps = hash:/etc/mail/aliases
alias_database = hash:/etc/mail/aliases
home_mailbox = .Maildir/

header_checks = regexp:/etc/postfix/header_checks
smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)
mydestination = $myhostname, localhost.$mydomain, $myhostname.$mydomain, mail.$mydomain, localhost
debug_peer_level = 2
debugger_command =
         PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
         xxgdb $daemon_directory/$process_name $process_id &amp;amp; sleep 5
sendmail_path = /usr/sbin/sendmail
mailq_path = /usr/bin/mailq
setgid_group = postdrop
html_directory = /usr/share/doc/postfix-2.2.10/html
manpage_directory = /usr/share/man
sample_directory = /etc/postfix
readme_directory = /usr/share/doc/postfix-2.2.10/readme
smtpd_use_tls = yes
smtpd_tls_loglevel = 1
smtpd_tls_cert_file = /etc/ssl/postfix/server.crt
smtpd_tls_key_file = /etc/ssl/postfix/server.key
smtpd_tls_session_cache_database = btree:/etc/postfix/smtpd_scache
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtp_sasl_security_options = noanonymous
allow_mail_to_commands = alias,forward,include
message_size_limit = 1024000
smtpd_client_restrictions =
            permit_mynetworks,
            permit_sasl_authenticated,
            permit_auth_destination,
            reject

vi /etc/postfix/master.cf

submission inet n      -       n       -       -       smtpd
        -o smtpd_etrn_restrictions=reject
        -o smtpd_client_restrictions=permit_sasl_authenticated,reject
</pre>
<h4>saslの設定</h4>
<pre class="brush: bash; title: ; notranslate">
vi /etc/sasl2/smtpd.conf

pwcheck_method: saslauthd

mkdir /var/state/saslauthd
chmod 700 /var/state/saslauthd
chown postfix /var/state/saslauthd
</pre>
<h4>dovecotの設定</h4>
<pre class="brush: bash; title: ; notranslate">
vi /etc/dovecot.conf

protocols = pop3 imap
ssl_disable = no
ssl_cert_file = /etc/ssl/postfix/server.crt
ssl_key_file = /etc/ssl/postfix/server.key
default_mail_env = maildir:%h/.Maildir

chmod 755 /var/run/dovecot
chmod 750 /var/run/dovecot/login
</pre>
<p>あとはデフォルトのまま。</p>
<h4>クライアントの設定</h4>
<p>まずはオレオレ認証局の証明書をクライアントに入れる必要がある（やらなくてもいいが警告が出るので…）。別にどうやってクライアントに渡してもOK。FTPとかSCPとかで適当に。メーラによって操作が違うがThunderbirdの場合は、ツール→オプション→プライバシー→セキュリティ→証明書を表示→認証局証明書→インポートと進んで、cacert.derを選択すればOK。あとはIMAPでアカウントを作って、受信は143番ポートでTLSを使うようにし、送信は587番ポートで同じくTLSを使うように設定する。送信テストするとユーザ名とパスワードが聞かれるので「パスワード無しで送信できないこと」「間違ったパスワードを入れて送信できないこと」「正しいパスワードを入れて送信できること」の3つを確認して終了。</p>
]]></content:encoded>
			<wfw:commentRss>http://nobu666.com/2006/10/29/423.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[memo] iptablesが使えないのでkernel再構築 &amp; sshdへのアタックをどうにかする</title>
		<link>http://nobu666.com/2006/10/28/421.html</link>
		<comments>http://nobu666.com/2006/10/28/421.html#comments</comments>
		<pubDate>Fri, 27 Oct 2006 19:12:00 +0000</pubDate>
		<dc:creator>nobu</dc:creator>
				<category><![CDATA[gentoo]]></category>
		<category><![CDATA[memo]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://nobu666.com/2006/10/28/000421.html</guid>
		<description><![CDATA[なんつーかね、某krからのsshdへのBrute force attacksが酷すぎる。auth.logを埋め尽くすほどのアタックを食らったので対策することに。だが普通にインストールするとiptablesが動いてくれない &#8230;<p class="read-more"><a href="http://nobu666.com/2006/10/28/421.html">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>なんつーかね、某krからのsshdへのBrute force attacksが酷すぎる。auth.logを埋め尽くすほどのアタックを食らったので対策することに。だが普通にインストールするとiptablesが動いてくれないので、カーネル再構築に挑戦する。</p>
<p>別に今回はkernelのバージョンを上げたいわけではなく、単純にカーネルのオプションを変えたいだけなので、emerge gentoo-sourcesはやらない。以下、rootになって作業を行う。あとmenuconfigはscreenの中でやると表示が乱れて酷いことになるので、screenをデタッチするなり抜けるなりしてからやったほうがいい。</p>
<pre class="brush: bash; title: ; notranslate">
cd /usr/src/linux
make menuconfig
</pre>
<p>Confgurationが立ち上がったら、まずLoad an Alternate Configuration Fileを選ぶ。&#8221;.config&#8221;が入力されているはずなので、そのままOKすると現在の設定が読み込まれる。そしたら</p>
<pre>
Networking  ---&gt;
  Networking options  ---&gt;
    Network packet filtering (replaces ipchains)  ---&gt;
      Core Netfilter Configuration  ---&gt;
         Netfilter Xtables support (required for ip_tables)
</pre>
<p>を選択。その下に色々あるが、よくわからないならMにしといてあとでModuleとして読めるようにしておくと吉。必要なのに何もチェックしないでおくと、再度カーネル再構築が必要になって面倒なので。チェックしたら1つ戻ってIP: Netfilter Configurationの中に入る。とりあえず必須なのはIP tables support (required for filtering/masq/NAT)と、IP range match support、Packet filtering、REJECT target support、address type match support、Full NAT、MASQUERADE target supportとかそのへん。終わったらTOPまで戻って、念のため設定ファイルをなんか名前付けて保存しておいたほうがいい。</p>
<p>あとはその辺のサイトに書いてあるとおり、お約束でOK。</p>
<pre class="brush: bash; title: ; notranslate">
make &amp;&amp; make modules_install
cp arch/x86_64/boot/bzImage /boot/なんか適当な名前
vi /boot/grub/grub.conf
</pre>
<p>grub.confの設定では、元々書いてあるものを絶対に消さないこと。消しちゃうと万が一再構築したカーネルで起動できなかったときに面倒。</p>
<p>[sourecode lang="text"]<br />
title=Gentoo Linux 2.6.17-r8<br />
root (hd0,0)<br />
kernel /さっきbootの下にcpしたファイル名 root=/dev/sda3 vga=ask<br />
[/sourcecode]</p>
<p>とかで問題なし。vga=askの部分はまぁお好みで。/usr/src/linux/Documentation/fb/vesafb.txtとかを参考に。基本的にはこれでrebootして、上のtitleでつけた名前を選択して起動してやればとりあえずOKなはずだ。失敗したら残しておいた方で起動して修正すべし。消してしまったお馬鹿さんはinstall cdから起動して/dev/sda1とかをmountして編集すれば戻せる。あとvgaとかvideoのオプションは、間違うと画面に何も表示されなくなるので注意。まぁリモート操作がメインならそれでもいいのかも知れないけど、何かあったときにアレなんで…心配ならaskにしておいて選択するのが間違いない。</p>
<p>そこまで出来たらDebian GNU/Linux 3.1(sarge)運用ノートの<a href="http://www.musicae.ath.cx/diary/?200506c&amp;to=200506272#200506272" target="_blank">SSH Brute force attacks</a>の通りに設定してから</p>
<pre class="brush: bash; title: ; notranslate">
/etc/init.d/iptables save
/etc/init.d/iptables start
rc-update add iptables default
</pre>
<p>以上で終了。エラーが出てiptablesが動かない場合は必要なモジュールが選択漏れでコンパイルされていないとか、Mを選択したのにmodprobeなりinsmodしてない。てか俺もこの手順にたどり着くまで5回くらい再構築してこんな時間に…もう寝る!</p>
]]></content:encoded>
			<wfw:commentRss>http://nobu666.com/2006/10/28/421.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[memo] postfix + dovecotでSMTP AUTH &amp; IMAPなメールサーバを立ち上げる</title>
		<link>http://nobu666.com/2006/10/25/420.html</link>
		<comments>http://nobu666.com/2006/10/25/420.html#comments</comments>
		<pubDate>Wed, 25 Oct 2006 14:59:30 +0000</pubDate>
		<dc:creator>nobu</dc:creator>
				<category><![CDATA[gentoo]]></category>
		<category><![CDATA[memo]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://nobu666.com/2006/10/25/000420.html</guid>
		<description><![CDATA[2006/10/29追記: イマイチ不正確なので[修正版][memo] postfix + dovecotでSMTP AUTH &#38; IMAPなメールサーバを立ち上げるで書き直しました。そちらをみてください。]]></description>
			<content:encoded><![CDATA[<p>2006/10/29追記: イマイチ不正確なので<a href="http://nobu666.com/2006/10/29/000423.html">[修正版][memo] postfix + dovecotでSMTP AUTH &amp; IMAPなメールサーバを立ち上げる</a>で書き直しました。そちらをみてください。</p>
]]></content:encoded>
			<wfw:commentRss>http://nobu666.com/2006/10/25/420.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[memo] サーバのCPU動作周波数を動的に変える</title>
		<link>http://nobu666.com/2006/10/24/418.html</link>
		<comments>http://nobu666.com/2006/10/24/418.html#comments</comments>
		<pubDate>Tue, 24 Oct 2006 06:50:23 +0000</pubDate>
		<dc:creator>nobu</dc:creator>
				<category><![CDATA[gentoo]]></category>
		<category><![CDATA[memo]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://nobu666.com/2006/10/24/000418.html</guid>
		<description><![CDATA[[memo] サーバのCPU動作周波数を下げるの続き。 やってみないとわからんので、cpufreq_ondemandを試してみる。 詳細はKernel メモ ondemand参照。とりあえずignore_nice_loa &#8230;<p class="read-more"><a href="http://nobu666.com/2006/10/24/418.html">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://nobu666.com/2006/10/23/000415.html">[memo] サーバのCPU動作周波数を下げる</a>の続き。</p>
<p>やってみないとわからんので、cpufreq_ondemandを試してみる。</p>
<pre class="brush: bash; title: ; notranslate">
modprobe cpufreq_ondemand
echo ondemand &amp;gt; /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

cd /sys/devices/system/cpu/cpu0/cpufreq/ondemand/
ls
ignore_nice_load  sampling_down_factor  sampling_rate  sampling_rate_max  sampling_rate_min  up_threshold

cat ignore_nice_load
0

cat sampling_down_factor
1

cat sampling_rate
1040000

cat sampling_rate_max
520000000

cat sampling_rate_min
520000

cat up_threshold
80
</pre>
<p>詳細は<a href="http://mowamowa.p.utmc.or.jp/~amedama/cgi-bin/wiki/wiki.cgi?page=Kernel+%A5%E1%A5%E2+ondemand" target="_blank">Kernel メモ ondemand</a>参照。とりあえずignore_nice_loadは1に設定しておいた。急がないけど負荷になりそうな作業なんかはniceすること。</p>
<p>実際にemerge &#8211;syncとかして/proc/cpuinfoを見てたら、普段1GHzで動作しているのが2GHz→1.8GHzとなって1GHzに戻った。上手く動いているっぽい。試しにnice revdep-rebuildとかすると1GHzから変わらないことも確認。とりあえずこのまま運用してみる。</p>
]]></content:encoded>
			<wfw:commentRss>http://nobu666.com/2006/10/24/418.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>[memo] TortoiseSVNからsvn+sshを使う</title>
		<link>http://nobu666.com/2006/10/24/417.html</link>
		<comments>http://nobu666.com/2006/10/24/417.html#comments</comments>
		<pubDate>Tue, 24 Oct 2006 06:36:27 +0000</pubDate>
		<dc:creator>nobu</dc:creator>
				<category><![CDATA[gentoo]]></category>
		<category><![CDATA[memo]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://nobu666.com/2006/10/24/000417.html</guid>
		<description><![CDATA[普通にsshで繋がるようになったらsvn+sshを使いたくなる。サーバー側はemerge subversionするぐらいで設定は特にない。svnadmin create /var/svn/hoge とか svn impo &#8230;<p class="read-more"><a href="http://nobu666.com/2006/10/24/417.html">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>普通にsshで繋がるようになったらsvn+sshを使いたくなる。サーバー側はemerge subversionするぐらいで設定は特にない。svnadmin create /var/svn/hoge とか svn import ~/moge file:///var/svn/hogeとかしておくだけ。svnserveを立ち上げる必要はない。svn+sshで接続するときは、sshで認証した後svnserve -tを勝手にしてくれ、接続を切るとsvnserveプロセスもなくなってくれる。よってルータで3690番のポートを開けておくとかいう作業は必要ない。22番だけ開いていればいい。</p>
<p>クライアント側は、Poderosaで作った鍵(例えばファイル名をid_rsaとする)しかない場合はPuTTY用の鍵を作る。puttygenを起動して、秘密鍵を読み込んでパスフレーズを入力すれば変換される。変換された秘密鍵をid_rsa.ppkとして保存。とりあえずPuTTYを起動して接続-データで自動ログインのユーザ名と、接続-SSH-認証で認証のためのプライベートキーファイルでさっきの.ppkファイルを設定。接続してみてパスフレーズ入力してログイン出来ればOK。</p>
<p>次にputty.exeと同じフォルダにあるpageant.exeを起動する。タスクトレイに常駐するので右クリックして鍵の追加を選んで、.ppkを選択する。パスフレーズを入力すれば作業終わり。以降、PuTTYでもTortoiseSVNでもパスフレーズは入力しないでもいい。ただ、これはWindowsにログインしなおすと消えてしまうので、ログイン毎に鍵の追加→パスフレーズの入力を行う必要がある。ランチャーに登録するかスタートアップに入れておく。</p>
<p>後はTortoiseSVNの設定で、ネットワークにあるSSHクライアントにTortoisePlink.exeを設定。これでTortoiseSVNからリボジトリブラウザを開いて、URL欄に svn+ssh://ユーザ名@ホスト名/var/svn/hoge と入力してエラーが出なければ終了。</p>
]]></content:encoded>
			<wfw:commentRss>http://nobu666.com/2006/10/24/417.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[memo] USEフラグをいい感じに管理する</title>
		<link>http://nobu666.com/2006/10/24/416.html</link>
		<comments>http://nobu666.com/2006/10/24/416.html#comments</comments>
		<pubDate>Mon, 23 Oct 2006 17:40:03 +0000</pubDate>
		<dc:creator>nobu</dc:creator>
				<category><![CDATA[gentoo]]></category>
		<category><![CDATA[memo]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://nobu666.com/2006/10/24/000416.html</guid>
		<description><![CDATA[俺のようにしょっちゅうemergeしたい人はUSEフラグの管理が大変だ。知らないうちに勝手にgtk2フラグが有効になっててXがインストールされたりして大変ウザイ。そんなわけでGentoo使いの先輩に教えて貰ったeixとe &#8230;<p class="read-more"><a href="http://nobu666.com/2006/10/24/416.html">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>俺のようにしょっちゅうemergeしたい人はUSEフラグの管理が大変だ。知らないうちに勝手にgtk2フラグが有効になっててXがインストールされたりして大変ウザイ。そんなわけでGentoo使いの先輩に教えて貰ったeixとeuseを使ってみる。</p>
<pre class="brush: bash; title: ; notranslate">
sudo emerge eix
sudo eix-sync
</pre>
<p>euseはgentoolkitに入っている。eixはemerge &#8211;searchと似たようなモンだがこっちのほうが速いし使いやすい。んで、本題のeuseだが、使い方自体は&#8211;helpすりゃわかるんだが。フラグの説明見たり、どれが使われてるか見れたり、フラグを有効にしたり無効にしたりできる。つーか詳細はman euseで（ｗ euse使うとmake.confのUSEフラグの部分が整形されて見やすくなるのも嬉しい。まぁ説明見るだけなら /usr/portage/profiles/use.desc<br />
 見ればいいんだが。</p>
<p>同じくgentoolkitに含まれているequeryも激しく便利。こいつで</p>
<pre class="brush: bash; title: ; notranslate">
equery depends mysql
</pre>
<p>とかやってやればmysqlフラグに依存しているパッケージを調べることが出来るし、dependsをdepgraphに変えてやると依存関係をツリーで見れる。超便利。</p>
]]></content:encoded>
			<wfw:commentRss>http://nobu666.com/2006/10/24/416.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[memo] サーバのCPU動作周波数を下げる</title>
		<link>http://nobu666.com/2006/10/23/415.html</link>
		<comments>http://nobu666.com/2006/10/23/415.html#comments</comments>
		<pubDate>Mon, 23 Oct 2006 14:59:04 +0000</pubDate>
		<dc:creator>nobu</dc:creator>
				<category><![CDATA[gentoo]]></category>
		<category><![CDATA[memo]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://nobu666.com/2006/10/23/000415.html</guid>
		<description><![CDATA[CPUに関する情報は/sys/devices/system/cpu/cpu0/cpufreq/で次のファイルをcatする。まぁファイル名のまんまだが。 affected_cpus : 影響する他のCPU。俺の場合はデュア &#8230;<p class="read-more"><a href="http://nobu666.com/2006/10/23/415.html">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>CPUに関する情報は/sys/devices/system/cpu/cpu0/cpufreq/で次のファイルをcatする。まぁファイル名のまんまだが。</p>
<ul>
<li>affected_cpus : 影響する他のCPU。俺の場合はデュアルコアなので当然0と1</li>
<li>cpuinfo_cur_freq : 現在の動作周波数</li>
<li>cpuinfo_max_freq : 最大周波数。AMD64X2 3800+の場合は2000000</li>
<li>cpuinfo_min_freq : 最低周波数。AMD64X2 3800+の場合は1000000</li>
<li>scaling_available_freqyencies : 設定可能な周波数。AMD64X2 3800+の場合は2000000/1800000/1000000しかない。intelだともっと多いらしい</li>
<li>scaling_available_governors : 設定可能な動作モード。Gentooのデフォルトではperformanceのみ</li>
<li>scaling_cur_freq : 現在の動作周波数</li>
<li>scaling_driver : 周波数コントロールのための仕組みの名前</li>
<li>scaling_governor : 動作モード。scaling_available_governorsのどれか</li>
<li>scaling_max_freq : cpuinfo_max_freqと何が違うのかわからん</li>
<li>scaling_min_freq : cpuinfo_min_freqと何が違うのかわからん</li>
</ul>
<p>普段は高周波数で動いてくれなくていいというか、その方が電気代が安くなって地球に優しいためいい感じ。そんなわけで以下の手順を踏んで周波数を下げてみた。</p>
<p>(今の周波数を確認)</p>
<pre class="brush: bash; title: ; notranslate">
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
</pre>
<p>(どんなdriverがあるか探す)</p>
<pre class="brush: bash; title: ; notranslate">
find /lib/modules/2.6.17-gentoo-r7/ -name '*.ko'|grep cpu
</pre>
<p>(明らかにそれっぽい奴を見つけたので読み込む)</p>
<pre class="brush: bash; title: ; notranslate">
sudo modprobe cpufreq_powersave
</pre>
<p>(動作モードが増えたことを確認)</p>
<pre class="brush: bash; title: ; notranslate">
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
</pre>
<p>(動作モードを上で確認したやつに変更)</p>
<pre class="brush: bash; title: ; notranslate">
su - ; echo &quot;powersave&quot; &gt; /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
exit
</pre>
<p>(周波数が下がったことを確認)</p>
<pre class="brush: bash; title: ; notranslate">
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
</pre>
<p>これだと確かに周波数は下がるが下がりっぱなしだ。Gentooだと最新を追っかけたい人はコンパイルをしょっちゅうするので、そういうときにいちいち戻すのが面倒だ。そこでcpufreq_ondeamndというdriverを使うと、なんかいい感じに自動化できそうな予感がする。が、もうちょっと調べて、しっかり設定しないと下がりっぱなしとか上がりっぱなしになりそうな予感がするのでとりあえずスルー。</p>
]]></content:encoded>
			<wfw:commentRss>http://nobu666.com/2006/10/23/415.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[memo] Gentooインストールメモ</title>
		<link>http://nobu666.com/2006/10/22/413.html</link>
		<comments>http://nobu666.com/2006/10/22/413.html#comments</comments>
		<pubDate>Sun, 22 Oct 2006 11:04:41 +0000</pubDate>
		<dc:creator>nobu</dc:creator>
				<category><![CDATA[gentoo]]></category>
		<category><![CDATA[memo]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://nobu666.com/2006/10/22/000413.html</guid>
		<description><![CDATA[特に書くことないほどあっさり終了。LiveCDを焼いてそいつでブートし、デスクトップ画面が出てきたら&#8221;Gentoo Linux installer&#8221;をダブルクリックして指示に従っていくだけ。つかパ &#8230;<p class="read-more"><a href="http://nobu666.com/2006/10/22/413.html">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>特に書くことないほどあっさり終了。<a href="http://mirror.gentoo.gr.jp/releases/amd64/current/livecd/livecd-amd64-installer-2006.1.iso">LiveCD</a>を焼いてそいつでブートし、デスクトップ画面が出てきたら&#8221;Gentoo Linux installer&#8221;をダブルクリックして指示に従っていくだけ。つか<a href="http://www9.ocn.ne.jp/~pcvolu/pcnet/gentopage122.htm" target="_blank">パソコンふぉあ障害者ず Gentoo Linux 2006.0(インストール-LiveCD-)</a>を参考に。変えたところはIPアドレスとかその辺のネットワーク設定周りと、ステージを3からにしたのと、CFLAGで-O3にしたぐらい。インストールが終わったら上部のメニューからrebootしてCD抜いて終わり。</p>
<p>pingして外に繋がることを確認したら</p>
<pre class="brush: bash; title: ; notranslate">
emerge --sync
</pre>
<p>してから、必要なものをガンガン入れるんだが、その前に</p>
<pre class="brush: bash; title: ; notranslate">
/etc/init.d/hdparm start
</pre>
<p>してDMAを有効にしておく。んでいい加減sshで繋いで作業したいので</p>
<pre class="brush: bash; title: ; notranslate">
nano -w /etc/ssh/sshd_config
</pre>
<p>で適切にsshを設定。</p>
<pre class="brush: plain; title: ; notranslate">
PermitRootLogin no
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication no
</pre>
<p>とかそんな感じに。</p>
<p>クライアントで鍵セットを作って、USBメモリでサーバに公開鍵を置く。マウントするのは</p>
<pre class="brush: bash; title: ; notranslate">
mkdir /mnt/usbmemory
mount -t vfat /dev/sdb1 /mnt/usbmemory
</pre>
<p>で、/mnt/usbmemoryが見えるようになる。後は公開鍵を置いてパーミッション変えればOK。</p>
<pre class="brush: bash; title: ; notranslate">
mkdir ~/.ssh
cat /mnt/usbmemory/id_rsa &gt;&gt; ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
</pre>
<p>クライアントからsshで繋いでrootになって、ひたすら<code>emerge -av パッケージ名</code>。入れたパッケージは以下の通り。</p>
<ul>
<li>管理系:gentoolkit/htop/traceroute/tcpdump</li>
<li>デーモン系:apache2/proftpd/mysql/subversion/trac/samba</li>
<li>ユーティリティ系:sudo/screen/ftp/zsh/w3m/svk/lv/nkf</li>
<li>言語:python/ruby/jdk/groovy</li>
</ul>
<p>keywordでmaskされてるとか怒られるやつは</p>
<pre class="brush: bash; title: ; notranslate">
ACCEPT_KEYWORDS=&quot;~amd64&quot; emerge -av パッケージ名
</pre>
<p>で入る。色々入れたり消したりしてるうちに依存関係がおかしくなったりしたときは、revdep-rebuildする。特定のライブラリに依存するもの、とかの指定もできる。</p>
<p>あとはapacheやらsambaやらの設定だな。</p>
]]></content:encoded>
			<wfw:commentRss>http://nobu666.com/2006/10/22/413.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

