この記事は mod_mruby ngx_mruby Advent Calendar 2017
の18日目の記事です。
時間オーバーしてますごめんなさい。 本題に入る前に、この記事をご覧の方の中に “MySQL HTTP Plugin”
をご存知の方はいらっしゃるでしょうか? (MySQL Casualな方々はこの辺でオチの予想がついたはず) MySQL HTTP
Pluginは2014年ころに MySQL Labs で公開されていた「実験室版」として配布されていて、
MySQLがHTTPをしゃべるようになるプラグイン です。
何言ってるのかよくわからないとか、誰得?
とか思うかも知れませんが、そんな細かいことを気にしてはいけません。とにかく、MySQL(mysqld)がHTTPをしゃべったんです。 …
1サーバーにゴツゴツmysqldを詰め込んでいる環境で、ふとこんなエラーでmysqldが起動しなかった。
2017-12-18 17:50:38 12256 [Note] InnoDB: Using Linux native AIO
2017-12-18 17:50:38 12256 [Note] InnoDB: Using CPU crc32 instructions
2017-12-18 17:50:38 7f2b86333740 InnoDB: Warning: io_setup() failed with EAGAIN. Will make 5 attempts before giving up.
InnoDB: Warning: io_setup() attempt 1 failed.
InnoDB: Warning: io_setup() attempt 2 failed.
InnoDB: Warning: io_setup() attempt 3 failed.
InnoDB: Warning: io_setup() attempt 4 failed.
InnoDB: Warning: io_setup() attempt 5 failed.
2017-12-18 17:50:40 7f2b86333740 InnoDB: Error: io_setup() failed with EAGAIN after 5 attempts.
InnoDB: You can disable Linux Native AIO by setting innodb_use_native_aio = 0 in my.cnf
2017-12-18 17:50:40 12256 [ERROR] InnoDB: Fatal : Cannot initialize AIO sub-system
2017-12-18 17:50:40 12256 [ERROR] Plugin …
[さらに読む]
2015/7/1 にうるう秒が挿入されるということで、うるう秒の話題が盛り上がってるようなので自分も書いてみます。
Linux 上のプログラムが時刻で60秒を刻むには、うるう秒対応のタイムゾーンを使う必要があります。
通常はうるう秒を考慮していないタイムゾーンが使用されているので、60秒を含む時刻になることはありません。
60秒を含む時刻を扱うには、right/Japan
のように right/
を前につけたタイムゾーンを指定します。
前回のうるう秒は 2012/7/1 08:59:60 (JST) だったので、これで試してみます。
% TZ=Japan date --date='2012-07-01 08:59:60' date: `2012-07-01 08:59:60' は無効な日付です % TZ=right/Japan date --date='2012-07-01 08:59:60' 2012年 7月 1日 日曜日 08:59:60 JST
Ruby
…
[さらに読む]
LOAD DATA INFILEで複数のファイルを順番(じゃなくてもいいけど)食わせる場合を考える。
↓こんなかんじ
$ ll *.tsv
-rw-rw-r-- 1 mysql mysql 541810051 Sep 16 10:51 20140912.tsv
-rw-rw-r-- 1 mysql mysql 523910384 Sep 16 10:52 20140913.tsv
-rw-rw-r-- 1 mysql mysql 513351897 Sep 16 10:53 20140914.tsv
-rw-rw-r-- 1 mysql mysql 513221906 Sep 16 10:54 20140915.tsv
無圧縮なファイルなら、シェルでぐるんぐるん回すのが便利。
$ for f in *.tsv ; do
> mysql -sse "LOAD DATA INFILE $f INTO TABLE .." && gzip $f
> done
成功したらgzip圧縮とかそのまんま書けるのでラク。
ただし、圧縮ファイルだと"展開" => "LOAD DATA INFILE" =>
"再圧縮"とか書くのはちょっと面倒だしなんかイヤだ。 …
Percona-Toolkitのうちの1つにpt-ioprofileというやつがあって、
straceでwriteやread, fsyncのシステムコール呼び出し状況を記録して、
lsofでファイルディスクリプタ番号と紐付けて、集計して出してくれたりする。
一番単純な使い方は多分こんな感じ。
# pt-ioprofile --cell sizes --run-time 60
2013年 1月 6日 日曜日 17:08:03 JST
Tracing process ID 1824
total read
pread64 pwrite64 write
open _llseek filename
2191 0
1024 1167
0 …
俺の仕事用VMはこんな感じでメジャーバージョン違いのMySQLが複数入っている(しかも、昨日から同時起動している)関係で、ポートやソケットファイルがデフォルトと違う状態で4つある。
色々あってそこにcactiを突っ込みたくなって、cactiのデータ格納用MySQLに5.5.29を任命。portは64055,
socketは/usr/mysql/5.5.29/data/mysql.sock。
さて、cacti/include/config.phpを書き換えてっと。
多分接続先をlocalhostにすると、TCP
portを使わずにソケット使おうとして、/var/lib/mysql/mysql.sockを見に行って転けるだろうから、(ソケットを指定できそうなパラメータはconfig.phpには無かったので)
$host = '127.0.0.1';$port = '64055';
にしておく。…が、敢え無く失敗。
…
意外に知られていない$HOME/.my.cnfを使って遊んでみよう企画。
$HOME/.my.cnfはMySQL関連のプログラムを起動した時に最後に読み込まれるオプションファイルで、オプションの優先順位が`後勝ち'なので直接渡したオプション以外はここに書いておいたものが/etc/my.cnfなんかと重複していても優先される。かつ、環境変数$HOMEに依存するので、特定のUNIXアカウントに対してのみ悪戯設定出来る。
ではれっつごー。
$ cat .my.cnf[mysql]execute = "SHOW PROCESSLIST"
$
mysql+----+------+-----------+------+---------+------+-------+------------------+|
Id | User | Host | db | Command | Time
| State | Info
|+----+------+-----------+------+---------+------+-------+------------------+|
7 | root | localhost | NULL | Query | …
https://groups.google.com/forum/#!topic/nodejs/aqVYp5ABX_4
LVM is an implementation of a logical volume manager for the
Linux kernel. The biggest advantage is that LVM provides the
ability to make a snapshot of any logical volume.
In a production environment many users access the same file (file
is open) or database. Suppose you start backup process when a
file is open, you will not get correct or updated copy of
file.
Read-only partition - to avoid inconsistent backupYou need to
mount partition as read only, so that no one can make changes to
file and make a backup:
# umount /home
# mount -o ro /home
# tar -cvf /dev/st0 /home
# umount /home
# mount -o rw /home
As you see, the draw back is service remains unavailable during
backup time to all end users. If you are using database then
shutdown database server and make a backup.
Logical Volume Manager snapshot to avoid inconsistent backupThis
solution will only work if you have created …
In the previous part of this article, we had a look at how to
configure LVM, and we had successfully setup a Volume Group and
two Logical Volumes. Now we are going to have a look at extending
the group and volumes.
So let’s start the story from the previous part of this
article!
Because, the mysql
volume was filling up quickly so
I decided to add a new disk of size 10 GB, and I really want to
extend the mysql
volume quickly, before the MySQL
server stalls. With LVM, thats no longer an issue.
Partitioning the new diskFirst let’s have a look at the partition
table,
$ fdisk -l
The new disk is /dev/sdb
, but its not partitioned,
so lets create a single partition spanning the whole disk.
We will do so using the fdisk utility,
$ fdisk /dev/sdb
which will provide you with an interactive console, that you will use to create the …
[さらに読む]