<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>QuickKnowLedge</title>
	<atom:link href="http://www.s-quad.com/wordpress/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.s-quad.com/wordpress</link>
	<description>役立つか役立たないか</description>
	<lastBuildDate>Sat, 12 May 2012 16:23:01 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>MySQL 異なるストレージエンジン間のレプリケーションをスムーズに行う</title>
		<link>http://www.s-quad.com/wordpress/?p=1497</link>
		<comments>http://www.s-quad.com/wordpress/?p=1497#comments</comments>
		<pubDate>Fri, 20 Apr 2012 17:43:26 +0000</pubDate>
		<dc:creator>panda</dc:creator>
				<category><![CDATA[Engines]]></category>
		<category><![CDATA[FEDERATION]]></category>
		<category><![CDATA[innodb]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[レプリケーション]]></category>
		<category><![CDATA[障害対応]]></category>
		<category><![CDATA[federated]]></category>
		<category><![CDATA[replication]]></category>
		<category><![CDATA[skip]]></category>
		<category><![CDATA[エラー]]></category>
		<category><![CDATA[スキップ]]></category>
		<category><![CDATA[ストレージエンジン]]></category>

		<guid isPermaLink="false">http://www.s-quad.com/wordpress/?p=1497</guid>
		<description><![CDATA[どもです。InfiiDBの最終章は、色々とトラブルがあって検証中です。もすこしで解決しそうなので、その時になったらまた記載させていただきます。ごめんなさり・・。今回は、そのトラブルの一つであった、「異なるストレージエンジ [...]]]></description>
			<content:encoded><![CDATA[<p>どもです。InfiiDBの最終章は、色々とトラブルがあって検証中です。もすこしで解決しそうなので、その時になったらまた記載させていただきます。ごめんなさり・・。今回は、そのトラブルの一つであった、「異なるストレージエンジン間のレプリケーション」の部分の話をさせてください。<br />
<a href="http://www.s-quad.com/wordpress/wp-content/uploads/2011/06/logomysql.gif"><img class="alignnone size-medium wp-image-990" title="logomysql" src="http://www.s-quad.com/wordpress/wp-content/uploads/2011/06/logomysql-300x199.gif" alt="" width="300" height="199" /></a></p>
<ul>
<li><strong>異なるストレージエンジン間のレプリケーションって何？</strong><br />
つまり以下のような構成のレプリケーションのことです。<br />
<a href="http://www.s-quad.com/wordpress/wp-content/uploads/2012/04/2012-04-19_005521.jpg"><img class="alignnone size-full wp-image-1498" title="2012-04-19_005521" src="http://www.s-quad.com/wordpress/wp-content/uploads/2012/04/2012-04-19_005521.jpg" alt="" width="498" height="469" /></a><br />
ちょっと前回の「<a title="Permalink to InfiniDB でリアルタイムDWHを作る PART3 ～驚速DWHの構築" href="http://www.s-quad.com/wordpress/?p=1479" rel="bookmark">InfiniDB でリアルタイムDWHを作る PART3 ～驚速DWHの構築</a>」のBLACKBOXの部分の話の種明かしをしてしまうと、リアルタイムのしくみは、このフェデレーションによる透過的なテーブル更新を利用してDWHに書き込んでしまえ！という話だったのです。実は今のところ、この試みはさまざまな問題があり、うまいこと話が進まない状態なので今現在は、ちゃんと説明できる状態にはなっておりません。すみません。それはさておき、上記の図は<br />
InnoDBのTAB1 (MASTER）→ FederationのTAB1 (SLAVE）→MyISAMのTABとう連鎖的なデータ更新を実現している図です。基本的（INSERT,UPDATE,DELETE）なことであれば、これで問題なく動きます。しかも速い！です。じゃあここで説明する、基本的なこと以外って何？ですが、InnoDBのTAB1 (MASTER）のTAB1の定義が変更になった場合のことを言います。通常、InnoDB→InnoDBのレプリケーションであれば定義の変更も問題なく行われます。うーそうですね。たとえば、schema1（MASTER)のTAB1にカラムが１つ追加になった場合などですかね・・。<br />
MySQLの良いところとしては、データの変更(DML）だけでなく定義の変更(DDL）もレプリケーションしてくれるというところだと思います。しかし、今回のように、InnoDB-&gt;Federationのレプリケーションの少し変わった構成でのレプリケーションなどを行った場合は、その便利な機能が災いします。・・で結果からいうと<strong>レプリケーションエラー</strong>になります。理由は、「Feaderation」ストレージエンジンは、ALTER TABLE等の定義変更をサポートしていないからです。Feaderationの定義変更は、基本、Drop &amp; Create です。そういう仕様です。これはこれでしょうがない・・。</li>
<li><strong>エラーでレプリケーションを止めないために</strong><br />
このままの状態で運用のラインに乗せた場合、定義の変更の作業が入ったと同時に必ずレプリケーションエラーが発生してしまいます。ん？スレーブ側のレプリケーションを止めて（stop slave）、スレーブ→マスターの順で定義を変更すれば問題ないんじゃないの？んー無理無理、スレーブ側を再会（start slave）したと同時にマスターの定義変更がレプリケーションしてくるので結局レプリケーションエラーになってしまうのです。</li>
<li><strong>結局エラーになるんじゃん？</strong><br />
はい、残念ながら結局エラーになるのです・・。<br />
もうエラーになるのがわかった以上、そのエラーはスルーしてレプリケーションを続けてくれ！という半ばやけくそ（でもないけど）な気分になってきます。</li>
<li><strong>結局どうするの？</strong><br />
そのエラーがきたら無視してレプリケーションを続行させればいいのです。どうすればいいのか？</p>
<pre>
--slave-skip-errors
</pre>
<p>を利用すればいいのです ^^; 荒業ではありますが、定義の変更毎にいちいち対応するよりましです。ちなみに、oracle 非推奨です<br />
また、上記図の話に戻りますが、マスターサーバの定義が変更になった場合、通常ではスレーブ側では以下のような状態になります。下記にて説明しているのは、innodbのストレージエンジンを利用したusersテーブル（MASTER）から、FEDERATEDストレージエンジンのusers（SLAVE)のレプリケーションの環境から、カラムを追加したときの挙動について説明しております。▼これがマスター側の設定</p>
<pre>
mysql&gt; show create table users;
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| users | CREATE TABLE `users` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`user_name` varchar(100) NOT NULL COMMENT 'ユーザー名',
`user_mail` varchar(100) NOT NULL COMMENT 'メールアドレス',
`last_update` datetime NOT NULL COMMENT '最終更新日',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)</pre>
<p>▼これがスレーブ側の設定</p>
<pre>
mysql&gt; show create table users;
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| users | CREATE TABLE `users` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`user_name` varchar(100) NOT NULL COMMENT 'ユーザー名',
`user_mail` varchar(100) NOT NULL COMMENT 'メールアドレス',
`last_update` datetime NOT NULL COMMENT '最終更新日',
PRIMARY KEY (`id`)
) ENGINE=FEDERATED DEFAULT CHARSET=utf8 CONNECTION='s' |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

[/shqll]

▼上記の構成で、マスター側のテーブルにcol1というカラムを追加する
[shell]
mysql&gt; alter table users add column col1 char(10);
Query OK, 6 rows affected (0.23 sec)
Records: 6 Duplicates: 0 Warnings: 0

mysql&gt; show create table users;
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| users | CREATE TABLE `users` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`user_name` varchar(100) NOT NULL COMMENT 'ユーザー名',
`user_mail` varchar(100) NOT NULL COMMENT 'メールアドレス',
`last_update` datetime NOT NULL COMMENT '最終更新日',
`col1` char(10) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 |
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
</pre>
<p>▼この状態でスレーブの状態を確認してみます。当然エラーになります。ここで、エラーNOを覚えておいてください。Last_SQL_Errno:  1032</p>
<pre>
mysql&gt; show slave status\G

*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.0.42
Master_User: slave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000006
Read_Master_Log_Pos: 542
Relay_Log_File: relay-bin.000006
Relay_Log_Pos: 474
Relay_Master_Log_File: mysql-bin.000006
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 1031
Last_Error: Error 'Table storage engine for 'users' doesn't have this option' on query. Default database: 'sqorder'. Query: 'alter table users add column col1 char(10)'
Skip_Counter: 0
Exec_Master_Log_Pos: 434
Relay_Log_Space: 878
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 1031
Last_SQL_Error: Error 'Table storage engine for 'users' doesn't have this option' on query. Default database: 'sqorder'. Query: 'alter table users add column col1 char(10)'
Replicate_Ignore_Server_Ids:
Master_Server_Id: 201
1 row in set (0.00 sec)
</pre>
<p>▼ SLAVEのMySQLに以下の設定を追記して再度SLAVEを開始します。</p>
<pre>

# vi /etc/my.cnf
---
# 下記のエラーコードはskipする
slave-skip-errors=1032,1031
</pre>
<p>▼レプリケーションが稼動している状態で、マスターに対して、再度alter table 文を実行します。尚、先ほどの検証で、col1というカラムを追加してしまいましたので、今回はcol1を削除してみます。目的は、SLAVE側でエラーをSKIPするところの部分なので、replicationがどーたらこうたらとかFEDERATIONがあ＾でもないこーでもないという話は割愛いたします。<br />
▼今回は以下のSQLでFEDERATON表である、userのSLAVEがエラーにならないことを確認する作業です</p>
<pre>
mysql&gt; alter table users drop col1 ;
</pre>
<p>▼結果、SLAVEのSTATUSはエラーになっていないのがわかるかと思います。</p>
<pre>

mysql&gt; show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.0.42
Master_User: slave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000006
Read_Master_Log_Pos: 836
Relay_Log_File: relay-bin.000012
Relay_Log_Pos: 346
Relay_Master_Log_File: mysql-bin.000006
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 836
Relay_Log_Space: 496
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 201
1 row in set (0.00 sec)
</pre>
<p>どうでしょうか？</p>
<p>&nbsp;</p>
<p>&nbsp;</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.s-quad.com/wordpress/?feed=rss2&#038;p=1497</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>DB2 でIDENTITY列（オートインクリメント列）を含むテーブルをSQLで抽出する方法</title>
		<link>http://www.s-quad.com/wordpress/?p=1515</link>
		<comments>http://www.s-quad.com/wordpress/?p=1515#comments</comments>
		<pubDate>Thu, 19 Apr 2012 10:01:12 +0000</pubDate>
		<dc:creator>panda</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[DB2]]></category>
		<category><![CDATA[db2]]></category>
		<category><![CDATA[identityoverride]]></category>
		<category><![CDATA[load]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[SYSCAT]]></category>
		<category><![CDATA[オプション]]></category>

		<guid isPermaLink="false">http://www.s-quad.com/wordpress/?p=1515</guid>
		<description><![CDATA[DB2のデータのEXPORT AND LOAD時、カラムにIDENTITY列（オートインクリメント）が存在する場合、ロードはエラーになってしまいます。その場合、LOADのオプションで、identityoverrideを指 [...]]]></description>
			<content:encoded><![CDATA[<p>DB2のデータのEXPORT AND LOAD時、カラムにIDENTITY列（オートインクリメント）が存在する場合、ロードはエラーになってしまいます。その場合、LOADのオプションで、identityoverrideを指定することで、IDENTITY列を上書きロードしてくれるのですが、対象のデータベース内に、数百、数千のテーブルが存在する場合、結構探すのに苦労してしまうと思うのです。</p>
<p>それをSQLで求めれば一発でわかるよという話です。</p>
<p><a href="http://www.s-quad.com/wordpress/wp-content/uploads/2010/12/db2.gif"><img class="alignnone size-full wp-image-46" title="db2" src="http://www.s-quad.com/wordpress/wp-content/uploads/2010/12/db2.gif" alt="" width="264" height="173" /></a></p>
<p>* ちなみにSQLはこんな感じで実行すると、結果がでます</p>
<pre>
$ db2 "select TABSCHEMA,TABNAME,COLNAME,IDENTITY,GENERATED from syscat.columns where IDENTITY = 'Y'"

TABSCHEMA TABNAME COLNAME IDENTITY GENERATED
--------------------------------------------------- ---------
DB2ADMIN TAB1 ID Y A
DB2ADMIN TAB2 ID Y A
DB2ADMIN TAB3 ID Y A
DB2ADMIN TAB4 ID Y A
</pre>
<p>* これだけだとつまらないので、SQLでさらに加工すれば、identityoverrideを含んだLOAD文を生成できます。</p>
<pre>
$ db2 -x "select 'load from ' || rtrim(TABSCHEMA) || '.' || rtrim(TABNAME) || '.ixf of IXF modified by identityoverride REPLACE ' || rtrim(TABSCHEMA) || '.' || rtrim(TABNAME) || ' NONRECOVERABLE' as LOAD_SQL from syscat.columns where IDENTITY = 'Y'" &gt; /tmp/load.sql; cat /tmp/load.sql
</pre>
<p>* 上記の出力結果</p>
<pre>
load from DB2ADMIN.TAB4.ixf of IXF modified by identityoverride REPLACE DB2ADMIN.TAB4 NONRECOVERABLE
load from DB2ADMIN.TAB1.ixf of IXF modified by identityoverride REPLACE DB2ADMIN.TAB1 NONRECOVERABLE
load from DB2ADMIN.TAB2.ixf of IXF modified by identityoverride REPLACE DB2ADMIN.TAB2 NONRECOVERABLE
load from DB2ADMIN.TAB3.ixf of IXF modified by identityoverride REPLACE DB2ADMIN.TAB3 NONRECOVERABLE
</pre>
<p>細かいオプションは別として、SYSCATVIEWを利用して、SQL文を生成する手法は結構便利なので、いろいろと応用することができます。</p>
<p>* 余談ですが、正式なロードの構文は以下のような感じになると思います。NONRECOVERABLE オプションは、ロードがエラーになっても、バックアップペンディングにならないよ！というオプションです。</p>
<pre>
$ db2 "load from tab1.ixf of ixf modified by identityoverride REPLACE into tab1 NONRECOVERABLE"
</pre>
<p>以上そんなところで・</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.s-quad.com/wordpress/?feed=rss2&#038;p=1515</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL クエリーキャッシュのヒット率を求めるSQL</title>
		<link>http://www.s-quad.com/wordpress/?p=1510</link>
		<comments>http://www.s-quad.com/wordpress/?p=1510#comments</comments>
		<pubDate>Wed, 18 Apr 2012 17:28:05 +0000</pubDate>
		<dc:creator>panda</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[Engines]]></category>
		<category><![CDATA[innodb]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[チューニング]]></category>
		<category><![CDATA[QCACHE]]></category>
		<category><![CDATA[show]]></category>
		<category><![CDATA[status]]></category>

		<guid isPermaLink="false">http://www.s-quad.com/wordpress/?p=1510</guid>
		<description><![CDATA[MySQLのクエリーキャッシュのヒット率を求めるSQLを作成しました。結果キャッシュのヒット率が二割以下の場合は、キャッシュを利用しない設定のほうがパフォーマンスを出すことができます。このクエリキャッシュヒット率をSQL [...]]]></description>
			<content:encoded><![CDATA[<p>MySQLのクエリーキャッシュのヒット率を求めるSQLを作成しました。結果キャッシュのヒット率が二割以下の場合は、キャッシュを利用しない設定のほうがパフォーマンスを出すことができます。このクエリキャッシュヒット率をSQLで求められるように作成してみました。みなさまのMySQLローカルサーバで直接実行して結果を確認してみてください</p>
<p><a href="http://www.s-quad.com/wordpress/wp-content/uploads/2011/06/logomysql.gif"><img class="alignnone size-medium wp-image-990" title="logomysql" src="http://www.s-quad.com/wordpress/wp-content/uploads/2011/06/logomysql-300x199.gif" alt="" width="300" height="199" /></a></p>
<p><a href="http://www.s-quad.com/wordpress/wp-content/uploads/2011/06/logomysql.gif"><span id="more-1510"></span></a>以下がクエリーキャッシュのヒット率を求めるSQLです。基本的には、show status で計算することができます。私の場合は、それすらめんどくさいので、SQLで対応しました。クエリーキャッシュのヒット率を以下の計算で求めることができます。</p>
<pre>
@QCACHE_HITS/(@QCACHE_HITS+@QCACHE_INSERTS+@QCACHE_NOT_CACHED)*100
</pre>
<p>・以下がクエリキャッシュヒット率を求めるSQLです。たぶん。。だけど合ってます。</p>
<pre>

SELECT
@QCACHE_FREE_BLOCKS := VARIABLE_VALUE
FROM
information_schema.`GLOBAL_STATUS`
where
VARIABLE_NAME = 'QCACHE_FREE_BLOCKS';

SELECT
@QCACHE_FREE_MEMORY := VARIABLE_VALUE
FROM
information_schema.`GLOBAL_STATUS`
where
VARIABLE_NAME = 'QCACHE_FREE_MEMORY';

SELECT
@QCACHE_HITS := VARIABLE_VALUE
FROM
information_schema.`GLOBAL_STATUS`
where
VARIABLE_NAME = 'QCACHE_HITS';

SELECT
@QCACHE_INSERTS := VARIABLE_VALUE
FROM
information_schema.`GLOBAL_STATUS`
where
VARIABLE_NAME = 'QCACHE_INSERTS';

SELECT
@QCACHE_LOWMEM_PRUNES := VARIABLE_VALUE
FROM
information_schema.`GLOBAL_STATUS`
where
VARIABLE_NAME = 'QCACHE_LOWMEM_PRUNES';

SELECT
@QCACHE_NOT_CACHED := VARIABLE_VALUE
FROM
information_schema.`GLOBAL_STATUS`
where
VARIABLE_NAME = 'QCACHE_NOT_CACHED';

SELECT
@QCACHE_QUERIES_IN_CACHE := VARIABLE_VALUE
FROM
information_schema.`GLOBAL_STATUS`
where
VARIABLE_NAME = 'QCACHE_QUERIES_IN_CACHE';

SELECT
@QCACHE_TOTAL_BLOCKS := VARIABLE_VALUE
FROM
information_schema.`GLOBAL_STATUS`
where
VARIABLE_NAME = 'QCACHE_TOTAL_BLOCKS';

select @QCACHE_HITS/(@QCACHE_HITS+@QCACHE_INSERTS+@QCACHE_NOT_CACHED)*100 as CACHE_HIT_RATE;
</pre>
<p><strong>ちなみに、当サイトのクエリキャッシュヒット率はどうかというとこんな感じです</strong></p>
<pre>

mysql&gt; select @QCACHE_HITS/(@QCACHE_HITS+@QCACHE_INSERTS+@QCACHE_NOT_CACHED)*100 as CACHE_HIT_RATE;
+------------------+
| CACHE_HIT_RATE |
+------------------+
| 80.5282490931393 |
+------------------+
1 row in set (0.00 sec)
</pre>
<p>クエリキャッシュヒット率は80%です。すごく優秀！！（ワードプレスが・・・）</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.s-quad.com/wordpress/?feed=rss2&#038;p=1510</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>InfiniDB でリアルタイムDWHを作る PART3 ～驚速DWHの構築</title>
		<link>http://www.s-quad.com/wordpress/?p=1479</link>
		<comments>http://www.s-quad.com/wordpress/?p=1479#comments</comments>
		<pubDate>Mon, 09 Apr 2012 11:20:56 +0000</pubDate>
		<dc:creator>panda</dc:creator>
				<category><![CDATA[Engines]]></category>
		<category><![CDATA[FEDERATION]]></category>
		<category><![CDATA[Infinidb]]></category>
		<category><![CDATA[innodb]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[DWH]]></category>
		<category><![CDATA[infinidb]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[インストール]]></category>
		<category><![CDATA[インフィニ]]></category>
		<category><![CDATA[パフォーマンス]]></category>
		<category><![CDATA[リアルタイム]]></category>
		<category><![CDATA[高速]]></category>

		<guid isPermaLink="false">http://www.s-quad.com/wordpress/?p=1479</guid>
		<description><![CDATA[さあ、いよいよ、リアルタイムDWHの構築です。環境につきましては、前回ここで説明した通りです、最終的なリアルタイムDWHを運用するまでには、すこし手間はかかりますが、順序を把握していれば数が増えても同じ手順で行えます。と [...]]]></description>
			<content:encoded><![CDATA[<p>さあ、いよいよ、リアルタイムDWHの構築です。環境につきましては、前回<a href="http://www.s-quad.com/wordpress/?p=1469" target="_blank">ここ</a>で説明した通りです、最終的なリアルタイムDWHを運用するまでには、すこし手間はかかりますが、順序を把握していれば数が増えても同じ手順で行えます。とか言ってみる</p>
<p><a href="http://www.s-quad.com/wordpress/wp-content/uploads/2011/01/infinidb_copy.gif"><img class="alignnone size-full wp-image-1447" title="infinidb_copy" src="http://www.s-quad.com/wordpress/wp-content/uploads/2011/01/infinidb_copy.gif" alt="" width="500" height="221" /></a></p>
<p><span id="more-1479"></span></p>
<p>前回の図を再度記載します。</p>
<p><a href="http://www.s-quad.com/wordpress/wp-content/uploads/2012/04/2012-04-07_0201191.jpg"><img class="alignnone size-full wp-image-1480" title="2012-04-07_020119" src="http://www.s-quad.com/wordpress/wp-content/uploads/2012/04/2012-04-07_0201191.jpg" alt="" width="378" height="529" /></a></p>
<p><strong>▼環境構成図</strong><br />
上記ホストとスキーマの関係を表したのが、下記の図になります。前回同様、肝の部分は、ブラックボックスなのですが、一度にここで書くと話がややこしくなるので、ここの話は次回にいたします。</p>
<p><a href="http://www.s-quad.com/wordpress/wp-content/uploads/2012/04/infini_detail.jpg"><img class="alignnone size-full wp-image-1481" title="infini_detail" src="http://www.s-quad.com/wordpress/wp-content/uploads/2012/04/infini_detail.jpg" alt="" width="448" height="449" /></a></p>
<p>host:sqdbm02 : MySQL5.5<br />
host:sqdbm03 : MySQL5.5<br />
host:sqdbm04 : MySQL5.5<br />
host:sqdwh01 : InfiniDB<br />
また今回の、sqdwh01で記載されているInfiniDBの構築方法につきましては、<a href="http://www.s-quad.com/wordpress/?p=1174" target="_blank">OSSなDWH InfiniDB 2.2.2最新版をインストールしてみる</a> をご参照ください。というわけでこちらの環境では、すでに作成されております。</p>
<p><strong>▼リアルタイムDWHの構築手順</strong><br />
1. DWH側の構築<br />
2. BLACKBOX側の構築<br />
の順で行います。sqdbm02と03につきましては、すでに存在しているデータベースという前提です。今回は「1. DWH側の構築について」説明します。</p>
<p><strong>▼必要テーブルの調査</strong><br />
今回のシナリオでは、必要なテーブルはすべてではなく、一部です。sqdbm02,03には、いくつかテーブルが存在しますがDWHで必要なテーブルは、trn_jyucyu、mst_item、usersの合計３つのテーブルだけです。</p>
<p><strong>▼構築手順</strong><br />
以下に構築手順を記載します。</p>
<p>【sqdwh01 : root】<br />
<strong>1. DWHのスキーマ作成</strong></p>
<p>1) ストレージエンジンの確認<br />
InfiniDB および、InnoDBが登録されていることを確認します。尚、InfiniDBのインストール時に、InnoDBはインストールされません、個別にインストールする必要がございます。</p>
<pre>
[root@sqdwh01 ~]# idbmysql -u sysadm -pmypasswd
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.1.39 MySQL Community / Calpont InfiniDB Community 2.2.6-1 Final (COSS LA)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql&gt; show engines;
+------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+------------+---------+----------------------------------------------------------------+--------------+------+------------+
| CSV | YES | CSV storage engine | NO | NO | NO |
| InnoDB | YES | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO |
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| InfiniDB | YES | Calpont InfiniDB storage engine | YES | NO | NO |
| MyISAM | DEFAULT | Default engine as of MySQL 3.23 with great performance | NO | NO | NO |
+------------+---------+----------------------------------------------------------------+--------------+------+------------+
7 rows in set (0.00 sec)
</pre>
<p>2)データベース（スキーマ）の作成<br />
図に習ってワーク用の、スキーマと、「Infinidb用」のスキーマを作成します。</p>
<pre>
mysql&gt; create database wrkorder;
Query OK, 1 row affected (0.00 sec)

mysql&gt; create database wrkitem;
Query OK, 1 row affected (0.00 sec)

mysql&gt; create database wrkuser;
Query OK, 1 row affected (0.00 sec)

mysql&gt; create database dwhorder;
Query OK, 1 row affected (0.00 sec)

mysql&gt; create database dwhitem;
Query OK, 1 row affected (0.00 sec)

mysql&gt; create database dwhuser;
Query OK, 1 row affected (0.00 sec)

mysql&gt; show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| calpontsys |
| dwhitem |
| dwhorder |
| dwhuser |
| infinidb_vtable |
| mysql |
| wrkitem |
| wrkorder |
| wrkuser |
+--------------------+
10 rows in set (0.00 sec)

mysql&gt; show create database wrkorder;
+----------+-------------------------------------------------------------------+
| Database | Create Database |
+----------+-------------------------------------------------------------------+
| wrkorder | CREATE DATABASE `wrkorder` /*!40100 DEFAULT CHARACTER SET utf8 */ |
+----------+-------------------------------------------------------------------+
1 row in set (0.00 sec)
</pre>
<p><strong>2. テーブルのダンプ</strong><br />
各サーバ、および各スキーマから必要なテーブルのみdumpファイルを取得します。</p>
<p>2.1) データ、定義を含むdumpを取得<br />
こちらは、ワークスキーマに格納するためのダンプです。</p>
<pre>
[root@sqdwh01 ~]# /usr/local/Calpont/mysql/bin/mysqldump -h sqdbm02 -u sysadm -pmypasswd sqorder trn_jyucyu &gt; /tmp/trn_jyucyu.dump
[root@sqdwh01 ~]# /usr/local/Calpont/mysql/bin/mysqldump -h sqdbm03 -u sysadm -pmypasswd sqitem mst_item &gt; /tmp/mst_item.dump
[root@sqdwh01 ~]# /usr/local/Calpont/mysql/bin/mysqldump -h sqdbm03 -u sysadm -pmypasswd squser users &gt; /tmp/users.dump
</pre>
<p>2.2) 定義のみのダンプを取得<br />
こちらは、後の、InfiniDB用に加工するために出力します</p>
<pre>
[root@sqdwh01 ~]# /usr/local/Calpont/mysql/bin/mysqldump -d -h sqdbm02 -u sysadm -pmypasswd sqorder trn_jyucyu &gt; /tmp/trn_jyucyu_def_only.sql
[root@sqdwh01 ~]# /usr/local/Calpont/mysql/bin/mysqldump -d -h sqdbm03 -u sysadm -pmypasswd sqitem mst_item &gt; /tmp/mst_item_def_only.sql
[root@sqdwh01 ~]# /usr/local/Calpont/mysql/bin/mysqldump -d -h sqdbm03 -u sysadm -pmypasswd squser users &gt; /tmp/users_def_only.sql
</pre>
<p><strong>3. テーブルのリストア</strong><br />
当該テーブルは、当該スキーマは後のデータ連携用ワークスキーマとして利用されます。よってストレージエンジン、およびテーブル定義は、sqdbm01と、sqdbm02のそれと何もかわりません。つまり、ストレージエンジンは、innodbであり、データも同様のものが入っております。</p>
<pre>
[root@sqdwh01 ~]# idbmysql -u sysadm -pmypasswd wrkorder &lt; /tmp/trn_jyucyu.dump
[root@sqdwh01 ~]# idbmysql -u sysadm -pmypasswd wrkitem &lt; /tmp/mst_item.dump
[root@sqdwh01 ~]# idbmysql -u sysadm -pmypasswd wrkuser &lt; /tmp/users.dump
</pre>
<p><strong>4. InfiniDBストレージエンジンテーブルの作成</strong><br />
InfiniDB用にカスタマイズしたテーブル定義を作成します。この定義を作成するために、「2.2) 定義のみのダンプを取得」にて作成しました定義をInfinbiDB用に加工します。どこをどう直すかについては、以下にdiffを作成しましたのでご確認ください。尚、Infinidbの制約事項に関しては、<a href="http://www.s-quad.com/wordpress/?p=1223" target="_blank">DWH InfiniDB community edition の制約事項</a>をご参照ください。</p>
<pre>
[root@sqdwh01 tmp]# cp trn_jyucyu_def_only.sql trn_jyucyu_infinidb.sql
[root@sqdwh01 tmp]# cp mst_item_def_only.sql mst_item_infinidb.sql
[root@sqdwh01 tmp]# cp users_def_only.sql users_infinidb.sql
[root@sqdwh01 tmp]# vi trn_jyucyu_infinidb.sql
[root@sqdwh01 tmp]# diff trn_jyucyu_def_only.sql trn_jyucyu_infinidb.sql
26,34c26,33
&lt; `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
&lt; `j_cd` int(11) NOT NULL COMMENT '受注コード',
&lt; `j_date` date NOT NULL COMMENT '受注日',
&lt; `s_cd` int(11) NOT NULL COMMENT '商品コード',
&lt; `j_price` int(11) NOT NULL COMMENT '受注金額',
&lt; `user_id` int(11) NOT NULL COMMENT 'ユーザーコード',
&lt; `last_update` datetime NOT NULL COMMENT '最終更新日',
&lt; PRIMARY KEY (`id`)
&lt; ) ENGINE=InnoDB AUTO_INCREMENT=599168 DEFAULT CHARSET=utf8;
---
&gt; `id` int(11) ,
&gt; `j_cd` int(11) COMMENT '受注コード',
&gt; `j_date` date COMMENT '受注日',
&gt; `s_cd` int(11) COMMENT '商品コード',
&gt; `j_price` int(11) COMMENT '受注金額',
&gt; `user_id` int(11) COMMENT 'ユーザーコード',
&gt; `last_update` datetime COMMENT '最終更新日'
&gt; ) ENGINE=InfiniDB DEFAULT CHARSET=utf8;

[root@sqdwh01 tmp]# idbmysql -u sysadm -pmypasswd dwhorder &lt; trn_jyucyu_infinidb.sql
[root@sqdwh01 tmp]# idbmysql -u sysadm -pmypasswd dwhitem &lt; mst_item_infinidb.sql
[root@sqdwh01 tmp]# idbmysql -u sysadm -pmypasswd dwhuser &lt; users_infinidb.sql
</pre>
<p>4.1) 作成された、InfiniDBストレージエンジンの定義を確認する<br />
ちょっとみずらくて申し訳けないですが、これがInfiniDBで定義したテーブル群になります、もちろん定義を作っただけなので、データは空です。</p>
<p>・ dwhorder</p>
<pre>
[root@sqdwh01 tmp]# idbmysql -u sysadm -pmypasswd dwhorder -e "show create table trn_jyucyu;"
+------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| trn_jyucyu | CREATE TABLE `trn_jyucyu` (
`id` int(11) DEFAULT NULL,
`j_cd` int(11) DEFAULT NULL COMMENT '受注コード',
`j_date` date DEFAULT NULL COMMENT '受注日',
`s_cd` int(11) DEFAULT NULL COMMENT '商品コード',
`j_price` int(11) DEFAULT NULL COMMENT '受注金額',
`user_id` int(11) DEFAULT NULL COMMENT 'ユーザーコード',
`last_update` datetime DEFAULT NULL COMMENT '最終更新日'
) ENGINE=InfiniDB DEFAULT CHARSET=utf8 |
+------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
</pre>
<p>・dwhuser</p>
<pre>
[root@sqdwh01 tmp]# idbmysql -u sysadm -pmypasswd dwhuser -e "show create table users;"
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| users | CREATE TABLE `users` (
`id` int(11) DEFAULT NULL,
`user_name` varchar(100) DEFAULT NULL COMMENT 'ユーザー名',
`user_mail` varchar(100) DEFAULT NULL COMMENT 'メールアドレス',
`last_update` datetime DEFAULT NULL COMMENT '最終更新日'
) ENGINE=InfiniDB DEFAULT CHARSET=utf8 |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
</pre>
<p>・dwhitems</p>
<pre>
[root@sqdwh01 tmp]# idbmysql -u sysadm -pmypasswd dwhitem -e "show create table mst_item;"
+----------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+----------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| mst_item | CREATE TABLE `mst_item` (
`id` int(11) DEFAULT NULL,
`item_name` varchar(100) DEFAULT NULL COMMENT '商品名',
`last_update` datetime DEFAULT NULL COMMENT '最終更新日'
) ENGINE=InfiniDB DEFAULT CHARSET=utf8 |
+----------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
</pre>
<p><strong>5. データのエクスポート</strong><br />
「2. テーブルのダンプ」でリストアしました。ワークスキーマ上のテーブルをCSVファイルに出力します</p>
<pre>
[root@sqdwh01 tmp]# idbmysql -u sysadm -pmypasswd -e "SELECT * FROM wrkorder.trn_jyucyu INTO OUTFILE '/tmp/trn_jyucyu.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"';"

[root@sqdwh01 tmp]# idbmysql -u sysadm -pmypasswd -e "SELECT * FROM wrkuser.users INTO OUTFILE '/tmp/users.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"';"

[root@sqdwh01 tmp]# idbmysql -u sysadm -pmypasswd -e "SELECT * FROM wrkitem.mst_item INTO OUTFILE '/tmp/mst_item.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"';"
</pre>
<p><strong>6. データのロード</strong><br />
上記5にて、エクスポートしたデータを、InifiniDBのバルクローダーでロードします（非常に高速！！）</p>
<pre>
[root@sqdwh01 tmp]# /usr/local/Calpont/bin/cpimport dwhorder trn_jyucyu '/tmp/trn_jyucyu.csv' -s , -E \"

Column delimiter : ,
Enclosed by Character : "

Using table OID 3000 as the default JOB ID
Bulkload root directory : /usr/local/Calpont/data/bulk
Job description file : /usr/local/Calpont/data/bulk/tmpjob/dwhorder_trn_jyucyu_D20120409_T163059_Job_3000.xml
Log file for this job: /usr/local/Calpont/data/bulk/log/Job_3000.log
2012-04-09 16:30:59 (17790) INFO : successfully loaded job file /usr/local/Calpont/data/bulk/tmpjob/dwhorder_trn_jyucyu_D20120409_T163059_Job_3000.xml
2012-04-09 16:30:59 (17790) INFO : Job file loaded, run time for this step : 0.00211215 seconds
2012-04-09 16:30:59 (17790) INFO : PreProcessing check starts
2012-04-09 16:30:59 (17790) INFO : PreProcessing check completed
2012-04-09 16:30:59 (17790) INFO : preProcess completed, run time for this step : 0.112508 seconds
2012-04-09 16:30:59 (17790) INFO : No of Read Threads Spawned = 1
2012-04-09 16:30:59 (17790) INFO : No of Parse Threads Spawned = 3
2012-04-09 16:31:07 (17790) INFO : For table dwhorder.trn_jyucyu: 599167 rows processed and 599167 rows inserted.
2012-04-09 16:31:07 (17790) WARN : Column dwhorder.trn_jyucyu.j_date; Number of invalid dates replaced with null: 3010
2012-04-09 16:31:07 (17790) INFO : Bulk load completed, total run time : 8.298 seconds

* 他のテーブルにつきましても同様の手順でロードします
[root@sqdwh01 tmp]# /usr/local/Calpont/bin/cpimport dwhuser users '/tmp/users.csv' -s , -E \"
[root@sqdwh01 tmp]# /usr/local/Calpont/bin/cpimport dwhitem mst_item '/tmp/mst_item.csv' -s , -E \"
</pre>
<p>以上で、初期データの作成は無事完了です！</p>
<p>&nbsp;</p>
<p><strong>▼ InfiniDBのパフォーマンス</strong><br />
InfiniDBは本当に速いです！！ InnoDBとInfiniDB、以下のようなSQLを発行し、InfiniDBと、InnoDBの速度比較を行いました。尚、当環境は、XEBのGUEST OSで検証しており、サーバのメモリは、2GBとしております。</p>
<p><strong>●SQL1</strong></p>
<p>1) InfiniDB</p>
<pre>
select
usr.id as user_id,
usr.user_name ,
itm.id as s_cd,
itm.item_name,
sum(j_price) as sum_price
from
dwhuser.users usr
inner join
dwhorder.trn_jyucyu trn
on
usr.id = trn.user_id
inner join
dwhitem.mst_item itm
on
itm.id = trn.s_cd
group by
usr.id,
itm.id,
usr.user_name,
itm.item_name
order by sum(j_price) desc
limit 100;
</pre>
<p>2) InnoDB</p>
<pre>
select
usr.id as user_id,
usr.user_name ,
itm.id as s_cd,
itm.item_name,
sum(j_price) as sum_price
from
wrkuser.users usr
inner join
wrkorder.trn_jyucyu trn
on
usr.id = trn.user_id
inner join
wrkitem.mst_item itm
on
itm.id = trn.s_cd
group by
usr.id,
itm.id,
usr.user_name,
itm.item_name
order by sum(j_price) desc
limit 100;
</pre>
<p><strong>●SQL2</strong></p>
<p>1) InfiniDB</p>
<pre>
select
usr.id as user_id,
usr.user_name ,
count(trn.id) as cnt
from
dwhuser.users usr
inner join
dwhorder.trn_jyucyu trn
on
usr.id = trn.user_id
group by
usr.id,
usr.user_name
order by
count(trn.id) desc;
</pre>
<p>2) InnoDB</p>
<pre>
select
usr.id as user_id,
usr.user_name ,
count(trn.id) as cnt
from
wrkuser.users usr
inner join
wrkorder.trn_jyucyu trn
on
usr.id = trn.user_id
group by
usr.id,
usr.user_name
order by
count(trn.id) desc;
</pre>
<p><strong>●SQL3</strong></p>
<p>1) InfiniDB</p>
<pre>
select
itm.id,
itm.item_name,
sum(trn.j_price) as sum_price
from
dwhorder.trn_jyucyu trn
inner join
dwhitem.mst_item itm
on
itm.id = trn.s_cd
group by
itm.id,
itm.item_name
order by sum(j_price) desc;
</pre>
<p>2) InnoDB</p>
<pre>
select
itm.id,
itm.item_name,
sum(trn.j_price) as sum_price
from
wrkorder.trn_jyucyu trn
inner join
wrkitem.mst_item itm
on
itm.id = trn.s_cd
group by
itm.id,
itm.item_name
order by sum(j_price) desc;
</pre>
<p>▼速度結果<br />
下図の通りのなりました。バーが短いほど、応答速度が速いことになります。平均的に３倍程度の速度向上が見られます。</p>
<p><a href="http://www.s-quad.com/wordpress/wp-content/uploads/2012/04/Infini_PAF.jpg"><img class="alignnone size-full wp-image-1482" title="Infini_PAF" src="http://www.s-quad.com/wordpress/wp-content/uploads/2012/04/Infini_PAF.jpg" alt="" width="746" height="438" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.s-quad.com/wordpress/?feed=rss2&#038;p=1479</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>InfiniDB でリアルタイムDWHを作る PART2（環境構成詳細）</title>
		<link>http://www.s-quad.com/wordpress/?p=1469</link>
		<comments>http://www.s-quad.com/wordpress/?p=1469#comments</comments>
		<pubDate>Fri, 06 Apr 2012 17:38:59 +0000</pubDate>
		<dc:creator>panda</dc:creator>
				<category><![CDATA[Engines]]></category>
		<category><![CDATA[Infinidb]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[column based]]></category>
		<category><![CDATA[infinidb]]></category>
		<category><![CDATA[データウェアハウス]]></category>
		<category><![CDATA[データ連携]]></category>
		<category><![CDATA[リアルタイムDWH]]></category>
		<category><![CDATA[レプリケーション]]></category>
		<category><![CDATA[列指向]]></category>

		<guid isPermaLink="false">http://www.s-quad.com/wordpress/?p=1469</guid>
		<description><![CDATA[前回のMySQLとInfiniDB でリアルタイムDWHを作る PART1から、だいぶ間が空いてしまいましたが、そろそろリアルタイムDWHの話を復活しようと思います。PART2では、リアルタイムDWHを構築する際の環境構 [...]]]></description>
			<content:encoded><![CDATA[<p>前回のMySQLと<a title="MySQLとInfiniDB でリアルタイムDWHを作る PART1" href="http://www.s-quad.com/wordpress/?p=1457" target="_blank">InfiniDB でリアルタイムDWHを作る PART1</a>から、だいぶ間が空いてしまいましたが、そろそろリアルタイムDWHの話を復活しようと思います。PART2では、リアルタイムDWHを構築する際の環境構成について説明し、結果何をどうしたいのか？の結果を記載します。<br />
<a href="http://www.s-quad.com/wordpress/wp-content/uploads/2011/01/infinidb_copy.gif"><img class="alignnone size-full wp-image-1447" title="infinidb_copy" src="http://www.s-quad.com/wordpress/wp-content/uploads/2011/01/infinidb_copy.gif" alt="" width="500" height="221" /></a></p>
<p><span id="more-1469"></span></p>
<p>・MySQL データベースサーバが３台、<br />
・MySQLデータ連携サーバが３台<br />
・InfiniDB データベースサーバが１台<br />
と書きましたが、すみません、そんなに環境ないので<br />
・MySQL データベースサーバが２台、<br />
・MySQLデータ連携サーバが１台でポート毎にインスタンスを作成（ポートは二種類）<br />
・InfiniDB データベースサーバが１台<br />
という構成に変更します（汗）もうすこし詳細を書きます。</p>
<p><strong>▼ 環境情報</strong><br />
二台で構成されており、受注DBとマスターDBがあり、マスターDB側には、商品スキーマとユーザースキーマがあるものと思ってください。</p>
<p><strong>★ 受注データベース</strong><br />
以下の環境構成です<br />
<strong></strong></p>
<p><strong>1-1) 受注スキーマ</strong></p>
<pre>
mysql&gt; show create database sqorder;
+----------+------------------------------------------------------------------+
| Database | Create Database |
+----------+------------------------------------------------------------------+
| sqorder | CREATE DATABASE `sqorder` /*!40100 DEFAULT CHARACTER SET utf8 */ |
+----------+------------------------------------------------------------------+
1 row in set (0.00 sec)
</pre>
<p><strong></strong></p>
<p><strong>1-2) 受注テーブル</strong></p>
<pre>
mysql&gt; show tables;
+-------------------+
| Tables_in_sqorder |
+-------------------+
| trn_jyucyu |
+-------------------+
1 row in set (0.00 sec)

CREATE TABLE `trn_jyucyu` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`j_cd` int(11) NOT NULL COMMENT '受注コード',
`j_date` date NOT NULL COMMENT '受注日',
`s_cd` int(11) NOT NULL COMMENT '商品コード',
`j_price` int(11) NOT NULL COMMENT '受注金額',
`user_id` int(11) NOT NULL COMMENT 'ユーザーコード',
`last_update` datetime NOT NULL COMMENT '最終更新日',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=599168 DEFAULT CHARSET=utf8
</pre>
<p><strong></strong></p>
<p><strong>1-3) データ内容/データ件数</strong></p>
<pre>
mysql&gt; select count(*) from trn_jyucyu;
+----------+
| count(*) |
+----------+
| 599167 |
+----------+
1 row in set (0.00 sec)

mysql&gt; select * from trn_jyucyu order by id desc limit 10;
+--------+------------+------------+------+---------+---------+---------------------+
| id | j_cd | j_date | s_cd | j_price | user_id | last_update |
+--------+------------+------------+------+---------+---------+---------------------+
| 599167 | 201227638 | 2012-05-25 | 6 | 1027 | 1 | 2012-04-06 22:35:30 |
| 599166 | 201293988 | 2012-05-29 | 10 | 7939 | 1 | 2012-04-06 22:35:30 |
| 599165 | 2147483647 | 2012-04-30 | 3 | 6629 | 2 | 2012-04-06 22:35:30 |
| 599164 | 2012125737 | 2012-01-07 | 6 | 6626 | 4 | 2012-04-06 22:35:30 |
| 599163 | 2147483647 | 2012-02-07 | 9 | 145 | 4 | 2012-04-06 22:35:30 |
| 599162 | 2012521227 | 2012-01-19 | 3 | 2585 | 5 | 2012-04-06 22:35:30 |
| 599161 | 2012526949 | 2012-04-19 | 7 | 6561 | 4 | 2012-04-06 22:35:29 |
| 599160 | 2147483647 | 2012-09-20 | 10 | 1059 | 5 | 2012-04-06 22:35:29 |
| 599159 | 201252333 | 2012-12-14 | 8 | 9579 | 5 | 2012-04-06 22:35:29 |
| 599158 | 2012225273 | 2012-06-20 | 3 | 1436 | 3 | 2012-04-06 22:35:29 |
+--------+------------+------------+------+---------+---------+---------------------+
10 rows in set (0.00 sec)
</pre>
<p><strong>★マスタデータベース（ユーザー情報）</strong><br />
<strong></strong></p>
<p><strong>1-1) ユーザースキーマ</strong></p>
<pre>
mysql&gt; show create database squser;
+----------+-----------------------------------------------------------------+
| Database | Create Database |
+----------+-----------------------------------------------------------------+
| squser | CREATE DATABASE `squser` /*!40100 DEFAULT CHARACTER SET utf8 */ |
+----------+-----------------------------------------------------------------+
1 row in set (0.00 sec)
</pre>
<p><strong></strong></p>
<p><strong>1-2) ユーザーテーブル</strong></p>
<pre>
mysql&gt; show tables;
+--------------------+
| Tables_in_squser |
+--------------------+
| user_address |
| user_bookmarks |
| user_delete |
| user_fav |
| user_login_history |
| users |
+--------------------+
6 rows in set (0.00 sec)

CREATE TABLE `users` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`user_name` varchar(100) NOT NULL COMMENT 'ユーザー名',
`user_mail` varchar(100) NOT NULL COMMENT 'メールアドレス',
`last_update` datetime NOT NULL COMMENT '最終更新日',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8
</pre>
<p><strong></strong></p>
<p><strong>1-3) データ内容/データ件数</strong></p>
<pre>
mysql&gt; select * from users;
+----+------------------+----------------------------------+---------------------+
| id | user_name | user_mail | last_update |
+----+------------------+----------------------------------+---------------------+
| 1 | テスト太郎1 | test_taro1@testdomain.test.local | 2012-04-07 01:28:26 |
| 2 | テスト太郎2 | test_taro2@testdomain.test.local | 2012-04-07 01:28:26 |
| 3 | テスト太郎3 | test_taro3@testdomain.test.local | 2012-04-07 01:28:26 |
| 4 | テスト太郎4 | test_taro4@testdomain.test.local | 2012-04-07 01:28:26 |
| 5 | テスト太郎5 | test_taro5@testdomain.test.local | 2012-04-07 01:28:26 |
+----+------------------+----------------------------------+---------------------+
5 rows in set (0.00 sec)

mysql&gt; select count(*) from users;
+----------+
| count(*) |
+----------+
| 5 |
+----------+
1 row in set (0.00 sec)
</pre>
<p><strong>★マスタデータベース（商品情報）</strong><br />
<strong></strong></p>
<p><strong>1-1) 商品スキーマ</strong></p>
<pre>
mysql&gt; show create database sqitem;
+----------+-----------------------------------------------------------------+
| Database | Create Database |
+----------+-----------------------------------------------------------------+
| sqitem | CREATE DATABASE `sqitem` /*!40100 DEFAULT CHARACTER SET utf8 */ |
+----------+-----------------------------------------------------------------+
1 row in set (0.00 sec)
</pre>
<p><strong></strong></p>
<p><strong>1-2) ユーザーテーブル</strong></p>
<pre>
mysql&gt; show tables;
+------------------+
| Tables_in_sqitem |
+------------------+
| item_zaiko |
| mst_item |
| mst_item_spec |
+------------------+
3 rows in set (0.00 sec)

CREATE TABLE `mst_item` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`item_name` varchar(100) NOT NULL COMMENT '商品名',
`last_update` datetime NOT NULL COMMENT '最終更新日',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;
</pre>
<p><strong></strong></p>
<p><strong>1-3) データ内容/データ件数</strong></p>
<pre>
mysql&gt; select * from mst_item;
+----+-------------+---------------------+
| id | item_name | last_update |
+----+-------------+---------------------+
| 1 | 商品名1 | 2012-04-07 01:45:19 |
| 2 | 商品名2 | 2012-04-07 01:45:19 |
| 3 | 商品名3 | 2012-04-07 01:45:19 |
| 4 | 商品名4 | 2012-04-07 01:45:19 |
| 5 | 商品名5 | 2012-04-07 01:45:19 |
| 6 | 商品名6 | 2012-04-07 01:45:19 |
| 7 | 商品名7 | 2012-04-07 01:45:19 |
| 8 | 商品名8 | 2012-04-07 01:45:19 |
| 9 | 商品名9 | 2012-04-07 01:45:19 |
| 10 | 商品名10 | 2012-04-07 01:45:19 |
+----+-------------+---------------------+
10 rows in set (0.00 sec)

mysql&gt; select count(*) from mst_item;
+----------+
| count(*) |
+----------+
| 10 |
+----------+
1 row in set (0.00 sec)
</pre>
<p><strong>▼上記をまとめますと、以下のような構成になります。</strong></p>
<p><a href="http://www.s-quad.com/wordpress/wp-content/uploads/2012/04/2012-04-07_020119.jpg"><img class="alignnone size-full wp-image-1470" title="2012-04-07_020119" src="http://www.s-quad.com/wordpress/wp-content/uploads/2012/04/2012-04-07_020119.jpg" alt="" width="378" height="529" /></a><br />
<strong>▼ポイント</strong><br />
・商品スキーマ、受注スキーマ、ユーザースキーマから<span style="color: #ff0000;">必要なテーブルのみ抽出</span>してDWHに格納する<br />
・テーブルの連携には、EXPORT/LOAD等の処理は<span style="color: #ff0000;">一切使わない</span><br />
・MySQLのレプリケーションで行う<br />
・DWHは、InfiniDBを利用する。つまり<span style="color: #ff0000;">ストレージエンジンは、InfiniDB</span>です</p>
<p>上記表中のBLACKBOXの部分は今回は触れません、しかしながら、この<span style="text-decoration: underline;">BLACKBOX</span>の設定が肝になります。こちらの設定については、次回PART3で触れたいと思います。</p>
<p>結局のところ、複数のデータベースサーバに散在している主要テーブルを一つのDWHサーバに収めJOINクエリーするようにするのが最終形です、しかも、InfiniDBだから、その速度は<span style="text-decoration: underline;">驚速</span>です。参考までに結果のサンプルクエリーを載せておきます。</p>
<p><strong>▼サンプルクエリーとサンプルの結果</strong><br />
サンプルでは、もっとも注文金額多いユーザー、商品別の一覧を出力しております。以下でJOINして結果を取得しているので、つまりは、ここがテーブルの集約地点（DWH）になっているわけです。</p>
<pre>
select
usr.id as user_id,
usr.user_name ,
itm.id as s_cd,
itm.item_name,
sum(j_price) as sum_price
from
users usr
inner join
trn_jyucyu trn
on
usr.id = trn.user_id
inner join
mst_item itm
on
itm.id = trn.s_cd
group by
usr.id,
itm.id
order by sum_price desc limit 10;

+---------+------------------+------+------------+-----------+
| user_id | user_name | s_cd | item_name | sum_price |
+---------+------------------+------+------------+-----------+
| 5 | テスト太郎5 | 9 | 商品名9 | 104926456 |
| 5 | テスト太郎5 | 7 | 商品名7 | 102576399 |
| 3 | テスト太郎3 | 9 | 商品名9 | 102194492 |
| 3 | テスト太郎3 | 7 | 商品名7 | 99681643 |
| 4 | テスト太郎4 | 9 | 商品名9 | 98271491 |
| 4 | テスト太郎4 | 7 | 商品名7 | 97877942 |
| 2 | テスト太郎2 | 7 | 商品名7 | 85680747 |
| 1 | テスト太郎1 | 7 | 商品名7 | 84988623 |
| 1 | テスト太郎1 | 9 | 商品名9 | 84576007 |
| 2 | テスト太郎2 | 9 | 商品名9 | 84506047 |
+---------+------------------+------+------------+-----------+
10 rows in set (2.07 sec)
</pre>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.s-quad.com/wordpress/?feed=rss2&#038;p=1469</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CENTOS 5.X でOSが起動しなくなってしまった場合の対処方法</title>
		<link>http://www.s-quad.com/wordpress/?p=1463</link>
		<comments>http://www.s-quad.com/wordpress/?p=1463#comments</comments>
		<pubDate>Wed, 28 Mar 2012 01:00:07 +0000</pubDate>
		<dc:creator>panda</dc:creator>
				<category><![CDATA[CENTOS]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[couldn't boot due to problems with the filesystems]]></category>
		<category><![CDATA[fsck]]></category>
		<category><![CDATA[maitenance]]></category>

		<guid isPermaLink="false">http://www.s-quad.com/wordpress/?p=1463</guid>
		<description><![CDATA[単なるメモ書きですが・・OSブート時に以下のメッセージが出てCENTOSが起動できなくなってしまった場合の作業メモです。エラーメッセージは以下の通り couldn't boot due to problems with  [...]]]></description>
			<content:encoded><![CDATA[<p>単なるメモ書きですが・・OSブート時に以下のメッセージが出てCENTOSが起動できなくなってしまった場合の作業メモです。エラーメッセージは以下の通り</p>
<pre>
couldn't boot due to problems with the filesystems in /dev/VolGroup00/LogVol00
</pre>
<p>まあ・・あれです・・ほとんどの場合ブートセクターが破損した場合なので、ハードディスクに障害があるかその類の問題であることはたしかなのですが、なんとか起動までもっていきたい場合など、直る可能性もありますので是非とｋも試してみてください。結果からいうと、fsckかけるだけです。</p>
<p>・上記のエラーを出力後、以下のようなプロンプトが表示されます。あれですね、パスワードを入れるか、CTRL + D で再起動するかどっちかにしろってことだと思いますが、ここで、OSのrootパスワードを入力してENTERキーを押します</p>
<pre>
*** An error occured during the file system check
*** Dropping you to a shell; the system will reboot when you leave the shell
Give root password for maintenance
(Or type Control-D to continue):
</pre>
<p>・メンテナンスモードがきっと起動しますので、fsckとタイプします、リペアするセクタの確認画面がでますが、とにかく全部 ENTERキーで進めます。（デフォルトでは、Yesです）</p>
<pre>

(Repair filesystem) 1 # fsck
fsck 1.38 (30-Jun-2005)
e2fsck 1.38 (30-Jun-2005)
/dev/VolGroup00/LogVol00: contains a file system with errors, check forced.
Inode 2127913 has illegal bloick(s): Clear&lt;y&gt;?
</pre>
<p>・ひとおりの、fsckが終了したあと、OSを再起動して、うまく動けばラッキーっつうことでｗ</p>
<pre>
(Repair filesystem) 3 # reboot
</pre>
<p>あと、特に説明することないのですが、再起動後起動しないのであれば、もうあきらめたほうが良いかも・・</p>
]]></content:encoded>
			<wfw:commentRss>http://www.s-quad.com/wordpress/?feed=rss2&#038;p=1463</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQLとInfiniDB でリアルタイムDWHを作る PART1</title>
		<link>http://www.s-quad.com/wordpress/?p=1457</link>
		<comments>http://www.s-quad.com/wordpress/?p=1457#comments</comments>
		<pubDate>Tue, 27 Mar 2012 17:11:13 +0000</pubDate>
		<dc:creator>panda</dc:creator>
				<category><![CDATA[BI]]></category>
		<category><![CDATA[BLACKHOLE]]></category>
		<category><![CDATA[Infinidb]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[DWH]]></category>
		<category><![CDATA[infinidb]]></category>
		<category><![CDATA[OSS]]></category>
		<category><![CDATA[カラム指向]]></category>
		<category><![CDATA[データウェアハウス]]></category>
		<category><![CDATA[フリー]]></category>
		<category><![CDATA[リアルタイム]]></category>
		<category><![CDATA[レプリケーション]]></category>
		<category><![CDATA[業界初]]></category>
		<category><![CDATA[無償]]></category>
		<category><![CDATA[連携]]></category>

		<guid isPermaLink="false">http://www.s-quad.com/wordpress/?p=1457</guid>
		<description><![CDATA[むかしむかし、僕のブログでこんなことを書きました。 (OSSなDWH InfiniDB の話 ⑤ ～リアルタイムDWH化について) もう一年以上経っちゃいました・・・。この話、もちろん忘れていたわけでもなく、需要があまり [...]]]></description>
			<content:encoded><![CDATA[<p>むかしむかし、僕のブログでこんなことを書きました。<br />
(<a href="http://www.s-quad.com/wordpress/?p=699" target="_blank">OSSなDWH InfiniDB の話 ⑤ ～リアルタイムDWH化について</a>)<br />
もう一年以上経っちゃいました・・・。この話、もちろん忘れていたわけでもなく、需要があまりなかったので、「ふーん、世間ではそんなにニーズがないのかな？」と思いつつ、特になにもしていなかったのですが、ようやく世間が僕に追い付いた（嘘）ので、そろそろ書こうと思った次第です。</p>
<p><a href="http://www.s-quad.com/wordpress/wp-content/uploads/2011/01/infinidb_copy.gif"><img class="alignnone size-full wp-image-1447" title="infinidb_copy" src="http://www.s-quad.com/wordpress/wp-content/uploads/2011/01/infinidb_copy.gif" alt="" width="500" height="221" /></a></p>
<p>&#8211;<br />
<strong>前回までのおさらいで結局リアルタイムDWHってな～に？</strong></p>
<p>実は自分もいまだによくわかってないのです。googleで「リアルタイムDWH」検索しても、これか！って思うページが出てきません。<br />
しかし、よく見かけるキーワードが、「10TBのデータロードを高速に実現！」とか「Hadoopを利用したなんとかノードで並列のなんとか」とか、なんだ・・結局DWHとしてはリアルタイムじゃないんじゃん・・とか思っちゃうわけです・・・とか書くと前回の同じ内容になってしまいますのでここでは割愛します。私の実現したいことは</p>
<p>・高速な検索<br />
・複数に散在しているデータの更新をリアルタイムにDWHに集約したい<br />
・なおかつ、サービスで利用しているデータベース群には、分析のためにアクセスさせたくない！</p>
<p>という要件を満たしたいのです。経営ダッシュボード等を含むリアルタイムBIは、今まさに、色々なところで実現されております。しかし、いまだに追い付いていないのは、データ（DWH）のリアルタイム化。これが実現出来れば、業界初の試み！（自分調べ）になるわけです。きっと数あるDWHのベンダーから掲載差し止め要求がくること必至です。</p>
<p>このままですと、前回同様能書きで終わってしまいますので、ある意味、ニーズに沿った環境で、その「リアルタイムDWH」をどう実現するのかを、順序だてて書く関係で、このページだけで書ききるのは困難なため、数回にわけて掲載していきたいと思います。</p>
<p>とりあえず！</p>
<p>こんな環境で、こんなことを結果的に実現したいと思っています。それに行き着くまでの、作業過程は必ず書きますので、期待して待っててくださいね。</p>
<p><strong>▼ 実現したい最終構成</strong><br />
以下のような形にしたいと考えております。キーワードはリアルタイムです。</p>
<p><a href="http://www.s-quad.com/wordpress/wp-content/uploads/2012/03/2012-03-28_013612.jpg"><img class="alignnone  wp-image-1458" title="2012-03-28_013612" src="http://www.s-quad.com/wordpress/wp-content/uploads/2012/03/2012-03-28_013612.jpg" alt="" width="498" height="231" /></a></p>
<p><strong>▼ （自分として）の目標</strong><br />
・商用DB（DWH）は一切使わない、つまりお金はかけない（ハードウェアは例外）<br />
・あくまでもリアルタイム反映が目標なので、データロード等の行為は一切行わない<br />
・アドホッククエリー（ad hoc query）でも充分なレスポンスタイムを実現できること</p>
<p><strong>▼ 環境構成</strong><br />
上記に目標を実現させるための構成としてどれが一番スムーズにそれが実現できるか考えた結果</p>
<p>・MySQL 5.5<br />
<a href="http://www.s-quad.com/wordpress/wp-content/uploads/2011/08/MySQL.jpg"><img class="alignnone  wp-image-1082" title="MySQL" src="http://www.s-quad.com/wordpress/wp-content/uploads/2011/08/MySQL-265x300.jpg" alt="" width="186" height="210" /></a><br />
・InfiniDB (MySQL 5.1ベースの列指向DWH）<br />
<a href="http://www.s-quad.com/wordpress/wp-content/uploads/2011/01/infinidb_copy.gif"><img class="alignnone  wp-image-1447" title="infinidb_copy" src="http://www.s-quad.com/wordpress/wp-content/uploads/2011/01/infinidb_copy.gif" alt="" width="300" height="133" /></a></p>
<p>を利用することに決定しました。InfiniDBは、最近国内のサポートも正式に決まり、これから世の中に出回っていくカラムベースのDWHです。これの、フリー版を利用します。あとは、いわずと知れたMySQL、この２つを選択した理由は、一言・・「オール MySQLベースだから」ですｗ ベースが同じものであれば、レプリケーションもきっとできるし、問題がでた場合も、容易に壁を乗り越えれそうだからです。</p>
<p>上記に踏まえ、<br />
・MySQL データベースサーバが３台、<br />
・MySQLデータ連携サーバが３台<br />
・InfiniDB データベースサーバが１台<br />
の合計７台構成で実現します。</p>
<p>MySQL データベースサーバについては、既に構築済みということを前提に次回は掲載します、乞うご期待！！</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.s-quad.com/wordpress/?feed=rss2&#038;p=1457</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>レプリケーションを利用したMySQLのサービス無停止バックアップ</title>
		<link>http://www.s-quad.com/wordpress/?p=1450</link>
		<comments>http://www.s-quad.com/wordpress/?p=1450#comments</comments>
		<pubDate>Mon, 26 Mar 2012 15:46:08 +0000</pubDate>
		<dc:creator>panda</dc:creator>
				<category><![CDATA[innodb]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[cvzf]]></category>
		<category><![CDATA[mysq]]></category>
		<category><![CDATA[mysqldump]]></category>
		<category><![CDATA[replication]]></category>
		<category><![CDATA[scp]]></category>
		<category><![CDATA[tar]]></category>
		<category><![CDATA[ホットバックアップ]]></category>
		<category><![CDATA[レプリケーション]]></category>

		<guid isPermaLink="false">http://www.s-quad.com/wordpress/?p=1450</guid>
		<description><![CDATA[MySQLのバックアップってどうやってますか？単純なバックアップであれば、mysqldumpでもデータディレクトリを丸ごとコピーでも好きな方法でやればいいと思いますが、じゃあそれが止めることが許されないサービスだったら？ [...]]]></description>
			<content:encoded><![CDATA[<p>MySQLのバックアップってどうやってますか？単純なバックアップであれば、mysqldumpでもデータディレクトリを丸ごとコピーでも好きな方法でやればいいと思いますが、じゃあそれが止めることが許されないサービスだったら？というところを突き詰めて「サービス無停止バックアップ」について考えてみたいと思います。</p>
<p><a href="http://www.s-quad.com/wordpress/wp-content/uploads/2011/06/logomysql.gif"><img class="alignnone size-medium wp-image-990" title="logomysql" src="http://www.s-quad.com/wordpress/wp-content/uploads/2011/06/logomysql-300x199.gif" alt="" width="300" height="199" /></a></p>
<p>&nbsp;</p>
<p><span id="more-1450"></span><br />
ここで説明する想定の条件は以下の通りとします。</p>
<p>・MySQLのサーバ数は、20台で、20台それぞれが異なるスキーマである<br />
・MySQLのテーブルはInnoDBテーブルのみ<br />
・MySQLサーバーを止めずにバックアップする<br />
・4重のバックアップ手法をとり、どんなことがあろうと障害復旧時点までリカバリできる構成を作ること</p>
<p>ここでは、有償の製品の話は割愛しますね。MySQLでinnodbのバックアップ方法は2通りあり、一つは、前述の通りなのですが、MySQLサービスを停止して、ディレクトリごと、丸々コピーする方法と、mysqldumpでスキーマのバックアップをとる方法があるのですが、そちらにしてもサービスは止まり、ディレクトリごとバックアップする方法に関しては、そもそもサービスを停止する方法があるのでNGですし、mysqldumpに関しては、mysqldump取得時に、テーブルにロックがかかりますよね。なので、「止めることが許されないサービス」には当てはまらないのです。Oracle社は公式に、バックアップはサービスを止めてディレクトリ毎コピーすることを推奨しております。</p>
<p>・・で以下の４つを中心に考え、サービス無停止バックアップを考えてみます。</p>
<p><strong>▼MySQLのバックアップは、mysqldumpを利用</strong><br />
mysqldumpはmysqldumpであってバックアップではないの理解しつつ、あえてこれを利用します</p>
<p><strong>▼ レプリケーションを利用する</strong><br />
上記方法だけは要件を満たすことができないため、今回はMySQLレプリケーションを応用して検討します</p>
<p><strong>▼ バイナリログのローテートを活用する</strong><br />
バイナリログのローテート先を対象DBサーバとは別の筐体に保存し、ハードディスク障害のリスクを分散します。</p>
<p><strong>▼ バックアップ集中サーバを構築する</strong><br />
潤沢に資金があるのであれば、1サーバ毎に1バックアップサーバでいけるのですが、ただバックアップのためにだけ・・それらのサーバを容易するのは、金銭面で苦労するでしょう。なのでバックアップ集中サーバは一台で回していきます。</p>
<p>今回の検証では、以下のサーバがあると仮定します。</p>
<p><strong>・マスターサーバ</strong><br />
&gt; ブログスキーマ * 1台 : &lt;&lt;host;sqdbm01&gt;&gt;<br />
&gt; ログ * 1台 : &lt;&lt;host:sqdbm03&gt;&gt;</p>
<p><strong>・バックアップサーバ</strong><br />
&gt; バックアップ集中サーバ * 1台 : &lt;&lt;host:sqdbm99&gt;&gt;</p>
<p><strong>・ファイルサーバ</strong><br />
&gt; NFSサーバ * 1台 : &lt;&lt;host:sqnas01&gt;&gt;</p>
<p>というわけで合計 5台です。今回ここで説明するのは、バックアップサーバの話だけです。バックアップサーバ集中サーバ以外のホストにつきましては、別に何も設定は必要ではありません。</p>
<p><a href="http://www.s-quad.com/wordpress/wp-content/uploads/2012/03/2012-03-27_003734.jpg"><img class="alignnone size-full wp-image-1451" title="2012-03-27_003734" src="http://www.s-quad.com/wordpress/wp-content/uploads/2012/03/2012-03-27_003734.jpg" alt="" width="395" height="361" /></a></p>
<p>&#8212;&#8211;<br />
<strong>▼集中バックアップサーバを構築する</strong><br />
MySQLのインストール手順については割愛します、mysqlはrpmでインストールしております。</p>
<p>・my.cnfの編集<br />
my.cnfの編集をします。図のとおり、複数のDBサーバから一台のバックアップスレーブサーバにデータをレプリケーションする構成のため、MySQLのマルチ起動をする必要があります。mysqlには、mysqld_muiti というユティリティがあるのですが、私的には、my.cnfの管理がしずらく、あまり便利なユティリティにも思えなかったため、mysqld_safe で個々にプロセスを起動する方法をとりました。なので手順は一般的なものと違いますので、mysqld_muitiでやりたい方は、その設定に併せてください。</p>
<p><strong>・ポート毎のディレクトリを作成</strong><br />
ポート毎（socket毎）にデータディレクトリを分けます。</p>
<pre>
[root@sqdbm99 ~]# su - mysql
-bash-3.2$ mkdir /var/lib/mysql/data1
-bash-3.2$ mkdir /var/lib/mysql/data2
-bash-3.2$ mysql_install_db --datadir=/var/lib/mysql/data1/
-bash-3.2$ mysql_install_db --datadir=/var/lib/mysql/data2/
</pre>
<p><strong>・my.cnf の編集</strong><br />
バックアップサーバは・・・ここの環境は、あまりスペックの良いPCではありません。なので、my-small.cnfをベースにします。<br />
レプリケーションマスターは二台なので、二台分のmy.cnfを作成します。変更箇所は、server-idとソケットディレクトリ、およびポート番号です</p>
<pre>
[root@sqdbm99 ~]# cp /usr/share/mysql/my-small.cnf /etc/my.cnf
------------------------------------------------------------------------
[root@sqdbm99 ~]# diff /usr/share/mysql/my-small.cnf /etc/my.cnf
20,21c20,21
&lt; port = 3306
&lt; socket = /var/lib/mysql/mysql.sock
---
&gt; port = 3307
&gt; socket = /var/lib/mysql/data1/mysql.sock
28c28
&lt; socket = /var/lib/mysql/mysql.sock
---
&gt; socket = /var/lib/mysql/data1/mysql.sock
46c46
&lt; server-id = 1
---
&gt; server-id = 1010
------------------------------------------------------------------------
[root@sqdbm99 ~]# cp -arf /etc/my.cnf /etc/my.cnf1
[root@sqdbm99 ~]# cp -arf /etc/my.cnf /etc/my.cnf2
[root@sqdbm99 ~]# vi /etc/my.cnf2
※ディレクトリとポート番号および、サーバIDのみ変更してください
</pre>
<p><strong>・ポート（ソケット）毎にmysqldを起動する</strong><br />
rpmおよびyumでインストールされた方は。/etc/init.d/mysql startとかやっちゃいがちですが、以下のようなパラメータを添えてポート毎に起動してください</p>
<pre>
# mysqld_safe --defaults-file=/etc/my.cnf1 --datadir=/var/lib/mysql/data1 &amp;
# mysqld_safe --defaults-file=/etc/my.cnf2 --datadir=/var/lib/mysql/data2 &amp;
</pre>
<p>・あとはおのおのの、ソケット毎に、レプリケーション設定を入れるだけです。あ、ちなみに、ソケット毎の接続方法は以下の通りです。</p>
<p><strong>・サーバローカルでの接続方法</strong></p>
<pre>
# mysql -u root -pmypassword -S /var/lib/mysql/data1/mysql.sock
# mysql -u root -pmypassword -S /var/lib/mysql/data2/mysql.sock
</pre>
<p><strong>・リモートからの接続方法</strong></p>
<pre>
# mysql -u root -pmypassword -p 3306
# mysql -u root -pmypassword -p 3307
</pre>
<p>尚、レプリケーションの設定そのものについては、ポートが違おうとデータディレクトリが違おうと、変わりはないので<br />
<a href="http://www.s-quad.com/wordpress/?p=1017" target="_blank"> http://www.s-quad.com/wordpress/?p=1017</a> あたりを参考にしてください。</p>
<p><strong>▼集中バックアップサーバからバックアップファイルをdumpする</strong><br />
ポート毎にmysqlが起動できた、そしてポート毎にレプリケーションが行えた！からバックアップ環境ができたわけではありません。<br />
より確実にバックアップを行うためには、このバックアップサーバ外の部分にデータを退避する必要があります。手順としては、</p>
<p>・slaveを停止する<br />
・mysqldumpを実行する（ポート毎）<br />
・slaveを再開する</p>
<p>だと思います。以下簡単ですが、バックアップのshellみたいのを作成しました（本当はエラーチェック等もっと細かく書きます）</p>
<pre>

# cat mysql_backup.sh
#!/bin/bash

# ---------------------------------------------
# MySQL BACKUP
# $1 mysql port no
# ---------------------------------------------

. /usr/local/shell/include/mysql_common_functions.sh

_LOGDIR=/backups/log
_LOGFILE=$_LOGDIR/mysql_dump.log
_DATE=`date +"%Y%m%d"`
# datetime
# _DATE=`date +%Y%m%d%H%M`
_HOSTNAME=`hostname -a`

if [ "$1" != "" ];
then
_SOCK=" -S /var/lib/mysql/$1/mysql.sock"
else
_SOCK=""
fi

_BACKUPDIR="/backups/${_HOSTNAME}/$1"

# ログファイルディレクトリが存在しない場合は新規で作成する
if [ ! -d $_LOGDIR ]; then
mkdir -p $_LOGDIR
chmod 775 $_LOGDIR
fi

# バックアップディレクトリが存在しない場合は新規で作成する
if [ ! -d $_BACKUPDIR ]; then
echo "create directory $_shelldir"
mkdir -p $_BACKUPDIR
chmod 775 $_BACKUPDIR
fi
_NOW=`date`
echo "*** MySQL Backup Start *** ${_NOW}" &gt;&gt; $_LOGFILE

# DB Config
_DBUSER=myuser
_DBPASSWD=mypass

# mysqldump実行
# 1) flush table
# 2) slave stop
# 3) mysqldump (full)
# 4) slave start
mysql -u ${_DBUSER} -p${_DBPASSWD} ${_SOCK} -e "flush tables;"
mysql -u ${_DBUSER} -p${_DBPASSWD} ${_SOCK} -e "stop slave;"
mysqldump -u ${_DBUSER} -p${_DBPASSWD} ${_SOCK} -x --all-databases &gt; ${_BACKUPDIR}/${_DATE}_${_HOSTNAME}_FULL.dump
mysql -u ${_DBUSER} -p${_DBPASSWD} ${_SOCK} -e "start slave;"
mysql -u ${_DBUSER} -p${_DBPASSWD} ${_SOCK} -e "show slave status\G;"

# バックアップファイルを圧縮
cd ${_BACKUPDIR}/
tar cvzf ${_DATE}_${_HOSTNAME}_FULL.dump.tar.gz ${_DATE}_${_HOSTNAME}_FULL.dump
rm -f ${_DATE}_${_HOSTNAME}_FULL.dump

# 7日まえの古いバックアップファイルを削除する
find ${_BACKUPDIR}/ -mtime +7 -exec rm -f {} \;

_NOW=`date`
echo "--backup dir ${_BACKUPDIR}" &gt;&gt; $_LOGFILE
echo "--backup file ${_BACKUPDIR}/${_DATE}_${_HOSTNAME}_FULL.dump.tar.gz" &gt;&gt; $_LOGFILE

echo "*** MySQL Backup End *** ${_NOW}" &gt;&gt; $_LOGFILE

exit 0
</pre>
<p>ローテートの話にまったく触れてなかったとです・・・。いかがでしょうか？これでサービス無停止バックアップが実現できる状態になったかと思います。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.s-quad.com/wordpress/?feed=rss2&#038;p=1450</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>munin 楽々インストールでMySQLを監視する！</title>
		<link>http://www.s-quad.com/wordpress/?p=1442</link>
		<comments>http://www.s-quad.com/wordpress/?p=1442#comments</comments>
		<pubDate>Fri, 16 Mar 2012 17:24:38 +0000</pubDate>
		<dc:creator>panda</dc:creator>
				<category><![CDATA[CENTOS]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[munin]]></category>
		<category><![CDATA[監視]]></category>

		<guid isPermaLink="false">http://www.s-quad.com/wordpress/?p=1442</guid>
		<description><![CDATA[MySQLとかの状態監視したいんだけど、なんかいいツールないかな？と思ったのがきっかけて、muninとか入れてみました。負荷監視ツールとして有名なのはMRTGですが、私はよくわからんのと設定がめんどくさそうなので（もちろ [...]]]></description>
			<content:encoded><![CDATA[<p>MySQLとかの状態監視したいんだけど、なんかいいツールないかな？と思ったのがきっかけて、muninとか入れてみました。負荷監視ツールとして有名なのはMRTGですが、私はよくわからんのと設定がめんどくさそうなので（もちろん人によっては、使いやすいと思うのですが）自宅のサーバはインストールと設定が簡単なmuninにしたわけです。</p>
<p><a href="http://www.s-quad.com/wordpress/wp-content/uploads/2012/03/munin.png"><img class="alignnone size-full wp-image-1444" title="munin" src="http://www.s-quad.com/wordpress/wp-content/uploads/2012/03/munin.png" alt="" width="305" height="80" /></a></p>
<p>&nbsp;</p>
<p><strong>▼ munin とは何？</strong><br />
ここ（http://gigazine.net/news/20060904_munin/）に詳しく書かれておりますが、『簡単に負荷やトラフィックをグラフ化できる』ツールです。プラグインの種類が豊富で、xenやらmysqlやらapacheやら、簡単利用することができます。個人的には、MySQLの計測関連が豊富なのと動作がものすっごく軽いので気に入りました。<br />
<strong>▼インストールはどうするの？</strong><br />
インストールは簡単です。簡単ですといいながらも、私はソースをコンパイルしてメイクとかするのすら嫌なのですべてyumでインストルする方法で記載することにしました。</p>
<p>今回の例では</p>
<p>munin サーバ<br />
&gt; ホスト名：muninsrv<br />
mysqlserver<br />
&gt; ホスト名：muninclient</p>
<p>という構成にして設定してみたいと思います。また、クラインアントは、MySQLなので、MySQLを中心としたプラグインで構成していきます。OSは、CENTOS5.7の64bit版で行いました。</p>
<p>でわ早速インストール手順などを書きます。</p>
<p><strong>&lt;&lt;サーバ、クライアント共通手順&gt;&gt;</strong></p>
<p>* epelのインストール<br />
munin自体はCENTOSの標準のyumリポジトリには存在しないので、remiやらepelとかをインストールしてからインストールできるところまで手順で書くことにします。</p>
<pre>
[root@muninsrv html]# cd /usr/local/src/
[root@muninsrv src]# wget http://ftp-srv2.kddilabs.jp/Linux/distributions/fedora/epel/5/x86_64/epel-release-5-4.noarch.rpm
[root@muninsrv src]# rpm -ivh epel-release-5-4.noarch.rpm
[root@muninsrv src]# cp /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.20120304
[root@muninsrv src]# cd /etc/yum.repos.d/
[root@muninsrv yum.repos.d]# diff epel.repo epel.repo.20120304
7d6
&lt; enabled=1

* remiのインストール
[root@muninsrv yum.repos.d]# rpm -import http://rpms.famillecollet.com/RPM-GPG-KEY-remi
[root@muninsrv yum.repos.d]# wget http://rpms.famillecollet.com/remi-enterprise.repo
[root@muninsrv yum.repos.d]# cp /etc/yum.repos.d/remi-enterprise.repo /etc/yum.repos.d/remi-enterprise.repo.20120304
[root@muninsrv yum.repos.d]# vi /etc/yum.repos.d/remi-enterprise.repo
[root@muninsrv yum.repos.d]# diff /etc/yum.repos.d/remi-enterprise.repo /etc/yum.repos.d/remi-enterprise.repo.201203045c5
&lt; enabled=1
---
&gt; enabled=0
</pre>
<p><strong>&lt;&lt;サーバの設定&gt;&gt;</strong><br />
・前提条件<br />
apacheがインストールされていること</p>
<p>・yumでmuninをインストールします</p>
<pre>
[root@muninsrv ~]# yum -y install munin
</pre>
<p>・環境設定ファイルの編集をします</p>
<pre>
[root@muninsrv ~]# cd /etc/munin/
[root@muninsrv munin]# cp -prf munin.conf munin.conf.20110314
[root@muninsrv munin]# vi munin.conf
--------------------------------------------------------------------------------------------------------------
# 基本的に、ノードの登録のみ行います。
# 形式は、[グループ名;ホスト名（FQDN）]になります。私の場合は、wwwグループとdbmsグループに分けております。
# Drop somejuser@fnord.comm and anotheruser@blibb.comm an email everytime
# something changes (OK -&gt; WARNING, CRITICAL -&gt; OK, etc)
#contact.someuser.command mail -s "Munin notification" somejuser@fnord.comm
#contact.anotheruser.command mail -s "Munin notification" anotheruser@blibb.comm
#
# For those with Nagios, the following might come in handy. In addition,
# the services must be defined in the Nagios server as well.
#contact.nagios.command /usr/bin/send_nsca nagios.host.comm -c /etc/nsca.conf

[dbms;muninclient]
address 192.168.101.41
use_node_name yes
--------------------------------------------------------------------------------------------------------------
</pre>
<p>* デーモンとかの開始はありません。yumでインストールした場合は、cronに自動登録されます（デフォルトですと５分に一回ですね）</p>
<pre>
root@muninsrv munin]# cat /etc/cron.d/munin
#
# cron-jobs for munin
#

MAILTO=root

*/5 * * * * munin test -x /usr/bin/munin-cron &amp;&amp; /usr/bin/munin-cron
</pre>
<p>以上、munin-serverの設定は終わりです</p>
<p><strong>&lt;&lt;クライアントの設定&gt;&gt;</strong></p>
<p>* クライアントのインストール</p>
<pre>
[root@muninclient ~]# yum -y install munin-node
</pre>
<p>* munin-node.conf の編集</p>
<pre>
[root@muninclient munin]# cd /etc/munin/
[root@muninclient munin]# cp -p munin-node.conf munin-node.conf.20120314
[root@muninclient munin]# vi munin-node.conf
--------------------------------------------------------------------------
# Set this if the client doesn't report the correct hostname when
# telnetting to localhost, port 4949
# munin サーバのホスト名を指定してください
host_name muninsrv.squad.local

# A list of addresses that are allowed to connect. This must be a
# regular expression, since Net::Server does not understand CIDR-style
# network notation unless the perl module Net::CIDR is installed. You
# may repeat the allow line as many times as you'd like
# munin サーバのホスト名のIPアドレスを指定してください
allow ^192\.168\.101\.34$
--------------------------------------------------------------------------
</pre>
<p>* mysql plugin関連のモジュールをインストール<br />
基本上記のままの設定ですと、デフォルトでは以下の監視が設定されます。また、プラグインの登録は、シンボリックリンクで</p>
<pre>
# pwd
/etc/munin/plugins
# ll
合計 0
lrwxrwxrwx 1 root root 28 3月 15 11:18 cpu -&gt; /usr/share/munin/plugins/cpu
lrwxrwxrwx 1 root root 27 3月 15 11:18 df -&gt; /usr/share/munin/plugins/df
lrwxrwxrwx 1 root root 33 3月 15 11:18 df_inode -&gt; /usr/share/munin/plugins/df_inode
lrwxrwxrwx 1 root root 34 3月 15 11:18 diskstats -&gt; /usr/share/munin/plugins/diskstats
lrwxrwxrwx 1 root root 32 3月 15 11:18 if_err_eth0 -&gt; /usr/share/munin/plugins/if_err_
lrwxrwxrwx 1 root root 28 3月 15 11:18 if_eth0 -&gt; /usr/share/munin/plugins/if_
lrwxrwxrwx 1 root root 31 3月 15 11:18 iostat -&gt; /usr/share/munin/plugins/iostat
lrwxrwxrwx 1 root root 35 3月 15 11:18 iostat_ios -&gt; /usr/share/munin/plugins/iostat_ios
lrwxrwxrwx 1 root root 33 3月 15 11:18 irqstats -&gt; /usr/share/munin/plugins/irqstats
lrwxrwxrwx 1 root root 29 3月 15 11:18 load -&gt; /usr/share/munin/plugins/load
lrwxrwxrwx 1 root root 31 3月 15 11:18 memory -&gt; /usr/share/munin/plugins/memory
lrwxrwxrwx 1 root root 32 3月 15 11:18 netstat -&gt; /usr/share/munin/plugins/netstat
※尚、以下の部分は私はリンクをはずしました。除外した理由は監視項目多数ですと、本来、必要なMySQLの監視項目がぼやけるからです。
lrwxrwxrwx 1 root root 30 3月 15 11:18 forks -&gt; /usr/share/munin/plugins/forks
lrwxrwxrwx 1 root root 38 3月 15 11:18 http_loadtime -&gt; /usr/share/munin/plugins/http_loadtime
lrwxrwxrwx 1 root root 32 3月 15 11:18 entropy -&gt; /usr/share/munin/plugins/entropy
lrwxrwxrwx 1 root root 35 3月 15 11:18 fw_packets -&gt; /usr/share/munin/plugins/fw_packets
lrwxrwxrwx 1 root root 35 3月 15 11:18 interrupts -&gt; /usr/share/munin/plugins/interrupts
lrwxrwxrwx 1 root root 31 3月 15 11:18 lpstat -&gt; /usr/share/munin/plugins/lpstat
lrwxrwxrwx 1 root root 36 3月 15 11:18 nfs4_client -&gt; /usr/share/munin/plugins/nfs4_client
lrwxrwxrwx 1 root root 39 3月 15 11:18 ntp_kernel_err -&gt; /usr/share/munin/plugins/ntp_kernel_err
lrwxrwxrwx 1 root root 44 3月 15 11:18 ntp_kernel_pll_freq -&gt; /usr/share/munin/plugins/ntp_kernel_pll_freq
lrwxrwxrwx 1 root root 43 3月 15 11:18 ntp_kernel_pll_off -&gt; /usr/share/munin/plugins/ntp_kernel_pll_off
lrwxrwxrwx 1 root root 35 3月 15 11:18 ntp_offset -&gt; /usr/share/munin/plugins/ntp_offset
lrwxrwxrwx 1 root root 35 3月 15 11:18 open_files -&gt; /usr/share/munin/plugins/open_files
lrwxrwxrwx 1 root root 36 3月 15 11:18 open_inodes -&gt; /usr/share/munin/plugins/open_inodes
lrwxrwxrwx 1 root root 33 3月 15 11:18 proc_pri -&gt; /usr/share/munin/plugins/proc_pri
lrwxrwxrwx 1 root root 34 3月 15 11:18 processes -&gt; /usr/share/munin/plugins/processes
lrwxrwxrwx 1 root root 43 3月 15 11:18 sendmail_mailqueue -&gt; /usr/share/munin/plugins/sendmail_mailqueue
lrwxrwxrwx 1 root root 43 3月 15 11:18 sendmail_mailstats -&gt; /usr/share/munin/plugins/sendmail_mailstats
lrwxrwxrwx 1 root root 45 3月 15 11:18 sendmail_mailtraffic -&gt; /usr/share/munin/plugins/sendmail_mailtraffic
lrwxrwxrwx 1 root root 29 3月 15 11:18 swap -&gt; /usr/share/munin/plugins/swap
lrwxrwxrwx 1 root root 32 3月 15 11:18 threads -&gt; /usr/share/munin/plugins/threads
lrwxrwxrwx 1 root root 31 3月 15 11:18 uptime -&gt; /usr/share/munin/plugins/uptime
lrwxrwxrwx 1 root root 30 3月 15 11:18 users -&gt; /usr/share/munin/plugins/users
lrwxrwxrwx 1 root root 31 3月 15 11:18 vmstat -&gt; /usr/share/munin/plugins/vmstat
lrwxrwxrwx 1 root root 28 3月 15 11:18 yum -&gt; /usr/share/munin/plugins/yum
</pre>
<p>* MySQLに必要なパッケージをインストールします</p>
<pre>
yum install --enablerepo=epel perl-IPC-ShareLite perl-Cache-Cache perl-Cache perl-DBD-MySQL
</pre>
<p>* 現在登録されている、MySQLの監視項目をmunin-node-configure にて確認します</p>
<pre>
munin-node-configure --suggest|grep -i mysql
mysql_ | yes | yes (commands connections innodb_bpool innodb_io innodb_log innodb_tnx myisam_indexes network_traffic qcache qcache_mem select_types slow table_locks +bin_relay_log +files_tables +innodb_bpool_act +innodb_insert_buf +innodb_io_pend +innodb_rows +innodb_semaphores +replication +sorts +tmp_tables)
</pre>
<p>* MySQLの監視項目を追加します</p>
<pre>
cd /etc/munin/plugins
ln -s /usr/share/munin/plugins/mysql_ mysql_commands
ln -s /usr/share/munin/plugins/mysql_ mysql_innodb_bpool
ln -s /usr/share/munin/plugins/mysql_ mysql_innodb_io
ln -s /usr/share/munin/plugins/mysql_ mysql_innodb_log
ln -s /usr/share/munin/plugins/mysql_ mysql_innodb_tnx
ln -s /usr/share/munin/plugins/mysql_ mysql_select_types
ln -s /usr/share/munin/plugins/mysql_ mysql_table_locks
ln -s /usr/share/munin/plugins/mysql_ mysql_connections
ln -s /usr/share/munin/plugins/mysql_ mysql_slow
ln -s /usr/share/munin/plugins/mysql_ mysql_myisam_indexes
ln -s /usr/share/munin/plugins/mysql_ mysql_network_traffic
ln -s /usr/share/munin/plugins/mysql_ mysql_qcache
ln -s /usr/share/munin/plugins/mysql_ mysql_qcache_mem
</pre>
<p>* 結果以下のプラグインのものを監視するようにしました</p>
<pre>
lrwxrwxrwx 1 root root 28 3月 14 15:46 cpu -&gt; /usr/share/munin/plugins/cpu
lrwxrwxrwx 1 root root 27 3月 14 15:46 df -&gt; /usr/share/munin/plugins/df
lrwxrwxrwx 1 root root 33 3月 14 15:46 df_inode -&gt; /usr/share/munin/plugins/df_inode
lrwxrwxrwx 1 root root 34 3月 14 15:46 diskstats -&gt; /usr/share/munin/plugins/diskstats
lrwxrwxrwx 1 root root 32 3月 14 15:46 entropy -&gt; /usr/share/munin/plugins/entropy
lrwxrwxrwx 1 root root 30 3月 14 15:46 forks -&gt; /usr/share/munin/plugins/forks
lrwxrwxrwx 1 root root 32 3月 14 15:46 if_err_eth0 -&gt; /usr/share/munin/plugins/if_err_
lrwxrwxrwx 1 root root 28 3月 14 15:46 if_eth0 -&gt; /usr/share/munin/plugins/if_
lrwxrwxrwx 1 root root 35 3月 14 15:46 interrupts -&gt; /usr/share/munin/plugins/interrupts
lrwxrwxrwx 1 root root 31 3月 14 15:46 iostat -&gt; /usr/share/munin/plugins/iostat
lrwxrwxrwx 1 root root 29 3月 14 15:46 load -&gt; /usr/share/munin/plugins/load
lrwxrwxrwx 1 root root 31 3月 14 15:46 memory -&gt; /usr/share/munin/plugins/memory
lrwxrwxrwx 1 root root 31 3月 14 15:57 mysql_commands -&gt; /usr/share/munin/plugins/mysql_
lrwxrwxrwx 1 root root 31 3月 14 21:07 mysql_connections -&gt; /usr/share/munin/plugins/mysql_
lrwxrwxrwx 1 root root 31 3月 14 15:57 mysql_innodb_bpool -&gt; /usr/share/munin/plugins/mysql_
lrwxrwxrwx 1 root root 31 3月 14 15:57 mysql_innodb_io -&gt; /usr/share/munin/plugins/mysql_
lrwxrwxrwx 1 root root 31 3月 14 15:57 mysql_innodb_log -&gt; /usr/share/munin/plugins/mysql_
lrwxrwxrwx 1 root root 31 3月 14 15:57 mysql_innodb_tnx -&gt; /usr/share/munin/plugins/mysql_
lrwxrwxrwx 1 root root 31 3月 14 21:07 mysql_myisam_indexes -&gt; /usr/share/munin/plugins/mysql_
lrwxrwxrwx 1 root root 31 3月 14 21:07 mysql_network_traffic -&gt; /usr/share/munin/plugins/mysql_
lrwxrwxrwx 1 root root 31 3月 14 21:07 mysql_qcache -&gt; /usr/share/munin/plugins/mysql_
lrwxrwxrwx 1 root root 31 3月 14 21:07 mysql_qcache_mem -&gt; /usr/share/munin/plugins/mysql_
lrwxrwxrwx 1 root root 31 3月 14 15:57 mysql_select_types -&gt; /usr/share/munin/plugins/mysql_
lrwxrwxrwx 1 root root 31 3月 14 21:07 mysql_slow -&gt; /usr/share/munin/plugins/mysql_
lrwxrwxrwx 1 root root 31 3月 14 15:57 mysql_table_locks -&gt; /usr/share/munin/plugins/mysql_
lrwxrwxrwx 1 root root 35 3月 14 15:46 open_files -&gt; /usr/share/munin/plugins/open_files
lrwxrwxrwx 1 root root 36 3月 14 15:46 open_inodes -&gt; /usr/share/munin/plugins/open_inodes
lrwxrwxrwx 1 root root 33 3月 14 15:46 proc_pri -&gt; /usr/share/munin/plugins/proc_pri
lrwxrwxrwx 1 root root 34 3月 14 15:46 processes -&gt; /usr/share/munin/plugins/processes
lrwxrwxrwx 1 root root 29 3月 14 15:46 swap -&gt; /usr/share/munin/plugins/swap
lrwxrwxrwx 1 root root 32 3月 14 15:46 threads -&gt; /usr/share/munin/plugins/threads
lrwxrwxrwx 1 root root 31 3月 14 15:46 uptime -&gt; /usr/share/munin/plugins/uptime
lrwxrwxrwx 1 root root 31 3月 14 15:46 vmstat -&gt; /usr/share/munin/plugins/vmstat
</pre>
<p>*  munin-node（plugin側）内にmysqlの接続設定を追記します</p>
<pre>
# vi /etc/munin/plugin-conf.d/munin-node

# This file is used to configure how the plugins are invoked.
# Place in /etc/munin/plugin-conf.d/ or corresponding directory.
#
# PLEASE NOTE: Changes in the plugin-conf.d directory are only
# read at munin-node startup, so restart at any changes.
#
# user &lt;user&gt; # Set the user to run the plugin as
# group &lt;group&gt; # Set the group to run the plugin as
# command &lt;command&gt; # Run &lt;command&gt; instead of the plugin. %c
# expands to what would normally be run.
# env.&lt;variable&gt; &lt;value&gt; # Sets &lt;variable&gt; in the plugin's environment, see the
# individual plugins to find out which variables they
# care about.
#
#

[mysql*]
env.mysqlconnection DBI:mysql:mysql;host=192.168.0.49;port=3306
env.mysqluser mysqluserid
env.mysqlpassword mysqlpasswd

[exim*]
group mail

[cps*]
user root

[apt]
user root

[vlan*]
user root

[postfix*]
user root
</pre>
<p>* munin-node を開始します</p>
<pre>
[root@muninclient munin]# /etc/init.d/munin-node start
[root@muninclient munin]# /sbin/chkconfig munin-node on
</pre>
<p>以上でクライアントの設定は終わりです。どうでしょうか？結構簡単に設定できたのではないでしょうか？ここがmuninをお勧めする理由の一つです。20台、30台のPCであれば、zabbixなりでやったほうが管理しやすいかと思いますが、これが数百台規模になってきますと、このmuninのような監視ツールの方が設定が高速で且つ、動作が軽いのでないかと思っております。</p>
<p>最後に、上記にて設定を行うと、WEB上ではどのようなイメージで表示できるかを掲載したいと思います。どうでしょうか？個人的には見やすくて好きです</p>
<p><a href="http://www.s-quad.com/wordpress/wp-content/uploads/2012/03/2012-03-17_021947.jpg"><img class="alignnone  wp-image-1443" title="2012-03-17_021947" src="http://www.s-quad.com/wordpress/wp-content/uploads/2012/03/2012-03-17_021947.jpg" alt="" width="570" height="307" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.s-quad.com/wordpress/?feed=rss2&#038;p=1442</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MySQL データディレクトリのパーミッション設定とかの話</title>
		<link>http://www.s-quad.com/wordpress/?p=1436</link>
		<comments>http://www.s-quad.com/wordpress/?p=1436#comments</comments>
		<pubDate>Tue, 13 Mar 2012 07:13:36 +0000</pubDate>
		<dc:creator>panda</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[障害対応]]></category>
		<category><![CDATA[chown]]></category>
		<category><![CDATA[dhmod]]></category>
		<category><![CDATA[lib]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[rpm]]></category>
		<category><![CDATA[var]]></category>
		<category><![CDATA[オーナー]]></category>
		<category><![CDATA[ディレクトリパーミッション]]></category>

		<guid isPermaLink="false">http://www.s-quad.com/wordpress/?p=1436</guid>
		<description><![CDATA[知っている方にはどうでもいい情報なのですが、例えばMySQLのレプリケーションスレーブを作成する際に、mysqldumpからのダンプファイルを、リストアする・・なんていうのがどうしようもなくめんどくさい人は、データディレ [...]]]></description>
			<content:encoded><![CDATA[<p>知っている方にはどうでもいい情報なのですが、例えばMySQLのレプリケーションスレーブを作成する際に、mysqldumpからのダンプファイルを、リストアする・・なんていうのがどうしようもなくめんどくさい人は、データディレクトリ丸ごとスレーブサーバに転送してレプリケーションスレーブサーバを構築するのだと思いますが、その際のパーミッションには注意をお願いしますね。という話です。</p>
<p><a href="http://www.s-quad.com/wordpress/wp-content/uploads/2011/06/logomysql.gif"><img class="alignnone size-medium wp-image-990" title="logomysql" src="http://www.s-quad.com/wordpress/wp-content/uploads/2011/06/logomysql-300x199.gif" alt="" width="300" height="199" /></a></p>
<p><span id="more-1436"></span></p>
<p>▼パーミッションがおかしいの何がどうなるのか？<br />
・こんなエラーが出たりします</p>
<pre>
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: Error: could not open single-table tablespace file
InnoDB: ./crmdb/vv_mysql_indexes.ibd!
InnoDB: We do not continue the crash recovery, because the table may become
InnoDB: corrupt if we cannot apply the log records in the InnoDB log to it.
InnoDB: To fix the problem and start mysqld:
InnoDB: 1) If there is a permission problem in the file and mysqld cannot
InnoDB: open the file, you should modify the permissions.
InnoDB: 2) If the table is not needed, or you can restore it from a backup,
InnoDB: then you can remove the .ibd file, and InnoDB will do a normal
InnoDB: crash recovery and ignore that table.
InnoDB: 3) If the file system or the disk is broken, and you cannot remove
InnoDB: the .ibd file, you can set innodb_force_recovery &gt; 0 in my.cnf
InnoDB: and force InnoDB to continue crash recovery here.
120313 12:22:50 mysqld_safe mysqld from pid file /var/lib/mysql/dbcrmh01..pid ended
</pre>
<p>・あと、仮にサービスが再開できたとしても・・<br />
テーブルがあるのに、存在しないとかわけのわからんエラーがでます（not exist!）</p>
<p>▼作業の前提とか・・<br />
・サーバを停止できるものであれば・・・<br />
例えばサーバを停止できるのであれば、やっぱりとめちゃったほうが安全かと思うのです。今回の例では、マスターデータベース停止した際のデータディレクトリをまんまるスレーブサーバに転送してレプリケーションを構築する例です。。あ・・レプリケーションの話にはまったく触れません。。</p>
<p>▼ オーナ・パーミッションの変更作業<br />
下記例では、MySQL5.5のrpm版をベースに書いてます。またデータディレクトリは、/var/lib/mysql です。<br />
・サービスの停止<br />
mysqlサービスはとめておいてください。</p>
<pre>
[root@db1 mysql]# /etc/init.d/mysql stop
</pre>
<p>・オーナーの変更<br />
オーナーは、全て mysql グループも mysql でかまいません</p>
<pre>
[root@db1mysql]# chown -Rf mysql:mysql /var/lib/mysql
</pre>
<p>・不要なファイルを削除します</p>
<pre>
[root@db1 mysql]# cd /var/lib/mysql
[root@db1 mysql]# rm -f mysql-bin.*
[root@db1mysql]# rm -f mysqld-slow*
[root@db1 mysql]# rm -f *.err
[root@db1 mysql]# rm -f query.log
</pre>
<p>・パーミッションの変更<br />
今回の例では、スキーマ名にmyschema1,myschema2というものが存在しております。スキーマにつきましては、データディレクトリ内のサブディレクトリとして作成されます。なので、複数スキーマを構築している場合は、全てのスキーマのパーミッションを変更する必要がございます。</p>
<pre>
chmod -Rf 600 mysql/
chmod 711 mysql/

chmod -Rf 660 performance_schema/
chmod 700 performance_schema/

chmod -Rf 660 myschema1/
chmod -Rf 660 myschema2

chmod 700 myschema1/
chmod 700 myschema2/
</pre>
<p>・サービスの再開をします</p>
<pre>
[root@dbcrmh01 mysql]# /etc/init.d/mysql start
</pre>
<p>以上、やることはきまっているのでたいした話ではないのですが、突然このような状態になった場合、結構パニックになるので注意が必要です。</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.s-quad.com/wordpress/?feed=rss2&#038;p=1436</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

