Innotop是一款十分強大的MySQL監控工具,用perl所寫,通過文本模式展示MysQL伺服器和Innodb的運作狀況。
安裝innotop
下載下傳位址:https://github.com/innotop/innotop
Github上提供兩種版本,一種是開發版(innotop-master),一種是穩定版(innotop-gtid)。在這裡,我們使用的是開發版。
注意:網上提供的下載下傳位址是http://code.google.com/p/innotop/,但這個是原先的維護位址,該項目現已遷移到Github上,而且,innotop-1.9.0.tar.gz這個版本也測試了下(google code上面的最新版本是1.9.1),很多功能都無法使用,可能與MySQL的版本有關,建議還是直接從Github上下載下傳。
# unzip innotop-master.zip
# cd innotop-master
# perl Makefile.PL
Checking if your kit is complete...
Looks good
Warning: prerequisite Term::ReadKey 2.1 not found.
Writing Makefile for innotop
報以上錯誤,缺少ReadKey包。
# yum search ReadKey --注意:基本上缺失的Perl Module都可以通常yum擷取
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* extras: centos.ustc.edu.cn
* updates: centos.ustc.edu.cn
================================================= N/S matched: ReadKey ==================================================
perl-TermReadKey.x86_64 : A perl module for simple terminal control
Name and summary matches only, use "search all" for everything.
# yum install -y perl-TermReadKey
Writing Makefile for innotop
# make install
cp innotop blib/script/innotop
/usr/bin/perl -MExtUtils::MY -e 'MY->fixin(shift)' -- blib/script/innotop
Manifying blib/man1/innotop.1
Installing /usr/local/share/man/man1/innotop.1
Installing /usr/local/bin/innotop
Appending installation info to /usr/lib64/perl5/perllocal.pod
如何使用Innotop
首先我們通過innotop --help檢視其常見的啟動參數
# innotop --help
Usage: innotop <options> <innodb-status-file>
--[no]color -C Use terminal coloring (default)
--config -c Config file to read
--count Number of updates before exiting
--delay -d Delay between updates in seconds
--help Show this help message
--host -h Connect to host
--[no]inc -i Measure incremental differences
--mode -m Operating mode to start in
--nonint -n Non-interactive, output tab-separated fields
--password -p Password to use for connection
--port -P Port number to use for connection
--skipcentral -s Skip reading the central configuration file
--socket -S MySQL socket to use for connection
--spark Length of status sparkline (default 10)
--timestamp -t Print timestamp in -n mode (1: per iter; 2: per line)
--user -u User for login if not current user
--version Output version information and exit
--write -w Write running configuration into home directory if no config files were loaded
其中,
-d:多久時間更新一次
-h:連接配接的主機名
-p:連接配接的端口
-S:socket的位置
-u:連接配接的使用者
熟悉MysQL的童鞋不難了解。
登入進來後,預設是Dashboard。Innotop支援多種模式,Dashboard隻是其中一種模式。通過“?”鍵我們可以檢視所有模式
通過上述字母可切換到不同的狀态下。
如何檢視innotop的文檔
1. # man innotop
2. # perldoc innotop
如何監控多個MySQL伺服器
有兩種方式:
一、直接在innotop互動式界面中添加,步驟如下:
# innotop
進入到互動式界面後,點選@鍵,會進入到連接配接配置界面
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIyZuBnL1YzN0ATOyUDOtITM1YzM3MTNxUDMxAjNxAjMtQTNxYzN18CXxAjNxAjMvwFN1EjN3UzLcd2bsJ2Lc12bj5ycn9Gbi52YuUTMwIzcldWYtl2Lc9CX6MHc0RHaiojIsJye.png)
下面開始填寫,主要有以下幾項:
說明如下:
Choose connections for this mode:選擇連接配接,如果連接配接不存在,則手動建立。是以下面會有提示“There is no connection called 'master26',create it?:”。
填寫y,然後回車,會提示填寫DSN string,按格式來即可。
其中在Enter password這一項需要注意,你輸入密碼的時候光标沒有動,但實際上它是有輸入,輸入完畢,直接回車即可。
對于該種方法,簡單,在監控機器較少的情況下,比較适用,但該方法的弊端在于一旦退出innotop,所有的配置資訊都會丢失,重新進入,需重新配置。
是以,推薦的方法如下。
二、利用配置檔案
# innotop --write,進入互動式界面後退出。會在目前目錄下生成一個.innotop/innotop.conf
# ls .innotop/
innotop.conf plugins
# vim .innotop/innotop.conf
該配置檔案中有關連接配接的配置資訊,預設有一個localhost。
[connections]
localhost=user= have_user= have_pass= dsn=DBI:mysql:;host=localhost;mysql_read_default_group=client savepass= dl_table=test.innotop_dl
[/connections]
當然,這個對我們編輯自己的配置資訊沒有多大用處,可以删除掉。
在此,可根據第一種方式添加一個connection資訊,然後根據該資訊進行相應的編輯。
以第一種方式中的master26為例,添加後,innotop.conf中的資訊如下:
[connections]
localhost=user= have_user= have_pass= dsn=DBI:mysql:;host=localhost;mysql_read_default_group=client savepass= dl_table=test.innotop_dl
master26=user=root have_user=1 pass=123 have_pass=1 dsn=DBI:mysql:;host=192.168.91.26;port=3306 savepass=1
[/connections]
根據實際生産的需求,編輯innotop.conf檔案。
[connections]
master26=user=root have_user=1 pass=123 have_pass=1 dsn=DBI:mysql:;host=192.168.91.26;port=3306 savepass=1
slave25=user=root have_user=1 pass=123 have_pass=1 dsn=DBI:mysql:;host=192.168.91.25;port=3306 savepass=1
slave22=user=root have_user=1 pass=123 have_pass=1 dsn=DBI:mysql:;host=192.168.91.22;port=3306 savepass=1
[/connections]
啟動innotop,預設監控的是master26的資訊。
可通過“n”或“@”選擇相應的伺服器。
好雖好,但不夠直覺,我們希望本例中三個伺服器的資訊能顯示在一個螢幕裡,這樣就不需要進行來回的切換,更直覺。這裡,就需要用到SERVER GROUPS的功能。
SERVER GROUPS
顧名思義,就是講伺服器進行分組,這種資訊展示的粒度就不在是伺服器,而是整個組了。
同樣有兩種方式添加:
一、直接在innotop互動式界面中添加
使用“#”鍵,首先建立組的名字,然後添加伺服器,如下所示:
二、編輯配置檔案
[server_groups]
master-slave=master26 slave22 slave25
[/server_groups]
下面,我們來看看叢集顯示的效果
對于監控主從叢集的狀況,完全夠用。
注意: 在innotop互動式界面中配置完畢後,需退出innotop,再進入,不然就不會顯示CXN列。
總結:
1. 可能有人有疑慮,将密碼儲存到配置檔案中,是否不安全,尤其是在生産環境下。其實,密碼也可以不儲存在配置檔案中,配置如下:
[connections]
server144=user=root have_user=1 have_pass=1 dsn=DBI:mysql:;host=192.168.244.144;port=3306 savepass= dl_table=
[/connections]
如果是在innotop互動式界面中添加,則最後一步Save password in plain text in the config file?: 寫“n”即可。
2. 除了上述功能,innotop還是蠻強大的。譬如在M模式,即Replication Status下,可通過“o”鍵給伺服器發送指令。如下所示:
Anyway,Innotop功能還是及其強大的,大家慢慢琢磨吧~
參考:
https://www.percona.com/blog/2013/10/14/innotop-real-time-advanced-investigation-tool-mysql/