วันจันทร์, พฤษภาคม 29, 2549

Upgrade PHP from 4.4.1 to 5.1.4

Old Configuration:

PHP Version 4.4.1


Configure Command '/SourceCache/apache_mod_php/apache_mod_php-18.4/php/configure' '--prefix=/usr' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--disable-dependency-tracking' '--with-apxs' '--with-ldap=/usr' '--with-kerberos=/usr' '--enable-cli' '--with-zlib-dir=/usr' '--enable-trans-sid' '--with-xml' '--enable-exif' '--enable-ftp' '--enable-mbstring' '--enable-mbregex' '--enable-dbx' '--enable-sockets' '--with-iodbc=/usr' '--with-curl=/usr' '--with-config-file-path=/etc' '--sysconfdir=/private/etc' '--with-mysql=/usr' '--with-mysql-sock=/var/mysql/mysql.sock'
Server API Apache
Virtual Directory Support disabled
Configuration File (php.ini) Path /private/etc/php.ini
PHP API 20020918
PHP Extension 20020429
Zend Extension 20050606
Debug Build no
Zend Memory Manager enabled
Thread Safety disabled
Registered PHP Streams php, http, ftp, compress.zlib

ขี้เกียจคอมไพล์เอง เลยอัพเดทแบบไบนารี่ เอามาจากเว๊บนี้ http://www.entropy.ch/software/macosx/php/#update

โหลดอันของ Apache 1.3 มาเพราะไม่อยากอัพเกรด Apache ไปเป็น ๒ ไม่งั้นคงลำบากน่าดู.
php5 ถูกติดตั้งลงไปที่ /usr/local/php5.
หลังจากติดตั้งแล้วสตาร์ทอะปาชี่ไม่ติดเพราะเหมือนกับว่า php4 และ php5 มันถูกโหลดทั้งคู่เลยตีกัน.
(php5 ถูกโหลดโดย /etc/httpd/users/+entropy-php.conf ซึ่งเป็น symbolic link ไปที่ /usr/local/php5/entropy-php.conf

ลองลบส่วนที่เป็นของ php4 ออก
แล้วอาศัยการ include โดยแยกส่วนที่ include php4 กับส่วนของ php5 ออกจากกันแล้วใช้การรีเนมเอา
Include /private/etc/httpd/users/*.conf
/private/etc/httpd/users/+php4.conf กับ +php5.conf

วันอาทิตย์, พฤษภาคม 28, 2549

DSpace : Export items in a collection.

refer to the system document, we can export items in a specific collection by :

$ /bin/dsrun org.dspace.app.itemexport.ItemExport --type=COLLECTION --id= --dest=/some/where/destination/ --number=


ทำโหลดบาลานซิ่ง http://sunsite.utk.edu/diglib/dspace/contrib/loadbal.txt
######################################################
# This document was kindly contributed by Larry
# Lansing (lansil @ fuzzynerd.com). For any questions
# regarding this information, please contact him
# directly.
######################################################

As promised, here are my loadbalancing configuration files. These are
still works-in-progress--there are probably mistakes and omissions. I
hope someone finds these useful.

Notes: The apache server (I'll call it "www") relays connections to
two tomcat servers called "jsp1" and "jsp2", using ajp13. www runs
Apache2.0, with mod_jk. jsp1 and jsp2 run Tomcat 4.1.24. I have
tried to simplify my configs by disabling unnecessary tomcat
connectors, such as the standalone port 8080 HTTP connector.

www configs
-----------
httpd.conf must include these lines in appropriate places:
***
LoadModule jk_module libexec/apache2/mod_jk.so
Include /usr/local/etc/apache2/mod_jk.conf
***

mod_jk.conf:
***


JkWorkersFile /usr/local/etc/apache2/workers.properties
JkLogFile logs/jk.log
JkLogLevel warn
JkMount /dspace/* loadbalancer
JkMount /dspace-oai/* loadbalancer

***

workers_properties:
***
worker.list=loadbalancer

worker.jsp1.port=8009
worker.jsp1.host=jsp1
worker.jsp1.type=ajp13
worker.jsp1.lbfactor=1

worker.jsp2.port=8009
worker.jsp2.host=jsp2
worker.jsp2.type=ajp13
worker.jsp2.lbfactor=1

worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=jsp1, jsp2
***

jsp1 and jsp2
-------------
Tomcat's server.xml (still a bit "raw" until I figure out what each
option does):
***








port="8009" minProcessors="5" maxProcessors="75"
acceptCount="10" debug="0"/>





prefix="catalina_log." suffix=".txt"
timestamp="true"/>





unpackWARs="true" autoDeploy="true">


directory="logs" prefix="localhost_access_log." suffix=".txt"
pattern="common"/>


directory="logs" prefix="localhost_log." suffix=".txt"
timestamp="true"/>





allowLinking="true" docBase="" />


allowLinking="true" docBase="" />









***

วันเสาร์, พฤษภาคม 27, 2549

jLibrary

หลังจากลง tomcat ใหม่เป็น 5.5 แล้วก็ลองใส่ jLibrary ดู ทำตามนี้ตรงๆ :


To install the jLibrary WAR application you should follow the next steps:

  1. Go to the jLibrary downloads section on sourceforge.net and download the .WAR distribution bundle. If you want to create an up-to-date distribution, checkout the build guide on the developers section to find how to build jLibrary sources from CVS.
  2. Once you have downloaded the bundle, you'll find a zip file with the web application archive. Also there is some documentation in the form of a README.txt file, and a jaas.config file. Now, you can place the jlibrary.war file on your webapps directory.
  3. The next step is to add the jaas.config file to your Apache Tomcat conf directory. If you already have a jaas.config file, then you can add to it the following lines:
    Jackrabbit {
    org.apache.jackrabbit.core.security.SimpleLoginModule required anonymousId="anonymous";
    };
  4. And finally you must tell to tomcat where is the jaas.config file if you haven't done yet. This can
    be done in several ways from your catalina file. For example adding the following line to the
    java command, or to the CATALINA_OPTS environment variable:

    -Djava.security.auth.login.config=%CATALINA_HOME%/conf/jaas.config

Configure different storage locations.

On the jLibrary configuration file there are several locations in which you will have to define paths to directories in which content will be stored. For example, the he first section of the jLibrary configuration allows you to change the location on the file system where the jLibrary repositories system data will be created. You can see it here:

    



As you can see, this section (and many others on the configuration file) is using a special variable ${rep.home}. The real location on the file system for this variable depends on the applaction server in which you are running jLibrary. For example, on Apache Tomcat it will be the bin directory. Proabably you really won't like to store contents on that place. If this is the case, you can replace all the occurrences of the ${rep.home} with any other custom location. Even more, you can use different locations for different things. This is a sample with the location changed:
    


These are all the places in which the ${rep.home} variable appears and that you can easily replace by other locations:
  • Base repository structure location (seen on the example)
  • Workspaces location. This will correspod with each jLibrary repositry.
  • Versions location. The place in which version history file data will be stored.
  • System index. The place in which the search information for version history will be stored.

วันพุธ, พฤษภาคม 24, 2549

find และ xargs

เค้าว่าใช้ find ... | (ไปป์ไปที่) xargs ... นั้นมันให้เพอร์ฟอร์มานซ์ดีกว่าใช้ find ... -exec ...
เพราะว่า find -exec มัน fork เยอะ
(อ้างอิง)
http://www.sunmanagers.org/pipermail/summaries/2005-March/006255.html

Thanks very much for the quick responses - herewith a summary of what I learned:

The problem is not one of recursion limit, but one of (in)efficiency.

It is much more efficient to use find | xargs than find -exec {} \;

"find ... -exec command {} \;" runs the command once for each name.

If find identifies 10000 files, using -exec grep ... as an example,
find would fork off a child copy of itself, the copy would become a
grep working on a single file. Meanwhile the original parent find
would sleep waiting for its child (grep) to finish before searching
for the next file that meets the find criteria. That means 10000
executions of grep and pauses of find.

"xargs command" reads names on its standard input, and feeds them in
bunches to command, so that command is run fewer times (only once, in
most cases). So, if we use find | xargs grep ..., the find is able to
work "non-stop" filling the pipe with found file names. xargs
collects groups of about 20 - 50 names and does a single grep for the
collection. Find doesn't pause and you only do about 200 greps, not
10000. There isn't a forked process for every single file.

The weaknesses of xargs are (1) it can be confused by "funny"
filenames (which is why Gnu has find -print0 |xargs -0, or you can
pipe through sed to add backslashes everywhere), and (2) it can feed
zero arguments to command which might then
just sit there waiting (this is why Gnu xargs has -r which means:
don't run command if stdin is empty).

These days, you can use "find ... -exec command {} +" which groups
arguments together. However, I found that this did not give
satisfactory grep results when invoked as:

find /usr/include -type f -exec grep NFS_VERSION {} \+ -print (or
without the escaped +)

The following examples show the time difference (and slightly more
useful output of xargs):

$ time find /usr/include -type f -exec grep NFS_VERSION {} \; -print
#define NFS_VERSION ((rpcvers_t)2)
/usr/include/nfs/nfs.h
#define NFS_VERSION 2
/usr/include/rpcsvc/nfs_prot.h
version NFS_VERSION {
/usr/include/rpcsvc/nfs_prot.x

real 0m9.883s
user 0m3.340s
sys 0m5.900s
$ time find /usr/include -type f|xargs grep NFS_VERSION
/usr/include/nfs/nfs.h:#define NFS_VERSION ((rpcvers_t)2)
/usr/include/rpcsvc/nfs_prot.h:#define NFS_VERSION 2
/usr/include/rpcsvc/nfs_prot.x: version NFS_VERSION {

real 0m0.677s
user 0m0.380s
sys 0m0.310s

Thanks,

Steve Nelson


ตัวอย่างการใช้ เช่น เราจะหา md5 checksum ของไฟล์หลายๆไฟล์แบบเวียนเกิด recursively ก็ใช้คำสั่ง

$ find . -type f \! -name "._*" -print0 | xargs -0 md5sum

เอาเฉพาะ regular file
อันที่ไม่ได้ขึ้นต้นด้วย ._ ใน Mac OS มันชอบมีไฟล์ที่ขึ้นต้นด้วย ._ เยอะ
print ออกมาโดยใส่ null (\0) แทน whitespace ธรรมดา เพราะ xargs มันไม่ค่อยฉลาดตรงนี้

t I jojo$ time find . \! -name ".*" -print0 | xargs -0 md5sum
17c6d0eb1e725ef16e78bfd8c99219c7 ./01 ใคร.m4a
a0bbe221525288210e0a1cdb4f03eb95 ./02 ผมแอบชอบคุณอยู่.m4a
df68e7fc0984fa7dbe1172d476300c2b ./03 คนข้างล่าง.m4a
ccf9def29b9027d62f597c6e31e07066 ./04 Live & Learn.m4a
a1be585bd5e1b304aec8905a1959621c ./05 นานแค่ไหน.m4a
9759b2c841786f07d70260975932a4d7 ./06 ล้มบ้างก็ได้.m4a
214db53c2c2f519f59cc3b24fd6eb360 ./07 เหมือนเคย.m4a
3945193b6ecb2497cf04acb5f26d5ea3 ./08 พอ.m4a
7d2d16c919de20d1e3d174699f0aa821 ./09 หัวใจผูกกัน.m4a
babba2eb62de6f080280ec896016fe5c ./10 Who,What,When,Where,Why.m4a
55f6de761c829ea1adc227f14ad181f6 ./11 ต่างมุม.m4a
afe989790d19fd36b8f8c28fa8e555c4 ./12 เพลงรัก.m4a

real 0m56.337s
user 0m12.174s
sys 0m1.962s

วันอังคาร, พฤษภาคม 23, 2549

Samba บน Solaris และ PostgreSQL บน Mac สำหรับ DSpace

จะลงแซมบ้า บนโซลาลิสเครื่อง lxx-xx16 มาหลายทีแล้ว แต่ว่ามีปัญหาหลายๆอย่าง จนกิ๊บอัพไปหลายครา คราวนี้เอาจริง คอมไพล์เอง ไม่ใช้จากแพคเกจแล้ว พอดีก็มีปัญหาอีกที่ว่า ไอ่ /usr/local มันถูกเมาท์โดย NFS ทำให้เราไม่อยากจะเข้าไปแก้ ก็เลยต้องลงใน $HOME/sys เอาละกัน
คำสั่งคอนฟิก

./configure --prefix=$HOME/sys/opt/samba --with-acl-support --with-quotas --with-included-popt --localstatedir=$HOME/sys/var/lib/samba --with-piddir=$HOME/sys/var/run --with-logfilebase=$HOME/sys/var/log/samba --with-privatedir=$HOME/etc/samba/private --with-configdir=$HOME/etc/samba
--with-ldap=no --with-ads=no
คอมไพล์ไม่ผ่าน สุดท้ายต้องใช้ package pkgadd -d samba...pkg.bz
มันจะติดตั้งไปที่ /opt/samba. เป็น Samba เวอร์ชั่น 3.0.22
samba-3.0.20a-1-noads-sunos5.9-sparc.pkg:
./configure --prefix=/opt/samba --with-acl-support --with-quotas --with-included-popt --localstatedir=/var/lib/samba --with-piddir=/var/run --with-logfilebase=/var/log/samba --with-privatedir=/etc/samba/private --with-configdir=/etc/samba --with-ldap=no --with-ads=no


ขั้นต่อมาแก้ /etc/samba/smb.conf เพิ่มส่วนที่ต้องการแชร์ลงไป ตัวอย่างเช่น
[myshare]
comment = My FileServer
path = /some/where/to/share
valid users = my_user_name
public = no
writable = yes
printable = no
create mask = 0700 or 0644
directory mask = 0700

---
create mask = 0644

The option create mask specifies and sets the necessary permissions according to the mapping from DOS modes to UNIX permissions. With this option set to 0644, all file copying or creating from a Windows system to the Unix system will have a permission of 0644 by default.

directory mask = 0755

The option directory mask specifies and set the octal modes, which are used when converting DOS modes to UNIX modes when creating UNIX directories. With this option set to 0755, all directory copying or creating from a Windows system to the Unix system will have a permission of 0755 by default.

และเพื่อความปลอดภัย อย่าลืม disable anonymous เพิ่มบรรทัดนี้เข้าไปในส่วน [global]
restrict anonymous = 2
client plaintext auth = no
---
ขั้นต่อมาก็เช็ค smb.conf ว่าโอมั้ย
# /opt/samba/bin/testparm

จากนั้นก็ต้องแก้ไข inetd เล็กน้อยเพื่อให้มัน start Samba daemons:

Most of Samba's services are provided by means of three servers or daemons: smbd is the Samba server, nmbd is the NetBIOS name server and swat is a Web-based Samba configuration tool. These deal with incoming connections on ports 137, 139 and 901 respectively and we need to tell the Solaris internet daemon, inetd, to start the appropriate Samba daemons whenever an incoming request is received on these ports.

Edit /etc/services and make the following changes.

Immediately after the line which reads:

sunrpc 111/tcp rpcbind
insert the two lines:

netbios-ns 137/udp # Samba nmbd
netbios-ssn 139/tcp # Samba smbd
and, after the line which reads:

ldaps 636/udp # LDAP protocol over TLS/SSL (was sldap)
insert the line:

swat 901/tcp # Samba swat
Now edit /etc/inetd.conf and add the following three lines to the end of the file:

netbios-ssn stream tcp nowait root /usr/local/samba/bin/smbd smbd
netbios-ns dgram udp wait root /usr/local/samba/bin/nmbd nmbd
swat stream tcp nowait.400 root /usr/local/samba/bin/swat swat
If you have TCP wrappers installed (see Installing and configuring TCP Wrappers on Solaris), the three lines to be added should read:

netbios-ssn stream tcp nowait root /usr/sbin/tcpd /usr/local/samba/bin/smbd smbd
netbios-ns dgram udp wait root /usr/sbin/tcpd /usr/local/samba/bin/nmbd nmbd
swat stream tcp nowait.400 root /usr/sbin/tcpd /usr/local/samba/bin/swat swat
Tell the inetd daemon to re-read its configuration file:

# pkill -HUP inetd
and Samba is installed and working.


ระวัง: ถึงแม้เวลาเรา ps -ef | grep smbd ดูโพรเสสแล้วไม่เจอ แล้วก็คิดว่ามันไม่เวิร์คตรงไหน?
จริงๆมันรันอยู่แล้ว เราต้องลอง connect เข้าไปดูถ้า connect ติดถึงจะมี smbd รันให้เห็นกะตา

นอกจากนี้เรายังสามารถให้ swat ได้ที่ http://localhost:901/ แต่ผมยังไม่ได้ลอง

เย่ สำเร็จ เท่านี้ก็มีไฟล์เซิร์ฟเวอร์ให้ถลุงแล้ว


ลง PostgreSQL ใน Mac OS X
อ้างอิงจาก: http://developer.apple.com/internet/opensource/postgres.html

เริ่มจากลง readline ใน Fink ด้วยคำสั่ง
$ sudo /sw/bin/fink install readline

แล้วก็ดาวน์โหลด postgresql มา ครั้งนี้เราโหลด 8.1.4 มา

./configure --prefix=$HOME/sys/usr/local/pgsql --with-includes=/sw/include --with-libraries=/sw/lib --enable-multibyte --enable-unicode --enable-locale --with-java --with-openssl --with-pam --with-bonjour
จากนั้นก็อาจจะ make check เพื่อความชัวร์ แต่ไม่จำเป็น install ได้เลยโดย make install

su -l postgres

$POSTGRESQL/bin/initdb -D $POSTGRESQL/data

Success. You can now start the database server using:

./bin/postmaster -D ./data
or
./bin/pg_ctl -D ./data -l logfile start
PostgreSQL ships with fairly lax access rules. If you’ll be using your
database in a production environment, or on any kind of shared server,
you should add at least a basic level of security. User authentication
rules are defined in the file /usr/local/pgsql/data/pg_hba.conf. As explained in the PostgreSQL documentation,
you can edit this file to password-protect user accounts, change
authentication methods for local and remote connections, and enable or
disable user access to various parts of the system.

# TYPE DATABASE USER IP-ADDRESS IP-MASK METHOD

host all postgres 127.0.0.1 255.255.255.255 md5
host samegroup all 127.0.0.1 255.255.255.255 md5
local all postgres md5
local samegroup all md5

After editing the file, I need to create a password for the “postgres” superuser, and restart the database server so the changes will take effect:

postgres@mail:~> psql test

test=# alter user postgres with password 'your_password';
test=# \q

For 8.0+, in postgresql.conf uncomment the line starting:

listen_addresses = 'localhost'

Then tighten up security a bit by editing pg_hba.conf and adding this line:

host dspace dspace 127.0.0.1 255.255.255.255 md5

# Jakarta Tomcat 4.x/5.x or equivalent, such as Jetty or Caucho Resin.

Note that DSpace will need to run as the same user as Tomcat, so you might want to install and run Tomcat as a user called 'dspace'. สำหรับกรณีนี้เราไม่

You need to ensure that Tomcat has a) enough memory to run DSpace and b) uses UTF-8 as its default file encoding for international character support. So ensure in your startup scripts (etc) that the following environment variable is set:

JAVA_OPTS="-Xmx512M -Xms64M -Dfile.encoding=UTF-8"

You also need to alter Tomcat's default configuration to support searching and browsing of multi-byte UTF-8 correctly. You need to add a configuration option to the element in [tomcat]/conf/server.xml:

URIEncoding="UTF-8"

e.g. if you're using the default Tomcat config, it should read:

URIEncoding="UTF-8" />

Jetty and Resin are configured for correct handling of UTF-8 by default.


DSpace Quick Installation Steps

First, a Word on Directories and Path Names

DSpace uses three separate directory trees. Although you don't need to know all the details of them in order to install DSpace, you do need to know they exist and also know how they're referred to in this document:

  • the source directory, referred to as [dspace-source]
  • the install directory, referred to as [dspace]
  • the web deployment directory. If you're using Tomcat, this will be [tomcat]/webapps/dspace (with [tomcat] being wherever you installed Tomcat--also known as $CATALINA_HOME). This directory is generated by the web server when it unpacks dspace.war, and should never be edited.
  1. Download the latest DSpace source code release and unpack it:

    gunzip -c dspace-source-1.x.tar.gz | tar -xf -
  2. Copy the PostgreSQL JDBC driver (.jar file) into [dspace-source]/lib. Download it directly from the PostgreSQL JDBC site. Make sure you get the driver for the version of PostgreSQL you're running and for JDBC2. เราลองใช้ JDBC3 ถ้าไม่เวิร์คเราจะกลับมาใช้ 2

  3. Create a dspace database, owned by the dspace PostgreSQL user:

    createuser -U postgres -d -A -P dspace ; createdb -U postgres -O dspace -E UNICODE dspace

    เราเปลี่ยนคำสั่ง createdb โดยให้ postgres ซึ่งเป็น DB admin ครีเอท เพราะไม่สามารถให้ dspace DB user create ได้โดยตรง

  4. As the dspace UNIX user, compile and install DSpace:

    cd [dspace-source] ; ant fresh_install

ติดตั้ง handle server
  1. Run /dspace/bin/dsrun net.handle.server.SimpleSetup /dspace/handle-server. Follow the instructions, answering relatively simple questions. Another option might be to run /dspace/bin/make-handle-config after configuring dspace.cfg, but we did not do this.
  2. Mail the file /dspace/handle-server/sitebndl.zip to hdladmin@cnri.reston.va.us. They will quickly create your global identifier and email you with the appropriate information.
  3. Once you receive the email, you must edit the Handle configuration file (/dspace/handle-server/config.dct). Just as the DSpace instructions say, เพิ่ม "storage_type" = "CUSTOM" และก็ "storage_class" = "org.dspace.handle.HandlePlugin" ลงไปในส่วนของ server_config.
  4. While still in config.dct, update any lines that say something like YOUR_NAMING_AUTHORITY with the appropriate number as sent to you in the email from the Handle admin people. For instance, here at UTK we have a line that reads "server_admins" = ( "300:0.NA/1785" ). We made this change in three places, under server_admins, backup_admins, and replication_admins.
  5. Edit /dspace/config/dspace.cfg, changing handle.prefix to whatever number you were assigned (in our case, the line reads handle.prefix = 1785), and changing if necessary handle.dir to point to the right place, usually /dspace/handle-server.
====================================================================
[echo] The DSpace code has been installed, and the database initialized.
[echo]
[echo] To complete installation, you should do the following:
[echo]
[echo] * Install the DSpace UI (dspace.war) and OAI-PMH (dspace-oai.war)
[echo] Web applications from the 'build' directory in the appropriate
[echo] place for your servlet container. e.g. '/opt/tomcat/webapps'
[echo]
[echo] * Make an initial administrator account (an e-person) in DSpace:
[echo]
[echo] /Users/jojo/sys/usr/local/dspace/bin/create-administrator
[echo]
[echo] * Start up your servlet container (Tomcat etc.)
[echo]
[echo] You should then be able to access your DSpace's 'home page':
[echo] https://bossanova.jaist.ac.jp:8080/dspace
[echo]
[echo] You should also be able to access the administrator UI:
[echo]
[echo] https://xxx.xxx.xxx.xxx:8080/dspace/dspace-admin
====================================================================



ปัญหา!!!!
สตาร์ทอัพ DSpace ไม่ได้เพราะเหมือนกับว่า หลังรันคำสั่งแล้วมันจะให้ใส่ passphrase ซึ่งไม่สามารถใส่ได้
ทางแก้: ลองใหม่โดยไม่ encrypt key ด้วย passphrase ก็จะสามารถสตาร์ทได้

== ไม่จำเป็นต้องติดตั้งใหม่ทั้งหมด ==
หลังจาก Handle-server เอย การ customize ไฟล์ input-forms.xml เอย ลงตัวแล้ว
เราสามารถเคลียร์ db เก่าโดยไม่ต้องลงใหม่ทั้งหมด (fresh_install) ด้วยการ:
1. ลบ dspace database ทิ้ง
2. ไปที่ [dspace-src] แล้ว $ ant setup_database && $ ant load_registries
3. ไปที่ [dspace] แล้ว $ ./bin/create-administrator

วันอาทิตย์, พฤษภาคม 14, 2549

Firefox Extensions

ที่ใช้อยู่ตอนนี้ก็มี
  1. Tab Mix Plus
  2. Mouse Gestures
  3. PDF download
  4. Down Them All
  5. Permit Cookies
  6. Flashblock
  7. Firefox Google Bookmarks