■PostgreSQL について
< PostgreSQL → apache( → GD関連 ) → php の順にインストールする >
●ソースからビルド
# rpm -e postgresql (RPMパッケージを消す)
依存関係でerrorになるものがあるので最初にそれらを消す
# rpm -e xxxxx ← errorになったもの
# bin/rm -r /var/lib/pgsql
# /usr/sbin/useradd postgres
# passwd postgres
# mkdir /usr/local/pgsql
# chown postgres:postgres /usr/local/pgsql
/usr/local/src/ に postgresql-?.?.?.tar.gz を置く
# cd /usr/local/src
# su postgres
$ tar zxvf postgresql-?.?.?.tar.gz
$ cd postgresql-?.?.?
$ ./configure --with-mb=EUC_JP
$ make all
$ make install
パスを通す
$ cd /home/postgres
$ vi .bashrc
PATH=/usr/local/pgsql/bin:"$PATH"
ログアウト→ログイン(postgres)
$ cd /usr/local/pgsql
$ mkdir data
$ initdb
ブート時起動に設定
# cd /usr/local/src/postgresql-?.?.?/contrib/start-scripts
# cp linux /etc/rc.d/init.d/postgresql
# /sbin/chkconfig --add postgresql
# /sbin/chkconfig --level 0126 postgresql off
# /sbin/chkconfig --level 345 postgresql on
# reboot
●PostgreSQLユーザの作成
○通常の作成
$ createuser user1
Shall the new user be allowed to create database? (y/n)
Shall the new user be allowed to create more new users? (y/n)
○パスワード付きで作成
$ createuser -P -E user1
Enter password for user "user1":
Enter it again:
Shall the new user be allowed to create database? (y/n)
Shall the new user be allowed to create more new users? (y/n)
●ODBC接続のための設定
○7系以前の設定
$ vi /usr/local/pgsql/data/postgresql.conf
tcpip_socket = true
silent_mode = true
$ vi /usr/local/pgsql/data/pg_hba.conf
host all 0.0.0.0 0.0.0.0 trust
○8系からの設定
$ vi /usr/local/pgsql/data/postgresql.conf
listen_addresses = '*'
デフォルトは 'localhost'
特定のIPを許す場合 'localhost, 192.168.1.11'
すべてのインターフェースを許す場合 '*'
$ vi /usr/local/pgsql/data/pg_hba.conf
host all all 192.168.1.0/32 trust
●チューニング(8系)
# vi /usr/local/pgsql/data/postgresql.conf
shared_buffers = 1000 → 12800
work_mem = 1024 → 2048
maintenance_work_mem = 16384 → 100000
bgwriter_percent = 1 → 5
bgwriter_maxpages = 100 → 200
fsync = true → false
silent_mode = false → true
deadlock_timeout = 1000 → 5000
●主要コマンド
psql [DB名] [DB名]に対するSQLモードになる
\du (ユーザリストの表示)
psql -l DBリストを表示
createdb [DB名] DBを作る
dropdb [DB名] DBを削除する
pg_dump [DB名] > [ファイル名] DBバックアップ
psql -e [DB名] < [ファイル名] DBバックアップを戻す(drop→create後)
vacuumdb [DB名] DB最適化
vacuumdb -z [DB名] DB最適化(処理速度Up期待)
vacuumdb -z -f [DB名] DB最適化(フル機能の最適化)
●コールドバックアップ&リストア
○バックアップ
$ pg_ctl stop
$ su
# tar cvf /dev/nst0 /usr/local/pgsql/data DDS-3テープへ
(# tar cvzf backupdb.tar.gz /var/lib/pgsql/data)
# exit
$ pg_ctl start
○リストア
# cd /tmp
# tar xvf /dev/nst0 DDS-3テープより
(# tar xvzf backupdb.tar.gz)
# cp -apf data /usr/local/pgsql
●DB破損時の対処例
> vacuumdb → エラー → Standalone PostgreSQL で REINDEX
以下のようなエラー
> NOTICE: Index pg_attribute_relid_attnum_index: NUMBER OF INDEX'
> TUPLES (23224) IS NOT THE SAME AS HEAP' (23399).
> Recreate the index.
: : :
: : :
postmasterを停止
# /etc/rc.d/init.d/postgresql stop
standaloneでpostgresを起動
# /etc/rc.d/init.d/postgresql -P -O データベース名
こわれているsystem indexを作り直す
reindex table pg_attribute force;
reindex table pg_class force;
reindex table pg_index force;
standalone postgresの終了
(Ctrl-D)
postmasterを起動
# /etc/rc.d/init.d/postgresql start
■Apache2 について
< PostgreSQL → apache( → GD関連 ) → php の順にインストールする >
●RPMパッケージがあったら消す
# rpm -e apache (RPMパッケージを消す)
依存関係でerrorになるものがあるので最初にそれらを消す
# rpm -e xxxxx ← errorになったもの
●ソースからビルドする
/usr/local/src/ に httpd-2.?.?.tar.gz を置く。
# cd /usr/local/src
# tar zxvf httpd-2.?.?.tar.gz
# cd httpd-2.?.?
# ./configure --enable-module=so
# make
# make install
# cd /usr/local/apache/bin
# cp apachectl /etc/rc.d/init.d/.
# vi /etc/rc.d/init.d/apachectl
#!/bin/sh の下に、次の行を追加する
# chkconfig: 345 85 15
# description: Apache
# processname: httpd
# /sbin/chkconfig --add apachectl
●httpd.confの設定
# vi /usr/local/apache2/conf/httpd.conf
○phpを使う場合の設定
DirectoryIndex index.html index.php (index.php3)
:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
( AddType application/x-httpd-php .php3
AddType application/x-httpd-php-source .phps )
#AddDefaultCharset ISO-8859-1 ←コメント化(最新版には無い?)
○タイムアウトを延長
Timeout 300 → 6000
○ユーザのディレクトリを登録
ユーザのディレクトリ /home/user/public_html/ をブラウザで
URL → http://xxxxx/~user/ と指定できるようにする
<IfModule mod_userdir.c>
UserDir public_html
</IfModule>
<Directory /home/*/public_html>
:
</Directory>
を生かす(=コメントを外す)。
URL に ~(チルダ)を付けたくない場合、Alias を設定する。
Alias /user/ "/home/user/public_html/"
の行を追加。
URL → http://xxxxx/user/ と指定できるようになる。
○ディレクトリ・インデックスを表示させない設定
URLでディレクトリ指定して、そこに index.html や index.php
(DirectoryIndexで定義したファイル)が無い場合に、ディレクトリの
ファイル一覧が表示される。これを表示させないようにする設定
<Directory xxxxxxxxx>
Options xxxxx xxxxx Indexes xxxxx
</Directory>
の "Indexes" を削除する。
○IP制限をかける
(1)/usr/local/apache2/htdocs について、
PrivateIP(192.168.1.0-192.168.1.255)のみ許可する
<Directory "/usr/local/apache2/htdocs">
:
Order deny,allow 拒否→許可の順に評価する
Deny from all すべてを拒否する
Allow from 192.168.1. 192.168.1.xx を許可する
</Directory>
(2)/usr/local/apache2/htdocs について、
GlobalIP(200.232.0.0-200.232.255.255)を拒否する
<Directory "/usr/local/apache2/htdocs">
:
Order allow,deny 許可→拒否の順に評価する
Allow from all すべてを許可する
Deny from 200.232. 200.232.xx.xx を拒否する
</Directory>
○.htaccessによるID+Password制限をかける
<Directory /home/*/public_html> 制限をかけるDir
AllowOverride AuthConfig Limit ←これが記述されていること
/home/user1/publin_html に制限をかける
# vi /home/user1/public_html/.htaccess ←新規作成
AuthType Basic
AuthUserFile /home/user1/.htpasswd
AuthName "Input ID and Password"
<Limit GET>
require valid-user
</Limit>
※パーミッションは 644
# /usr/local/apache/bin/htpasswd -c /home/user1/.htpasswd user1
←user1というIDを作る (新規の時だけ -c )
<Password>
<Password>
※パーミッションは 644
●再起動
# /etc/rc.d/init.d/apachectrl restart
または
# reboot
■GD関連 について
●jpegライブラリ
/usr/local/src に jpegsrc.v6b.tar.gz を置く
# cd /usr/local/src
# tar zxvf jpegsrc.v6b.tar.gz
# cd jpeg-6b/
# ./configure --enable-shared
# make
# make install
●zlib
/usr/local/src に zlib-1.2.1.tar.gz を置く
# cd /usr/local/src
# tar zxvf zlib-1.2.1.tar.gz
# cd zlib-1.2.1/
# ./configure
# make
# make install
●pngライブラリ
○最近のバージョン
/usr/local/src に libpng-1.2.8-config.tar.gz を置く
# cd /usr/local/src
# tar zxvf libpng-1.2.8-config.tar.gz
# cd libpng-1.2.8-config/
# ./configure
# make
# make install
○以前のバージョン
/usr/local/src に libpng-1.2.5.tar.gz を置く
# cd /usr/local/src
# tar zxvf libpng-1.2.5.tar.gz
# cd libpng-1.2.5/
# cp scripts/makefile.linux makefile
# vi makefile
------------------------------------
#ZLIBLIB=/usr/local/lib
#ZLIBINC=/usr/local/include
ZLIBLIB=../zlib
ZLIBINC=../zlib
↓修正↓
ZLIBLIB=/usr/local/lib
ZLIBINC=/usr/local/include
#ZLIBLIB=../zlib
#ZLIBINC=../zlib
------------------------------------
# make
# make install
●freetype
/usr/local/src に freetype-2.1.9.tar.gz を置く
# cd /usr/local/src
# tar zxvf freetype-2.1.9.tar.gz
# cd freetype-2.1.9/
# ./configure
# make
# make install
●GD
/usr/local/src に gd-2.0.28.tar.gz を置く
# cd /usr/local/src
# tar zxvf gd-2.0.28.tar.gz
# cd gd-2.0.28/
# ./configure
# make
# make install
●GDのテスト(phpスクリプト)
<?php
$im = imagecreate(170, 50);
$blue = imagecolorallocate($im, 0, 0, 255);
$white = imagecolorallocate($im, 255, 255, 255);
imagerectangle($im, 0, 0, 169, 49, $blue);
#$f = "/usr/lib/X11/fonts/TrueType/dfmimp3.ttc";
$f = "/usr/lib/X11/fonts/TrueType/tlgothic.ttc";
$txt = "日本語表示";
imagettftext($im, 25, 0, 0, 35, $white, $f, $txt);
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
?>
●PNGのテスト(phpスクリプト)
<?php
Header("Content-Type: image/x-png");
$im = ImageCreate(100, 100);
$black = ImageColorAllocate($im, 0, 0, 0);
$white = ImageColorAllocate($im, 255, 255, 255);
ImageLine($im, 0, 0, 99, 99, $white);
ImagePng($im);
ImageDestroy($im);
?>
■PHP について
< PostgreSQL → apache( → GD関連 ) → php の順にインストールする >
●RPMパッケージがあったら消す
# rpm -e php
依存関係でerrorになるものがあるので最初にそれらを消す
# rpm -e xxxxx ← errorになったもの
●phpをソースからビルドする
/usr/local/src/ に php-4.4.0.tar.gz を置く。
# cd /usr/local/src
# tar zxvf php-4.4.0.tar.gz
# cd php-4.4.0
# ./configure \
--enable-trans_sid \
--enable-mbstring \
--enable-mbstr-enc-trans \
--enable-mbregex \
--with-pgsql=/usr/local/pgsql \
--with-mysql \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-gd=/usr/local \
--with-jpeg-dir=/usr/local \
--with-zlib=/usr/local \
--with-png-dir=/usr/local \
--with-freetype-dir=/usr/local
(--with-mysql はデフォルトなので指定しなくても可)
# make
# make install
●php.iniの設定
# cp php.ini-dist /usr/local/lib/php.ini
# vi /usr/local/lib/php.ini
register_globals = On ← 変えない!
output_handler = mb_output_handler ← 変えない!
●apacheの設定
# vi /usr/local/apache2/conf/httpd.conf
DirectoryIndex index.html index.php
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
# /etc/rc.d/init.d/apachectl restart
●phpコマンドライン版(CLI)もビルドする場合(php4.3より前)
# ./configure を --with-apxs=・・・ を外して再実行
# make
# make install
※php4.3以降からは標準で、CGI版・CLI版ともインストールされるようになったので
再実行は不要になった。
■wwwcount について
/usr/local/src に wwwcount2.5.tar.gz を置く。
# cd /usr/local/src
# tar zxvf wwwcount2.5.tar.gz
# cd wwwcount2.5
# ./configure
# make all
# make install
# vi /usr/local/etc/Counter/conf/count.cfg
[authorized]
domain1.jp
host1.domain1.jp
localhost
192.168.1.11
# cp bin/Count.cgi /usr/local/apache2/cgi-bin
# vi /usr/local/apache2/conf/httpd.conf
#AddHandler cgi-script .cgi → #消す
Counterの値管理ファイルは、/usr/local/etc/Counter/data/ に在る。
(htmlの <img src="cgi-bin/Count.cgi?df=count.dat"> の df のファイル)
■qmailについて
●qmailのインストール
# mkdir /var/qmail/
# groupadd nofiles
# useradd -g nofiles -d /var/qmail/alias -s /sbin/nologin alias
# useradd -g nofiles -d /var/qmail -s /sbin/nologin qmaild
# useradd -g nofiles -d /var/qmail -s /sbin/nologin qmaill
# useradd -g nofiles -d /var/qmail -s /sbin/nologin qmailp
# groupadd qmail
# useradd -g qmail -d /var/qmail -s /sbin/nologin qmailq
# useradd -g qmail -d /var/qmail -s /sbin/nologin qmailr
# useradd -g qmail -d /var/qmail -s /sbin/nologin qmails
# groupadd vida
# useradd -g vida -d /var/qmail/users -s /sbin/nologin qmailu
# useradd -g vida -d /var/qmail/authdb -s /sbin/nologin authdb
# useradd -g vida -d /home/pop -s /bin/bash pop
qmail関連のソースを集める。
ftp://ftp.jp.qmail.org/qmail/qmail-1.03.tar.gz
http://cr.yp.to/checkpwd/checkpassword-0.90.tar.gz
http://cr.yp.to/ucspi-tcp/ucspi-tcp-0.88.tar.gz
http://keihanna.dl.sourceforge.jp/qmail-vida/2100/qmail-vida-0.53.tar.gz
ftp://ftp.nlc.net.au/pub/unix/mail/qmail/qmail-date-localtime.patch
(↑リンク切れ。↓から)
http://mirror.averse.net/pub/FreeBSD/ports/local-distfiles/sada/
http://www.ckdhr.com/ckd/qmail-103.patch
http://honana.com/files/errno.patch
/usr/local/src/に以下を置く。
qmail-1.03.tar.gz
checkpassword-0.90.tar.gz
ucspi-tcp-0.99.tar.gz
qmail-vida-0.53.tar.gz
qmail-date-localtime.patch
qmail-103.patch
errno.patch
# cd /usr/local/src
# tar zxvf qmail-1.03.tar.gz
# tar zxvf checkpassword-0.90.tar.gz
# tar zxvf ucspi-tcp-0.88.tar.gz
# tar zxvf qmail-vida-0.53.tar.gz
# cd qmail-vida-0.53
# make patch
# make copy
# cd ../qmail-1.03
# patch < ../qmail-date-localtime.patch
# patch < ../qmail-103.patch
# patch < ../errno.patch
# make setup check
# cd ../checkpassword-0.90
# patch < ../errno.patch
# make
# make setup check
# cd ../ucspi-tcp-0.88
# patch < ../errno.patch
# make setup check
# cd ../qmail-vida-0.53/src/vida
# patch < ../../../errno.patch
# make
# make setup check
# cd ../..
# make install-doc
実在ドメイン・実在ユーザ、実在ドメイン・仮想ユーザ用のパスワードデータベースを作成。
# /var/qmail/bin/vida-pwdbinit
●qmailの設定
/var/qmail/control/下に設定ファイルを生成させる
# cd /usr/local/src/qmail-1.03
# ./config-fast mail.domain.jp
/var/qmail/control/下に以下のファイルができる
defaultdomain ホストアドレスにドット(.)が無い場合に追加する値
local ローカルメールアドレスとみなすメールアドレス
me ローカルサーバーのホスト名 ■重要■
plusdomain プラス記号(+)で終わるアドレスに追加するドメイン名
rcpthosts 別のホスト,ドメイン宛てのメッセージを受け取れるようにする
その他のファイル
defaulthost ホスト名が指定されていない場合に追加する値(例 domain.jp)
(sendmailの)sendmailコマンドをqmailのsendmailコマンドに置き換える。
# ln -fns /var/qmail/bin/sendmail /usr/sbin/sendmail
# ln -fns /var/qmail/bin/sendmail /usr/lib/sendmail
●qmailエイリアスの作成
root宛てのメール、postmaster, webmaster, mailer-daemon宛てのメールを
ユーザー user1に転送する設定
# echo user1 > /var/qmail/alias/.qmail-postmaster
# echo user1 > /var/qmail/alias/.qmail-webmaster
# echo user1 > /var/qmail/alias/.qmail-mailer-daemon
# echo user1 > /var/qmail/alias/.qmail-root
●tcpserverによる接続
# vi /etc/tcp.smtp 新規作成(以下内容)
127.0.0.: allow,RELAYCLIENT=""
192.168.1.: allow,RELAYCLIENT=""
:allow ←これも必要か
(localhostと192.168.1.0からの接続を許可する)
# /usr/local/bin/tcprules /etc/tcp.smtp.cdb /etc/tcp.smtp.tmp < /etc/tcp.smtp
(cdbデータベースを作成する)
# vi /etc/tcp.pop3 新規作成(以下内容)
:allow,ALLOWPLAIN="",DOMAINOWNER=""
(すべての接続を許可する)
# /usr/local/bin/tcprules /etc/tcp.pop3.cdb /etc/tcp.pop3.tmp < /etc/tcp.pop3
(cdbデータベースを作成する)
# cp /var/qmail/boot/home /var/qmail/rc
(起動スクリプトをコピーする)
# vi /var/qmail/rc (以下の内容に編集)
------------------------------------------------------------
#!/bin/sh
# Using splogger to send the log through syslog.
# Using qmail-local to deliver messages to ~/Mailbox by default.
exec env - PATH="/var/qmail/bin:$PATH" \
qmail-start ./Maildir/ splogger qmail &
/usr/local/bin/tcpserver -H -R -u [uid] -g [gid] -v -x /etc/tcp.smtp.cdb 0 25 \
/usr/local/bin/rblsmtpd -r relays.ordb.org -r bl.spamcop.net -r list.dsbl.org \
/var/qmail/bin/qmail-smtpd 2>&1 | /var/qmail/bin/splogger smtpd &
/usr/local/bin/tcpserver -H -R -v -x /etc/tcp.pop3.cdb 0 110 \
/var/qmail/bin/qmail-popup mail.domain1.jp \
/var/qmail/bin/checkpassword \
/var/qmail/bin/qmail-pop3d Maildir 2>&1 | /var/qmail/bin/splogger pop3d &
------------------------------------------------------------
[uid]...qmaildのuid
[gid]...nofilesのgid
( # id qmaild コマンドで確認できる)
●qmail自動起動スクリプト
# vi /etc/rc.d/init.d/qmail 新規作成(以下内容)
------------------------------------------------------------
#!/bin/bash
#
# qmail This shell script takes care of starting and stopping qmail.
#
# chkconfig: 2345 80 30
# description: qmail is a Mail Transport Agent, which is the program \
# that moves mail from one machine to another.
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
# See how we were called.
case "$1" in
start)
# Start daemons.
echo -n "Starting qmail: "
if ! $0 status|grep " locked"; then
daemon /var/qmail/rc
echo
touch /var/lock/subsys/qmail
fi
;;
stop)
# Stop daemons.
echo -n "Shutting down qmail: "
killproc qmail-send
killproc /usr/local/bin/tcpserver
rm -f /var/lock/subsys/qmail
echo
;;
status)
status qmail
exit $?
;;
restart)
$0 stop
$0 start
exit $?
;;
*)
echo "Usage: qmail {start|stop|status}"
exit 1
esac
exit 0
------------------------------------------------------------
# chmod 755 /etc/rc.d/init.d/qmail
# chkconfig --add qmail
●実在ユーザーアカウントの作成
# su user1
$ cd
$ /var/qmail/bin/maildirmake $HOME/Maildir
$ /var/qmail/bin/vida-passwd
$ echo ./Maildir/ > $HOME/.qmail
(loginユーザのHomeディレクトリに Maildir を設定する)
●仮想ユーザーアカウントの作成
# su pop
$ /var/qmail/bin/vida-passwd -a -u vuser1
$ /var/qmail/bin/vida-assign -a -u vuser1
$ /var/qmail/bin/vida-maildirmake vuser1 Maildir
$ echo ./Maildir/ > /home/pop/vuser1/Maildir/.qmail ←誤り?
$ echo ./Maildir/ > /home/pop/vuser1/.qmail ←正しい?
●仮想ユーザーアカウントの削除
# su pop
$ /var/qmail/bin/vida-passwd -d -u vuser1
$ /var/qmail/bin/vida-assign -d -u vuser1
$ cd
$ rm -rf vuser1
●あるメアドを空メール用にする
空メールが来たら /home/user1/public_html/recieve.php にデータを渡す
# su pop
$ cd
$ vi [メアド]/.qmail
○メールも残しておく場合
./Maildir/
| /home/user1/public_html/recieve.php
○メールを残さない場合
| /home/user1/public_html/recieve.php
※qmailの再起動は不要
■MySQLについて
●ソースからビルド
※最初にRPMを消すべき
# groupadd mysql
# adduser -g mysql -d /usr/local/var mysql
# cd /usr/local/src
# tar zxvf mysql-3.22.32.tar.gz
# cd mysql-3.22.32/
# ./configure --with-charset=ujis --with-mysqld-user=mysql
# make
# make install
# cd /usr/local/src/mysql-3.22.32/support-files
# cp mysql.server /etc/rc.d/init.d/mysqld
# chmod a+x /etc/rc.d/init.d/mysqld
# cp my-medium.cnf /etc/my.cnf
# /sbin/chkconfig --add mysqld (すでにある時は、消してから)
# chown -R mysql /usr/local/var
# chgrp -R mysql /usr/local/var
# /usr/local/bin/mysql_install_db --user=mysql
# /etc/rc.d/init.d/mysqld start
●動作確認
mysqlでログインし直して、テスト。
$ mysqladmin version OK.
$ mysqladmin variables OK.
$ mysqlshow OK. DBリストを表示
$ mysqlshow mysql Error. テーブルリストを表示
(rootログインで、# mysqlshow mysql だと OK.)
mysqlにスーパーユーザ権限を付与。
$ mysql -u root mysql
mysql> GRANT ALL PRIVILEGES ON *.* TO mysql@localhost;
mysql> GRANT ALL PRIVILEGES ON *.* TO mysql@"%";
(Password を付ける場合、
IDENTIFIED BY 'password'
GRANT で他ユーザに特権を与えられるようにする場合、
WITH GRANT OPTION
をうしろに付ける。)
再度テスト。
$ mysqlshow mysql OK.
上記は以下でも可。
$ mysql -u root -p
mysql> show databases; DBリストを表示
mysql> use mysql; DBをmysqlに切り替え
mysql> show tables; テーブルリストを表示
mysql> select * from user; ユーザテーブルの中身を全表示
●主要コマンド
バックアップを取る(CREATE TABLE, INSERT INTO のSQLスクリプト)
# mysqldump --database DB名 > バックアップファイル名
バックアップを戻す
# mysqladmin drop DB名 ← DBを消す
# mysqladmin create DB名 ← DBを作成する
# mysql DB名 < バックアップファイル名 ← バックアップ戻し
データファイルの検査
# myisamchk データファイル.MYI
データファイルの修復・最適化
# /etc/rc.d/init.d/mysqld stop
# myisamchk -r データファイル.MYI
これで解決しないときは、以下。
# myisamchk -o データファイル.MYI