上班坐下來沒多久,接同事電話說有兩台mysql伺服器無法訪問,其中這兩台伺服器是mycat伺服器+MySQL伺服器,具體處理過程如下: 一、錯誤信息 錯誤信息01: 錯誤信息02: 錯誤信息03: 二、錯誤原因 1、針對錯誤信息01,基本可以斷定是由於伺服器jvm設置不當,導致記憶體溢出。 2、針對錯 ...
上班坐下來沒多久,接同事電話說有兩台mysql伺服器無法訪問,其中這兩台伺服器是mycat伺服器+MySQL伺服器,具體處理過程如下:
一、錯誤信息
錯誤信息01:
INFO | jvm 3 | 2018/05/10 10:00:54 | 2018-05-10 10:00:54,406 [INFO ][$_NIOREACTOR-3-RW] close connection,reason:Bad: java.lang.OutOfMemoryError: Unable to acquire 131072 bytes of memory, got 0 ,MySQLConnection [id=6173, lastTime=1525917654 250, user=username, schema=database10, old shema=database10, borrowed=true, fromSlaveDB=true, threadId=42067, charset=utf8, txIsolation=3, autocommit=true, attachment=dn10{SELECT * INFO | jvm 3 | 2018/05/10 10:00:54 | FROM cu_link INFO | jvm 3 | 2018/05/10 10:00:54 | WHERE (customer_id = 1964 INFO | jvm 3 | 2018/05/10 10:00:54 | OR customer_link_id = 1964) INFO | jvm 3 | 2018/05/10 10:00:54 | AND state = 1 INFO | jvm 3 | 2018/05/10 10:00:54 | AND company_id = '3BD' INFO | jvm 3 | 2018/05/10 10:00:54 | LIMIT 100000000}, respHandler=io.mycat.backend.mysql.nio.handler.MultiNodeQueryH andler@530d01dc, host=xx.xx.xx.xx, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false] (io.mycat.net. AbstractConnection:AbstractConnection.java:508) INFO | jvm 3 | 2018/05/10 10:00:54 | 2018-05-10 10:00:54,407 [ERROR][$_NIOREACTOR-3-RW] caught err: java.lang.OutOfM emoryError: Unable to acquire 131072 bytes of memory, got 0 INFO | jvm 3 | 2018/05/10 10:00:54 | at io.mycat.memory.unsafe.memory.mm.MemoryConsumer.allocateLongArray(Memor yConsumer.java:92) INFO | jvm 3 | 2018/05/10 10:00:54 | at io.mycat.memory.unsafe.utils.sort.UnsafeInMemorySorter.<init>(UnsafeInM emorySorter.java:114) INFO | jvm 3 | 2018/05/10 10:00:54 | at io.mycat.memory.unsafe.utils.sort.UnsafeExternalSorter.<init>(UnsafeExt ernalSorter.java:131) INFO | jvm 3 | 2018/05/10 10:00:54 | at io.mycat.memory.unsafe.utils.sort.UnsafeExternalSorter.create(UnsafeExt ernalSorter.java:98) INFO | jvm 3 | 2018/05/10 10:00:54 | at io.mycat.memory.unsafe.utils.sort.UnsafeExternalRowSorter.<init>(Unsafe ExternalRowSorter.java:64) INFO | jvm 3 | 2018/05/10 10:00:54 | at io.mycat.sqlengine.mpp.DataNodeMergeManager.onRowMetaData(DataNodeMerge Manager.java:249) INFO | jvm 3 | 2018/05/10 10:00:54 | at io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler.fieldEofRespon se(MultiNodeQueryHandler.java:643) INFO | jvm 3 | 2018/05/10 10:00:54 | at io.mycat.backend.mysql.nio.MySQLConnectionHandler.handleFieldEofPacket( MySQLConnectionHandler.java:192) INFO | jvm 3 | 2018/05/10 10:00:54 | at io.mycat.backend.mysql.nio.MySQLConnectionHandler.handleData(MySQLConne ctionHandler.java:118) INFO | jvm 3 | 2018/05/10 10:00:54 | at io.mycat.net.handler.BackendAsyncHandler.offerData(BackendAsyncHandler. java:36) INFO | jvm 3 | 2018/05/10 10:00:54 | at io.mycat.backend.mysql.nio.MySQLConnectionHandler.handle(MySQLConnectio nHandler.java:80) INFO | jvm 3 | 2018/05/10 10:00:54 | at io.mycat.net.AbstractConnection.handle(AbstractConnection.java:263) INFO | jvm 3 | 2018/05/10 10:00:54 | at io.mycat.net.AbstractConnection.onReadData(AbstractConnection.java:321) INFO | jvm 3 | 2018/05/10 10:00:54 | at io.mycat.net.NIOSocketWR.asynRead(NIOSocketWR.java:190) INFO | jvm 3 | 2018/05/10 10:00:54 | at io.mycat.net.AbstractConnection.asynRead(AbstractConnection.java:273) INFO | jvm 3 | 2018/05/10 10:00:54 | at io.mycat.net.NIOReactor$RW.run(NIOReactor.java:102) INFO | jvm 3 | 2018/05/10 10:00:54 | at java.lang.Thread.run(Thread.java:745) INFO | jvm 3 | 2018/05/10 10:00:54 | (io.mycat.net.NIOReactor$RW:NIOReactor.java:132)
錯誤信息02:
LIMIT 100000000}, packetId=1], host=xx.xx.xx.xx, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false] frontend host:x.x.x.x/49657/username 2018-05-10 10:25:39.883 WARN [$_NIOREACTOR-2-RW] (io.mycat.backend.mysql.nio.handler.SingleNodeHandler.backConnectionErr(SingleNodeHandler.java:249)) - execute sql err : errno:1146 Table 'cr.vacode' doesn't exist con:MySQLConnection [id=89, lastTime=1525919139870, user=username, schema=cr, old shema=cr, borrowed=true, fromSlaveDB=true, threadId=553442, charset=utf8, txIsolation=3, autocommit=true, attachment=dn00{SELECT * FROM vaCode ORDER BY id DESC
錯誤信息03:
java.sql.SQLNonTransientException: find no Route:SELECT * FROM `database03`.`cain` LIMIT 0
二、錯誤原因
1、針對錯誤信息01,基本可以斷定是由於伺服器jvm設置不當,導致記憶體溢出。
2、針對錯誤信息02,基本可以斷定是由於在資料庫伺服器新增表,沒有配置在mycat中或由於MyCAT大小寫配置和資料庫伺服器表名大小寫配置有關
3、針對錯誤信息03,基本可以斷定路由問題
三、解決方案
1、查看系統記憶體
[root@localhost ~]# free -g total used free shared buffers cached Mem: 15 15 0 5 0 6 -/+ buffers/cache: 8 6 Swap: 7 5 2
2、查看系統日誌
[root@localhost logs]#vi /var/log/message
如果是OOM的話,系統日誌會記錄的。
3、查看資料庫日誌和mycat日誌
[root@localhost logs]#vi /home/mysql/err.log
[root@localhost logs]# vi /usr/local/mycat/logs/mycat.log
[root@localhost logs]# [root@localhost logs]# vi /usr/local/mycat/logs/wrapper.log
4、查看監控情況
通過zabbix查看系統CPU、記憶體、SWAP使用情況
5、查看具體進程對應資源消耗
[root@localhost ~]# top -p 31665
[root@localhost ~]# top -p 30388
通過ps 查看系統進程的時候和top查看資源消耗的時候,發現居然還跑著oracle進程,而且其sga設置為8G,PGA設置的是2G
這裡看到實際設置的最大應用記憶體(21G+)已經超過了物理記憶體的實際最大值(15G),而寫看到系統已經使用了swap分區(雖然現在看著還有7G左右的cache),說明
6、查看mycat的進程運行記憶體
下麵的最大堆記憶體4G(具體使用情況可以通過jmap查看),單線程記憶體最大64M,最大的nio記憶體2G(DirectMemory是java nio引入的,直接以native的方式分配記憶體,不受jvm管理)
查看其具體配置文件
[root@localhost mycat]# more /usr/local/mycat/conf/wrapper.conf
# Java Additional Parameters #wrapper.java.additional.1= wrapper.java.additional.1=-DMYCAT_HOME=. wrapper.java.additional.2=-server wrapper.java.additional.3=-XX:MaxPermSize=64M wrapper.java.additional.4=-XX:+AggressiveOpts wrapper.java.additional.5=-XX:MaxDirectMemorySize=2G wrapper.java.additional.6=-Dcom.sun.management.jmxremote wrapper.java.additional.7=-Dcom.sun.management.jmxremote.port=1984 wrapper.java.additional.8=-Dcom.sun.management.jmxremote.authenticate=false wrapper.java.additional.9=-Dcom.sun.management.jmxremote.ssl=false wrapper.java.additional.10=-Xmx4G wrapper.java.additional.11=-Xms1G # Initial Java Heap Size (in MB) #wrapper.java.initmemory=3 # Maximum Java Heap Size (in MB) #wrapper.java.maxmemory=64 # Application parameters. Add parameters as needed starting from 1 wrapper.app.parameter.1=io.mycat.MycatStartup wrapper.app.parameter.2=start
這裡看記憶體設置還是正常範圍內
7、最終解決方案
(由於開發聯繫我時,我測試資料庫服務、MyCAT服務均正常,所以具體排查過程大致如上,後經與開發溝通,他們說是磁碟空間不足導致的,清理磁碟重啟mycat問題解決)
8、資源統計
[root@localhost logs]# dstat -lrmc --top-io --top-mem --top-cpu
Terminal width too small, trimming output.
---load-avg--- --io/total- ------memory-usage----- ----total-cpu-usage---- ----most-expensive---- --most-expensive->
1m 5m 15m | read writ| used buff cach free|usr sys idl wai hiq siq| i/o process | memory process >
0.86 0.56 0.47|76.7 105 |8825M 7816k 6938M 181M| 4 1 92 3 0 0|init 16M 477k|mysqld 5789M>
0.86 0.56 0.47|1083 177 |8835M 7828k 6928M 181M| 30 4 47 19 0 1|mysqld 416k 4354k|mysqld 5789M>