VMWare上のGuestOS(Linux)の時刻がズレる件について

VMWare EXi 上で動作させている、CentOS4.9について、どうもサーバの時刻がズレる。

色々と調査したところ、どうやら時刻のカウントの仕方が悪いらしい。
※「VMWare」「Linux」「サーバ時刻」あたりでググると出てきます

って事で、やった事は以下。
カーネルの起動オプションに「clock=pit」を追加 → 時間が進む場合の対策らしい
カーネルの起動オプションに「nosmp noapic nolapic」を追加 → 時間が遅れる場合の対策らしい

# cd /boot/grub/
# vi grub.conf

カーネルの起動オプションの末尾にコレ追加
clock=pit nosmp noapic nolapic

# shutdown -r now

※設定は自己責任でお願いします

設定後、とりあえずズレる事は無くなった。

vmware-toolsインストールして「tools.syncTime = "TRUE"」の設定もやった方がいいみたい。

それはまだやってないけど。

そんな感じで。

でわ。

LinuxにUSB外付けフロッピードライブを接続してFDをフォーマット

ちょっとハマった。


PowerEdge R200 の筐体で、RAIDのドライバをインストールしようとしたのだが、
そもそもFDDがついていなかったので、外付けFDDを接続した。


で、普通にマウント出来ると思ったのだが・・・


以下手順にてフォーマットしてマウントしました。

# view /var/log/messages
(snip)
May  7 17:54:44 HOST_NAME kernel: ohci_hcd 0000:00:0f.2: wakeup
May  7 17:54:44 HOST_NAME kernel: usb 1-3: new full speed USB device using ohci_hcd and address 3
May  7 17:54:44 HOST_NAME kernel: usb 1-3: configuration #1 chosen from 1 choice
May  7 17:54:44 HOST_NAME kernel: scsi2 : SCSI emulation for USB Mass Storage devices
May  7 17:54:49 HOST_NAME kernel:   Vendor: NEC       Model: USB UF000x        Rev: 2.00
May  7 17:54:49 HOST_NAME kernel:   Type:   Direct-Access                      ANSI SCSI revision: 00
May  7 17:54:50 HOST_NAME kernel: SCSI device sdb: 2880 512-byte hdwr sectors (1 MB)
May  7 17:54:50 HOST_NAME kernel: sdb: Write Protect is off
May  7 17:54:50 HOST_NAME kernel: sdb: assuming drive cache: write through
May  7 17:54:51 HOST_NAME kernel: SCSI device sdb: 2880 512-byte hdwr sectors (1 MB)
May  7 17:54:51 HOST_NAME kernel: sdb: Write Protect is off
May  7 17:54:51 HOST_NAME kernel: sdb: assuming drive cache: write through
May  7 17:54:51 HOST_NAME kernel:  sdb: unknown partition table
May  7 17:54:51 HOST_NAME kernel: sd 2:0:0:0: Attached scsi removable disk sdb
May  7 17:54:51 HOST_NAME kernel: sd 2:0:0:0: Attached scsi generic sg3 type 0
May  7 18:11:51 HOST_NAME kernel: usb 1-3: USB disconnect, address 3

※上記により、USB接続FDDは/dev/sdbのデバイスと言う事が判明

# mkdir /mnt/fdd
※マウントポイントを作成

# mkfs.ext2 /dev/sdb
※フォーマット

# mount /dev/sdb /mnt/fdd
※マウント

フォーマットせずにマウントしようとしたら、ファイルシステムが不明とか言われたので、
フォーマットしてからマウント。


でわ。

MySQLでテーブル毎に設定されているストレージエンジンを確認する方法

MySQLでは、各テーブル毎にストレージエンジンを設定する事が出来ます。


大体は、この2つのどちらかになるかと思います。
MyISAM:検索に強いらしい
InnoDBトランザクションが使えるらしい


と言う事で、各テーブル毎に設定されているストレージエンジンを確認する方法です。

# mysql -u root

mysql> use information_schema;
mysql> select table_name, engine from tables where table_schema = DB_NAME;
+--------------------+--------+
| table_name         | engine |
+--------------------+--------+
| hogehoge           | InnoDB |
| hagehage           | MyISAM |
| higehige           | InnoDB |
+--------------------+--------+
mysql> exit;

「show table status」でも確認出来ますが、複数DBが動いている状態だと、全てのDBのテーブルが表示されてしまうので。


でわ。

MySQLで予約語をフィールド名に設定する方法

掲題の件、基本的にはやっちゃダメです。


ですが、よく分かってない人がDB設計やったりすると、予約語をフィールド名に設定されたりします。


で、Create Table する時に、エラーになったり・・・


