2009/03/04

WebObjects 5.2.4 を Apache 2.2 (CentOS 5.2) で動かす

アップル - WebObjects

WebObjects とは、アップル社が開発した、Java による Webアプリケーションフレームワークで、強力なWebサービスを簡単に構築することができる素晴らしいツールです。


Apple社自身でも、Apple Store, MobileMe(旧.Mac), iTunes Store などを WebObjects で構築しています。


そんな WebObjects ですが、弊社で使用している WebObjects 5.2 は、Linux の場合 Apache 1.3 でないと動いてくれません。


しかしながら、最近の OS はより高機能な Apache 2.2 系が搭載されており、できれば Apache 2.2 系で動作させたいものです。

これまで何度かチャレンジしたものの、なかなかうまく動いてくれませんでした・・・。


今回やっとうまくいったのでメモしておきます。



Java のインストール


WebObjects 5.2.4 では、Java 1.4 系を使用します。


$ chmod +x j2re-1_4_2_19-linux-i586-rpm.bin
$ ./j2re-1_4_2_19-linux-i586-rpm.bin
inflating: j2re-1_4_2_19-linux-i586.rpm
Done.

$ sudo rpm -ihv j2re-1_4_2_19-linux-i586.rpm
########################################### [100%]

$ sudo vi /etc/profile.d/java.sh
# Java
export JAVA_HOME=/usr/java/j2re1.4.2_19
export PATH=$PATH:$JAVA_HOME/bin

$ sudo chmod +x /etc/profile.d/java.sh
$ source /etc/profile.d/java.sh

$ java -version
java version "1.4.2_19"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_19-b04)
Java HotSpot(TM) Client VM (build 1.4.2_19-b04, mixed mode)

$ java -version -server
java version "1.4.2_19"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_19-b04)
Java HotSpot(TM) Server VM (build 1.4.2_19-b04, mixed mode)


WebObjects 5.2 のインストール


さて、本体のインストールです。インストールCDの Deployment/SOLARIS フォルダを ftp でアップしています。


はじめに install.sh を修正します。修正内容は、"-pxZf" を "-pxzf" に修正します。(3か所あります)


$ sudo ./install.sh -license X-NNN-XXX-NNN-XXX-NNN-XXX-NNN-XXX-NNN -adaptorsOnly NO -minimalInstall NO -cgibin /var/www/cgi-bin -docroot /var/www/html -woroot /opt/Apple

INSTALLATION:
Beginning WebObjects 5.2 full installation:

. Creating WebObjects installation directory ...
. Creating WebObjects' Applications and Frameworks directories ...
. Installing WebObjects Adaptor source ...
. Installing WebObjects Deployment ...
. Installing WODocumentRoot frameworks into document root ...
. Creating startup scripts ...
. ... Done.

WebObjects 5.2 Deployment, Full Install is now installed.

$ sudo chmod +x /etc/profile.d/webobjects.sh
# WebObjects
export NEXT_ROOT=/opt/Apple

$ sudo chmod +x /etc/profile.d/webobjects.sh
$ source /etc/profile.d/webobjects.sh


WebObjects 5.2 を WebObjects 5.2.4 へ


WebObjects 5.2 の最終バージョンは 5.2.4 ですので、アップデートします。アップデートファイルはこちらから。


$ wget http://download.info.apple.com/Apple_Support_Area/Apple_Software_Updates/MultiCountry/Enterprise/webobjects/patches/5.2/WO524Solaris.tar.gzip
$ wget http://download.info.apple.com/Apple_Support_Area/Apple_Software_Updates/MultiCountry/Enterprise/scripts/patcher.sh
$ vi patcher.sh
# COMPRESS=Z # gnutar compress flag: 'Z' or 'z' or ''
# Z を z に修正
COMPRESS=z # gnutar compress flag: 'Z' or 'z' or ''

$ chmod 511 patcher.sh
$ sudo ln -s /bin/tar /bin/gnutar
$ sudo ./patcher.sh -install WO524Solaris.tar.gzip -next_root $NEXT_ROOT
No errors, extracting patch

Install of wo524/WO524Solaris.tar.gzip successful

$ sudo cp -rf $NEXT_ROOT/Library/WebObjects/WODocumentRoot/WebObjects /var/www/html/

$ sudo vi $NEXT_ROOT/Library/Frameworks/JavaWebObjects.framework/Resources/WebServerConfig.plist
//DocumentRoot = "/Library/WebServer/Documents";
DocumentRoot = "/var/www/html";



アダプタの作成


いよいよ本番、Apache 2.2 対応のアダプタを作成します。ソースは Project Wonder から取得します。


$ sudo yum install httpd-devel
$ wget http://webobjects.mdimension.com/wonder/releases/Wonder-5.0.0.8972-Source.tar.gz
$ tar -zxvf Wonder-5.0.0.8972-Source.tar.gz
$ cd Wonder/Utilities/Adaptors/

$ vi make.config
#ADAPTOR_OS = MACOS
ADAPTOR_OS = LINUX
CC = gcc

