CAT部署.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. 1. 构建CAT war包
  2. 在CAT目录下,用maven构建项目
  3. mvn clean install –DskipTests
  4. 2. 创建CAT库表
  5. 新建cat数据库并执行源码/source/cat/script/Cat.sql脚本完成表结构的创建。
  6. 3. 配置文件:
  7. 拷贝client.xml、server.xml、datasources.xml文件到/data/appdatas/cat/目录中
  8. Cat服务端配置
  9. A、 客户端配置
  10. 打开/data/appdatas/cat/client.xml客户端配置文件
  11. <?xml version="1.0" encoding="utf-8"?>
  12. <config mode="client" xmlns:xsi="http://www.w3.org/2001/XMLSchema" xsi:noNamespaceSchemaLocation="config.xsd">
  13. <servers>
  14. <!-- Local mode for development -->
  15. <server ip="172.16.136.143" port="2280" http-port="8999" />
  16. <server ip="172.16.114.114" port="2280" http-port="8999" />
  17. </servers>
  18. </config>
  19. 配置说明:
  20. * mode : 定义配置模式,固定值为client;--暂未使用
  21. * servers : 定义多个服务端信息;
  22. * server : 定义某个服务端信息;
  23. * ip : 配置服务端(cat-home)对外IP地址
  24. * port : 配置服务端(cat-home)对外TCP协议开启端口,固定值为2280;
  25. * http-port : 配置服务端(cat-home)对外HTTP协议开启端口, 如:tomcat默认是8080端口,若未指定,默认为8080端口;
  26. B、 数据库配置
  27. 打开/data/appdatas/cat/datasources.xml数据库配置文件
  28. <?xml version="1.0" encoding="utf-8"?>
  29. <data-sources>
  30. <data-source id="cat">
  31. <maximum-pool-size>3</maximum-pool-size>
  32. <connection-timeout>1s</connection-timeout>
  33. <idle-timeout>10m</idle-timeout>
  34. <statement-cache-size>1000</statement-cache-size>
  35. <properties>
  36. <driver>com.mysql.jdbc.Driver</driver>
  37. <url><![CDATA[jdbc:mysql://mysql.rds.aliyuncs.com:3306/cat]]></url>
  38. <user>rw</user>
  39. <password>111</password>
  40. <connectionProperties><![CDATA[useUnicode=true&characterEncoding=UTF-8&autoReconnect=true]]></connectionProperties>
  41. </properties>
  42. </data-source>
  43. <data-source id="app">
  44. <maximum-pool-size>3</maximum-pool-size>
  45. <connection-timeout>1s</connection-timeout>
  46. <idle-timeout>10m</idle-timeout>
  47. <statement-cache-size>1000</statement-cache-size>
  48. <properties>
  49. <driver>com.mysql.jdbc.Driver</driver>
  50. <url><![CDATA[jdbc:mysql://mysql.rds.aliyuncs.com:3306/cat]]></url>
  51. <user>rw</user>
  52. <password>222</password>
  53. <connectionProperties><![CDATA[useUnicode=true&characterEncoding=UTF-8&autoReconnect=true]]></connectionProperties>
  54. </properties>
  55. </data-source>
  56. </data-sources>
  57. 配置说明:
  58. * 生成配置文件时,输入的数据库连接信息已写入此文件,如不换数据库,不用做任何修改
  59. * 主要修改:url(数据库连接地址)、user(数据库用户名)、password(数据用户登录密码)
  60. C、 服务端服务配置
  61. 打开/data/appdatas/cat/server.xml服务端服务配置文件
  62. <?xml version="1.0" encoding="utf-8"?>
  63. <!-- Configuration for development environment-->
  64. <config local-mode="false" hdfs-machine="false" job-machine="true" alert-machine="true">
  65. <storage local-base-dir="/data/appdatas/cat/bucket/" max-hdfs-storage-time="15" local-report-storage-time="7" local-logivew-storage-time="7">
  66. </storage>
  67. <console default-domain="Cat" show-cat-domain="true">
  68. <remote-servers>172.16.29.225:8999, 172.16.136.143:8999, 172.16.114.114:8999</remote-servers>
  69. </console>
  70. <ldap ldapUrl="ldap://192.168.50.11:389/DC=dianpingoa,DC=com"/>
  71. </config>
  72. 配置说明:
  73. * local-mode : 定义服务是否为本地模式(开发模式),在生成环境时,设置为false,启动远程监听模式。默认为 false;(示例为报警报告机配置)
  74. * hdfs-machine : 定义是否启用HDFS存储方式,默认为 false;
  75. * job-machine : 定义当前服务是否为报告工作机(开启生成汇总报告和统计报告的任务,只需要一台服务机开启此功能),默认为 false;
  76. * alert-machine : 定义当前服务是否为报警机(开启各类报警监听,只需要一台服务机开启此功能),默认为 false;
  77. * storage : 定义数据存储配置信息
  78. * local-report-storage-time : 定义本地报告存放时长,单位为(天)
  79. * local-logivew-storage-time : 定义本地日志存放时长,单位为(天)
  80. * local-base-dir : 定义本地数据存储目录
  81. * hdfs : 定义HDFS配置信息,便于直接登录系统
  82. * server-uri : 定义HDFS服务地址
  83. * console : 定义服务控制台信息
  84. * remote-servers : 定义HTTP服务列表,(远程监听端同步更新服务端信息即取此值)
  85. * ldap : 定义LDAP配置信息
  86. * ldapUrl : 定义LDAP服务地址
  87. 4. 拷贝监控系统源码/source/cat/cat-home/target/目录下的cat-alpha-1.3.3.war到web应用服务器的发布目录
  88. (如:$TOMCAT_HOME$/webapps/),并修改war包名称为cat.war
  89. 5. 启动应用服务器,如tomcat
  90. 6. 登录CAT HOME系统,修改配置
  91. A、修改路由配置
  92. 选择‘配置-->全局警告配置–>客户端路由’,
  93. 或者在浏览器地址栏中直接输入http:/172.16.29.225:8999/cat/s/config?op=routerConfigUpdate,打开客户端路由配置界面
  94. <?xml version="1.0" encoding="utf-8"?>
  95. <router-config backup-server="172.16.29.225" backup-server-port="2280">
  96. <default-server id="172.16.136.143" weight="1.0" port="2280" enable="true"/>
  97. <default-server id="172.16.114.114" weight="1.0" port="2280" enable="true"/>
  98. </router-config>
  99. 配置说明:
  100. * 把backup-server设置为当前服务器对外IP地址,端口固定为2280;
  101. * default-server定义可跳转的路由地址,可以设置多个。default-server的id属性配置可路由的cat-home服务IP地址,端口固定为2280;若需要禁用路由地址,可把enable设置为false。
  102. * 点击“提交”按钮,保存修改的路由配置
  103. B、修改告警服务端配置
  104. 选择‘配置-->全局警告配置–>告警服务端’,
  105. 或者在浏览器地址栏中直接输入http:/172.16.29.225:8999/cat/s/config?op=alertSenderConfigUpdate,打开客户端路由配置界面
  106. 删除默认sender-config配置,点击“提交”按钮,保存修改
  107. <?xml version="1.0" encoding="utf-8"?>
  108. <sender-config>
  109. </sender-config>
  110. C、修改Ping告警配置
  111. 选择‘配置-->应用监控配置–>ping告警配置’,
  112. 或者在浏览器地址栏中直接输入http:/172.16.29.225:8999/cat/s/config?op=thirdPartyRuleConfigs,打开客户端路由配置界面
  113. 删除默认url (http监控)配置
  114. 7.部署其他监控集群
  115. A. 拷贝运行正常的CAT机器/data/appdatas/cat/目录中client.xml、server.xml、datasources.xml三个配置文件到监控机相同目录中
  116. B. 修改server.xml配置中的 job-machine 和 alert-machine属性,都设置为false,禁用生成报告和报警功能,只开启监听功能
  117. C. 拷贝cat.war到其他监控集群
  118. D. 启动应用服务器,开启cat服务,完成服务端的配置及启动
  119. Cat客户端配置
  120. 1. 配置app.properties文件
  121. 在resources资源文件META-INF下新建app.properties,注意是src/main/resources/META-INF/文件夹。
  122. 内容如:app.name=${appName};appName表示项目名
  123. 2. 配置客户端文件,拷贝client.xml文件
  124. A、Linux\Mac 到/data/appdatas/cat下
  125. B、Windows 到系统运行盘的根目录/data/appdatas/cat下
  126. 打开/data/appdatas/cat/client.xml客户端配置文件
  127. <?xml version="1.0" encoding="utf-8"?>
  128. <config mode="client" xmlns:xsi="http://www.w3.org/2001/XMLSchema" xsi:noNamespaceSchemaLocation="config.xsd">
  129. <servers>
  130. <!-- Local mode for development -->
  131. <server ip="10.1.5.87" port="2280" http-port="8999" />
  132. <!-- If under production environment, put actual server address as list. -->
  133. <!--
  134. <server ip="192.168.7.71" port="2280" />
  135. <server ip="192.168.7.72" port="2280" />
  136. -->
  137. </servers>
  138. </config>
  139. 配置说明:
  140. * servers : 定义多个服务端信息;
  141. * server : 定义某个服务端信息;
  142. * ip : 配置服务端(cat-home)对外IP地址
  143. * port : 配置服务端(cat-home)对外TCP协议开启端口,固定值为2280;
  144. * http-port : 配置服务端(cat-home)对外HTTP协议开启端口, 如:tomcat默认是8080端口,若未指定,默认为8080端口;
  145. Cat监控机配置
  146. 在/data/appdatas/cat下,配置client.xml
  147. <?xml version="1.0" encoding="utf-8"?>
  148. <config mode="client" xmlns:xsi="http://www.w3.org/2001/XMLSchema" xsi:noNamespaceSchemaLocation="config.xsd">
  149. <servers>
  150. <server ip="172.16.29.225" port="2280" http-port="8999" />
  151. <server ip="172.16.136.143" port="2280" http-port="8999" />
  152. <server ip="172.16.114.114" port="2280" http-port="8999" />
  153. <server ip="10.2.221.153" port="2280" http-port="8999" />
  154. <server ip="172.16.6.43" port="2280" http-port="8999" />
  155. <server ip="172.16.3.11" port="2280" http-port="8999" />
  156. <!-- If under production environment, put actual server address as list. -->
  157. </servers>
  158. </config>
  159. 系统集成CAT及埋点实现
  160. 1、如果是web项目,可添加filter到web.xml,该filter已经对URL请求做了大部分的埋点工作。
  161. <filter>
  162. <filter-name>cat-filter</filter-name>
  163. <filter-class>com.dianping.cat.servlet.CatFilter</filter-class>
  164. </filter>
  165. <filter-mapping>
  166. <filter-name>cat-filter</filter-name>
  167. <url-pattern>/*</url-pattern>
  168. <dispatcher>REQUEST</dispatcher>
  169. <dispatcher>FORWARD</dispatcher>
  170. </filter-mapping>
  171. 2、配置pom.xml导入jar包
  172. <dependency>
  173. <groupId>com.dianping.cat</groupId>
  174. <artifactId>cat-client</artifactId>
  175. <version>2.0.0</version>
  176. </dependency>
  177. 目前针对业务已经实现的CAT埋点监控包括以下三种形式:
  178. 1、SQL埋点
  179. A、配置mybatis-config文件,插入Mybatis Plugin
  180. <!--mybatis + cat interceptor -->
  181. <plugin interceptor="com.test.center.util.aspect.CatMybatisInterceptor">
  182. <property name="datasourceUrl" value="${center.jdbc.url}"/>
  183. </plugin>
  184. B、实现CatMybatisInterceptor类,详见com.test.center.util.aspect.CatMybatisInterceptor
  185. 2、Cache埋点
  186. 实现CatAspect类,详见com.test.center.util.aspect.CatAspect
  187. 3、 Dubbo集成
  188. 配置pom.xml导入Dubbo jar包
  189. <dependency>
  190. <groupId>com.alibaba</groupId>
  191. <artifactId>dubbo</artifactId>
  192. <version>2.5.4_cat-SNAPSHOT</version>
  193. </dependency>
  194. 4、 API Sample,详见com.dianping.cat.Cat
  195. 5、 基于注解CAT URL聚合
  196. 以切面方式进行动态URL聚合,降低CAT服务压力,具体如下:
  197. A、CatAspect类中添加切面方法
  198. @After("@annotation(catHttpRequestTransaction)")
  199. public void catHttpRequestProcess(CatHttpRequestTransaction catHttpRequestTransaction) {
  200. HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
  201. if(StringUtils.hasText(catHttpRequestTransaction.name())){
  202. String transName = catHttpRequestTransaction.name();
  203. request.setAttribute("cat-page-uri", transName);
  204. }
  205. }
  206. B、新建注解类CatHttpRequestTransaction
  207. @Retention(RetentionPolicy.RUNTIME)
  208. @Target(ElementType.METHOD)
  209. public @interface CatHttpRequestTransaction {
  210. String name() default "";
  211. String type() default "URL";
  212. }
  213. C、在聚合的controller请求上添加注解,如下所示