Pinpoint - 應用性能管理(APM)平臺實踐之部署篇

0.0 前言html

國內的APM行業這兩年剛剛起步,可是在國外卻比較成熟了,而且因爲這兩年人力成本的快速提升,國內外涌現了幾家很是不錯的APM企業,例如APPdynamic,Dynamic,NewRelic等。java

咱們這裏不考慮商業化的實現方案,如何可以提供一種免費的開源實現方案呢?linux

下面給你們介紹一個開源的 APM (Application Performance Management/應用性能管理)工具 - Pinpoint。一個分佈式事務跟蹤系統的平臺,思路基於google Dapper,用於基於java的大規模分佈式系統,經過跟蹤分佈式應用之間的調用來提供解決方案,以幫助分析系統的整體結構和內部模塊之間如何相互聯繫。Pinpoint的目標就是爲n(n>=1)層架構開發新的跟蹤平臺,爲n層架構的系統提供解決方案。git

0.1 Pinpoint的特色以下:github

  • 分佈式事務跟蹤,跟蹤跨分佈式應用的消息
  • 自動檢測應用拓撲,幫助你搞清楚應用的架構
  • 水平擴展以便支持大規模服務器集羣
  • 提供代碼級別的可見性以便輕鬆定位失敗點和瓶頸
  • 使用字節碼加強技術,添加新功能而無需修改代碼
  • 安裝探針不須要修改哪怕一行代碼及trace server端部署簡單,支持hdfs存儲
  • 具備簡單的閥值觸發報警功能
  • 移植性比較強的,會比較討人喜歡(相比cat)
  • 插件化功能可擴展(https://github.com/naver/pinpoint/wiki/Pinpoint-Plugin-Developer-Guide)

0.2 Pinpoint 架構web

pp-architecture

1.0 環境準備sql

爲了省事能夠直接就到這裏(https://get.k8scn.org/packages/others/pinpoint/)下載所需安裝包,統一放置在 /root/pp/目錄下面。shell

apache-tomcat-8.0.36.tar.gz hbase-1.0.3-bin.tar.gz jdk-8u92-linux-x64.rpm pinpoint-agent-1.5.2.tar.gz pinpoint-collector-1.5.2.war pinpoint-web-1.5.2.war pp-collector pp-web zookeeper-3.4.6-10.el6.x86_64.rpm

1.1 部署環境約定數據庫

192.168.56.11 CentOS6(jdk1.8.0) Pinpoint-collector, Pinpoint-web, zookeeper # 下面咱們將簡稱pp-collector&pp-web  192.168.56.12 CentOS6(jdk1.8.0) Hbase 192.168.56.13 CentOS6(jdk1.8.0) Pinpoint-agent(demo應用)

1.2 系統環境說明apache

$ /etc/init.d/iptables stop $ setenforce 0

這裏咱們爲了避免影響模塊之間的相互通訊,暫時先把幾臺設備的iptables都關閉了。

2.0 開始部署 咱們採用rpm方式安裝jdk,這裏就略過安裝過程了,主要說一下Tomcat 和Bbase的安裝和配置

2.1 部署和初始化 Hbase

$ vim ~/.bashrc # Java Environment Variables export JAVA_HOME=/usr/java/default export PATH=$PATH:$JAVA_HOME/bin $ source ~/.bashrc $ tar xf /root/pp/hbase-1.0.3-bin.tar.gz /usr/local/ $ cd /usr/local/hbase-1.0.3/conf $ vim hbase-env.sh export JAVA_HOME=/usr/java/default/ # 指到本身對應的JAVA_HOME,默認使用java6 $ vim hbase-site.xml <configuration> <property> <name>hbase.rootdir</name> <value>file:///data/hbase</value> # 這裏咱們指定Hbase本地來存儲數據,生產環境將數據建議存入HDFS中。 </property> </configuration> $ ../bin/start-hbase.sh // 啓動 Hbase

注意: 這裏說明一下,咱們是最簡方式啓動的Hbase,沒有單獨部署Hbase集羣管理的zookeeper,而是直接使用Hbase自帶的zk模塊。另外,Hbase牆裂建議將數據存入HDFS裏面,目前咱們是存在Hbase本地的。

2.1.1 驗證Hbase是否啓動成功

$ jps 8114 Jps 7820 HMaster

2.1.2下載並執行pp的Hbase初始化表語句

$ wget -c https://raw.githubusercontent.com/naver/pinpoint/master/hbase/scripts/hbase-create.hbase -P /root/pp/ $ cd /usr/local/hbase-1.0.3 $ ./bin/hbase shell /root/pp/hbase-create.hbase # 這裏須要大概半分鐘時間完成pp的表初始化 $ ./bin/hbase shell 2016-07-14 20:57:10,606 WARN [main] util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable HBase Shell; enter 'help<RETURN>' for list of supported commands. Type "exit<RETURN>" to leave the HBase Shell Version 1.0.3, rf1e1312f9790a7c40f6a4b5a1bab2ea1dd559890, Tue Jan 19 19:26:53 PST 2016 hbase(main):001:0> status 'detailed' # 我這裏已經初始化pp相關表,因此數據展現比較多 version 1.0.3 0 regionsInTransition master coprocessors: [] 1 live servers c612:46781 1468494831781 requestsPerSecond=0.0, numberOfOnlineRegions=194, usedHeapMB=18, maxHeapMB=241, numberOfStores=322, numberOfStorefiles=3, storefileUncompressedSizeMB=0, storefileSizeMB=0, memstoreSizeMB=0, storefileIndexSizeMB=0, readRequestsCount=9272, writeRequestsCount=385, rootIndexSizeKB=2, totalStaticIndexSizeKB=1, totalStaticBloomSizeKB=0, totalCompactingKVs=0, currentCompactedKVs=0, compactionProgressPct=NaN, coprocessors=[MultiRowMutationEndpoint] "AgentEvent,,1468495003477.b13eb3203210fb9d94feb1a445e0ad1b." numberOfStores=1, numberOfStorefiles=0, storefileUncompressedSizeMB=0, storefileSizeMB=0, memstoreSizeMB=0, storefileIndexSizeMB=0, readRequestsCount=0, writeRequestsCount=0, rootIndexSizeKB=0, totalStaticIndexSizeKB=0, totalStaticBloomSizeKB=0, totalCompactingKVs=0, currentCompactedKVs=0, compactionProgressPct=NaN, completeSequenceId=-1, dataLocality=0.0 "AgentInfo,,1468494998919.fa9d36f7b52b95ee5216a1ec757ad690." ...

咱們同時能夠登陸Hbase Web管理控制檯來驗證相關數據 http://192.168.56.12:16010/master-status

2.2 部署和配置pp-collector和pp-web

2.2.1 這裏咱們還須要部署一個zookeeper。從pinpoint1.5.0開始,pp-web到pp-agent的request請求直接經過pp-collector來統籌管理,包括一些real-time級別的信息監測,而zookeeper在其中間協調三者之間的通訊溝通。若是zookeeper部署在獨立的一臺設備,這裏我就須要修改一下pp-colletor & pp-web的配置文件pinpoint-collector.properties,pinpoint-web.properties,否則會致使倆個模塊啓動失敗。詳細描述參見官方文檔

$ rpm -ivh /root/pp/zookeeper-3.4.6-10.el6.x86_64.rpm $ /etc/init.d/zookeeper start # 保證zookeeper的2181端口起來就能夠了

2.2.2 pp-collector的配置

$ mkdir -p /data/service/ $ tar xf /root/pp/apache-tomcat-8.0.35.tar.gz -C /data/service/;cd /data/service/ $ mv apache-tomcat-8.0.35/ pinpoint-collector $ vim /data/service/pinpoint-collector/conf/server.xml # 由於咱們的pp-collector和pp-web部署在同臺設備,因此請確認tomcat啓動端口不會衝突 <Server port="8005" shutdown="SHUTDOWN"> <Connector port="8085" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <!-- <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> --> # 註釋該行 $ rm -rf /data/service/pinpoint-collector/webapps/* $ unzip pinpoint-collector-1.5.2.war -d /data/service/pinpoint-collector/webapps/ROOT/ $ cd /data/service/pinpoint-collector/webapps/ROOT/WEB-INF/classes $ ls -al -rw-rw-r-- 1 root root 15835 Apr 7 14:43 applicationContext-collector.xml -rw-rw-r-- 1 root root 7485 Apr 7 14:43 applicationContext-hbase.xml -rw-rw-r-- 1 root root 757 Apr 7 14:43 hbase.properties -rw-rw-r-- 1 root root 1845 Apr 7 14:43 log4j.xml -rw-rw-r-- 1 root root 1360 Apr 7 14:43 pinpoint-collector.properties # 主要針對pp-agent的配置,同時支持tcp和udp協議數據傳輸 -rw-rw-r-- 1 root root 3292 Apr 7 14:43 servlet-context.xml ...

這裏大概說一下: applicationContext-collector.xml, applicationContext-hbase.xml 這倆個配置文件時collector與agent和Hbase之間通訊時須要設定的一些參數,在後續調優的時候須要用到,hbase.properties 主要是設定後端存儲的鏈接配置,log4j.xml那就是log相關了。

$ vim hbase.properties hbase.client.host=192.168.56.12 # 這裏咱們只修改這一項配置就好,可以讓collector將彙報上來的數據存儲到Hbase hbase.client.port=2181

這裏tomcat咱們就用默認的啓動端口了,實際的生產環境可能須要根據實際狀況修改tomcat偵聽端口。OK,到此,pp-collector咱們就基本上配置完成了。接下來咱們開始配置pp-web,它與collector很相似。

2.2.3 pp-web的配置

$ cd /data/service/ $ tar xf /root/pp/apache-tomcat-8.0.35.tar.gz -C /data/service/ $ mv apache-tomcat-8.0.35 pinpoint-web $ cd pinpoint-web/webapps/;rm -rf *;mkdir ROOT;cd ROOT/ $ unzip /root/pinpoint-web-1.5.2.war $ vim /data/service/pinpoint-web/conf/server.xml # 由於咱們的pp-collector和pp-web部署在同臺設備,因此請確認tomcat啓動端口不會衝突 <Server port="8006" shutdown="SHUTDOWN"> <Connector port="8086" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <!-- <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> --> # 註釋該行 $ cd /data/service/pinpoint-web/webapps/ROOT/WEB-INF/classes $ vim hbase.properties hbase.client.host=192.168.56.12 # 設置Hbase數據源 hbase.client.port=2181 ... $ ls -al total 88 -rw-rw-r-- 1 root root 2164 Apr 7 14:43 applicationContext-cache.xml -rw-rw-r-- 1 root root 3649 Apr 7 14:43 applicationContext-dao-config.xml -rw-rw-r-- 1 root root 1490 Apr 7 14:43 applicationContext-datasource.xml -rw-rw-r-- 1 root root 6680 Apr 7 14:43 applicationContext-hbase.xml -rw-rw-r-- 1 root root 1610 Apr 7 14:43 applicationContext-websocket.xml -rw-rw-r-- 1 root root 6576 Apr 7 14:43 applicationContext-web.xml -rw-rw-r-- 1 root root 106 Apr 7 14:43 batch.properties -rw-rw-r-- 1 root root 682 Apr 7 14:43 ehcache.xml -rw-rw-r-- 1 root root 1005 Jul 14 21:45 hbase.properties -rw-rw-r-- 1 root root 153 Apr 7 14:43 jdbc.properties -rw-rw-r-- 1 root root 3338 Apr 7 14:43 log4j.xml -rw-rw-r-- 1 root root 1420 Apr 7 14:43 mybatis-config.xml -rw-rw-r-- 1 root root 630 Apr 7 14:43 pinpoint-web.properties -rw-rw-r-- 1 root root 141 Apr 7 14:43 project.properties -rw-rw-r-- 1 root root 3872 Apr714:43 servlet-context.xml drwxrwxr-x 2 root root 4096Jul1421:46 sql ...

這裏說明一下:

  • hbase.properties 配置咱們pp-web從哪一個數據源獲取採集數據,這裏咱們只指定Hbase的zookeeper地址。
  • jdbc.properties pp-web鏈接自身Mysql數據庫的鏈接認證配置。
  • sql目錄 pp-web自己有些數據須要存放在MySQL數據庫中,這裏須要初始化一下表結構。
  • pinpoint-web.properties 這裏pp-web集羣的配置文件,若是你須要pp-web集羣的話。
  • applicationContext-*.xml 這些文件在後續的調優工做中會用到。
  • log4j.xml 日誌相關配置。

好了,pp-web終於算是配置完成了。

2.3 到這裏,咱們就能夠啓動pp-colletor和pp-web了

$ cp /root/pp/pp-* /etc/init.d/ $ chmod +x /etc/init.d/pp-* $ /etc/init.d/pp-web restart $ /etc/init.d/pp-collector restart

3.0 咱們這個時候能夠部署一個pp-agent試玩一下了,其實也就是不少APM廠商傳說中的探針。這裏個人探針是部署在本身的應用下面的,就只貼一下跑在tomcat下的探針配置信息了。順帶說明一下部署上的注意點。

如下是pp目前支持埋點的java模塊:

JDK 6+ Tomcat 6/7/8, Jetty 8/9 Spring, Spring Boot Apache HTTP Client 3.x/4.x, JDK HttpConnector, GoogleHttpClient, OkHttpClient, NingAsyncHttpClient Thrift Client, Thrift Service, DUBBO PROVIDER, DUBBO CONSUMER MySQL, Oracle, MSSQL, CUBRID, DBCP, POSTGRESQL, MARIA Arcus, Memcached, Redis, CASSANDRA iBATIS, MyBatis gson, Jackson, Json Lib log4j, Logback

3.1 部署pp-agent (探針)

咱們約定tomcat容器安裝位置 /data/projects/service/app_demo,這裏咱們就將pp-agent解壓至 /data/projects/service/下。

$ tar xf /root/pp/pinpoint-agent-1.5.2.tar.gz -C /data/projects/service/ $ cd /data/projects/service/pinpoint-agent-1.5.2/ $ vim pinpoint.config profiler.collector.ip=192.168.56.11

這裏說明一下: 咱們只要指定pp-colletor的地址就能夠了,至於端口若是以前pp-colletor沒有變動這裏也不須要修改。若是你的生產環境特殊,pinpoint支持仍是很豐富的,同時支持tcp和udp協議傳輸。

$ pwd /data/projects/service/pinpoint-agent-1.5.2 $ ls -al total 80 drwxrwxr-x 6 ceph ceph 4096 Jul 14 22:11 . drwxr-xr-x 3 root root 4096 Jul 14 22:08 .. drwxrwxr-x 2 ceph ceph 4096 Apr 7 13:43 boot drwxrwxr-x 2 ceph ceph 4096 Apr 7 13:43 lib -rw-rw-r-- 1 ceph ceph 27603 Apr 7 13:42 pinpoint-bootstrap-1.5.2.jar -rw-rw-r-- 1 ceph ceph 14278 Apr 7 13:30 pinpoint.config -rw-rw-r-- 1 ceph ceph 11988 Apr 7 13:30 pinpoint-real-env-lowoverhead-sample.config drwxrwxr-x 2 ceph ceph 4096 Apr 7 13:43 plugin drwxrwxr-x 2 ceph ceph 4096 Apr 7 13:43 script

此刻,咱們開始往咱們的應用裏部署探針。

$ vim /data/projects/service/app_demo/bin/catalina.sh AGENT_VERSION="1.5.2" AGENT_ID="pp201606011442" APPLICATION_NAME="app-192-168-56-13" AGENT_PATH="/data/projects/service/pinpoint-agent-1.5.2" CATALINA_OPTS="$CATALINA_OPTS -javaagent:$AGENT_PATH/pinpoint-bootstrap-${AGENT_VERSION}.jar" CATALINA_OPTS="$CATALINA_OPTS -Dpinpoint.agentId=$AGENT_ID" CATALINA_OPTS="$CATALINA_OPTS -Dpinpoint.applicationName=$APPLICATION_NAME"

這裏說明一下:

  • 探針配置項寫到 CATALINA_OPTS 變量下一行便可。
  • AGENT_ID 命名必須在生產環境裏惟一,不然後面將會混亂。
  • APPLICATION_NAME 配置爲一個服務組的ID號,即服務組下的實例ID。
  • 此外參考官方agent文檔說明

4.0. 重啓被採集端的應用,使探針生效。

5.0. 打開瀏覽器,訪問以下pp-web的頁面驗證咱們的探針部署是否成功。其中,第二個連接是pp的APM主頁面能夠看到探針彙報上來的信息了。

http://192.168.56.11:8086/stat.html # pp-agent 信息統計頁面,即探針部署狀況的統計信息  http://192.168.56.11:8086/#/main # pp APM信息主頁面

5.1 頁面訪問效果以下(沒有找到一個好的demo應用,這部分後續補齊,因此頁面沒有信息採集上來):

Pinpoint AgentPinpoint Main

6.0. 問題排查

  • 看日誌,看日誌,看日誌。
  • 部署成功調試完成最好把agent端log級別調高一些,少打印日誌。講真,否則在你實時查看日誌定位程序問題時,你會發現打印一堆了無效信息,絕對懵B。

7.0. 最後這裏咱們講一下如何製做本身的Pinpoint定製版war包

7.1 編譯環境要求

maven:3.2+ jdk-6/7/8

7.2 獲取pp源代碼

$ git clone https://github.com/naver/pinpoint.git $ git branch -a * master remotes/origin/1.0.x remotes/origin/1.1.x remotes/origin/1.5.0-branch remotes/origin/1.5.x remotes/origin/HEAD -> origin/master remotes/origin/master $ git checkout 1.5.x // pp v1.6.x屬於活躍開發版不建議編譯安裝,除非你很是熟悉pp的代碼

7.3 設置JAVA環境變量爲JDK-1.8.0。這裏小小解釋一下: 由於pp同時支持java多版本,這也是pp最可愛的地方,因此咱們須要設置一下。

$ export JAVA_6_HOME=/usr/java/default $ export JAVA_7_HOME=/usr/java/default $ export JAVA_8_HOME=/usr/java/default $ export JAVA_HOME=/usr/java/default

7.4 開始war包製做

$ cd pinpoint $ mvn -f ./pom.xml install -Dmaven.test.skip=true [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] Reactor Build Order: [INFO] [INFO] pinpoint [INFO] pinpoint-thrift [INFO] pinpoint-commons [INFO] pinpoint-commons-hbase [INFO] pinpoint-commons-server [INFO] pinpoint-bootstrap-core [INFO] pinpoint-bootstrap [INFO] pinpoint-rpc [INFO] pinpoint-profiler ...

編譯過程可能有些長,尤爲在國內的網絡環境。結束之後,請到target目錄獲取相應的pp war包。

7.5 編譯過程遇到的問題:

[INFO] --- maven-enforcer-plugin:1.4.1:enforce (enforce-pinpoint-build-requirements) @ pinpoint --- [WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireMavenVersion failed with message: Detected Maven Version: 3.0.5 is not in the allowed range 3.2. [INFO] ---------------------------------------------------------

問題解決:升級的maven版本,須要至少3.2+以上。

好了,今天先寫到這,歡迎你們加羣討論(Pinpoint中文社區QQ羣563655806)。

參考文檔:

https://github.com/naver/pinpoint/blob/master/doc/installation.mdhttp://hbase.apache.org/book.html#standalone_dist Apache HBase ™ Reference Guide

相關文章
相關標籤/搜索