1. 程式人生 > >Mycat快速入門(六): Mycat管理命令和監控

Mycat快速入門(六): Mycat管理命令和監控

一:Mycat管理命令和監控

Mycat可以通過終端來監控mycat的各項指標,埠為9066

mysql -h127.0.0.1 -P9066 -uroot -proot123

mysql> show @@help;
+--------------------------------------------------------------+--------------------------------------------+
| STATEMENT                                                    | DESCRIPTION                                |
+--------------------------------------------------------------+--------------------------------------------+ | show @@time.current | Report current timestamp | | show @@time.startup | Report startup timestamp
| | show @@version | Report Mycat Server version | | show @@server | Report server status | | show @@threadpool |
Report threadPool status | | show @@database | Report databases | | show @@datanode | Report dataNodes | | show @@datanode where schema = ? | Report dataNodes | | show @@datasource | Report dataSources | | show @@datasource where dataNode = ? | Report dataSources | | show @@datasource.synstatus | Report datasource data synchronous | | show @@datasource.syndetail where name=? | Report datasource data synchronous detail | | show @@datasource.cluster | Report datasource galary cluster variables | | show @@processor | Report processor status | | show @@command | Report commands status | | show @@connection | Report connection status | | show @@cache | Report system cache usage | | show @@backend | Report backend connection status | | show @@session | Report front session details | | show @@connection.sql | Report connection sql | | show @@sql.execute | Report execute status | | show @@sql.detail where id = ? | Report execute detail status | | show @@sql | Report SQL list | | show @@sql.high | Report Hight Frequency SQL | | show @@sql.slow | Report slow SQL | | show @@sql.resultset | Report BIG RESULTSET SQL | | show @@sql.sum | Report User RW Stat | | show @@sql.sum.user | Report User RW Stat | | show @@sql.sum.table | Report Table RW Stat | | show @@parser | Report parser status | | show @@router | Report router status | | show @@heartbeat | Report heartbeat status | | show @@heartbeat.detail where name=? | Report heartbeat current detail | | show @@slow where schema = ? | Report schema slow sql | | show @@slow where datanode = ? | Report datanode slow sql | | show @@sysparam | Report system param | | show @@syslog limit=? | Report system mycat.log | | show @@white | show mycat white host | | show @@white.set=?,? | set mycat white host,[ip,user] | | show @@directmemory=1 or 2 | show mycat direct memory usage | | show @@check_global -SCHEMA= ? -TABLE=? -retry=? -interval=? | check mycat global table consistency | | switch @@datasource name:index | Switch dataSource | | kill @@connection id1,id2,... | Kill the specified connections | | stop @@heartbeat name:time | Pause dataNode heartbeat | | reload @@config | Reload basic config from file | | reload @@config_all | Reload all config from file | | reload @@route | Reload route config from file | | reload @@user | Reload user config from file | | reload @@sqlslow= | Set Slow SQL Time(ms) | | reload @@user_stat | Reset show @@sql @@sql.sum @@sql.slow | | rollback @@config | Rollback all config from memory | | rollback @@route | Rollback route config from memory | | rollback @@user | Rollback user config from memory | | reload @@sqlstat=open | Open real-time sql stat analyzer | | reload @@sqlstat=close | Close real-time sql stat analyzer | | offline | Change MyCat status to OFF | | online | Change MyCat status to ON | | clear @@slow where schema = ? | Clear slow sql by schema | | clear @@slow where datanode = ? | Clear slow sql by datanode | +--------------------------------------------------------------+--------------------------------------------+ 59 rows in set (0.01 sec) mysql> show @@server; +-------------+-------------+--------------+------------+---------------+---------------+---------+--------+ | UPTIME | USED_MEMORY | TOTAL_MEMORY | MAX_MEMORY | RELOAD_TIME | ROLLBACK_TIME | CHARSET | STATUS | +-------------+-------------+--------------+------------+---------------+---------------+---------+--------+ | 8m 7s 538ms | 230861432 | 1029177344 | 3817865216 | 1541149359926 | -1 | utf8 | ON | +-------------+-------------+--------------+------------+---------------+---------------+---------+--------+ mysql> show @@database; +----------+ | DATABASE | +----------+ | testdb | +----------+ 1 row in set (0.00 sec) mysql> show @@heartbeat; +------------+-------+----------------+------+---------+-------+--------+---------+--------------+---------------------+-------+ | NAME | TYPE | HOST | PORT | RS_CODE | RETRY | STATUS | TIMEOUT | EXECUTE_TIME | LAST_ACTIVE_TIME | STOP | +------------+-------+----------------+------+---------+-------+--------+---------+--------------+---------------------+-------+ | hostMaster | mysql | 172.16.128.148 | 3306 | 1 | 0 | idle | 30000 | 1,2,2 | 2018-11-02 17:09:40 | false | | hostMaster | mysql | 172.16.128.153 | 3306 | 1 | 0 | idle | 30000 | 1,1,1 | 2018-11-02 17:09:40 | false | | hostMaster | mysql | 172.16.128.152 | 3306 | 1 | 0 | idle | 30000 | 1,2,2 | 2018-11-02 17:09:40 | false | +------------+-------+----------------+------+---------+-------+--------+---------+--------------+---------------------+-------+ 3 rows in set (0.00 sec) -- 顯示快取的使用情況,對於效能監控和調優很有價值 mysql> show @@cache; +-------------------------------------+-------+------+--------+------+------+-------------+----------+ | CACHE | MAX | CUR | ACCESS | HIT | PUT | LAST_ACCESS | LAST_PUT | +-------------------------------------+-------+------+--------+------+------+-------------+----------+ | ER_SQL2PARENTID | 1000 | 0 | 0 | 0 | 0 | 0 | 0 | | SQLRouteCache | 10000 | 0 | 0 | 0 | 0 | 0 | 0 | | TableID2DataNodeCache.TESTDB_ORDERS | 50000 | 0 | 0 | 0 | 0 | 0 | 0 | +-------------------------------------+-------+------+--------+------+------+-------------+----------+ 3 rows in set (0.00 sec) mysql> show @@connection; +------------+------+-----------+------+------------+------+--------+---------+--------+---------+---------------+-------------+------------+---------+------------+ | PROCESSOR | ID | HOST | PORT | LOCAL_PORT | USER | SCHEMA | CHARSET | NET_IN | NET_OUT | ALIVE_TIME(S) | RECV_BUFFER | SEND_QUEUE | txlevel | autocommit | +------------+------+-----------+------+------------+------+--------+---------+--------+---------+---------------+-------------+------------+---------+------------+ | Processor3 | 1 | 127.0.0.1 | 9066 | 62623 | root | NULL | utf8:33 | 314 | 9785 | 869 | 4096 | 0 | | | +------------+------+-----------+------+------------+------+--------+---------+--------+---------+---------------+-------------+------------+---------+------------+ 1 row in set (0.00 sec) -- 重新載入配置檔案schema.xml使其生效。 mysql> reload @@config; mysql> show @@datanode;

