[TOC]
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來(lái)自于我們對(duì)這個(gè)行業(yè)的熱愛(ài)。我們立志把好的技術(shù)通過(guò)有效、簡(jiǎn)單的方式提供給客戶,將通過(guò)不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:域名申請(qǐng)、虛擬空間、營(yíng)銷軟件、網(wǎng)站建設(shè)、合作網(wǎng)站維護(hù)、網(wǎng)站推廣。
關(guān)于SkyWalking的基礎(chǔ)使用參考:
官方文檔:
首先我們需要獲取到SkyWalking的下載地址,官方下載地址如下:
http://skywalking.apache.org/downloads/
這里我選擇當(dāng)前最新的6.6.0版本的二進(jìn)制包,由于一會(huì)需要對(duì)接的es服務(wù)版本為7.x,所以這里得選擇for ElasticSearch 7:
復(fù)制下載地址到服務(wù)器上進(jìn)行下載并解壓,具體步驟如下:
[root@localhost ~]# cd /usr/local/src
[root@localhost /usr/local/src]# wget http://mirror.bit.edu.cn/apache/skywalking/6.6.0/apache-skywalking-apm-es7-6.6.0.tar.gz
[root@localhost /usr/local/src]# mkdir ../skywalking && tar -zxvf apache-skywalking-apm-es7-6.6.0.tar.gz -C ../skywalking --strip-components 1
[root@localhost /usr/local/src]# cd ../skywalking/
[root@localhost /usr/local/skywalking]# ll -rh # 解壓后的目錄文件如下
total 88K
drwxr-xr-x 2 root root 53 Dec 28 18:22 webapp
-rw-rw-r-- 1 1001 1002 2.0K Dec 24 14:10 README.txt
drwxrwxr-x 2 1001 1002 12K Dec 24 14:28 oap-libs
-rwxrwxr-x 1 1001 1002 32K Dec 24 14:10 NOTICE
drwxrwxr-x 3 1001 1002 4.0K Dec 28 18:22 licenses
-rwxrwxr-x 1 1001 1002 29K Dec 24 14:10 LICENSE
drwxr-xr-x 2 root root 221 Dec 28 18:22 config
drwxr-xr-x 2 root root 241 Dec 28 18:22 bin
drwxrwxr-x 8 1001 1002 143 Dec 24 14:21 agent
[root@localhost /usr/local/skywalking]#
SkyWalking 的組成在邏輯上分為四部分:探針、平臺(tái)后端、存儲(chǔ)和用戶界面。其中平臺(tái)后端服務(wù)是用于收集agent上傳的監(jiān)控?cái)?shù)據(jù),其核心配置文件位于:config/application.yml
。
如果沒(méi)有任何要求,基本上是無(wú)需修改配置就可以直接啟動(dòng) SkyWalking 服務(wù)。但通常線上都對(duì)監(jiān)控?cái)?shù)據(jù)有持久化需求,而SkyWalking 默認(rèn)使用的是H2這種內(nèi)存數(shù)據(jù)庫(kù),不具有持久存儲(chǔ)的特性。所以我們需要修改其存儲(chǔ)配置,接入elasticsearch服務(wù)作為存儲(chǔ)組件。
首先將默認(rèn)的H2數(shù)據(jù)庫(kù)配置給注釋掉:
[root@ip-236-048 skywalking]# vim config/application.yml
# h3:
# driver: ${SW_STORAGE_H2_DRIVER:org.h3.jdbcx.JdbcDataSource}
# url: ${SW_STORAGE_H2_URL:jdbc:h3:mem:skywalking-oap-db}
# user: ${SW_STORAGE_H2_USER:sa}
# metadataQueryMaxSize: ${SW_STORAGE_H2_QUERY_MAX_SIZE:5000}
然后將elasticsearch7配置的注釋解開,并修改如下:
storage:
elasticsearch7:
# nameSpace: ${SW_NAMESPACE:""}
clusterNodes: ${SW_STORAGE_ES_CLUSTER_NODES:192.168.3.10:9200}
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}
advanced: ${SW_STORAGE_ES_ADVANCED:""}
另外一個(gè)常見(jiàn)需求就是修改監(jiān)聽的ip和端口號(hào),skywalking默認(rèn)12800為rest api通信端口,默認(rèn)11800為gRPC api通信端口。這些都可以在配置文件中進(jìn)行修改,而我這里保持默認(rèn):
core:
default:
# Mixed: Receive agent data, Level 1 aggregate, Level 2 aggregate
# Receiver: Receive agent data, Level 1 aggregate
# Aggregator: Level 2 aggregate
role: ${SW_CORE_ROLE:Mixed} # Mixed/Receiver/Aggregator
restHost: ${SW_CORE_REST_HOST:0.0.0.0}
restPort: ${SW_CORE_REST_PORT:12800}
restContextPath: ${SW_CORE_REST_CONTEXT_PATH:/}
gRPCHost: ${SW_CORE_GRPC_HOST:0.0.0.0}
gRPCPort: ${SW_CORE_GRPC_PORT:11800}
完成以上配置后,運(yùn)行bin
目錄下的startup.sh
腳本即可啟動(dòng)skywalking服務(wù):
[root@localhost /usr/local/skywalking]# bin/startup.sh
SkyWalking OAP started successfully!
SkyWalking Web Application started successfully!
[root@localhost /usr/local/skywalking]#
SkyWalking控制臺(tái)服務(wù)默認(rèn)監(jiān)聽8080端口,若有防火墻需要開放該端口:
[root@localhost /usr/local/skywalking]# firewall-cmd --zone=public --add-port=8080/tcp --permanent
success
[root@localhost /usr/local/skywalking]# firewall-cmd --reload
success
[root@localhost /usr/local/skywalking]#
若希望允許遠(yuǎn)程傳輸,則還需要開放11800(gRPC)和12800(rest)端口,遠(yuǎn)程agent將通過(guò)該端口傳輸收集的數(shù)據(jù):
[root@localhost /usr/local/skywalking]# firewall-cmd --zone=public --add-port=11800/tcp --permanent
success
[root@localhost /usr/local/skywalking]# firewall-cmd --zone=public --add-port=12800/tcp --permanent
success
[root@localhost /usr/local/skywalking]# firewall-cmd --reload
success
[root@localhost /usr/local/skywalking]#
正常啟動(dòng)成功后,使用瀏覽器訪問(wèn)主頁(yè)如下:
logs/skywalking-oap-server.log
接下為項(xiàng)目集成java agent探針,看看skywalking是否能正常監(jiān)控到數(shù)據(jù)。首先創(chuàng)建兩個(gè)簡(jiǎn)單的Spring Cloud項(xiàng)目,分別是consumer和producer:
這兩個(gè)項(xiàng)目中均包含基礎(chǔ)的組件依賴:nacos-discovery、openfeign及web。因?yàn)镾kyWalking是通過(guò)Java agent這種語(yǔ)言探針的方式進(jìn)行數(shù)據(jù)的收集和上傳,所以不需要像zipkin那樣添加額外的依賴和配置。
consumer將調(diào)用producer提供的接口,以達(dá)到后續(xù)在SkyWalking上展示一個(gè)簡(jiǎn)單的調(diào)用鏈路效果。故在producer中編寫一個(gè)接口,代碼如下:
@Slf4j
@RestController
@RequestMapping("/producer")
public class ProducerController {
@GetMapping
public String producer() {
log.info("received a request");
return "this message from producer";
}
}
而consumer也有一個(gè)接口,該接口內(nèi)則是調(diào)用了producer的接口。代碼如下:
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/consumer")
public class ConsumerController {
private final ProducerClient producerClient;
@GetMapping
public String consumer() {
log.info("consumer something");
// 通過(guò)feign調(diào)用
String result = producerClient.producer();
return "consumer: " + result;
}
}
ProducerClient
代碼如下:
@FeignClient("producer")
public interface ProducerClient {
@GetMapping("/producer")
String producer();
}
由于本地調(diào)試需要使用到SkyWalking提供的Java Agent jar包,所以得到之前的下載頁(yè)面中下載對(duì)應(yīng)平臺(tái)的壓縮包:
解壓后的目錄文件內(nèi)容如下:
我們主要是使用到agent目錄下的jar包:
為了方便起見(jiàn),這里就不單獨(dú)為每個(gè)服務(wù)拷貝一個(gè)agent目錄了。通過(guò)添加JVM啟動(dòng)參數(shù)的方式來(lái)覆寫配置項(xiàng):
# 指定java agent的jar包路徑
-javaagent:E:\skywalking\apache-skywalking-apm-bin\agent\skywalking-agent.jar
# 指定skywalking agent的服務(wù)名稱,通常對(duì)應(yīng)項(xiàng)目的服務(wù)名稱
-Dskywalking.agent.service_name=consumer
# 指定skywalking后端平臺(tái)收集服務(wù)的連接ip及端口號(hào)
-Dskywalking.collector.backend_service=192.168.10.6:11800
完成以上步驟后,在IDEA中引導(dǎo)類的配置界面里設(shè)置JVM啟動(dòng)參數(shù)。如下:
分別啟動(dòng)兩個(gè)項(xiàng)目,然后訪問(wèn)/consumer
接口:
此時(shí),到SkyWalking的監(jiān)控頁(yè)面上,進(jìn)入“追蹤”頁(yè)面,并選擇正確的時(shí)間范圍,就可以看到該接口的鏈路追蹤信息:
服務(wù)拓?fù)鋱D:
服務(wù)監(jiān)控:
服務(wù)實(shí)例監(jiān)控:
端點(diǎn)監(jiān)控:
如果項(xiàng)目正確集成agent成功后,卻依舊發(fā)現(xiàn)監(jiān)控頁(yè)面上沒(méi)有數(shù)據(jù),日志里又沒(méi)有錯(cuò)誤信息的話,很有可能是時(shí)間范圍沒(méi)有選擇正確:
新聞標(biāo)題:搭建SkyWalking服務(wù)(ForElasticSearch7)
文章URL:http://www.rwnh.cn/article40/jehdeo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站、微信公眾號(hào)、App設(shè)計(jì)、軟件開發(fā)、網(wǎng)站營(yíng)銷、電子商務(wù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)