$ make
$ cd Apache2.2/
$ sudo /usr/sbin/apxs -i -a -n WebObjects mod_WebObjects.la

$ vi apache.conf
LoadModule WebObjects_module modules/mod_WebObjects.so
#LoadModule WebObjects_module modules/mod_WebObjects.so

$ sudo cp apache.conf /etc/httpd/conf.d/webobjects.conf
$ sudo chmod 644 /etc/httpd/conf.d/webobjects.conf

$ sudo vi /etc/httpd/conf/httpd.conf
#ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

$ sudo /usr/sbin/httpd -M
Loaded Modules:
WebObjects_module (shared)
Syntax OK

$ sudo /etc/rc.d/init.d/httpd restart


SELinux


SELinux を使っている場合は、httpd よる 1085 ポート(wotaskd)への接続が拒否されてしまいます。


setroubleshoot: SELinux は http デーモンによるネットワークポート 1085 ヘの接続を阻止しています。 For complete SELinux messages.

次のようにして httpd がネットワークポートに接続するのを許可します。


$ sudo /usr/sbin/setsebool -P httpd_can_network_connect=1


動作確認


最後に、起動スクリプトの作成と自動起動です。


$ sudo vi /etc/rc.d/init.d/WOServices
#!/bin/sh
#
# Startup script for the WebObjects
#
# chkconfig: 345 85 15
# description: WebObject services
#

# Source function library.
. /etc/rc.d/init.d/functions

export PATH=/usr/java/j2re1.4.2_19/bin/:$PATH
WOSERVICES_SCRIPT="/opt/Apple/Library/WebObjects/Executables/WOServices"

# See how we were called.
case "$1" in
start)
echo -n "Starting WebObjects: "
daemon ${WOSERVICES_SCRIPT} start
echo
touch /var/lock/subsys/WebObjects
;;
stop)
echo -n "Shutting down WebObjects: "
${WOSERVICES_SCRIPT} stop
echo
rm -f /var/lock/subsys/WebObjects
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac

exit 0


$ sudo chmod +x /etc/rc.d/init.d/WOServices
$ sudo /etc/rc.d/init.d/WOServices start
Starting WebObjects: Beginning WebObjects services startup...
[ OK ]
$ sudo /sbin/chkconfig --add WOServices


root より JavaMonitor が起動できればOKです。


# $NEXT_ROOT/Library/WebObjects/JavaApplications/JavaMonitor.woa/JavaMonitor -WOPort 56789 &

Monitor for WebObjects 5

参考:


2009/02/27

CentOS 5.2 の vsftpd

www.centos.org - The Community ENTerprise Operating System

CentOS 5.2 標準の FTPサーバ vsftpd ですが、設定は間違ってないはずなのになぜかログインできません。


FTP クライアントのログには次のように出力されています。


500 OOPS: cannot change directory:/home/xxx
500 OOPS: child died
ログインできません.


サーバのログを見ると・・・


setroubleshoot: SELinux は ftp デーモンによるユーザーのホームディレ クトリ (./home) の読み込みを阻止しています。 For complete SELinux messages.


どうやら、OS のセキュリティを高める機能である、SELinux が vsftp によるホームディレクトリへのアクセスを拒否していたようです。


次のようにすることで、解除できます。


$ sudo /usr/sbin/setsebool -P ftp_home_dir 1

これで問題なくアクセスできます。

2009/02/26

MySQL 3.23.58 を CentOS 5.2 にインストールする

MySQL ::  世界でもっとも普及している、オープン ソース データベース
[10.09.15 update]ソースファイルのリンクを修正

自社サーバを一台新調することになったのですが、とある事情から MySQL は Ver 3.23.58 を使用しなければならず、でも Apache は 2.2 系を使いたい!

というわけで、OS やその他の環境は最新の CentOS 5.2 を使用し、MySQL 3.23.58 はソースからインストールすることにしました。

しかしながら、最新の環境にきわめて古いソフトをインストールすると、ほぼ間違いなく躓くもので。


ダウンロード


まずはダウンロードですが、もはや公式サイトのアーカイブにも見当たりません・・・

ので、MySQL日本正規代理店の SoftAgency 様から拝借いたします。

既に SoftAgency 様にも見当たらなくなってしまいました。
ですので、ソースファイルはこちらにアップしておきます。

>> Download MySQL-3.23.58

$ wget http://download.softagency.net/MySQL/Downloads/MySQL-3.23/mysql-3.23.58.tar.gz
$ tar -zxvf mysql-3.23.58.tar.gz
$ cd mysql-3.23.58/


Configure


Makefile ファイルを作成するために、configure を実行します。

$ ./configure \
 --prefix=/usr/local/mysql \
 --with-charset=sjis \
 --with-extra-charsets=all \
 --with-mysqld-user=mysql \
 --without-bench \
 --localstatedir=/home/mysql/data

checking "LinuxThreads"... "Not found"
configure: error: This is a linux system and Linuxthreads was not
found. On linux Linuxthreads should be used.  Please install Linuxthreads
(or a new glibc) and try again.  See the Installation chapter in the
Reference Manual for more information.