二:Mycat-Eye安裝

  1. 新建資料庫mycat_eye,匯入build/mycat_eye.sql檔案,並在此資料庫中新建資料庫賬戶:dev,密碼:123456

    mysql -h127.0.0.1 -P3306  -uroot -proot123
    mysql> create database mycat_eye default character set utf8mb4 collate utf8mb4_unicode_ci;
    
    mysql> use mycat_eye;
    
    mysql> source /Users/mengday/Softwares/Mycat-Eye/build/mycat_eye.sql
    
    mysql> CREATE USER 'dev'@'%' IDENTIFIED BY '07fa533360d9';
    mysql> update mysql.user set authentication_string=password('123456') where user='dev';
    mysql> grant all privileges on *.* to 'dev'@'%';
    mysql> flush privileges;
    
    ➜  ~ cd /Users/mengday/Softwares/Mycat-Eye
    ➜  mvn clean install
    
    cd /var/log
    sudo touch dbeye-for-nosql.log
    sudo chmod 777 dbeye-for-nosql.log
    

    ①:命令列啟動

    # 啟動mycateye-agent-xx.jar
    cd ~/Softwares/Mycat-Eye/mycateye-agent/target/
    java -jar mycateye-agent-0.8.jar --mysql.host=localhost --spring.profiles.active=prod &
    
    # 啟動mycateye-web-xx.jar
    java -jar mycateye-web-0.8.jar --mysql.host=localhost --agent.url=http://127.0.0.1:7003/agent &
    

    ②:IDEA中啟動程式 DbeyeAgentApplication

  2. 修改/Mycat-Eye/mycateye-agent/src/main/resources/application.properties

    spring.profiles.active=prod
    
  3. 修改application-prod.properties 中的mysql地址

    mysql.host=127.0.0.1
    
  4. 執行Mycat-Eye/mycateye-agent/src/main/java/io/mycat/eye/agent/DbeyeAgentApplication.java

  5. 修改mycateye-web中的application.properties中的環境
    /Mycat-Eye/mycateye-web/src/main/resources/application.properties

    spring.profiles.active=test
    
  6. 執行Mycat-Eye/mycateye-web/src/main/java/io/mycat/eye/web/MycatEyeApplication.java

  7. 訪問http://localhost:7001/