rootkit検知ツール(chkrootkit)

2009, 02, 16

chkrootkit は、システムにrootkitが組み込まれていないかを検査してくれるツール。 rootkit とは、不正アクセスの痕跡を消し去り、それを隠ぺいし、さらなる標的を攻撃することを可能とするツール群。 chkrootkit は、いくつかの rootkit を検出できるが、 検出しても駆除する機能はない。しかし不正侵入検知には役立つ。

■chkrootkitのインストール
chkrootkitをインストール
[root@linux ~]# yum -y install chkrootkit


■chkrootkitの実行
chkrootkitを実行
[root@linux ~]# chkrootkit
ROOTDIR is `/'
Checking `amd'... not found
Checking `basename'... not infected
Checking `biff'... not found
Checking `chfn'... not infected
・
・
・
Checking `scalper'... not infected
Checking `slapper'... not infected
Checking `z2'... user root deleted or never logged from lastlog!
Checking `chkutmp'... chkutmp: nothing deleted
実行結果中に"INFECTED"という行がなければ問題ない


■chkrootkitの定期自動実行設定
rootkitを発見したときroot宛にメールが来るように設定
chkrootkitの実行スクリプトを作成
[root@linux ~]# vi /root/chkrootkit.sh
#!/bin/sh

/usr/bin/chkrootkit > /var/log/chkrootkit_log
grep "INFECTED" /var/log/chkrootkit_log
chmod 600 /var/log/chkrootkit_log

chkrootkitの実行スクリプトに実行権限を与える
[root@linux ~]# chmod 700 /root/chkrootkit.sh

cronを編集
[root@linux ~]# crontab -e
00 02 * * * /root/chkrootkit.sh
毎日2:00にchkrootkitの実行スクリプトを実行


■chkrootkitで使用するコマンド群のコピー
chkrootkitが使用するコマンド群をコピーしておき、必要な場合にそのコマンド群でchkrootkitを実行する。
chkrootkitで使用するコマンド群の退避先ディレクトリの作成
[root@linux ~]# mkdir chkrootkitcmd

chkrootkitで使用するコマンド群を退避先ディレクトリへコピー
[root@linux ~]# cp `which --skip-alias awk cut echo egrep find head id ls netstat ps strings sed uname` chkrootkitcmd/

退避したchkrootkitでchkrootkit実行
[root@linux ~]# chkrootkit -p /root/chkrootkitcmd|grep INFECTED

chkrootkitで使用するコマンド群の退避先ディレクトリを圧縮
[root@linux ~]# zip -r chkrootkitcmd.zip chkrootkitcmd/
  adding: chkrootkitcmd/ (stored 0%)
  adding: chkrootkitcmd/id (deflated 55%)
  adding: chkrootkitcmd/egrep (deflated 49%)
  adding: chkrootkitcmd/sed (deflated 54%)
  adding: chkrootkitcmd/netstat (deflated 58%)
  adding: chkrootkitcmd/echo (deflated 54%)
  adding: chkrootkitcmd/find (deflated 50%)
  adding: chkrootkitcmd/awk (deflated 51%)
  adding: chkrootkitcmd/head (deflated 53%)
  adding: chkrootkitcmd/strings (deflated 53%)
  adding: chkrootkitcmd/ps (deflated 59%)
  adding: chkrootkitcmd/uname (deflated 55%)
  adding: chkrootkitcmd/ls (deflated 53%)
  adding: chkrootkitcmd/cut (deflated 53%)

退避先ディレクトリの削除
[root@linux ~]# rm -rf chkrootkitcmd

圧縮したzipファイルを送信するのに必要なuuencodeコマンドのインストール
[root@linux ~]# yum -y install sharutils
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * addons: ftp.riken.jp
 * base: ftp.riken.jp
 * centosplus: ftp.riken.jp
 * epel: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
addons                                                                       |  951 B     00:00
base                                                                         | 2.1 kB     00:00
centosplus                                                                   | 1.9 kB     00:00
epel                                                                         | 3.4 kB     00:00
extras                                                                       | 2.1 kB     00:00
updates                                                                      | 1.9 kB     00:00
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package sharutils.i386 0:4.6.1-2 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================
 Package                   Arch                 Version                  Repository            Size
====================================================================================================
Installing:
 sharutils                 i386                 4.6.1-2                  base                 201 k

Transaction Summary
====================================================================================================
Install       1 Package(s)
Upgrade       0 Package(s)

Total download size: 201 k
Downloading Packages:
sharutils-4.6.1-2.i386.rpm                                                   | 201 kB     00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : sharutils                                                                    1/1

Installed:
  sharutils.i386 0:4.6.1-2

Complete!

圧縮したzipファイルをroot宛にメール送信
[root@linux ~]# uuencode chkrootkitcmd.zip chkrootkitcmd.zip|mail root

圧縮したzipファイルを削除
[root@linux ~]# rm -f chkrootkitcmd.zip


ファイル改竄検知システム(Tripwire)

2009, 02, 16

Tripwireはサーバーのファイルの改竄を検知するシステム。 Tripwireを使用すると、重要なシステムファイルとディレクトリに対する変更をすべて検出することで、それらの保全性を確保することができる。セキュリティを万全にするために、ファイルが改竄される前に、Tripwireをインストールして基準データベースを作成しておく。基準データベースが作成されると、Tripwireは現在のファイルをこれと比較し、変更、追加、削除のいずれかがあれば報告するようにする。

■Tripwireのインストール
Tripwireをダウンロード(最新版 をダウンロード
[root@linux ~]# wget http://downloads.sourceforge.net/tripwire/tripwire-2.4.1.2-src.tar.bz2

ダウンロードしたtripwireを展開
[root@linux ~]# tar jxvf tripwire-2.4.1.2-src.tar.bz2

Tripwireの展開先ディレクトリへ移動
[root@linux ~]# cd tripwire-2.4.1.2-src

tripwireのインストール
[root@linux tripwire-2.4.1.2-src]# ./configure --prefix=/usr/local/tripwire sysconfdir=/etc/tripwire && make && make install

Press ENTER to view the License Agreement. ← 空ENTER

SPACEキー押下でライセンス表示を流す

Please type "accept" to indicate your acceptance of this
license agreement. [do not accept] accept ← acceptを入力

Continue with installation? [y/n] y ← y

Enter the site keyfile passphrase: ← サイトパスフレーズを設定
Verify the site keyfile passphrase: ← サイトパスフレーズを再度入力

Enter the local keyfile passphrase: ← ローカルパスフレーズを設定
Verify the local keyfile passphrase: ← ローカルパスフレーズを再度入力

Creating signed configuration file...
Please enter your site passphrase: ← サイトパスフレーズを入力

Creating signed policy file...
Please enter your site passphrase: ← サイトパスフレーズを入力

The installation succeeded.

[root@linux tripwire-2.4.1.2-src]# cd ← tripwire展開先ディレクトリを抜ける

[root@linux ~]# rm -rf tripwire-2.4.1.2-src ← tripwire展開先ディレクトリを削除

[root@linux ~]# rm -f tripwire-2.4.1.2-src.tar.bz2 ← tripwireを削除

[root@linux ~]# echo PATH=$PATH:/usr/local/tripwire/sbin >> .bashrc ; source .bashrc ← tripwire実行ファイル格納ディレクトリへパスを通す


■Tripwireの設定
設定ファイル(テキスト版)を編集
[root@linux ~]# vi /etc/tripwire/twcfg.txt
ROOT                   =/usr/sbin
POLFILE                =/etc/tripwire/tw.pol
DBFILE                 =/var/lib/tripwire/$(HOSTNAME).twd
REPORTFILE             =/var/lib/tripwire/report/$(HOSTNAME)-$(DATE).twr
SITEKEYFILE            =/etc/tripwire/site.key
LOCALKEYFILE           =/etc/tripwire/$(HOSTNAME)-local.key
EDITOR                 =/bin/vi
LATEPROMPTING          =false
LOOSEDIRECTORYCHECKING =false
↓
LOOSEDIRECTORYCHECKING =true
MAILNOVIOLATIONS       =true
EMAILREPORTLEVEL       =3
REPORTLEVEL            =3
↓
REPORTLEVEL            =4
MAILMETHOD             =SENDMAIL
SYSLOGREPORTING        =false
MAILPROGRAM            =/usr/sbin/sendmail -oi -t

設定ファイル(テキスト版⇒暗号署名版)を作成
[root@linux ~]# twadmin -m F -c /etc/tripwire/tw.cfg -S /etc/tripwire/site.key /etc/tripwire/twcfg.txt

Please enter your site passphrase: ← サイトパスフレーズを入力
Wrote configuration file: /etc/tripwire/tw.cfg

セキュリティ確保のため設定ファイル(テキスト版)を削除
[root@linux ~]# rm -f /etc/tripwire/twcfg.txt

設定ファイル(テキスト版)を復活させる場合は以下のコマンドで復活できる
[root@linux ~]# twadmin --print-cfgfile > /etc/tripwire/twcfg.txt


■ポリシーファイルの設定
ポリシーファイルの最適化スクリプトを作成
[root@linux ~]# vi /etc/tripwire/twpolmake.pl
#!/usr/bin/perl
# Tripwire Policy File customize tool
# ----------------------------------------------------------------------
# Copyright (C) 2003 Hiroaki Izumi
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
# ----------------------------------------------------------------------
# Usage:
#    perl twpolmake.pl {Pol file}
# ----------------------------------------------------------------------
#
$POLFILE=$ARGV[0];

open(POL,"$POLFILE") or die "open error: $POLFILE" ;
my($myhost,$thost) ;
my($sharp,$tpath,$cond) ;
my($INRULE) = 0 ;

while (<POL>) {
    chomp;
    if (($thost) = /^HOSTNAME\s*=\s*(.*)\s*;/) {
        $myhost = `hostname` ; chomp($myhost) ;
        if ($thost ne $myhost) {
            $_="HOSTNAME=\"$myhost\";" ;
        }
    }
    elsif ( /^{/ ) {
        $INRULE=1 ;
    }
    elsif ( /^}/ ) {
        $INRULE=0 ;
    }
    elsif ($INRULE == 1 and ($sharp,$tpath,$cond) = /^(\s*\#?\s*)(\/\S+)\b(\s+->\s+.+)$/) {
        $ret = ($sharp =~ s/\#//g) ;
        if ($tpath eq '/sbin/e2fsadm' ) {
            $cond =~ s/;\s+(tune2fs.*)$/; \#$1/ ;
        }
        if (! -s $tpath) {
            $_ = "$sharp#$tpath$cond" if ($ret == 0) ;
        }
        else {
            $_ = "$sharp$tpath$cond" ;
        }
    }
    print "$_\n" ;
}
close(POL) ;

ポリシーファイルの最適化
[root@linux ~]# perl /etc/tripwire/twpolmake.pl /etc/tripwire/twpol.txt > /etc/tripwire/twpol.txt.new

ポリシーファイル(暗号署名版)を作成
[root@linux ~]# twadmin -m P -c /etc/tripwire/tw.cfg -p /etc/tripwire/tw.pol -S /etc/tripwire/site.key /etc/tripwire/twpol.txt.new
Please enter your site passphrase: ← サイトパスフレーズを入力
Wrote policy file: /etc/tripwire/tw.pol

ポリシーファイル(テキスト版)を削除
[root@linux ~]# rm -f /etc/tripwire/twpol.txt*

ポリシーファイル(テキスト版)を復活させる場合は以下のコマンドで復活できる
[root@linux ~]# twadmin -m p -c /etc/tripwire/tw.cfg -p /etc/tripwire/tw.pol -S /etc/tripwire/site.key > /etc/tripwire/twpol.txt


■Tripwireのデータベース作成
ポリシーファイルよりデータベースを作成
[root@linux ~]# tripwire -m i -s -c /etc/tripwire/tw.cfg
Please enter your local passphrase: ← ローカルパスフレーズを入力
※データベースを作成するには結構時間かかる


■Tripwireの確認
ファイル変更をチェック ※結構時間かかる
[root@linux ~]# tripwire -m c -s -c /etc/tripwire/tw.cfg
Open Source Tripwire(R) 2.4.1 Integrity Check Report

Report generated by:          root
Report created on:            2008年06月29日 21時51分09秒
Database last updated on:     Never

===============================================================================
Report Summary:
===============================================================================

Host name:                    linux.yokensaka.com
Host IP address:              192.168.1.4
Host ID:                      None
Policy file used:             /etc/tripwire/tw.pol
Configuration file used:      /etc/tripwire/tw.cfg
Database file used:           /usr/local/tripwire/lib/tripwire/linux.yokensaka.com.twd
Command line used:            tripwire -m c -s -c /etc/tripwire/tw.cfg

===============================================================================
Rule Summary:
===============================================================================

-------------------------------------------------------------------------------
  Section: Unix File System
-------------------------------------------------------------------------------

  Rule Name                       Severity Level    Added    Removed  Modified
  ---------                       --------------    -----    -------  --------
* Tripwire Data Files             0                 1        0        0
* Monitor Filesystems             0                 0        0        3
  User Binaries and Libraries     0                 0        0        0
  Tripwire Binaries               0                 0        0        0
  OS Binaries and Libraries       0                 0        0        0
  Temporary Directories           0                 0        0        0
  Global Configuration Files      0                 0        0        0
  System Boot Changes             0                 0        0        0
  RPM Checksum Files              0                 0        0        0
  OS Boot Files and Mount Points  0                 0        0        0
  OS Devices and Misc Directories 0                 0        0        0
  Root Directory and Files        0                 0        0        0

Total objects scanned:  148758
Total violations found:  4

===============================================================================
Object Summary:
===============================================================================

-------------------------------------------------------------------------------
# Section: Unix File System
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
Rule Name: Monitor Filesystems (/usr)
Severity Level: 0
-------------------------------------------------------------------------------

Modified:
"/usr/ddns/NEW_IP.dat"

-------------------------------------------------------------------------------
Rule Name: Tripwire Data Files (/usr/local/tripwire/lib/tripwire)
Severity Level: 0
-------------------------------------------------------------------------------

Added:
"/usr/local/tripwire/lib/tripwire/linux.yokensaka.com.twd"

-------------------------------------------------------------------------------
Rule Name: Monitor Filesystems (/var)
Severity Level: 0
-------------------------------------------------------------------------------

Modified:
"/var/spool/postfix/public/pickup"
"/var/spool/postfix/public/qmgr"

===============================================================================
Error Report:
===============================================================================

No Errors

-------------------------------------------------------------------------------
*** End of report ***

Open Source Tripwire 2.4 Portions copyright 2000 Tripwire, Inc. Tripwire is a registered
trademark of Tripwire, Inc. This software comes with ABSOLUTELY NO WARRANTY;
for details use --version. This is free software which may be redistributed
or modified only under certain conditions; see COPYING for details.
All rights reserved.


■Tripwireの定期自動実行設定
Tripwireの定期実行スクリプトを作成
[root@linux ~]# vi tripwire.sh
#!/bin/bash

PATH=/usr/sbin:/usr/bin:/bin:/usr/local/tripwire/sbin

# パスフレーズ設定
LOCALPASS=xxxxxxxx # ローカルパスフレーズ
SITEPASS=xxxxxxxx  # サイトパスフレーズ

cd /etc/tripwire

# Tripwireチェック実行
tripwire -m c -s -c tw.cfg|mail -s "Tripwire(R) Integrity Check Report in `hostname`" root

# ポリシーファイル最新化
twadmin -m p -c tw.cfg -p tw.pol -S site.key > twpol.txt
perl twpolmake.pl twpol.txt > twpol.txt.new
twadmin -m P -c tw.cfg -p tw.pol -S site.key -Q $SITEPASS twpol.txt.new > /dev/null
rm -f twpol.txt* *.bak

# データベース最新化
rm -f /usr/local/tripwire/lib/tripwire/*.twd*
tripwire -m i -s -c tw.cfg -P $LOCALPASS

実行スクリプトに実行権を与える
[root@linux ~]# chmod 700 tripwire.sh

cronを編集
[root@linux ~]# crontab -e
00 01 * * * /root/tripwire.sh
毎日1:00にTripwireの定期実行スクリプトを実行


データベースサーバ(MySQL)

2009, 02, 16

MySQL は高速性と堅牢性を追及したマルチユーザ・マルチスレッドのSQLデータベースで、 世界で最も人気のあるフリーのリレーショナルデータベースサーバ。 Movable TypeとかNucleus等を利用する場合は各種データをMySQLデータベースに保存するようになっているので、ここではMySQLを使ったデータベースサーバを構築する。

■MySQLインストール
mysql-serverをインストール
[root@linux ~]# yum -y install mysql-server


■MySQL起動
MySQLの起動
[root@linux ~]# /etc/init.d/mysqld start
MySQL データベースを初期化中:  Installing all prepared tables
Fill help tables

To start mysqld at boot time you have to copy support-files/mysql.server
to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h linux.yokensaka.com password 'new-password'
See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with the benchmarks in the 'sql-bench' directory:
cd sql-bench ; perl run-all-tests

Please report any problems with the /usr/bin/mysqlbug script!

The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
                                                           [  OK  ]
MySQL を起動中:                                   [  OK  ]


■MySQL自動起動設定
MySQLの自動起動設定
[root@linux ~]# chkconfig mysqld on

MySQLの自動起動設定確認
[root@linux ~]# chkconfig --list mysqld
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
           ランレベル2〜5がオンの状態であることを確認


■rootユーザへのパスワード設定
MySQLのrootユーザにはデフォルトではパスワードが設定されていないため、安全のためにパスワードを設定。
MySQLサーバーへrootユーザでログイン
[root@linux ~]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 94200
Server version: 5.0.45 Source distribution

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

登録済ユーザ及びパスワードの確認
mysql> select user,host,password from mysql.user;
+------+---------------------+----------+
| user | host                | password |
+------+---------------------+----------+
| root | localhost           |          | ← パスワードが設定されていない
| root | linux.yokensaka.com |          | ← パスワードが設定されていない
|      | linux.yokensaka.com |          |
|      | localhost           |          |
+------+---------------------+----------+
4 rows in set (0.00 sec)

localhostのrootユーザにパスワードを設定
mysql> set password for root@localhost=password('パスワード');
Query OK, 0 rows affected (0.00 sec)

linux.yokensaka.comのrootユーザにパスワードを設定
mysql> set password for root@linux.yokensaka.com=password('パスワード');
Query OK, 0 rows affected (0.00 sec)

mysql> exit ← いったんログアウト
Bye

rootユーザでパスワードありでMySQLサーバーへログイン
[root@linux ~]# mysql -u root -pパスワード
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 94200
Server version: 5.0.45 Source distribution

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

登録済ユーザ及びパスワードの確認
mysql> select user,host,password from mysql.user;
+------+---------------------+------------------+
| user | host                | password         |
+------+---------------------+------------------+
| root | localhost           | 1fd201a955bab306 | ← パスワードが設定された
| root | linux.yokensaka.com | 1e6055bd75163e03 | ← パスワードが設定された
|      | linux.yokensaka.com |                  |
|      | localhost           |                  |
+------+---------------------+------------------+
4 rows in set (0.00 sec)

mysql> exit ← いったんログアウト
Bye


■匿名ユーザの削除
MySQLには匿名ユーザがデフォルトで登録されており、ユーザ名とパスワードなしでMySQLサーバーへログインできてしまうため、安全のためにこのユーザを削除。
rootユーザでパスワードありでMySQLサーバーへログイン
[root@linux ~]# mysql -u root -pパスワード
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 94200
Server version: 5.0.45 Source distribution

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

登録ユーザの確認を
mysql> select user,host from mysql.user;
+------+---------------------+
| user | host                |
+------+---------------------+
|      | linux.yokensaka.com |
| root | linux.yokensaka.com |
|      | localhost           |
| root | localhost           |
+------+---------------------+
4 rows in set (0.00 sec)

匿名ユーザを削除
mysql> delete from mysql.user where user='';
Query OK, 2 rows affected (0.00 sec)

匿名ユーザが削除されてるか確認
mysql> select user,host from mysql.user;
+------+---------------------+
| user | host                |
+------+---------------------+
| root | linux.yokensaka.com |
| root | localhost           |
+------+---------------------+
2 rows in set (0.00 sec)

mysql> exit ← いったんログアウト
Bye

匿名ユーザでMySQLサーバーへログインできないことを確認
[root@linux ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)


■testデータベースの削除
MySQLにはデフォルトでtestという空のデータベースが登録されているが、不要のため、このデータベースを削除。
rootユーザでMySQLサーバーへログイン
[root@linux ~]# mysql -u root -pパスワード
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 94200
Server version: 5.0.45 Source distribution

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

登録データベースを確認
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)

testデータベースを削除
mysql> drop database test;
Query OK, 0 rows affected (0.01 sec)

testデータベースが削除されてるか確認
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
+--------------------+
2 rows in set (0.00 sec)

mysql> exit ← ログアウト
Bye


■MySQL確認
rootでMySQLサーバーへログイン
[root@linux ~]# mysql -u root -pパスワード
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 94200
Server version: 5.0.45 Source distribution

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

takaデータベースへの全てのアクセス権限を持った、新規ユーザtakaを登録
mysql> grant all privileges on taka.* to taka@localhost identified by 'パスワード';
Query OK, 0 rows affected (0.00 sec)

mysql> select user from mysql.user where user='taka'; ← takaユーザ登録確認
+--------+
| user   |
+--------+
| taka   |
+--------+
1 row in set (0.00 sec)

mysql> exit ← ログアウト
Bye

takaユーザでMySQLサーバーへログイン
[root@linux ~]# mysql -u taka -pパスワード
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 94200
Server version: 5.0.45 Source distribution

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

mysql> create database taka; ← takaデータベース作成
Query OK, 1 row affected (0.00 sec)

mysql> show databases; ← データベース作成確認
+--------------------+
| Database           |
+--------------------+
| information_schema | 
| taka               | 
+--------------------+
2 rows in set (0.00 sec)

mysql> use taka ← takaデータベースへ接続
Database changed

mysql> create table taka(num int, name varchar(50)); ← takaテーブル作成
Query OK, 0 rows affected (0.01 sec)

mysql> show tables; ← テーブル作成確認
+----------------+
| Tables_in_test |
+----------------+
| taka           |
+----------------+
1 row in set (0.00 sec)

mysql> insert into taka values(1,'データAB'); ← takaテーブルへデータ登録
Query OK, 1 row affected (0.00 sec)

mysql> select * from taka; ← データ登録確認
+------+----------+
| num  | name     |
+------+----------+
|    1 | データAB |
+------+----------+
1 row in set (0.01 sec)

mysql> update taka set name='データAB'; ← takaテーブル内データ更新
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0

mysql> select * from taka; ← データ更新確認
+------+----------+
| num  | name     |
+------+----------+
|    1 | データAB |
+------+----------+
1 row in set (0.00 sec)

mysql> delete from taka where num=1; ← takaテーブル内データ削除
Query OK, 1 row affected (0.02 sec)

mysql> select * from taka; ← データ削除確認
Empty set (0.00 sec)

mysql> drop table taka; ← testテーブル削除
Query OK, 0 rows affected (0.00 sec)

mysql> show tables; ← テーブル削除確認
Empty set (0.00 sec)

mysql> drop database taka; ← データベースtaka削除
Query OK, 0 rows affected (0.00 sec)

mysql> show databases; ← データベース削除確認
+--------------------+
| Database           |
+--------------------+
| information_schema | 
+--------------------+
1 row in set (0.00 sec)

mysql> exit ← ログアウト
Bye

rootでMySQLサーバーへログイン
[root@linux ~]# mysql -u root -pパスワード
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 94200
Server version: 5.0.45 Source distribution

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

takaユーザから全てのデータベースへのアクセス権限を剥奪
mysql> revoke all privileges on *.* from taka@localhost;
Query OK, 0 rows affected (0.00 sec)

takaユーザ削除
mysql> delete from mysql.user where user='taka' and host='localhost';
Query OK, 1 row affected (0.03 sec)

takaユーザ削除確認
mysql> select user from mysql.user where user='taka';
Empty set (0.00 sec)

mysql> flush privileges; ← takaユーザの削除をMySQLサーバーへ反映
Query OK, 0 rows affected (0.02 sec)

mysql> exit ← ログアウト
Bye


■Movable Typeの初期設定
Movable Typeのブログデータを保存するデータベースの初期設定を行います。
rootでMySQLサーバーへログイン
[root@linux ~]# mysql -u root -pパスワード
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 94200
Server version: 5.0.45 Source distribution

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

mysql>

「mt」というデータベースを作成
mysql> create database mt;
Query OK, 1 row affected (0.01 sec)

管理DBをデフォルト(管理をカレント)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

「mt」というデータベースにログインするユーザー名とパスワードを設定
mysql> grant usage on mt.* to higo@localhost identified by 'パスワード';
Query OK, 0 rows affected (0.00 sec)

「mt」というデータベースに対してすべての権限を「higo」に許す
mysql> grant all on mt.* to higo@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql> exit ← ログアウト
Bye


POP/IMAPサーバ(Dovecot)

2009, 02, 16

Postfixをインストールしただけでは、メールの読み出しは出来ない。 Postfixはメールを配信するためのSMTPサーバーとしての機能しか持たない。ここではdovecotをインストールすることにより、POP3/IMAP4どちらでもメールを読み出せるようにする。

■dovecotのインストール
dovecotは高セキュリティー性を重要視して開発されたPOP3/IMAP4サーバーソフトウェアー。
[root@linux ~]# yum -y install dovecot


■dovecotの設定ファイルの編集
dovecotはPOP3/IMAP4どちらにも対応している。しかしインストールした時点では、IMAP4サーバーとしてしか動作できない。そこでPOP3サーバーとしてもメールが読み出せるように、設定ファイルを編集。
[root@linux ~]# vi /etc/dovecot.conf ← dovecot.confを開く
# Base directory where to store runtime data.
#base_dir = /var/run/dovecot/

# Protocols we want to be serving: imap imaps pop3 pop3s
# If you only want to use dovecot-auth, you can set this to "none".
#protocols = imap imaps pop3 pop3s
↓
protocols = imap imaps pop3 pop3s ← #を外す

メールボックス格納形式をMaildir形式とする
#   mail_location = maildir:~/Maildir
#   mail_location = mbox:~/mail:INBOX=/var/mail/%u
#   mail_location = mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%n
#
# <doc/wiki/MailLocation.txt>
#
#mail_location =
↓
mail_location = maildir:~/Maildir ← #を外し maildir:~/Maildirを追記


■dovecotの起動
[root@linux ~]# /etc/rc.d/init.d/dovecot start
Dovecot Imap を起動中:                                     [  OK  ]

dovecotの自動起動設定
[root@linux ~]# chkconfig dovecot on

dovecotの自動起動設定確認
[root@linux ~]# chkconfig --list dovecot
dovecot         0:off   1:off   2:on    3:on    4:on    5:on    6:off
                (ランレベル2〜5のonを確認)


POP/IMAPサーバを使うには、ルーターの設定が必要なので、110番(POPの場合)または143番(IMAPの場合)のポートを開ける。

■ ポートチェック【ポート開放確認】
「管理しているサーバーが外部から接続アクセスできるか?」「ポートは開放されているか?」「portは閉じているか?」「ルータのポートは開放されているか」等の
ポートチェック・ポートの疎通確認テストはこちらで

■メールアドレスの作成
メールアドレスは新しくユーザーを追加することにより作成可能だが、メールのみ使用するユーザーが telnetやsshを使える状態にしておくのは望ましいことではない。 useraddに -sオプションを付けてシェルを/sbin/nologinに設定することでログインできなくなる。
t-higoというメールアドレスを追加したい場合は、以下のコマンドを実行。
[root@linux ~]# useradd -s /sbin/nologin t-higo


■ユーザーt-higoのパスワードを設定
[root@linux ~]# passwd t-higo
Changing password for user t-higo.
New UNIX password: ← パスワードを入力(表示されない)
BAD PASSWORD: it is based on a (reversed) dictionary word
Retype new UNIX password: ← 再度同じパスワードを入力
passwd: all authentication tokens updated successfully.
これで以下のようなメールアドレスが使用可能となる。

メールアドレス   t-higo@yokensaka.com


■セキュリティレベルの設定
CentOSのインストールに時ファイアウォールを有効にした場合は、メールサーバーへのアクセスは出来ない。そこで、セキュリティーレベルを変更して、SMTPサーバー及びPOPサーバー、IMAPサーバーへアクセスできるようにする。 X Window Systemで起動し「アプリケーション・メニュー」から「システム設定」-「セキュリティレベル」を選択して「セキュリティレベルの設定ツール」を起動する。メールの送受信を可能にするには、「セキュリティレベル」で「ファイアウォールを有効にする」を選択し、「信頼できるサービス」の「メール(SMTP)」にチェックをし、「他のポート」に「110:tcp,110:udp,143:udp,993:tcp,993:udp,995:tcp,995:udp」と入力する。

画像処理(ImageMagick)

2009, 02, 15

ブログなどでサムネイルを作成するにはImageMagickとPerlMagickをサポートしたサーバーが必要で、サポートしてないサーバーでは元画像が縮小表示で表示され重くなる。そこで自宅サーバでもImageMagickとPerlMagickをインストールして、サムネイルを作れるようにする。

■ ImageMagickのインストール(デフォルトでインストールされている。)
[root@linux ~]# yum -y install ImageMagick


■ PerlMagickのインストール
[root@linux ~]# yum -y install ImageMagick-perl


■Nucleusでサムネイルを作成するには
Nucleusでサムネイルを作成するのに必要なphp-gdをインストール。
[root@linux ~]# yum -y install php-gd

httpd を再起動
[root@linux ~]# service httpd restart
httpd を停止中: [ OK ]
httpd を起動中: [ OK ]