と言う事で、予約語をフィールド名に設定する方法です。

create table test_table (
  id int(5) not null auto_increment, 
  option varchar(100), 
  group char(10)
) type=MyISAM;

この場合、「option」「group」が予約語になります。

このままこのSQLを発行するとエラーになります。

なので、こうやって書いてやります。

create table test_table (
  id int(5) not null auto_increment, 
  `option` varchar(100), 
  `group` char(10)
) type=MyISAM;

これで、Create Table が成功します。


Insertする時やUpdateする時も同じようにやってあげる必要があるかもです。

そのあたりは各自で検証を・・・


でわ。

CentOS4.6+MySQL 4.0.26 その2

昨年末より色々と調べていた、MySQL 4.0.26 の設置にようやく成功した。

# rpm -ivh ./MySQL-server-4.0.26-0.i386.rpm 
Preparing...                ########################################### [100%]
   1:MySQL-server           ########################################### [100%]
Preparing db table
Preparing host table
Preparing user table
Preparing func table
Preparing tables_priv table
Preparing columns_priv table
Installing all prepared tables
Fatal error: Can't change to run as user 'mysql'.  Please check that the user exists!
091130  7:05:11 Aborting

091130  7:05:11 /usr/sbin/mysqld: Shutdown Complete

Installation of grant tables failed!

Examine the logs in /var/lib/mysql for more information.
You can also try to start the mysqld daemon with:
/usr/sbin/mysqld --skip-grant &
You can use the command line tool
/usr/bin/mysql to connect to the mysql
database and look at the grant tables:

shell> /usr/bin/mysql -u root mysql
mysql> show tables

Try 'mysqld --help' if you have problems with paths. Using --log
gives you a log in /var/lib/mysql that may be helpful.

The latest information about MySQL is available on the web at
http://www.mysql.com
Please consult the MySQL manual section: 'Problems running mysql_install_db',
and the manual section that describes problems on your OS.
Another information source is the MySQL email archive.
Please check all of the above before mailing us!
And if you do mail us, you MUST use the /usr/bin/mysqlbug script!


とりあえず、以下コマンドにて、ちゃんとmysqlという名称のDBが設置されているかどうか、確認した。

# mysql -u root mysql

すると、

 -bash: mysql: command not found

との事。


mysql のクライアントを入れ忘れていたので、他のも含めてインストール。

# rpm -ivh MySQL-client-4.0.26-0.i386.rpm
# rpm -ivh MySQL-devel-4.0.26-0.i386.rpm
# rpm -ivh MySQL-Max-4.0.26-0.i386.rpm

でもって、再度「mysql -u root mysql」を実行も、mysql自体が動いていないから見れないわけで・・・


/etc/my.cnf を作って、mysqlのログを吐くように指定などなど。

# vi /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
     
[mysql.server]
user=mysql
basedir=/var/lib

[safe_mysqld]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

でもって、「/etc/rc.d/init.d/mysql start」を実行も、動かない。


ログを参照したところ、以下が出力されていましたわ。

100309 03:18:51  mysqld started
100309  3:18:51  InnoDB: Started
100309  3:18:51 Fatal error: Can't open privilege tables: Table 'mysql.host' doesn't exist
100309  3:18:51 Aborting

100309  3:18:51  InnoDB: Starting shutdown...
100309  3:18:53  InnoDB: Shutdown completed
100309  3:18:53 /usr/sbin/mysqld-max: Shutdown Complete

100309 03:18:53  mysqld ended

あれ?
そもそも、「mysql.host」が無いって、ダメじゃね?


って事で、色々とまた調査開始。


そう言えば、postgreSQLは「initdb」とかあったな、とか思って、実はMySQLでも必要じゃね?と。


ありました。


mysql_install_db」が。


つか、最初のエラーメッセージのところにも、ちゃんと書いてあったね。。。
「'Problems running mysql_install_db'」
って。。。


早速実行。

/usr/bin/mysql_install_db
# mysql_install_db 
Neither host 'localhost.localdomain' nor 'localhost' could not be looked up with
/usr/bin/resolveip
Please configure the 'hostname' command to return a correct hostname.
If you want to solve this at a later stage, restart this script with
the --force option

おう?


ホスト名を設定しろって事かね?


とりあえず、ホスト名を設定。

hostname www.example.com


再度実行。

/usr/bin/mysql_install_db
# mysql_install_db 
Neither host 'www.example.com' nor 'localhost' could not be looked up with
/usr/bin/resolveip
Please configure the 'hostname' command to return a correct hostname.
If you want to solve this at a later stage, restart this script with
the --force option

あれ?


また調査開始。


