如何优化网站速度是个老生常谈的问题,优化Nginx,PHP,Mysql等等,优化速度之前,首先要找出哪里慢,再适当的调优配置,整体优化速度。通过链路追踪,可以精准的定位慢接口,慢查询等。
本次用到的链路追踪系统 Skywalking是由国内开源爱好者吴晟(原OneAPM工程师,目前在华为)开源并提交到Apache孵化器的产品,它同时吸收了Zipkin/Pinpoint/CAT的设计思路,支持非侵入式埋点。是一款基于分布式跟踪的应用程序性能监控系统。另外社区还发展出了一个叫OpenTracing的组织,旨在推进调用链监控的一些规范和标准工作。
功能列表
SkyWalking 有哪些功能?
FROM http://skywalking.apache.org/
多种监控手段。可以通过语言探针和 service mesh 获得监控是数据。
多个语言自动探针。包括 Java,.NET Core 和 Node.JS。
轻量高效。无需大数据平台,和大量的服务器资源。
模块化。UI、存储、集群管理都有多种机制可选。
支持告警。
优秀的可视化解决方案。
搭建 SkyWalking 单机环境
第一步,搭建一个 Elasticsearch 服务。
第二步,下载 SkyWalking 软件包。
第三步,搭建一个 SkyWalking OAP 服务。
第四步,启动一个PHP 应用,并配置 SkyWalking Agent。
第五步,搭建一个 SkyWalking UI 服务。
Elasticsearch 搭建
FROM https://www.elastic.co/cn/products/elasticsearch
Elasticsearch 是一个分布式、RESTful 风格的搜索和数据分析引擎,能够解决不断涌现出的各种用例。 作为 Elastic Stack 的核心,它集中存储您的数据,帮助您发现意料之中以及意料之外的情况。
参考《Elasticsearch 极简入门》的「1. 单机部署」小节,搭建一个 Elasticsearch 单机服务。
不过要注意,本文使用的是 Elasticsearch 7.5.1
版本。因为 SkyWalking 6.6.0
版本,增加了对 Elasticsearch 7.X 版本的支持。当然,如果胖友使用 Elasticsearch 6.X 版本也是可以的
下载 SkyWalking 软件包
对于 SkyWalking 的软件包,有两种方式获取:
-
手动编译
-
官方包
一般情况下,我们建议使用官方包
在 http://skywalking.apache.org/downloads/ 下,下载操作系统对应的发布版。
这里,选择 Binary Distribution for ElasticSearch 7 (Linux) 版本
# 创建目录 mkdir -p /opt/skywalking cd /opt/skywalking/ # 下载 wget https://www.apache.org/dyn/closer.cgi/skywalking/8.1.0/apache-skywalking-apm-es7-8.1.0.tar.gz # 解压 tar -zxvf apache-skywalking-apm-es7-8.1.0.tar.gz cd apache-skywalking-apm-es7-8.1.0 ls -ls 4 drwxr-xr-x 8 root root 4096 Sep 9 15:09 agent # SkyWalking Agent 4 drwxr-xr-x 2 root root 4096 Sep 9 15:44 bin # 执行脚本 4 drwxr-xr-x 2 root root 4096 Sep 9 15:44 config # SkyWalking OAP Server 配置文件 32 -rwxr-xr-x 1 root root 28903 Sep 9 14:32 LICENSE 4 drwxr-xr-x 3 root root 4096 Sep 9 15:44 licenses 32 -rwxr-xr-x 1 root root 31850 Sep 9 14:32 NOTICE 16 drwxr-xr-x 2 root root 16384 Sep 9 15:22 oap-libs # SkyWalking OAP Server 4 -rw-r--r-- 1 root root 1978 Sep 9 14:32 README.txt 4 drwxr-xr-x 2 root root 4096 Sep 9 15:44 webapp # SkyWalking UI
SkyWalking OAP 搭建
修改 OAP 配置文件
vi config/application.yml storage: elasticsearch7: nameSpace: ${SW_NAMESPACE:"elasticsearch"} clusterNodes: ${SW_STORAGE_ES_CLUSTER_NODES:localhost:9200} //修改对应的es地址 protocol: ${SW_STORAGE_ES_HTTP_PROTOCOL:"http"} # trustStorePath: ${SW_SW_STORAGE_ES_SSL_JKS_PATH:"../es_keystore.jks"} # trustStorePass: ${SW_SW_STORAGE_ES_SSL_JKS_PASS:""} user: ${SW_ES_USER:""} password: ${SW_ES_PASSWORD:""} indexShardsNumber: ${SW_STORAGE_ES_INDEX_SHARDS_NUMBER:2} indexReplicasNumber: ${SW_STORAGE_ES_INDEX_REPLICAS_NUMBER:0} # Those data TTL settings will override the same settings in core module. recordDataTTL: ${SW_STORAGE_ES_RECORD_DATA_TTL:7} # Unit is day otherMetricsDataTTL: ${SW_STORAGE_ES_OTHER_METRIC_DATA_TTL:45} # Unit is day monthMetricsDataTTL: ${SW_STORAGE_ES_MONTH_METRIC_DATA_TTL:18} # Unit is month # Batch process setting, refer to https://www.elastic.co/guide/en/elasticsearch/client/java-api/5.5/java-docs-bulk-processor.html bulkActions: ${SW_STORAGE_ES_BULK_ACTIONS:1000} # Execute the bulk every 1000 requests flushInterval: ${SW_STORAGE_ES_FLUSH_INTERVAL:10} # flush the bulk every 10 seconds whatever the number of requests concurrentRequests: ${SW_STORAGE_ES_CONCURRENT_REQUESTS:2} # the number of concurrent requests resultWindowMaxSize: ${SW_STORAGE_ES_QUERY_MAX_WINDOW_SIZE:10000} metadataQueryMaxSize: ${SW_STORAGE_ES_QUERY_MAX_SIZE:5000} segmentQueryMaxSize: ${SW_STORAGE_ES_QUERY_SEGMENT_SIZE:200} # 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} # metadataQueryMaxSize: ${SW_STORAGE_H2_QUERY_MAX_SIZE:5000}
-
storage.elasticsearch7
配置项,设置使用 Elasticsearch 7.X 版本作为存储器。
-
这里,我们打开注释,并记得通过
nameSpace
设置 Elasticsearch 集群名。
-
-
storage.elasticsearch
配置项,设置使用 Elasticsearch 6.X 版本作为存储器。
-
这里,我们无需做任何改动。
-
如果使用 Elasticsearch 6.X 版本作为存储器,记得设置这个配置项,而不是
storage.elasticsearch7
配置项。
-
-
storage.h2
配置项,设置使用 H2 作为存储器。
-
这里,需要手动注释掉,因为 H2 是默认配置的存储器。
-
启动 SkyWalking OAP 服务
bin/oapService.sh SkyWalking OAP started successfully!
是否真正启动成功,胖友打开 logs/skywalking-oap-server.log
日志文件,查看是否有错误日志。首次启动时,因为 SkyWalking OAP 会创建 Elasticsearch 的索引,所以会“疯狂”的打印日志。最终,我们看到如下日志,基本可以代表 SkyWalking OAP 服务启动成功:
2020-01-02 18:22:53,635 - org.eclipse.jetty.server.Server - 444 [main] INFO [] - Started @35249ms
SkyWalking UI 搭建
启动 SkyWalking UI 服务
bin/webappService.sh SkyWalking Web Application started successfully!
是否真正启动成功,胖友打开 logs/logs/webapp.log
日志文件,查看是否有错误日志。最终,我们看到如下日志,基本可以代表 SkyWalking UI 服务启动成功:
2020-01-02 18:27:02.824 INFO 48250 --- [main] o.a.s.apm.webapp.ApplicationStartUp : Started ApplicationStartUp in 7.774 seconds (JVM running for 8.316)
如果想要修改 SkyWalking UI 服务的参数,可以编辑 webapp/webapp.yml
配置文件。例如说:
-
server.port
:SkyWalking UI 服务端口。 -
collector.ribbon.listOfServers
:SkyWalking OAP 服务地址数组。因为 SkyWalking UI 界面的数据,是通过请求 SkyWalking OAP 服务来获得的。
访问 UI 界面:
浏览器打开 http://IP:8080
。界面如下图:
SkyWalking Agent
这里我们使用Skywalking-php-sdk 地址:https://github.com/SkywalkingContrib/skywalking-php-sdk.git 安装配制SkyWalking Agent
安装依赖:
Install Protobuf
git clone https://github.com/protocolbuffers/protobuf.git git submodule update --init --recursive ./autogen.sh ./configure make -j$(nproc) make check sudo make install sudo ldconfig # refresh shared library cache.
Install GRPC
git clone https://github.com/grpc/grpc.git cd grpc git submodule update --init --recursive mkdir -p cmake/build cd cmake/build cmake ../.. -DBUILD_SHARED_LIBS=ON -DgRPC_INSTALL=ON make -j$(nproc) sudo make install make clean sudo ldconfig
编译安装Skywalking-php-sdk
安装扩展
curl -Lo v3.3.2.tar.gz https://github.com/SkyAPM/SkyAPM-php-sdk/archive/v3.3.2.tar.gz tar zxvf v3.3.2.tar.gz cd SkyAPM-php-sdk-3.3.2 phpize && ./configure && make && make install
安装agent
go build -o sky-php-agent cmd/main.go chmod +x sky-php-agent cp sky-php-agent /usr/local/bin
配制php.ini
extension=skywalking.so skywalking.version = 8 skywalking.app_code = MyProjectName skywalking.sock_path=/tmp/sky-agent.sock
配置完毕后重启php-fpm
将agent添加系统服务
vim /usr/lib/systemd/system/ [Unit] Description=The SkyWalking PHP-Agent Process Manager After=syslog.target network.target [Service] Type=simple # Modify the corresponding directory and address here ExecStart=/usr/local/bin/sky-php-agent --grpc=127.0.0.1:11800 --sky-version=8 -- socket=/tmp/sky-agent.sock #此处地址配置为skywalking服务端地址 ExecStop=/bin/kill -SIGINT $MAINPID Restart=on-failure [Install] WantedBy=multi-user.target systemctl enable sky-php-agent.service
启动agent服务
# 启动服务 systemctl start sky-php-agent # 查看状态 systemctl status sky-php-agent -l 出现xxxx send success 说明服务启动成功
查看效果
随便访问几次网站,多点一些页面
浏览器打开http://IP:8080
,可以看到已经有数据进来
查看拓扑:
查看链路追踪:
https://zithromax.science/# azithromycin zithromax
PUBMED Abstract Griffin BB, Chou PM, George D, et al comprar cialis online
https://amoxil.science/# amoxicillin capsule 500mg price
https://stromectol.science/# minocycline uses
best over the counter toenail fungus medicine best over the counter cold medicine
over the counter nausea medicine for pregnancy over the counter diuretics
best over the counter skin tag removal over the counter cialis
cheap generic cialis Responses obtained from each patient were used to calculate the QOL score following the standard method, with low scores indicating poor QOL and vice versa
over the counter inhaler walmart over the counter acne treatments
cialis super active As described here, while debating this critical topic at the recent Miami Breast Cancer Conference, George W
amoxicillin over the counter naproxen 500mg over the counter
https://over-the-counter-drug.com/# over the counter pill for yeast infection
strongest over the counter diuretic flonase over the counter