Centos6搭建SkyWalking 作分佈式跟蹤

Apache Skywalking(Incubator)簡介

當企業應用進入分佈式微服務時代,應用服務依賴會愈來愈多,skywalking能夠很好的解決服務調用鏈路追蹤的問題,並且基於java探針技術,基本對應用零侵入零耦合。html

Apache Skywalking(Incubator) 專門爲微服務架構和雲原生架構系統而設計而且支持分佈式鏈路追蹤的APM系統,即應用性能監控系統,爲微服務架構和雲原生架構系統設計。它經過探針自動收集所需的指標,並進行分佈式追蹤。經過這些調用鏈路以及指標,Skywalking APM會感知應用間關係和服務間關係,並進行相應的指標統計。目前支持鏈路追蹤和監控應用組件以下,基本涵蓋主流框架和容器,如國產PRC Dubbo和motan等,國際化的spring boot,spring cloud都支持了。Apache Skywalking (Incubating)目前支持多種語言,其中包括Java,.Net Core,Node.js和Go語言。java

skywalaking整體架構分爲三部分mysql

  • skywalking-collector:鏈路數據歸集器,數據能夠落地ElasticSearch,單機也能夠落地H2,不推薦,H2僅做爲臨時演示用
  • skywalking-web:web可視化平臺,用來展現落地的數據
  • skywalking-agent:探針,用來收集和發送數據到歸集器

Centos6搭建SkyWalking 作分佈式跟蹤

Apache Skywalking(Incubator)共提供兩種部署模式:單節點模式和集羣模式,如下爲單節點模式部署步驟。web

依賴第三方組件spring

  • JDK8+
  • Mysql5.6 (不推薦)
  • ElasticSearch: 6.x

環境配置sql

  • skywalking-collector服務:192.168.1.100
  • skywalking-web服務:192.168.1.101
  • ES集羣:192.168.1.102

安裝ES集羣(推薦)

安裝詳情,見http://www.javashuo.com/article/p-nmpnbiiz-gv.html數據庫

安裝Mysql數據庫(不推薦)

wget http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
sudo yum -y localinstall mysql-community-release-el6-*.noarch.rpm 
yum install mysql-server mysql-client libmysqlclient-dev

/etc/init.d/mysqld start
mysql_secure_installation    #MySQL安全配置嚮導
  Enter current password for root (enter for none):  <–初次運行直接回車
  Set root password? [Y/n]   <– 是否設置root用戶密碼,輸入y並回車或直接回車
  Remove anonymous users? [Y/n]   <– 是否刪除匿名用戶,生產環境建議刪除,因此直接回車
  Disallow root login remotely? [Y/n]  <–是否禁止root遠程登陸,根據本身的需求選擇Y/n並回車,建議禁止
  Remove test database and access to it? [Y/n]   <– 是否刪除test數據庫,直接回車
  Reload privilege tables now? [Y/n]   <– 是否從新加載權限表,直接回車

//修改配置文件apache

cat /etc/my.cnf
---------------------------------------------------------------------------------
[mysqld]
port=3319
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
pid-file=/var/run/mysqld/mysqld.pid

innodb_large_prefix=on
innodb_file_format=Barracuda

# time zone
default-time-zone=system
character-set-server=utf8
default-storage-engine=InnoDB

skip-name-resolve
skip-symbolic-links
skip-external-locking
skip-slave-start

# res settings
back_log=128
max_connections=100
max_connect_errors=2000
#open_files_limit=10240

connect-timeout=10
wait-timeout=28800
interactive-timeout=28800
innodb_thread_concurrency=0 #不限制併發

# slow query log
slow_query_log=1
long-query-time=3 #慢查詢時間
slow_query_log_file=/data/logs/mysql/slow.log

log-warnings=1
log-error=/data/logs/mysql/mysql.err
log_output=FILE

general_log=1
general_log_file=/data/logs/mysql/mysql.log
max_binlog_size=1G
max_relay_log_size=1G

innodb_additional_mem_pool_size=16M
innodb_buffer_pool_instance=2
innodb_buffer_pool_size=256M
innodb_file_io_threads=4
innodb_flush_log_at_trx_commit=2
innodb_log_buffer_size=5M
innodb_log_file_size=100M

innodb_log_files_in_group=2
innodb_log_group_home_dir=/data/mysql/var/
innodb_old_blocks_pct=20
innodb_buffer_pool_dump_at_shutdown=1
innodb_buffer_pool_dump_now=1
innodb_buffer_pool_load_at_startup=1
innodb_buffer_pool_load_now=1
innodb_buffer_pool_filename=ib_buffer_pool

innodb_max_dirty_pages_pct=90
innodb_lock_wait_timeout=50

symbolic-links=0
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[mysql]
disable-auto-rehash
default-character-set=utf8
connect-timeout=3

//建立配置目錄vim

mkdir -p /data/logs/mysql
mkdir -p /data/mysql/var
chown -R mysql:mysql /data/mysql/var
chown -R mysql:mysql /data/logs/mysql

//重啓mysqlapi

/etc/init.d/mysqld restart

配置 Skywalking Collector服務

cd /data/packages/
wget http://mirrors.hust.edu.cn/apache/incubator/skywalking/6.0.0-GA/apache-skywalking-apm-incubating-6.0.0-GA.tar.gz
tar zxvf apache-skywalking-apm-incubating-6.0.0-GA.tar.gz
mv apache-skywalking-apm-incubating /opt/skywalking
ll /opt/skywalking

