最簡(jiǎn)單的網(wǎng)站制作360指數(shù)官網(wǎng)
目錄
使用 web? API
API使用簡(jiǎn)單舉例
查看所有的API
實(shí)例 JSON 詳解
API使用舉例
使用 web? API
orchestrator
提供精心設(shè)計(jì)的 Web API。
敏銳的 Web 開發(fā)人員會(huì)注意到(通過(guò)Firebug or Developer Tools)Web 界面如何完全依賴于 JSON API 請(qǐng)求。
開發(fā)人員可以使用 API 來(lái)實(shí)現(xiàn)自動(dòng)化。
API使用簡(jiǎn)單舉例
舉例來(lái)說(shuō):
/api/instance/:host/:port
:讀取并返回實(shí)例的詳細(xì)信息(示例/api/instance/mysql10/3306
)/api/discover/:host/:port
:發(fā)現(xiàn)給定實(shí)例(正在運(yùn)行的orchestrator
服務(wù)將從那里獲取它并遞歸掃描整個(gè)拓?fù)?#xff09;/api/relocate/:host/:port/:belowHost/:belowPort
(嘗試)將一個(gè)實(shí)例移動(dòng)到另一個(gè)實(shí)例下方。?orchestrator
選擇最佳行動(dòng)方案。/api/relocate-replicas/:host/:port/:belowHost/:belowPort
(嘗試)將一個(gè)實(shí)例的副本移動(dòng)到另一個(gè)實(shí)例下方。?orchestrator
選擇最佳行動(dòng)方案。/api/recover/:host/:post
:假設(shè)有需要恢復(fù)的內(nèi)容,在給定實(shí)例上啟動(dòng)恢復(fù)。/api/force-master-failover/:mycluster
:強(qiáng)制在給定集群上立即進(jìn)行故障轉(zhuǎn)移。
查看所有的API
事實(shí)上的列表是代碼,請(qǐng)參閱api.go(向下滾動(dòng)到?RegisterRequests
)。
您可能還會(huì)喜歡查看Orchestrator-client(源代碼)以了解命令行如何轉(zhuǎn)換為 API 調(diào)用。
或者,只需使用Orchestrator-client作為您的 API 客戶端,這就是它的用途。
實(shí)例 JSON 詳解
許多 API 調(diào)用返回?instance?對(duì)象,描述單個(gè) MySQL 服務(wù)器。該示例后面是字段細(xì)分:
{"Key": {"Hostname": "mysql.02.instance.com","Port": 3306},"Uptime": 45,"ServerID": 101,"Version": "5.6.22-log","ReadOnly": false,"Binlog_format": "ROW","LogBinEnabled": true,"LogReplicationUpdatesEnabled": true,"SelfBinlogCoordinates": {"LogFile": "mysql-bin.015656","LogPos": 15082,"Type": 0},"MasterKey": {"Hostname": "mysql.01.instance.com","Port": 3306},"ReplicationSQLThreadRuning": true,"ReplicationIOThreadRuning": true,"HasReplicationFilters": false,"SupportsOracleGTID": true,"UsingOracleGTID": true,"UsingMariaDBGTID": false,"UsingPseudoGTID": false,"ReadBinlogCoordinates": {"LogFile": "mysql-bin.015993","LogPos": 20146,"Type": 0},"ExecBinlogCoordinates": {"LogFile": "mysql-bin.015993","LogPos": 20146,"Type": 0},"RelaylogCoordinates": {"LogFile": "mysql_sandbox21088-relay-bin.000051","LogPos": 16769,"Type": 1},"LastSQLError": "","LastIOError": "","SecondsBehindMaster": {"Int64": 0,"Valid": true},"SQLDelay": 0,"ExecutedGtidSet": "230ea8ea-81e3-11e4-972a-e25ec4bd140a:1-49","ReplicationLagSeconds": {"Int64": 0,"Valid": true},"Replicas": [ ],"ClusterName": "mysql.01.instance.com:3306","DataCenter": "","PhysicalEnvironment": "","ReplicationDepth": 1,"IsCoMaster": false,"IsLastCheckValid": true,"IsUpToDate": true,"IsRecentlyChecked": true,"SecondsSinceLastSeen": {"Int64": 9,"Valid": true},"CountMySQLSnapshots": 0,"IsCandidate": false,"UnresolvedHostname": ""
}
實(shí)例的結(jié)構(gòu)不斷發(fā)展,而文檔總是會(huì)落后。話雖如此,關(guān)鍵屬性是:
Key
:實(shí)例的唯一指示符:主機(jī)和端口的組合ServerID
:MySQLserver_id
參數(shù)Version
:MySQL版本ReadOnly
:全局read_only
布爾值Binlog_format
:MySQL 全局參數(shù)binlog_format
LogBinEnabled
:是否啟用二進(jìn)制日志LogReplicationUpdatesEnabled
:MySQL參數(shù)是否log_slave_updates
啟用SelfBinlogCoordinates
:二進(jìn)制日志文件和此實(shí)例寫入的位置(如SHOW MASTER STATUS
)MasterKey
:主機(jī)名和端口(如果有)ReplicationSQLThreadRuning
: 直接映射自SHOW SLAVE STATUS
'sSlave_SQL_Running
ReplicationIOThreadRuning
: 直接映射自SHOW SLAVE STATUS
'sSlave_IO_Running
HasReplicationFilters
: true 如果有任何復(fù)制過(guò)濾器SupportsOracleGTID
:如果配置為 true?gtid_mode
(Oracle MySQL >= 5.6)UsingOracleGTID
:如果副本通過(guò) Oracle GTID 復(fù)制,則為 trueUsingMariaDBGTID
:如果副本通過(guò) MariaDB GTID 復(fù)制,則為 trueUsingPseudoGTID
:如果已知副本具有偽 GTID 坐標(biāo),則為 true(請(qǐng)參閱相關(guān)DetectPseudoGTIDQuery
配置)ReadBinlogCoordinates
:(復(fù)制時(shí))從主機(jī)讀取的坐標(biāo)(輪詢的內(nèi)容IO_THREAD
)ExecBinlogCoordinates
:(復(fù)制時(shí))現(xiàn)在正在執(zhí)行的master坐標(biāo)(SQL_THREAD
執(zhí)行了什么)RelaylogCoordinates
:(復(fù)制時(shí))當(dāng)前正在執(zhí)行的中繼日志的坐標(biāo)LastSQLError
: 復(fù)制自SHOW SLAVE STATUS
LastIOError
: 復(fù)制自SHOW SLAVE STATUS
SecondsBehindMaster
: 直接從SHOW SLAVE STATUS
' 映射Seconds_Behind_Master
?"Valid": false
表示 aNULL
SQLDelay
: 配置的MASTER_DELAY
ExecutedGtidSet
:如果使用Oracle GTID,執(zhí)行的GTID集ReplicationLagSeconds
:如果ReplicationLagQuery
提供,計(jì)算出的副本滯后;否則與SecondsBehindMaster
Replicas
:MySQL 副本主機(jī)名和端口列表)ClusterName
:與該實(shí)例關(guān)聯(lián)的集群的名稱;唯一標(biāo)識(shí)簇DataCenter
:(元數(shù)據(jù))數(shù)據(jù)中心的名稱,由DataCenterPattern
配置變量推斷PhysicalEnvironment
:(元數(shù)據(jù))環(huán)境名稱,由PhysicalEnvironmentPattern
配置變量推斷ReplicationDepth
:與master的距離(master是0
,直接副本是1
等等)IsCoMaster
:當(dāng)此實(shí)例是主-主對(duì)的一部分時(shí)為 trueIsLastCheckValid
:最后一次嘗試讀取此瞬間是否成功IsUpToDate
:該數(shù)據(jù)是否是最新的IsRecentlyChecked
:最近是否對(duì)此實(shí)例進(jìn)行了讀取嘗試SecondsSinceLastSeen
:自上次成功訪問(wèn)此實(shí)例以來(lái)經(jīng)過(guò)的時(shí)間CountMySQLSnapshots
:已知快照數(shù)量(數(shù)據(jù)由 提供orchestrator-agent
)IsCandidate
:(元數(shù)據(jù))true
當(dāng)該實(shí)例已通過(guò)CLI 命令標(biāo)記為候選實(shí)例register-candidate
時(shí)??捎糜诒罎⒒謴?fù)以優(yōu)先考慮故障轉(zhuǎn)移選項(xiàng)UnresolvedHostname
:此主機(jī)未解析的register-hostname-unresolve
名稱,如CLI 命令所示
API使用舉例
- 獲取有關(guān)集群的一般信息:
curl -s "http://my.orchestrator.service.com/api/cluster-info/my_cluster" | jq .{"ClusterName": "my-cluster-fqdn:3306","ClusterAlias": "my_cluster","ClusterDomain": "my-cluster.com","CountInstances": 10,"HeuristicLag": 0,"HasAutomatedMasterRecovery": true,"HasAutomatedIntermediateMasterRecovery": true
}
- 查找
my_cluster
沒有二進(jìn)制日志記錄的主機(jī):
curl -s "http://my.orchestrator.service.com/api/cluster/alias/my_cluster" | jq '.[] | select(.LogBinEnabled==false) .Key.Hostname' -r
my_cluster
找到的 master的直接副本:
curl -s "http://my.orchestrator.service.com/api/cluster/alias/my_cluster" | jq '.[] | select(.ReplicationDepth==1) .Key.Hostname' -r
或者:
master=$(curl -s "http://my.orchestrator.service.com/api/cluster-info/my_cluster" | jq '.ClusterName' | tr ':' '/')
curl -s "http://my.orchestrator.service.com/api/instance-replicas/${master}" | jq '.[] | .Key.Hostname' -r
- 查找所有中級(jí)大師
my_cluster
:
curl -s "http://my.orchestrator.service.com/api/cluster/alias/my_cluster" | jq '.[] | select(.MasterKey.Hostname!="") | select(.Replicas!=[]) .Key.Hostname'