參考官方文檔:https://github.com/dianping/cat/wiki/readme_server
1.數據庫相關
(1)創建數據庫cat,並執行以下sql創建相關表:
1 CREATE TABLE `dailyreport` ( 2 `id` int(11) NOT NULL AUTO_INCREMENT, 3 `name` varchar(20) NOT NULL COMMENT '報表名稱, transaction, problem...', 4 `ip` varchar(50) NOT NULL COMMENT '報表來自於哪台cat-consumer機器', 5 `domain` varchar(50) NOT NULL COMMENT '報表處理的Domain信息', 6 `period` datetime NOT NULL COMMENT '報表時間段', 7 `type` tinyint(4) NOT NULL COMMENT '報表數據格式, 1/xml, 2/json, 默認1', 8 `creation_date` datetime NOT NULL COMMENT '報表創建時間', 9 PRIMARY KEY (`id`), 10 UNIQUE KEY `period` (`period`,`domain`,`name`) 11 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='天報表'; 12 13 CREATE TABLE `weeklyreport` ( 14 `id` int(11) NOT NULL AUTO_INCREMENT, 15 `name` varchar(20) NOT NULL COMMENT '報表名稱, transaction, problem...', 16 `ip` varchar(50) NOT NULL COMMENT '報表來自於哪台cat-consumer機器', 17 `domain` varchar(50) NOT NULL COMMENT '報表處理的Domain信息', 18 `period` datetime NOT NULL COMMENT '報表時間段', 19 `type` tinyint(4) NOT NULL COMMENT '報表數據格式, 1/xml, 2/json, 默認1', 20 `creation_date` datetime NOT NULL COMMENT '報表創建時間', 21 PRIMARY KEY (`id`), 22 UNIQUE KEY `period` (`period`,`domain`,`name`) 23 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='周報表'; 24 25 CREATE TABLE `monthreport` ( 26 `id` int(11) NOT NULL AUTO_INCREMENT, 27 `name` varchar(20) NOT NULL COMMENT '報表名稱, transaction, problem...', 28 `ip` varchar(50) NOT NULL COMMENT '報表來自於哪台cat-consumer機器', 29 `domain` varchar(50) NOT NULL COMMENT '報表處理的Domain信息', 30 `period` datetime NOT NULL COMMENT '報表時間段', 31 `type` tinyint(4) NOT NULL COMMENT '報表數據格式, 1/xml, 2/json, 默認1', 32 `creation_date` datetime NOT NULL COMMENT '報表創建時間', 33 PRIMARY KEY (`id`), 34 UNIQUE KEY `period` (`period`,`domain`,`name`) 35 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='月報表'; 36 37 CREATE TABLE `hostinfo` ( 38 `id` int(11) NOT NULL AUTO_INCREMENT, 39 `ip` varchar(50) NOT NULL COMMENT '部署機器IP', 40 `domain` varchar(200) NOT NULL COMMENT '部署機器對應的項目名', 41 `hostname` varchar(200) DEFAULT NULL COMMENT '機器域名', 42 `creation_date` datetime NOT NULL, 43 `last_modified_date` datetime NOT NULL, 44 PRIMARY KEY (`id`), 45 UNIQUE KEY `ip_index` (`ip`) 46 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='IP和項目名的對應關系'; 47 48 CREATE TABLE `hourlyreport` ( 49 `id` int(11) NOT NULL AUTO_INCREMENT, 50 `type` tinyint(4) NOT NULL COMMENT '報表類型, 1/xml, 9/binary 默認1', 51 `name` varchar(20) NOT NULL COMMENT '報表名稱', 52 `ip` varchar(50) DEFAULT NULL COMMENT '報表來自於哪台機器', 53 `domain` varchar(50) NOT NULL COMMENT '報表項目', 54 `period` datetime NOT NULL COMMENT '報表時間段', 55 `creation_date` datetime NOT NULL COMMENT '報表創建時間', 56 PRIMARY KEY (`id`), 57 KEY `IX_Domain_Name_Period` (`domain`,`name`,`period`), 58 KEY `IX_Name_Period` (`name`,`period`), 59 KEY `IX_Period` (`period`) 60 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPRESSED COMMENT='用於存放實時報表信息,處理之后的結果'; 61 62 CREATE TABLE `hourly_report_content` ( 63 `report_id` int(11) NOT NULL COMMENT '報表ID', 64 `content` longblob NOT NULL COMMENT '二進制報表內容', 65 `period` datetime NOT NULL COMMENT '報表時間段', 66 `creation_date` datetime NOT NULL COMMENT '創建時間', 67 PRIMARY KEY (`report_id`), 68 KEY `IX_Period` (`period`) 69 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPRESSED COMMENT='小時報表二進制內容'; 70 71 CREATE TABLE `daily_report_content` ( 72 `report_id` int(11) NOT NULL COMMENT '報表ID', 73 `content` longblob NOT NULL COMMENT '二進制報表內容', 74 `period` datetime COMMENT '報表時間段', 75 `creation_date` datetime NOT NULL COMMENT '創建時間', 76 PRIMARY KEY (`report_id`), 77 KEY `IX_Period` (`period`) 78 )ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPRESSED COMMENT='天報表二進制內容'; 79 80 CREATE TABLE `weekly_report_content` ( 81 `report_id` int(11) NOT NULL COMMENT '報表ID', 82 `content` longblob NOT NULL COMMENT '二進制報表內容', 83 `period` datetime COMMENT '報表時間段', 84 `creation_date` datetime NOT NULL COMMENT '創建時間', 85 PRIMARY KEY (`report_id`), 86 KEY `IX_Period` (`period`) 87 )ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPRESSED COMMENT='周報表二進制內容'; 88 89 CREATE TABLE `monthly_report_content` ( 90 `report_id` int(11) NOT NULL COMMENT '報表ID', 91 `content` longblob NOT NULL COMMENT '二進制報表內容', 92 `period` datetime COMMENT '報表時間段', 93 `creation_date` datetime NOT NULL COMMENT '創建時間', 94 PRIMARY KEY (`report_id`), 95 KEY `IX_Period` (`period`) 96 )ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPRESSED COMMENT='月報表二進制內容'; 97 98 CREATE TABLE `businessReport` ( 99 `id` int(11) NOT NULL AUTO_INCREMENT, 100 `type` tinyint(4) NOT NULL COMMENT '報表類型 報表數據格式, 1/Binary, 2/xml , 3/json', 101 `name` varchar(20) NOT NULL COMMENT '報表名稱', 102 `ip` varchar(50) NOT NULL COMMENT '報表來自於哪台機器', 103 `productLine` varchar(50) NOT NULL COMMENT '指標來源於哪個產品組', 104 `period` datetime NOT NULL COMMENT '報表時間段', 105 `content` longblob COMMENT '用於存放報表的具體內容', 106 `creation_date` datetime NOT NULL COMMENT '報表創建時間', 107 PRIMARY KEY (`id`), 108 KEY `IX_Period_productLine_name` (`period`,`productLine`,`name`) 109 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPRESSED COMMENT='用於存放業務監控實時報表信息,處理之后的結果'; 110 111 CREATE TABLE `task` ( 112 `id` int(11) NOT NULL AUTO_INCREMENT, 113 `producer` varchar(20) NOT NULL COMMENT '任務創建者ip', 114 `consumer` varchar(20) NULL COMMENT '任務執行者ip', 115 `failure_count` tinyint(4) NOT NULL COMMENT '任務失敗次數', 116 `report_name` varchar(20) NOT NULL COMMENT '報表名稱, transaction, problem...', 117 `report_domain` varchar(50) NOT NULL COMMENT '報表處理的Domain信息', 118 `report_period` datetime NOT NULL COMMENT '報表時間', 119 `status` tinyint(4) NOT NULL COMMENT '執行狀態: 1/todo, 2/doing, 3/done 4/failed', 120 `task_type` tinyint(4) NOT NULL DEFAULT '1' COMMENT '0表示小時任務,1表示天任務', 121 `creation_date` datetime NOT NULL COMMENT '任務創建時間', 122 `start_date` datetime NULL COMMENT '開始時間, 這次執行開始時間', 123 `end_date` datetime NULL COMMENT '結束時間, 這次執行結束時間', 124 PRIMARY KEY (`id`), 125 UNIQUE KEY `task_period_domain_name_type` (`report_period`,`report_domain`,`report_name`,`task_type`) 126 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='后台任務'; 127 128 CREATE TABLE `project` ( 129 `id` int(11) NOT NULL AUTO_INCREMENT, 130 `domain` varchar(200) NOT NULL COMMENT '項目名稱', 131 `cmdb_domain` varchar(200) DEFAULT NULL COMMENT 'cmdb項目名稱', 132 `level` int(5) DEFAULT NULL COMMENT '項目級別', 133 `bu` varchar(50) DEFAULT NULL COMMENT 'CMDB事業部', 134 `cmdb_productline` varchar(50) DEFAULT NULL COMMENT 'CMDB產品線', 135 `owner` varchar(50) DEFAULT NULL COMMENT '項目負責人', 136 `email` longtext DEFAULT NULL COMMENT '項目組郵件', 137 `phone` longtext DEFAULT NULL COMMENT '聯系電話', 138 `creation_date` datetime DEFAULT NULL COMMENT '創建時間', 139 `modify_date` datetime DEFAULT NULL COMMENT '修改時間', 140 PRIMARY KEY (`id`), 141 UNIQUE KEY `domain` (`domain`) 142 )ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='項目基本信息'; 143 144 CREATE TABLE `topologyGraph` ( 145 `id` int(11) NOT NULL AUTO_INCREMENT, 146 `ip` varchar(50) NOT NULL COMMENT '報表來自於哪台cat-client機器ip', 147 `period` datetime NOT NULL COMMENT '報表時間段,精確到分鍾', 148 `type` tinyint(4) NOT NULL COMMENT '報表數據格式, 1/xml, 2/json, 3/binary', 149 `content` longblob COMMENT '用於存放報表的具體內容', 150 `creation_date` datetime NOT NULL COMMENT '報表創建時間', 151 PRIMARY KEY (`id`), 152 KEY `period` (`period`) 153 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用於存儲歷史的拓撲圖曲線'; 154 155 CREATE TABLE `config` ( 156 `id` int(11) NOT NULL AUTO_INCREMENT, 157 `name` varchar(50) NOT NULL COMMENT '配置名稱', 158 `content` longtext COMMENT '配置的具體內容', 159 `creation_date` datetime NOT NULL COMMENT '配置創建時間', 160 `modify_date` datetime NOT NULL COMMENT '配置修改時間', 161 PRIMARY KEY (`id`), 162 UNIQUE KEY `name` (`name`) 163 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用於存儲系統的全局配置信息'; 164 165 CREATE TABLE `baseline` ( 166 `id` int(11) NOT NULL AUTO_INCREMENT, 167 `report_name` varchar(100) DEFAULT NULL, 168 `index_key` varchar(100) DEFAULT NULL, 169 `report_period` datetime DEFAULT NULL, 170 `data` blob, 171 `creation_date` datetime DEFAULT NULL, 172 PRIMARY KEY (`id`), 173 KEY `period_name_key` (`report_period`,`report_name`,`index_key`) 174 ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 175 176 CREATE TABLE `alteration` ( 177 `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增長ID', 178 `type` varchar(64) NOT NULL COMMENT '分類', 179 `title` varchar(128) NOT NULL COMMENT '變更標題', 180 `domain` varchar(128) NOT NULL COMMENT '變更項目', 181 `hostname` varchar(128) NOT NULL COMMENT '變更機器名', 182 `ip` varchar(128) DEFAULT NULL COMMENT '變更機器IP', 183 `date` datetime NOT NULL COMMENT '變更時間', 184 `user` varchar(45) NOT NULL COMMENT '變更用戶', 185 `alt_group` varchar(45) DEFAULT NULL COMMENT '變更組別', 186 `content` longtext NOT NULL COMMENT '變更內容', 187 `url` varchar(200) DEFAULT NULL COMMENT '變更鏈接', 188 `status` tinyint(4) DEFAULT '0' COMMENT '變更狀態', 189 `creation_date` datetime NOT NULL COMMENT '數據庫創建時間', 190 PRIMARY KEY (`id`), 191 KEY `ind_date_domain_host` (`date`,`domain`,`hostname`) 192 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='變更表'; 193 194 CREATE TABLE `alert` ( 195 `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增長ID', 196 `domain` varchar(128) NOT NULL COMMENT '告警項目', 197 `alert_time` datetime NOT NULL COMMENT '告警時間', 198 `category` varchar(64) NOT NULL COMMENT '告警分類:network/business/system/exception -alert', 199 `type` varchar(64) NOT NULL COMMENT '告警類型:error/warning', 200 `content` longtext NOT NULL COMMENT '告警內容', 201 `metric` varchar(128) NOT NULL COMMENT '告警指標', 202 `creation_date` datetime NOT NULL COMMENT '數據插入時間', 203 PRIMARY KEY (`id`) 204 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='存儲告警信息'; 205 206 CREATE TABLE `alert_summary` ( 207 `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增長ID', 208 `domain` varchar(128) NOT NULL COMMENT '告警項目', 209 `alert_time` datetime NOT NULL COMMENT '告警時間', 210 `content` longtext NOT NULL COMMENT '統一告警內容', 211 `creation_date` datetime NOT NULL COMMENT '數據插入時間', 212 PRIMARY KEY (`id`) 213 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='統一告警信息'; 214 215 CREATE TABLE `operation` ( 216 `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增長ID', 217 `user` varchar(128) NOT NULL COMMENT '用戶名', 218 `module` varchar(128) NOT NULL COMMENT '模塊', 219 `operation` varchar(128) NOT NULL COMMENT '操作', 220 `time` datetime NOT NULL COMMENT '修改時間', 221 `content` longtext NOT NULL COMMENT '修改內容', 222 `creation_date` datetime NOT NULL COMMENT '數據插入時間', 223 PRIMARY KEY (`id`) 224 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用戶操作日志'; 225 226 CREATE TABLE `overload` ( 227 `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增長ID', 228 `report_id` int(11) NOT NULL COMMENT '報告id', 229 `report_type` tinyint(4) NOT NULL COMMENT '報告類型 1:hourly 2:daily 3:weekly 4:monthly', 230 `report_size` double NOT NULL COMMENT '報告大小 單位MB', 231 `period` datetime NOT NULL COMMENT '報表時間', 232 `creation_date` datetime NOT NULL COMMENT '創建時間', 233 PRIMARY KEY (`id`), 234 KEY `period` (`period`) 235 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='過大容量表'; 236 237 CREATE TABLE `config_modification` ( 238 `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增長ID', 239 `user_name` varchar(64) NOT NULL COMMENT '用戶名', 240 `account_name` varchar(64) NOT NULL COMMENT '賬戶名', 241 `action_name` varchar(64) NOT NULL COMMENT 'action名', 242 `argument` longtext COMMENT '參數內容', 243 `date` datetime NOT NULL COMMENT '修改時間', 244 `creation_date` datetime NOT NULL COMMENT '創建時間', 245 PRIMARY KEY (`id`) 246 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='配置修改記錄表'; 247 248 CREATE TABLE `user_define_rule` ( 249 `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增長ID', 250 `content` text NOT NULL COMMENT '用戶定義規則', 251 `creation_date` datetime NOT NULL COMMENT '創建時間', 252 PRIMARY KEY (`id`) 253 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用戶定義規則表'; 254 255 CREATE TABLE `business_config` ( 256 `id` int(11) NOT NULL AUTO_INCREMENT, 257 `name` varchar(20) NOT NULL DEFAULT '' COMMENT '配置名稱', 258 `domain` varchar(50) NOT NULL DEFAULT '' COMMENT '項目', 259 `content` longtext COMMENT '配置內容', 260 `updatetime` datetime NOT NULL, 261 PRIMARY KEY (`id`), 262 KEY `updatetime` (`updatetime`), 263 KEY `name_domain` (`name`,`domain`) 264 ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 265 266 CREATE TABLE `metric_screen` ( 267 `id` int(11) NOT NULL AUTO_INCREMENT, 268 `name` varchar(50) NOT NULL COMMENT '配置名稱', 269 `graph_name` varchar(50) NOT NULL DEFAULT '' COMMENT 'Graph名稱', 270 `view` varchar(50) NOT NULL DEFAULT '' COMMENT '視角', 271 `endPoints` longtext NOT NULL, 272 `measurements` longtext NOT NULL COMMENT '配置的指標', 273 `content` longtext NOT NULL COMMENT '配置的具體內容', 274 `creation_date` datetime NOT NULL COMMENT '配置創建時間', 275 `updatetime` datetime NOT NULL COMMENT '配置修改時間', 276 PRIMARY KEY (`id`), 277 UNIQUE KEY `name_graph` (`name`,`graph_name`) 278 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='系統監控的screen配置'; 279 280 CREATE TABLE `metric_graph` ( 281 `id` int(11) NOT NULL AUTO_INCREMENT, 282 `graph_id` int(11) NOT NULL COMMENT '大盤ID', 283 `name` varchar(50) NOT NULL COMMENT '配置ID', 284 `content` longtext COMMENT '配置的具體內容', 285 `creation_date` datetime NOT NULL COMMENT '配置創建時間', 286 `updatetime` datetime NOT NULL COMMENT '配置修改時間', 287 PRIMARY KEY (`id`), 288 UNIQUE `name` (`name`) 289 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='系統監控的graph配置'; 290 291 CREATE TABLE `server_alarm_rule` ( 292 `id` int(11) NOT NULL AUTO_INCREMENT, 293 `category` varchar(50) NOT NULL COMMENT '監控分類', 294 `endPoint` varchar(200) NOT NULL COMMENT '監控對象ID', 295 `measurement` varchar(200) NOT NULL COMMENT '監控指標', 296 `tags` varchar(200) NOT NULL DEFAULT '' COMMENT '監控指標標簽', 297 `content` longtext NOT NULL COMMENT '配置的具體內容', 298 `type` varchar(20) NOT NULL DEFAULT '' COMMENT '數據聚合方式', 299 `creator` varchar(100) DEFAULT '' COMMENT '創建人', 300 `creation_date` datetime NOT NULL COMMENT '配置創建時間', 301 `updatetime` datetime NOT NULL COMMENT '配置修改時間', 302 PRIMARY KEY (`id`), 303 KEY `updatetime` (`updatetime`) 304 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='系統告警的配置';
(2)一套獨立的CAT集群只需要一個數據庫;
(3)數據庫編碼使用utf8mb4,否則可能造成中文亂碼等問題;
2.服務端部署
(1)下載Tomcat服務器,如:https://tomcat.apache.org/download-80.cgi
(2)下載cat.war包,由於依賴問題,個人建議直接下載官網打好包的cat-home-3.0.0.war,然后重命名為cat.war,下載地址:http://unidal.org/nexus/service/local/repositories/releases/content/com/dianping/cat/cat-home/3.0.0/cat-home-3.0.0.war
(3)將cat.war放到解壓后的Tomcat的webapps目錄下
3.服務端配置
(1)創建相關目錄並賦權限,並在/data/appdatas/cat目錄下新建client.xml,server.xml,datasources.xml配置文件
mkdir -p /data/{appdatas,applogs}/cat
chmod -R 777 /data
(2)datasources.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 3 <data-sources> 4 <data-source id="cat"> 5 <maximum-pool-size>3</maximum-pool-size> 6 <connection-timeout>1s</connection-timeout> 7 <idle-timeout>10m</idle-timeout> 8 <statement-cache-size>1000</statement-cache-size> 9 <properties> 10 <driver>com.mysql.jdbc.Driver</driver> 11 <url><![CDATA[jdbc:mysql://192.168.0.1:3306/cat]]></url> <!-- 請替換為真實數據庫URL及Port --> 12 <user>test</user> 13 <password>test</password> 14 <connectionProperties><![CDATA[useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&socketTimeout=120000]]></connectionProperties> 15 </properties> 16 </data-source> 17 </data-sources>
(3)server.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 <!-- Configuration for development environment--> 3 <config local-mode="false" hdfs-machine="false" job-machine="true" alert-machine="true"> 4 <storage local-base-dir="/data/appdatas/cat/bucket/" max-hdfs-storage-time="15" local-report-storage-time="7" local-logivew-storage-time="7"> 5 </storage> 6 <console default-domain="Cat" show-cat-domain="true"> 7 <!--將172.16.90.114修改為部署CAT的內網IP,請不要寫127.0.0.1和外網IP --> 8 <remote-servers>10.223.123.221:8080</remote-servers> 9 </console> 10 </config>
(4)client.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 <config mode="client" xmlns:xsi="http://www.w3.org/2001/XMLSchema" xsi:noNamespaceSchemaLocation="config.xsd"> 3 <servers> 4 <!-- ip:部署CAT應用的服務器IP 5 port:CAT服務端接收客戶端數據的端口(不允許更改) 6 http-port:CAT應用部署到的容器的端口(tomcat的端口) 7 <servers> 8 <server ip="192.168.126.101" port="2280" http-port="8080" /> 9 <server ip="192.168.126.102" port="2280" http-port="8080" /> 10 <server ip="192.168.126.103" port="2280" http-port="8080" /> 11 </servers> 12 --> 13 14 <server ip="10.223.123.221" port="2280" http-port="8080" /> 15 </servers> 16 </config>
4.重算客戶端路由
(1)啟動Tomcat,訪問http://10.223.123.221:8080/cat/s/config?op=routerConfigUpdate

1 <?xml version="1.0" encoding="utf-8"?> 2 <router-config backup-server="部署CAT的服務器內網ip" backup-server-port="2280"> 3 <default-server id="部署CAT的服務器內網ip" weight="1.0" port="2280" enable="true"/> 4 <network-policy id="default" title="默認" block="false" server-group="default_group"> 5 </network-policy> 6 </router-config>
點擊提交按鈕,然后點擊重算路由按鈕,就緒后重啟Tomcat即可(測試不重啟Tomcat也能生效)
訪問http://10.223.123.221:8080/cat/r,如果顯示下圖則表示服務端部署成功

如果顯示“有問題的CAT服務器[ip]”,請核查一下配置文件以及客戶端路由中,都修改為內網ip。
5.客戶端springboot集成
(1)在項目的同一個盤符下創建client.xml配置文件和日志目錄,文件結構與服務端一致即可,ip改為cat服務端對應的IP,內容如下:
<?xml version="1.0" encoding="utf-8"?> <config mode="client" xmlns:xsi="http://www.w3.org/2001/XMLSchema" xsi:noNamespaceSchemaLocation="config.xsd"> <servers> <!-- ip:部署CAT應用的服務器IP port:CAT服務端接收客戶端數據的端口(不允許更改) http-port:CAT應用部署到的容器的端口(tomcat的端口) <servers> <server ip="192.168.126.101" port="2280" http-port="8080" /> <server ip="192.168.126.102" port="2280" http-port="8080" /> <server ip="192.168.126.103" port="2280" http-port="8080" /> </servers> --> <server ip="10.223.123.221" port="2280" http-port="8080" /> </servers> </config>
(2)下載cat-client依賴包,安裝到本地maven倉庫:
先打開該網址:https://mvnrepository.com/artifact/com.dianping.cat/cat-client/3.0.0===》http://unidal.org/nexus/content/repositories/releases/然后即可下載需要的jar包

本人在測試過程中,發現maven依賴的方式下載不下來,固直接下載jar包下來安裝到本地倉庫:http://unidal.org/nexus/content/repositories/releases/com/dianping/cat/cat-client/3.0.0/cat-client-3.0.0.jar
需要下載如下圖cat-client-3.0.0.jar,cat-core-3.0.0.jar按理說可以不要,我做測試的時候安裝了,應該沒有影響:

執行命令安裝:mvn install:install-file -Dfile=cat-client-3.0.0.jar -DgroupId=com.dianping.cat -DartifactId=cat-client -Dversion=3.0.0 -Dpackaging=jar

這樣就能在springboot項目中進行依賴了。
(3)項目配置和埋點

1 public List<UrlModel> fetchUrls(int limitCount, Set<Long> taskIds) { 2 Transaction t = Cat.newTransaction("DistributedSpiderApiImpl", "fetchUrls"); 3 Event event = Cat.newEvent("fetchUrlsEvent", "fetchUrlsQPS"); 4 List<UrlModel> urlModelList = null; 5 try { 6 urlModelList = businessCode(limitCount, taskIds); 7 event.setSuccessStatus(); 8 t.setStatus(Transaction.SUCCESS); 9 } catch (Exception e) { 10 event.setStatus("False"); 11 t.setStatus(e); 12 Cat.logError(e); 13 } finally { 14 event.complete(); 15 t.complete(); 16 } 17 return urlModelList; 18 }

看看效果:



6.集群搭建
(1)配置文件都改為集群的配置,共用一個mysql,datasources.xml文件每個集群機器都要放一份;
(2)server.xml配置
<?xml version="1.0" encoding="utf-8"?> <!-- Configuration for development environment--> <config local-mode="false" hdfs-machine="false" job-machine="true" alert-machine="true"> <storage local-base-dir="/data/appdatas/cat/bucket/" max-hdfs-storage-time="15" local-report-storage-time="7" local-logivew-storage-time="7"></storage> <console default-domain="Cat" show-cat-domain="true"> <remote-servers>10.126.0.119:8080,10.126.0.120:8080,10.126.0.130:8080</remote-servers> </console> </config>
(3)client.xml
<?xml version="1.0" encoding="utf-8"?> <config mode="client" xmlns:xsi="http://www.w3.org/2001/XMLSchema" xsi:noNamespaceSchemaLocation="config.xsd"> <!-- ip:部署CAT應用的服務器IP port:CAT服務端接收客戶端數據的端口(不允許更改) http-port:CAT應用部署到的容器的端口(tomcat的端口)--> <servers> <server ip="10.126.0.119" port="2280" http-port="8080" /> <server ip="10.126.0.120" port="2280" http-port="8080" /> <server ip="10.126.0.130" port="2280" http-port="8080" /> </servers> </config>
(4)客戶端路由配置
<?xml version="1.0" encoding="utf-8"?> <router-config backup-server="10.126.0.119" backup-server-port="2280"> <default-server id="10.126.0.119" weight="1.0" port="2280" enable="false"/> <default-server id="10.126.0.120" weight="1.0" port="2280" enable="true"/> <default-server id="10.126.0.130" weight="1.0" port="2280" enable="true"/> <network-policy id="default" title="default" block="false" server-group="default_group"></network-policy> <server-group id="default_group" title="default-group"> <group-server id="10.126.0.120"/> <group-server id="10.126.0.130"/> </server-group> </router-config>
(5)服務端配置,主要是配置remote-servers : 定義HTTP服務列表,(遠程監聽端同步更新服務端信息即取此值)http://10.126.0.130:8080/cat/s/config?op=serverConfigUpdate

<?xml version="1.0" encoding="utf-8"?> <server-config> <server id="default"> <properties> <property name="local-mode" value="false"/> <property name="job-machine" value="false"/> <property name="send-machine" value="false"/> <property name="alarm-machine" value="false"/> <property name="hdfs-enabled" value="false"/> <property name="remote-servers" value="10.126.0.119:8080,10.126.0.120:8080,10.126.0.130:8080"/> </properties> <storage local-base-dir="/data/appdatas/cat/bucket/" max-hdfs-storage-time="15" local-report-storage-time="2" local-logivew-storage-time="1" har-mode="true" upload-thread="5"> <hdfs id="dump" max-size="128M" server-uri="hdfs://127.0.0.1/" base-dir="/user/cat/dump"/> <harfs id="dump" max-size="128M" server-uri="har://127.0.0.1/" base-dir="/user/cat/dump"/> <properties> <property name="hadoop.security.authentication" value="false"/> <property name="dfs.namenode.kerberos.principal" value="hadoop/dev80.hadoop@testserver.com"/> <property name="dfs.cat.kerberos.principal" value="cat@testserver.com"/> <property name="dfs.cat.keytab.file" value="/data/appdatas/cat/cat.keytab"/> <property name="java.security.krb5.realm" value="value1"/> <property name="java.security.krb5.kdc" value="value2"/> </properties> </storage> <consumer> <long-config default-url-threshold="1000" default-sql-threshold="100" default-service-threshold="50"> <domain name="cat" url-threshold="500" sql-threshold="500"/> <domain name="OpenPlatformWeb" url-threshold="100" sql-threshold="500"/> </long-config> </consumer> </server> <server id="10.126.0.119"> <properties> <property name="job-machine" value="true"/> <property name="send-machine" value="true"/> <property name="alarm-machine" value="true"/> </properties> </server> </server-config>
集群效果圖如下:

