SkyWalking搭建,JAVA和PHP的接入

搭建一个ES集群

详细搭建步骤这里就不详细描述了,可以参考官方的 安装文档。

安装skywalking服务

1、下载解压skywalking

$ cd /data/download/
$ wget https://dlcdn.apache.org/skywalking/9.3.0/apache-skywalking-apm-9.3.0.tar.gz
$ tar zxvf apache-skywalking-apm-9.3.0.tar.gz
$ cd apache-skywalking-apm-bin

2、配置elasticsearch

$ vi ./config/application.yml

修改成下面的配置:

storage:
  selector: ${SW_STORAGE:elasticsearch} #指定采用什么存储,这里改成使用elasticsearch
  elasticsearch:
    namespace: ${SW_NAMESPACE:"runbany_erp"} # elasticsearch的集群名称
    clusterNodes: ${SW_STORAGE_ES_CLUSTER_NODES:10.100.0.30:9200,10.100.0.31:9200,10.100.0.32:9200} # elasticsearch节点信息
    protocol: ${SW_STORAGE_ES_HTTP_PROTOCOL:"http"}
    connectTimeout: ${SW_STORAGE_ES_CONNECT_TIMEOUT:3000}
    socketTimeout: ${SW_STORAGE_ES_SOCKET_TIMEOUT:30000}
    responseTimeout: ${SW_STORAGE_ES_RESPONSE_TIMEOUT:15000}
    numHttpClientThread: ${SW_STORAGE_ES_NUM_HTTP_CLIENT_THREAD:0}

更多的配置说明请参考 官方配置

3、启动 SkyWalking OAP

$ ./bin/oapService.sh
SkyWalking OAP started successfully!

查看一下启动日志,确认是否启动成功

$ tail -f ./logs/skywalking-oap-server.log
2023-01-10 10:08:31,926 - org.apache.skywalking.oap.server.library.server.grpc.GRPCServer - 131 [main] INFO  [] - Bind handler MeshGRPCHandler into gRPC server 0.0.0.0:11800
2023-01-10 10:08:31,930 - org.apache.skywalking.oap.server.library.module.BootstrapFlow - 43 [main] INFO  [] - start the provider default in configuration-discovery module.
2023-01-10 10:08:31,931 - org.apache.skywalking.oap.server.library.server.grpc.GRPCServer - 131 [main] INFO  [] - Bind handler ConfigurationDiscoveryServiceHandler into gRPC server 0.0.0.0:11800
2023-01-10 10:08:31,933 - org.apache.skywalking.oap.server.library.module.BootstrapFlow - 43 [main] INFO  [] - start the provider default in receiver-register module.
2023-01-10 10:08:31,934 - org.apache.skywalking.oap.server.library.server.grpc.GRPCServer - 131 [main] INFO  [] - Bind handler ManagementServiceGRPCHandler into gRPC server 0.0.0.0:11800
2023-01-10 10:08:31,937 - org.apache.skywalking.oap.server.library.server.grpc.GRPCServer - 131 [main] INFO  [] - Bind handler ManagementServiceGrpcHandlerCompat into gRPC server 0.0.0.0:11800
2023-01-10 10:08:31,939 - org.apache.skywalking.oap.server.library.server.http.HTTPServer - 86 [main] INFO  [] - Bind handler ManagementServiceHTTPHandler into http server 0.0.0.0:12800
2023-01-10 10:08:31,939 - org.apache.skywalking.oap.server.library.module.BootstrapFlow - 43 [main] INFO  [] - start the provider default in receiver-browser module.
2023-01-10 10:08:32,065 - org.apache.skywalking.oap.server.core.storage.model.ModelInstaller - 54 [main] INFO  [] - table: browser_app_error_rate does not exist
2023-01-10 10:08:32,103 - org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base.StorageEsInstaller - 188 [main] INFO  [] - create metrics-all index template finished, isAcknowledged: true
2023-01-10 10:08:32,127 - org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base.StorageEsInstaller - 202 [main] INFO  [] - update metrics-all-20230110 index finished, isAcknowledged: true, append mappings: Mappings(type=type, properties={numerator={type=long}, denominator={type=long}}, source=null)
2023-01-10 10:08:32,497 - org.apache.skywalking.oap.server.core.analysis.DispatcherManager - 117 [main] INFO  [] - Dispatcher org.apache.skywalking.oap.server.core.source.oal.rt.dispatcher.BrowserAppPagePerfDispatcher is added into DefaultScopeDefine 36.
2023-01-10 10:08:32,497 - org.apache.skywalking.oap.server.core.analysis.DispatcherManager - 117 [main] INFO  [] - Dispatcher org.apache.skywalking.oap.server.core.source.oal.rt.dispatcher.BrowserAppPageTrafficDispatcher is added into DefaultScopeDefine 40.
2023-01-10 10:08:32,497 - org.apache.skywalking.oap.server.core.analysis.DispatcherManager - 117 [main] INFO  [] - Dispatcher org.apache.skywalking.oap.server.core.source.oal.rt.dispatcher.BrowserAppSingleVersionTrafficDispatcher is added into DefaultScopeDefine 39.
2023-01-10 10:08:32,498 - org.apache.skywalking.oap.server.core.analysis.DispatcherManager - 117 [main] INFO  [] - Dispatcher org.apache.skywalking.oap.server.core.source.oal.rt.dispatcher.BrowserAppTrafficDispatcher is added into DefaultScopeDefine 38.
2023-01-10 10:08:32,500 - org.apache.skywalking.oap.server.library.server.grpc.GRPCServer - 131 [main] INFO  [] - Bind handler BrowserPerfServiceHandler into gRPC server 0.0.0.0:11800
2023-01-10 10:08:32,507 - org.apache.skywalking.oap.server.library.server.grpc.GRPCServer - 131 [main] INFO  [] - Bind handler BrowserPerfServiceHandlerCompat into gRPC server 0.0.0.0:11800
2023-01-10 10:08:32,511 - org.apache.skywalking.oap.server.library.server.http.HTTPServer - 86 [main] INFO  [] - Bind handler BrowserPerfServiceHTTPHandler into http server 0.0.0.0:12800
2023-01-10 10:08:32,511 - org.apache.skywalking.oap.server.library.module.BootstrapFlow - 43 [main] INFO  [] - start the provider default in receiver-event module.
2023-01-10 10:08:32,511 - org.apache.skywalking.oap.server.library.server.grpc.GRPCServer - 131 [main] INFO  [] - Bind handler EventGrpcServiceHandler into gRPC server 0.0.0.0:11800
2023-01-10 10:08:32,516 - org.apache.skywalking.oap.server.library.server.http.HTTPServer - 86 [main] INFO  [] - Bind handler EventRestServiceHandler into http server 0.0.0.0:12800
2023-01-10 10:08:32,516 - org.apache.skywalking.oap.server.library.module.BootstrapFlow - 43 [main] INFO  [] - start the provider default in receiver-log module.
2023-01-10 10:08:32,517 - org.apache.skywalking.oap.server.library.server.grpc.GRPCServer - 131 [main] INFO  [] - Bind handler LogReportServiceGrpcHandler into gRPC server 0.0.0.0:11800
2023-01-10 10:08:32,521 - org.apache.skywalking.oap.server.library.server.http.HTTPServer - 86 [main] INFO  [] - Bind handler LogReportServiceHTTPHandler into http server 0.0.0.0:12800
2023-01-10 10:08:32,521 - org.apache.skywalking.oap.server.library.module.BootstrapFlow - 43 [main] INFO  [] - start the provider default in receiver-ebpf module.
2023-01-10 10:08:32,521 - org.apache.skywalking.oap.server.library.server.grpc.GRPCServer - 131 [main] INFO  [] - Bind handler EBPFProcessServiceHandler into gRPC server 0.0.0.0:11800
2023-01-10 10:08:32,528 - org.apache.skywalking.oap.server.library.server.grpc.GRPCServer - 131 [main] INFO  [] - Bind handler EBPFProfilingServiceHandler into gRPC server 0.0.0.0:11800
2023-01-10 10:08:32,533 - org.apache.skywalking.oap.server.library.module.BootstrapFlow - 43 [main] INFO  [] - start the provider default in receiver-meter module.
2023-01-10 10:08:32,534 - org.apache.skywalking.oap.server.library.server.grpc.GRPCServer - 131 [main] INFO  [] - Bind handler MeterServiceHandler into gRPC server 0.0.0.0:11800
2023-01-10 10:08:32,539 - org.apache.skywalking.oap.server.library.server.grpc.GRPCServer - 131 [main] INFO  [] - Bind handler MeterServiceHandlerCompat into gRPC server 0.0.0.0:11800
2023-01-10 10:08:32,541 - org.apache.skywalking.oap.server.library.module.BootstrapFlow - 43 [main] INFO  [] - start the provider default in envoy-metric module.
2023-01-10 10:08:33,463 - org.apache.skywalking.oap.server.library.server.grpc.GRPCServer - 131 [main] INFO  [] - Bind handler MetricServiceGRPCHandler into gRPC server 0.0.0.0:11800
2023-01-10 10:08:33,468 - org.apache.skywalking.oap.server.library.server.grpc.GRPCServer - 131 [main] INFO  [] - Bind handler MetricServiceGRPCHandlerV3 into gRPC server 0.0.0.0:11800
2023-01-10 10:08:33,470 - org.apache.skywalking.oap.server.library.server.grpc.GRPCServer - 131 [main] INFO  [] - Bind handler AccessLogServiceGRPCHandler into gRPC server 0.0.0.0:11800
2023-01-10 10:08:33,475 - org.apache.skywalking.oap.server.library.server.grpc.GRPCServer - 131 [main] INFO  [] - Bind handler AccessLogServiceGRPCHandlerV3 into gRPC server 0.0.0.0:11800
2023-01-10 10:08:33,477 - org.apache.skywalking.oap.server.library.server.grpc.GRPCServer - 131 [main] INFO  [] - Bind handler SatelliteAccessLogServiceGRPCHandlerV3 into gRPC server 0.0.0.0:11800
2023-01-10 10:08:33,539 - com.linecorp.armeria.common.util.SystemInfo - 237 [main] INFO  [] - hostname: hk-nadiera-zkui-c-pro-010100000027 (from /proc/sys/kernel/hostname)
2023-01-10 10:08:34,216 - com.linecorp.armeria.server.Server - 797 [armeria-boss-http-*:12800] INFO  [] - Serving HTTP at /0:0:0:0:0:0:0:0%0:12800 - http://127.0.0.1:12800/
2023-01-10 10:08:34,219 - org.apache.skywalking.oap.server.core.storage.PersistenceTimer - 58 [main] INFO  [] - persistence timer start
2023-01-10 10:08:34,223 - org.apache.skywalking.oap.server.core.cache.CacheUpdateTimer - 46 [main] INFO  [] - Cache updateServiceInventory timer start
2023-01-10 10:08:37,058 - org.apache.skywalking.oap.server.starter.OAPServerBootstrap - 53 [main] INFO  [] - Version of OAP: 9.3.0-7ad0406

4、SkyWalking UI 启动

$ ./bin/webappService.sh
SkyWalking Web Application started successfully!

输入网址就可以访问了 http://127.0.0.1:8080/
SkyWalking搭建,JAVA和PHP的接入_第1张图片

Java接入SkyWalking

1、启动参数方式接入

# 下载Java Agent
$ cd /opt/
$ wget https://dlcdn.apache.org/skywalking/java-agent/8.13.0/apache-skywalking-java-agent-8.13.0.tgz
$ tar zxvf apache-skywalking-java-agent-8.13.0.tgz

# 启动脚本增加参数
$ java -DSW_AGENT_NAME=TEST -DSW_AGENT_COLLECTOR_BACKEND_SERVICES=127.0.0.1:11800 -DSW_AGENT_SPAN_LIMIT=2000 -DSW_AGENT_INSTANCE_NAME=$HOSTNAME -javaagent:/opt/skywalking-agent/skywalking-agent.jar -jar test.jar

2、IDEA参数调试

SkyWalking搭建,JAVA和PHP的接入_第2张图片

其实就是把启动的VM参数设置好,同步设置环境变量,这些变量java agent里面会用到,更多参数可以参考 官方配置说明

PHP接入SkyWalking

1、安装PHP扩展包

# 安装依赖包
$ yum install gcc make cargo clang protobuf-compiler

# perl安装
$ pecl install skywalking_agent

Build process completed successfully
Installing '/usr/lib64/php/modules/skywalking_agent.so'
install ok: channel://pecl.php.net/skywalking_agent-0.2.0
configuration option "php_ini" is not set to php.ini location
You should add "extension=skywalking_agent.so" to php.ini

错误:thread ‘main’ panicked at 'Unable to find libclang: "the libclang shared library at /usr/lib64/clang-private/libclang.so.7 could not be opened
解决:

$ rpm -qa | grep "llvm-private"
$ rpm -e --nodeps llvm-private-7.0.1-1.el7.x86_64
$ yum install -y clang llvm

错误:thread ‘main’ panicked at 'libclang function not loaded: clang_getTranslationUnitTargetInfo. This crate requires that libclang 3.9 or later be installed on your system, clang版本过低了,centos 7默认是3.4
解决:

$ yum install llvm-toolset-7
$ scl enable llvm-toolset-7 bash #激活clang并检查版本,clang相关依赖已经全部安装了

错误:Error: Custom { kind: Other, error: “protoc failed: language-agent/Tracing.proto:19:10: Unrecognized syntax identifier “proto3”. This parser only recognizes “proto2”.\n” } protobuf版本太低,centos7 YUM安装的是2.5
解决:

$ wget https://github.com/google/protobuf/releases/download/v3.6.1/protobuf-all-3.6.1.tar.gz
$ tar zxvf protobuf-all-3.6.1.tar.gz
$ cd protobuf-3.6.1/
$ ./autogen.sh
$ ./configure --prefix=/usr/local/protobuf
$ make
$ make install

$ vi /etc/profile
####### add protobuf lib path ########
#(动态库搜索路径) 程序加载运行期间查找动态链接库时指定除了系统默认路径之外的其他路径
exportLD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/protobuf/lib/

#(静态库搜索路径) 程序编译期间查找动态链接库时指定查找共享库的路径
exportLIBRARY_PATH=$LIBRARY_PATH:/usr/local/protobuf/lib/

#执行程序搜索路径
export PATH=$PATH:/usr/local/protobuf/bin/

#c程序头文件搜索路径
exportC_INCLUDE_PATH=$C_INCLUDE_PATH:/usr/local/protobuf/include/

#c++程序头文件搜索路径
exportCPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/local/protobuf/include/

#pkg-config 路径
exportPKG_CONFIG_PATH=/usr/local/protobuf/lib/pkgconfig/
######################################

$ source /etc/profile
$ protoc --version
libprotoc 3.6.1

2、PHP配置

$ vim php.ini
[skywalking]
extension=skywalking_agent.so

# Enable skywalking extension or not.
skywalking_agent.enable = On

# Log file path.
skywalking_agent.log_file = /tmp/skywalking_agent.log

# Log level: one of `OFF`, `TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`.
skywalking_agent.log_level = INFO

# Address of skywalking oap server.
skywalking_agent.server_addr = http://0.0.0.0:11800

# Application service name.
skywalking_agent.service_name = hello-skywalking

# Skywalking version.
skywalking_agent.skywalking_version = 9

# Skywalking worker threads, 0 will auto set as the cpu core size.
# skywalking_agent.worker_threads = 3

注:PHP必须是NTS版本,版本7.2及以上

你可能感兴趣的:(skywalking,java,php)