やっぱりエラーが。

どうやら CentOS 5 では Linuxthreads はサポートされなくなったようで(CentOS 4 まではサポートされていたようです)、configure のオプションで thread の方法を指定します。

$ ./configure \
 --prefix=/usr/local/mysql \
 --with-charset=sjis \
 --with-extra-charsets=all \
 --with-mysqld-user=mysql \
 --without-bench \
 --localstatedir=/home/mysql/data \
 --with-named-thread-libs="-lpthread"

checking for termcap functions library... configure: error: No curses/termcap library found

今度は、curses library がないとおっしゃいます。インストールし、再チャレンジ。

$ yum search ncurses
ncurses.i386 : A terminal handling library
ncurses-devel.i386 : Development files for the ncurses library

$ sudo yum install ncurses.i386
Package ncurses - 5.5-24.20060715.i386 is already installed.

$ sudo yum install ncurses-devel.i386
Installed: ncurses-devel.i386 0:5.5-24.20060715
Complete!

$ ./configure \
 --prefix=/usr/local/mysql \
 --with-charset=sjis \
 --with-extra-charsets=all \
 --with-mysqld-user=mysql \
 --without-bench \
 --localstatedir=/home/mysql/data \
 --with-named-thread-libs="-lpthread"

MySQL has a Web site at http://www.mysql.com/ which carries details on the
latest release, upcoming features, and other information to make your
work or play with MySQL more productive. There you can also find
information about mailing lists for MySQL discussion.

Remember to check the platform specific part of the reference manual for
hints about installing MySQL on your platform. Also have a look at the
files in the Docs directory.

Thank you for choosing MySQL!

OK! うまくいきました!


Make


さて、お次はコンパイルです。

$ make
mysqld.o: In function `main':
mysqld.cc:(.text+0x3450): undefined reference to `my_fast_mutexattr'
mysqld.cc:(.text+0x3464): undefined reference to `my_fast_mutexattr'
mysqld.cc:(.text+0x3478): undefined reference to `my_fast_mutexattr'
mysqld.o:mysqld.cc:(.text+0x34a0): more undefined references to `my_fast_mutexattr' follow
collect2: ld returned 1 exit status
make[4]: *** [mysqld] エラー 1

my_fast_mutexattr が定義されてないと。

そこで、定義を強制するように修正します。

$ vi mysys/my_thr_init.c
/my_fast_mutexattr

#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
pthread_mutexattr_t my_fast_mutexattr;
#endif

これを、下記のようにします。

//#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
pthread_mutexattr_t my_fast_mutexattr;
//#endif

これでなんとかコンパイルができました。


Maike Install


最後にインストールです。ここまでくればOKでしょう。

$ sudo make install

お疲れ様です!

2009/01/23

[GAE]Google App Engine を使ってみる Hello, webapp World!

前回は、単純な CGI を試してみましたが、今回は、Google App Engine に提供されている webapp というフレームワークを使ってみます。



Hello, webapp!


webapp は次の3つのパートからなります。



  • リクエストの処理と、レスポンスを生成する、RequestHandler クラス

  • URL に従ってリクエストをルーティングする、WSGIApplication インスタンス

  • WSGIApplication を起動する、メインルーチン


さっそく、helloworld.py を書き換えてみます。


helloworld/helloworld.py
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class MainPage(webapp.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Hello, webapp World!')

application = webapp.WSGIApplication(
[('/', MainPage)],
debug=True)

def main():
run_wsgi_app(application)

if __name__ == "__main__":
main()


開発サーバを起動し、http://localhost:8080 にアクセスします。

ブラウザに Hello, webapp World! が表示されれば成功です!




参考:


2009/01/22

[GAE]Google App Engine を使ってみる Hello, World!


昨年の4月にリリースされた、Google App Engine ですが、アカウントを申請したままずっと放置していました。


「一年の計は元旦にあり」ということで、今後ますますクラウド化していく世の中に備え、Google App Engine、Amazon Web Services は押さえておかなければなりません。


そこで、まずは Google App Engine を使ってみました。



使い始めるのは簡単で、



  1. Python のインストール

  2. Google App Engine SDK のインストール


これですぐにローカルで開発が始められます。


Hello, World!


なにはともあれ、まずは Hello, World! ですね。


シンプルな Request Handler を作成

helloworld ディレクトリを作成し、その中に helloworld.py を作成します。


helloworld/helloworld.py
print 'Content-Type: text/plain'
print ''
print 'Hello, World!'

設定ファイルを作成

helloworld ディレクトリに、app.yml を作成します。


helloworld/app.yml
application: helloworld
version: 1
runtime: python
api_version: 1

handlers:
- url: /.*
script: helloworld.py

アプリケーションのテスト

dev_appserver.py を実行し、ウェブサーバを起動します。実行するアプリケーションディレクトリのパスを渡します。


google_appengine/dev_appserver.py helloworld/

開発サーバが起動したら、http://localhost:8080 にアクセスします。

ブラウザに Hello, World! が表示されれば成功です!



参考: