携帯サイト:フォームのmode属性、istyle属性

携帯端末で利用する入力フォームでtextまたはpasswordコントロールに下記のような属性を与えれば入力モードの指定ができます。

istyle mode
全角かな 1 hiragana
半角カナ 2 katakana
英字 3 alphabet
数字 4 numeric

istyle属性はdocomoとauで有効。mode属性はvodafoneで有効です。

softbankはC2以降がmode属性に対応、C3以降はmode属性とistyle属性両方に対応しています。

このように両方を書いておけばどちらの機種にも対応できます。

<input type="text" name="text1" istyle="1" mode="hiragana">

mysql:MySQLのバックアップとリストア

mysqldumpでバックアップ&リストア

すべてのデータベースをdumpでバックアップ

$ mysqldump -u root -p -x –all-databases > dump.sql

特定のデータベースをバックアップするときは

$ mysqldump -u root -p データベース名 > dump.sql

すべてのデータベースを復元するときは

$ mysql -u root -p < dump.sql

特定のデータベースを復元するときは

$ mysql -u root -p データベース名 < dump.sql

mysql:mysqlとsennaのインストール

yumで要るものを全部入れる。

yum install mecab
yum install mecab-ipadic
yum install senna
yum install MySQL-shared
yum install MySQL-client
yum install MySQL-server

mysql -urootでログインして、↓このように”Tritonn Project”のバージョンが表示されればOK。 mysql -Vでは表示されないので注意。

Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 2419
Server version: 5.0.51a-modified-log MySQL Community Server (GPL) (portions (c) Tritonn Project)

Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

mysqlインストール後の儀式、rootのパスワードを変更する。

mysqladmin -u root password パスワード

次にmy.cnfを設定する。
/usr/share/mysql/にある雛形を使ってmy.cnfを作成する。雛形はサーバスペックにあわせて選ぶ。意味なく大きいのにしないこと。

my.cnf雛形選択の目安
my-small.cnf 64Mバイト以下のメモリの小規模サーバー向け
my-medium.cnf 32M~64Mバイトのメモリを持つMySQL専用サーバーか、128Mバイトのメモリを持つサーバー向け
my-large.cnf 512Mバイト程度のメモリを持ち、MySQL専用となる機械向け
my-huge.cnf 1G~2Gバイトのメモリを持つMySQL専用サーバー向け
my-innodb-heavy-4G.cnf 4Gバイトのメモリ、InnoDBのみ、ACID、少ない接続、大量のクエリ

/etc/my.cnfを作る

cp /usr/share/mysql/my-medium.cnf /etc/my.cnf

デフォルトUTF8で使うときの文字コードの設定をmy.cnfに追加する

/etc/my.cnf
[mysqld]
default-character-set=utf8
skip-character-set-client-handshake
character-set-server = utf8
collation-server = utf8_general_ci
init-connect = SET NAMES utf8

[mysqldump]
default-character-set = utf8

[mysql]
default-character-set = utf8

php:Postfixで自動返信メール

メールを受信するサーバにメール受信用ユーザを登録する。

受信するメールアドレスは[ユーザ名]@ホスト名になります。

# adduser [ユーザ名]
# passwd [パスワード]

.forwardに転送設定を記述

/home/[ユーザ名]/.forward
register,”| /usr/bin/php /path/to/autoreply.php

.転送先はphpスクリプト。パイプでメール内容を渡している。

autoreply.php(返信処理の内容)はこんなふうになる。

require_once("Mail/mimeDecode.php"); //REARモジュール
//メールソースを標準入力から読み込み
$source = file_get_contents("php://stdin");
if(!$source) {
    return false;    // 読み込み失敗
}
 
//メール解析
$params['include_bodies'] = true;
$params['decode_bodies'] = true;
$params['decode_headers'] = true;
$decoder = new Mail_mimeDecode($source);
$structure = $decoder->decode($params);
 
// 送信者のメールアドレスを取得する
$from_address = mb_convert_encoding(mb_decode_mimeheader($structure->headers['from'])
                         ,mb_internal_encoding(), "auto");

このスクリプトを標準入力無しで起動すると

$source = file_get_contents(“php://stdin”);

のところで入力待ちになって処理が中断しますが、ヘッダさえもnullなメールを送ることは出来ないので多分気にしなくてもいいはず。

Linux:ssh公開鍵認証

ローカルサーバ(接続元)からリモートサーバ(接続先)にパスワード無しでログインする設定。
以下ローカルサーバのfooユーザがリモートサーバにbarユーザでログインする場合。

ローカルサーバ(接続元)で認証キーを作る

# ssh-keygen -t rsa -N “” -f /home/foo/.ssh/authkey_bar

rsync.pub (公開鍵)をリモートサーバ(接続先)の/bar/.sshにコピーするローカルサーバからSCPで転送

# scp authkey_bar.pub bar@リモートサーバ:/tmp

この時点ではまだパスワードを聞かれるので入力する。

リモートサーバにbarでログインして/home/bar/.sshに移動し、パーミッション変更&authorized_keysに追記

authorized_keysのパーミッションは必ず600でなくてはいけない。644ではパスワードを聞かれます。

# chmod 700 /home/bar/.ssh
# mv /tmp/rsync.pub /home/bar/.ssh
# cat /home/bar/.ssh/authkey_bar.pub >> /root/.ssh/authorized_keys
# chmod 600 /home/bar/.ssh/authorized_keys
# rm /home/bar/.ssh/authkey_bar.pub

Linux:ソースからインストール&パッケージ作成

checkinstallなるものでソースからインストールしつつパッケージを作成できるらしいので試してみた。

まずはcheckinstallをインストールする。

wget http://asic-linux.com.mx/~izto/checkinstall/files/rpm/checkinstall-1.6.1-1.i386.rpm
rpm -ihv checkinstall-1.6.1

どこに入ったかわからなくなったので・・・^^;

rpm -ql checkinstall

どうやら/usr/local/sbin/checkinstall

-h でヘルプ表示

/usr/local/sbin/checkinstall -h

checkinstall 1.6.1, Copyright 2002 Felipe Eduardo Sanchez Diaz Duran
This software is released under the GNU GPL.

Usage: checkinstall [options] [command [command arguments]]
Options:
*Package type selection*
-t,–type= Choose packaging system
-S Build a Slackware package
-R Build a RPM package
-D Build a Debian package
*Install options*
–install= Toggle created package installation
–fstrans= Enable/disable the filesystem translation code
*Scripting options*
-y, –default Accept default answers to all questions
–pkgname= Set name
–pkgversion= Set version
-A, –arch, –pkgarch= Set architecture
–pkgrelease= Set release
–pkglicense= Set license
–pkggroup= Set software group
–pkgsource=Set source location
–pkgaltsource= Set alternate source location
–pakdir= The new package will be saved here
–maintainer= The package maintainer (.deb)
–provides= Features provided by this package (.rpm)
–requires= Features required by this package
–rpmflags= Pass this flags to the rpm installer
–rpmi Use the -i flag for rpm when installing a .rpm
–rpmu Use the -U flag for rpm when installing a .rpm
–dpkgflags= Pass this flags to the dpkg installer
–spec= .spec file location
–nodoc Do not include documentation files

*Info display options*

-d<0|1|2> Set debug level
-si Run an interactive install command
–showinstall= Toggle interactive install command
-ss Run an interactive Slackware installation script
–showslack= Toggle interactive Slackware installation script

*Package tuning options*

–autodoinst= Toggle the creation of a doinst.sh script
–strip= Strip any ELF binaries found inside the package
–stripso= Strip any ELF binary libraries (.so files)
–addso= Search for any shared libs and add
them to /etc/ld.so.conf
–reset-uids= Reset perms for all files/dirs to 755 and
the owner/group for all dirs to root.root
–gzman= Compress any man pages found inside the package
–docdir= Where to put documentation files
–umask= Set the umask value
–exclude= Exclude these files/directories from the package
–include= Force the inclusion in the package of the
files/dirs listed in “listfile”
–inspect Inspect the package’s file list
–review-spec Review the spec file before creating a .rpm
–review-control Review the control file before creating a .deb
–newslack Use the new (8.1+) Slackware description format
(“–newslack” implies “-S”)
–with-tar=/path/to/tar Manually set the path to the tar binary
in this system

*Cleanup options*

–deldoc= Delete doc-pak upon termination
–deldesc= Delete description-pak upon termination
–delspec= Delete spec file upon termination
–bk Backup any overwritten files
–backup= Toggle backup

*About CheckInstall*

–help, -h Show this message
–copyright Show Copyright information
–version Show version information

RPMは-Rか。

何かのソースからパッケージを作ってみたい。
今回試すのはsquidにしてみる。

wget http://www.squid-cache.org/Versions/v3/3.0/squid-3.0.STABLE13.tar.gz
tar zxfv squid-3.0.STABLE13.tar.gz
cd squid-3.0.STABLE13
./configure
make
make install
/usr/local/sbin/checkinstall -R

途中の入力は全部パスして進めると、最後にこう表示される。OKか?

**********************************************************************

Done. The new package has been saved to

/usr/src/redhat/RPMS/i386/squid-3.0.STABLE13-1.i386.rpm
You can install it in your system anytime using:

rpm -i squid-3.0.STABLE13-1.i386.rpm

**********************************************************************

とりあえず/usr/src/redhat/RPMS/i386/にrpmができているのは確認した。
しかし、このパッケージからインストールしようとするとgrepの競合というエラーが出る。
ソースからすでにインストールしたからかな?

linux:サーバのアーキテクチャを調べるには

パッケージをインストールするとき、どのアーキテクチャを選択すればよいかわからない時はuname -a

# uname -a
Linux localhost.localdomain 2.6.9-023stab046.2-smp #1 SMP Mon Dec 10 15:04:55 MSK 2007 x86_64 x86_64 x86_64 GNU/Linux

後ろのほうのx86_64がそのサーバのアーキテクチャ。
他にi386やi686などがある。
noarchは全アーキテクチャ共通のパッケージ

VirtualHost環境にMTOSをインストール

cgi-script のハンドラを有効にします。ついでに.plでもCGIが動くようにします。

/etc/httpd/conf/httpd.conf
#AddHandler cgi-script .cgi
AddHandler cgi-script .cgi .pl

VirtualHostを定義。
スクリプトは非公開領域で動くようにScriptAliasを設定する。

/etc/httpd/conf.d/vhosts.conf
<VirtualHost *:80>>
    DocumentRoot "/path/to/public_html"
    ScriptAlias /cgi-bin/ "/path/to/cgi/"
    ServerName example.com
    ErrorLog "logs/example.com-access.log"
    CustomLog "logs/example.com-error.log" common
</VirtualHost>

“/path/to/cgi”にソースを解答し、/cgi-bin/mt-check.cgiにアクセスして必要なライブラリを確認する。
yumまたはcpanで必要なライブラリを入れる。

yum install perl-GD
cpan> install DBI
cpan> install DBD::mysql
#…以下必要なだけインストール

cgiファイルの権限を変更し実行可能にする。

chmod 755 *.cgi

/cgi-bin/mt.cgiにアクセス。あとはウィザードに従ってインストール。

CentOS:memcachedをインストール

CentOs5.2のリポジトリにmemcachedは無いのでリポジトリを追加する。

cd /usr/local/src
wget http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
rpm -Uhv rpmforge-release-0.3.6-1.el5.rf.i386.rpm

mencachedを入れるのに必要なモジュールをインストールする。
たぶんこのあたりを入れておけばおっけーなはず。

yum install gcc
yum install memcached
yum install zlib-devel
yum install php-pecl-memcache

memcachedの設定は/etc/sysconfig/memcachedを編集する。
動かすだけならデフォルトのままでOK。
memcacheの起動

/etc/init.d/memcached start

サービスを自動起動にしておく。

chkconfig memcached on

テストスクリプト

<?php
    $cache = new Memcache;
    $key = 'cache_test';
    $cache->connect('localhost', 11211);
    if(!$cache->get($key)){
        // キャッシュの有効時間は15秒
        $cache->set($key, date('Y-m-d h:i:s'), MEMCACHE_COMPRESSED, 15);
    }
    echo $cache->get($key);
?>