Centos6搭建SkyWalking 作分佈式跟蹤

配置ES 存儲監控數據(推薦)
將儲存方式由 h2 修改成 elasticsearch:

storage:
# h2:
#   driver: org.h2.jdbcx.JdbcDataSource
#   url: jdbc:h2:mem:skywalking-oap-db
#   user: sa
  elasticsearch:
    clusterName: elk-cluster
    clusterNodes: 192.168.1.102:9200
    indexShardsNumber: 2
    indexReplicasNumber: 0
    # Batch process setting, refer to https://www.elastic.co/guide/en/elasticsearch/client/java-api/5.5/java-docs-bulk-processor.html
    bulkActions: 2000 # Execute the bulk every 2000 requests
    bulkSize: 20 # flush the bulk every 20mb
    flushInterval: 10 # flush the bulk every 10 seconds whatever the number of requests
    concurrentRequests: 2 # the number of concurrent requests

其中主要修改 clusterName 和 clusterNodes 和 已啓動的 elasticsearch 配置一致。

配置Mysql 存儲監控數據(不推薦)
一、將儲存方式由 h2 修改成 mysql:

cd /opt/skywalking
#修改 config/application.yml (# 修改storage部分,註釋掉h2,打開mysql,其餘保持不動):

core:
  default:
    restHost: 127.0.0.1
    restPort: 12800
    restContextPath: /
    gRPCHost: 127.0.0.1
    gRPCPort: 11800
storage:
#  h2:
#    driver: ${SW_STORAGE_H2_DRIVER:org.h2.jdbcx.JdbcDataSource}
#    url: ${SW_STORAGE_H2_URL:jdbc:h2:mem:skywalking-oap-db}
#    user: ${SW_STORAGE_H2_USER:sa}
....................此處省略N行..........................................
# 設置mysql 存儲監控數據
  mysql:         #取消此行註釋
#配置datasource, 修改 config/datasource-settings.properties 配置以下:

jdbcUrl=jdbc:mysql://localhost:3319/swtest
dataSource.user=root
dataSource.password=<your_pass>
dataSource.cachePrepStmts=true
dataSource.prepStmtCacheSize=250
dataSource.prepStmtCacheSqlLimit=2048
dataSource.useServerPrepStmts=true
dataSource.useLocalSessionState=true
dataSource.rewriteBatchedStatements=true
dataSource.cacheResultSetMetadata=true
dataSource.cacheServerConfiguration=true
dataSource.elideSetAutoCommits=true
dataSource.maintainTimeStats=false

二、下載mysql驅動包到 oap-libs 目錄下
下載地址:http://central.maven.org/maven2/mysql/mysql-connector-java/

cd /opt/skywalking/oap-libs/
wget http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.47/mysql-connector-java-5.1.47.jar

三、進入mysql 建立swtest 數據庫

[root@skywalking ]# mysql -uroot -p<your_pass>
mysql> CREATE DATABASE swtest;
Query OK, 1 row affected (0.00 sec)

啓動collector服務

#初始化
cd /opt/skywalking/bin/
./oapServiceInit.sh

#啓動collector服務
./oapService.sh

配置 Skywalking Web服務
一、修改配置

cd /opt/skywalking/webapp
# 修改webapp.yml 文件配置以下:
server:
  port: 8080
collector:
  path: /graphql
  ribbon:
    ReadTimeout: 10000
    # Point to all backend's restHost:restPort, split by ,
    listOfServers: 127.0.0.1:12800
security:
  user:
    # username
    admin:
      # password
      password:  <your_pass>    #此處修改你的網站管理員密碼

二、啓動web服務

cd /opt/skywalking/bin
./webappService.sh

啓動bin目錄下的startup.sh能夠將collector和Web模塊一塊兒啓動起來。

若是一切順利,這時候就能夠經過 http://192.168.1.100:8080 來查看 SkyWalking UI 了,默認帳號/密碼:admin/admin。

探針配置(agent)

一、被監控端下載skywalking

wget http://mirrors.hust.edu.cn/apache/incubator/skywalking/6.0.0-GA/apache-skywalking-apm-incubating-6.0.0-GA.tar.gz
tar zxvf apache-skywalking-apm-incubating-6.0.0-GA.tar.gz
mv apache-skywalking-apm-incubating /opt/skywalking

二、探針的配置 修改agent.config配置以下:

vim /opt/skywalking/agent/config/agent.config
-------------------------------------------------------------
agent.service_name=Your_ApplicationName  #改成你的項目名字
collector.backend_service=192.168.1.100:11800   #collector的端口服務地址;
logging.level=info

三、啓動Agent

  • 基於Tomcat的服務(SpringMvc)
    在tomcat的bin目錄下的catalina.sh中增長以下命令行

    CATALINA_OPTS="$CATALINA_OPTS -javaagent:/opt/skywalking/agent/skywalking-agent.jar"
    export CATALINA_OPTS
  • 基於JAR file的服務(SpringBoot)
    在啓動你的應用程序的命令行中添加 -javaagent 參數. 並確保在-jar參數以前添加它. 例如:
    java -javaagent:/opt/skywalking/agent/skywalking-agent.jar -jar yourApp.jar

而後重啓服務,就能夠看到頁面上有數據了;若是發生了其餘錯誤,請查看日誌進行詳細排查;collector的日誌和Web的日誌都是在SkyWalking根目錄的log目錄之中(會在collector啓動以後建立);Agent的目錄是在agent目錄之下。

相關文章
相關標籤/搜索