「--no-defaults」オプションを付けると出来るってエントリがあったので、やってみたけど、結果変わらず。


エラーメッセージを良く読んだところ、「--force」を付けろとの事。
やってみた。

# /usr/bin/mysql_install_db --force
Preparing db table
Preparing host table
Preparing user table
Preparing func table
Preparing tables_priv table
Preparing columns_priv table
Installing all prepared tables
100309  3:29:05 /usr/sbin/mysqld: Shutdown Complete


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 www.example.com password 'new-password'
See the manual for more instructions.

You can start the MySQL daemon with:
cd / ; /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 https://order.mysql.com

ふむ、どうやら出来たっぽい。


では、起動してみようって事で「/etc/rc.d/init.d/mysql start」を実行。


しかし、起動せず。


エラーログ参照。

100309 03:29:46  mysqld started
100309  3:29:46  InnoDB: Started
100309  3:29:46 /usr/sbin/mysqld-max: Can't find file: './mysql/host.frm' (errno: 13)
100309  3:29:46 Fatal error: Can't open privilege tables: Can't find file: './mysql/host.frm' (errno: 13)
100309  3:29:46 Aborting

100309  3:29:46  InnoDB: Starting shutdown...
100309  3:29:48  InnoDB: Shutdown completed
100309  3:29:48 /usr/sbin/mysqld-max: Shutdown Complete

100309 03:29:48  mysqld ended

エラーログ変わった。


「host.frm」が無い?
あぁ〜・・・
多分、パーミッションの問題っぽい。
って事で、パーミッションの設定を実施。

# cd /var/lib/mysql
# chown -R mysql:mysql ./mysql


んでもって、起動スクリプトを実施。
ログを参照。

100309 03:31:04  mysqld started
100309  3:31:04  InnoDB: Started
/usr/sbin/mysqld-max: ready for connections.
Version: '4.0.26-Max'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  Official MySQL RPM

プロセスを参照。

# ps auxwww | grep mysql
root      2531  0.0  0.1   2412  1076 pts/0    S    03:31   0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/www.example.com.pid
mysql     2562  0.0  1.5 120272 15792 pts/0    Sl   03:31   0:00 /usr/sbin/mysqld-max --basedir=/ --datadir=/var/lib/mysql --user=mysql --pid-file=/var/lib/mysql/www.example.com.pid --skip-locking --socket=/var/lib/mysql/mysql.sock

動いた!!!!

長い闘いは終わった・・・


あとは、Webのミドルウェアとの繋ぎ込みだな。


でわ。

MySQL備忘録−その1

■auto_incrementの値を初期化する方法
該当テーブルのレコードを全て削除し、以下SQLを発行する。

ALTER TABLE TABLE_NAME AUTO_INCREMENT = 1;


■重複レコードを抽出する方法

SELECT * FROM TABLE_NAME GROUP BY FIELD_A HAVING COUNT(FIELD_A) > 1;


ちょっとした事だし、忘れそうなので、書いておきます。


でわ。

CentOS5.3でのsymfony動作環境構築手順備忘録

掲題の通り。


OS:CentOS 5.3


まずは、PHPのバージョン確認。

# php -v
PHP 5.1.6 (cli) (built: May 24 2008 14:07:53) 
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies


PHPをバージョンアップしましょう。
PHP 5.3.1 にします。


その為には、remi のリポジトリを使います。
その下準備。

# cd /usr/local/src
# wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
# wget http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm
# rpm -Uvh remi-release-5.rpm epel-release-5-3.noarch.rpm


これで、remiのリポジトリ用のファイルが作成されるはずです。

# cd /etc/yum.repos.d/
# vi remi.repo
[remi]
priority=1  → 追加
# vi epel.repo
[epel]
priority=1  → 追加
enabled=0  → 設定


では、PHPをバージョンアップしましょう。

# yum -y --enablerepo=remi,epel update php php-mbstring php-mysql mysql*


バージョンアップ確認。

# php -v
PHP 5.3.1 (cli) (built: Nov 20 2009 17:51:14) 
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies


次に、PEARsymfonyのチャンネルを登録して、symfonyをインストール。

# pear channel-discover pear.symfony-project.com
# pear install symfony/symfony

あ、ちなみに、PEAR のバージョンが 1.4 以上が動作要件っぽいです。


途中でphp-xmlのエラーが出たら、これで回避。

# yum install --enablerepo=remi php-xml

リポジトリを指定しないと、デフォルトのリポジトリを見に行って、PHP 5.1.6 じゃないと・・・って言われるので。
足りないライブラリはガシガシ入れていきましょう。


symfonyの確認。

# symfony -v


でわ。