写点什么

运维进阶训练营 -W08H

作者:赤色闪电
  • 2022-12-18
    北京
  • 本文字数:4883 字

    阅读完需:约 16 分钟

基于 docker-compose 或二进制部署 SkyWalking

root@skywalking-server:~# mkdir -pv /data/elasticsearch/root@skywalking-server:~# chown 1000.1000 -R /data/elasticsearchroot@skywalking-server:~# mkdir /data/skywalking-9.3-docker-composefile -pvroot@skywalking-server:/data/skywalking-9.3-docker-composefile# cat docker-compose.ymlversion: "3"services: elasticsearch: image: elasticsearch:8.4.2 container_name: elasticsearch ports: - "9200:9200" healthcheck: test: ["CMD-SHELL", "curl -sf http://localhost:9200/_cluster/health || exit 1"] #⼼跳检测,成功之后不再执⾏后⾯的退出 interval: 60s #⼼跳检测间隔周期 timeout: 10s retries: 3 start_period: 60s #⾸次检测延迟时间 environment: discovery.type: single-node #单节点模式 ingest.geoip.downloader.enabled: "false" bootstrap.memory_lock: "true" ES_JAVA_OPTS: "-Xms512m -Xmx512m" TZ: "Asia/Shanghai" xpack.security.enabled: "false" #单机模式 ulimits: memlock: soft: -1 hard: -1 skywalking-oap: image: apache/skywalking-oap-server:9.3.0 container_name: skywalking-oap depends_on: elasticsearch: condition: service_healthy links: - elasticsearch environment: SW_HEALTH_CHECKER: default SW_STORAGE: elasticsearch SW_STORAGE_ES_CLUSTER_NODES: elasticsearch:9200 JAVA_OPTS: "-Xms2048m -Xmx2048m" TZ: Asia/Shanghai SW_TELEMETRY: prometheus healthcheck: test: ["CMD-SHELL", "/skywalking/bin/swctl ch"] interval: 30s timeout: 10s retries: 3 start_period: 10s restart: on-failure ports: - "11800:11800" - "12800:12800" skywalking-ui: image: apache/skywalking-ui:9.3.0 depends_on: skywalking-oap: condition: service_healthy links: - skywalking-oap ports: - "8080:8080" environment: SW_OAP_ADDRESS: http://skywalking-oap:12800 SW_HEALTH_CHECKER: default TZ: Asia/Shanghai healthcheck: test: ["CMD-SHELL", "curl -sf http://localhost:8080 || exit 1"] #⼼跳检测,成功之后不再执⾏后⾯的退出 interval: 60s #⼼跳检测间隔周期 timeout: 10s retries: 3 start_period: 60s #⾸次检测延迟时间root@skywalking-server:/data/skywalking-9.3-docker-composefile# docker-compose up -d
复制代码

实现单体服务 Halo 博客和 Jenkins 的请求链路跟踪

准备skywalking java agent:
root@skywalking-agent1:~# mkdir /data && cd /data
root@skywalking-agent1:/data# tar xvf apache-skywalking-java-agent-8.13.0.tgz
root@skywalking-agent1:/data# vim /data/skywalking-agent/config/agent.config
agent.service_name=${SW_AGENT_NAME:halo}
agent.namespace=${SW_AGENT_NAMESPACE:magedu}
collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES:172.31.2.161:11800} Halo 是一款现代化的个人独立博客系统,而且可能是最好的Java博客系统,从 1.4.3 起,版本要求为 11 以上的版本,1.4.3 以下需要 1.8 以上的版本。
安装要求:
https://docs.halo.run/getting-started/prepare
root@ubuntu:~# apt install openjdk-11-jdk
root@skywalking-agent:~# java -version
openjdk version "11.0.17" 2022-10-18
OpenJDK Runtime Environment (build 11.0.17+8-post-Ubuntu-1ubuntu222.04)
OpenJDK 64-Bit Server VM (build 11.0.17+8-post-Ubuntu-1ubuntu222.04, mixed mode, sharing 下载halo博客单体jar包:
root@skywalking-agent1:/data# mkdir /apps && cd /apps/
root@skywalking-agent1:/apps# wget https://dl.halo.run/release/halo-1.6.1.jar
root@skywalking-agent1:/apps# ls
halo-1.6.1.jar
相对路径启动命令:
root@skywalking-agent:/data/skywalking-agent# java -javaagent:./skywalking-agent.jar -jar /apps/halo-1.6.1.jar
绝对路径启动命令:
~# java -javaagent:/data/skywalking-agent/skywalking-agent.jar -jar /apps/halo-1.6.1.jar
生产环境示例:
# java -javaagent:/skywalking-agent/skywalking-agent.jar \
-DSW_AGENT_NAMESPACE=xyz \
-DSW_AGENT_NAME=abc-application \
-Dskywalking.collector.backend_service=skywalking.abc.xyz.com:11800 \
-jar abc-xyz-1.0-SNAPSHOT.jar
复制代码


基础环境准备:
https://skywalking.apache.org/docs/skywalking-java/latest/en/setup/service-agent/java-agent/readme/
部署jdk环境: 参考halo示例
部署skywalking java客户端:参考halo示例 部署tomcat:
下载并部署tomcat,
https://tomcat.apache.org/
root@skywalking-agent:/apps# pwd
/apps
root@skywalking-agent1:/apps# wget https://archive.apache.org/dist/tomcat/tomcat-8/v8.5.84/bin/apache-tomcat-8.5.84.tar.gz
root@skywalking-agent1:/apps# tar xvf apache-tomcat-8.5.84.tar.gz
root@skywalking-agent1:/apps# vim /apps/apache-tomcat-8.5.84/bin/catalina.sh
# -----------------------------------------------------------------------------
CATALINA_OPTS="$CATALINA_OPTS -javaagent:/data/skywalking-agent/skywalking-agent.jar"; export CATALINA_OPTS
配置skywalking-agent参数:
agent.service_name=${SW_AGENT_NAME:magedu}
agent.namespace=${SW_AGENT_NAMESPACE:jenkins}
collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES:172.31.2.161:11800} 上传Jenkins app并启动tomcat:
root@skywalking-agent1:/apps# ls /apps/apache-tomcat-8.5.84/webapps/
ROOT docs examples host-manager jenkins.war manager
root@skywalking-agent1:/apps# /apps/apache-tomcat-8.5.84/bin/catalina.sh run
复制代码

实现 Dubbo 微服务实现链路跟踪案例

部署注册中心(172.31.2.163):
root@skywalking-zookeeper:~# apt install openjdk-8-jdk
root@skywalking-zookeeper:~# java -version
openjdk version "1.8.0_352"
OpenJDK Runtime Environment (build 1.8.0_352-8u352-ga-1~22.04-b08)
OpenJDK 64-Bit Server VM (build 25.352-b08, mixed mode)
root@skywalking-zookeeper:~# mkdir /apps && cd /apps
root@skywalking-zookeeper:/apps# wget https://dlcdn.apache.org/zookeeper/zookeeper-3.7.1/apache-zookeeper-3.7.1-bin.tar.gz
root@skywalking-zookeeper:/apps# tar xvf apache-zookeeper-3.7.1-bin.tar.gz
root@skywalking-zookeeper:/apps# cp /apps/apache-zookeeper-3.7.1-bin/conf/zoo_sample.cfg /apps/apache-zookeeper-3.7.1-
bin/conf/zoo.cfg
root@skywalking-zookeeper:/apps# /apps/apache-zookeeper-3.7.1-bin/bin/zkServer.sh start
root@skywalking-zookeeper:/apps# lsof -i:2181
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 4419 root 70u IPv6 50491 0t0 TCP *:2181 (LISTEN)
部署provider(172.31.2.164):
root@skywalking-node1:~# apt install openjdk-8-jdk -y
root@skywalking-node1:~# mkdir /data && cd /data
root@skywalking-node1:/data# tar xvf apache-skywalking-java-agent-8.13.0.tgz
root@skywalking-node1:/data# vim /data/skywalking-agent/config/agent.config
20 agent.service_name=${SW_AGENT_NAME:dubbo-server1}
23 agent.namespace=${SW_AGENT_NAMESPACE:myserver}
101 collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES:172.31.2.161:11800}
添加主机名解析,dubbo里面的zookeeper地址写在了源代码中,域名变量为ZK_SERVER1:
root@skywalking-node1:~# vim /etc/profile
export ZK_SERVER1=172.31.2.163
root@skywalking-node1:~# source /etc/profile
root@skywalking-node1:~# echo $ZK_SERVER1
172.31.2.163
root@skywalking-node1:/data# mkdir -pv /apps/dubbo/provider
root@skywalking-node1:/data# java -javaagent:/data/skywalking-agent/skywalking-agent.jar -jar /apps/dubbo/provider/dubbo-
server.jar
部署consumer(172.31.2.166):
root@skywalking-node3:~# apt install openjdk-8-jdk -y
root@skywalking-node3:~# mkdir /data && cd /data
root@skywalking-node3:/data# tar xvf apache-skywalking-java-agent-8.13.0.tgz
root@skywalking-node3:/data# vim /data/skywalking-agent/config/agent.config
20 agent.service_name=${SW_AGENT_NAME:dubbo-consumer1}
23 agent.namespace=${SW_AGENT_NAMESPACE:myserver}
collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES:${SW_SERVER}:11800}
添加主机名解析,dubbo里面的zookeeper地址写在了源代码中,域名变量为ZK_SERVER1,SW也可以为agent设置环境变量:
root@skywalking-node3:~# vim /etc/profile
export SW_SERVER="172.31.2.161"
export ZK_SERVER1="172.31.2.163"
root@skywalking-node3:/data# source /etc/profile
root@skywalking-node3:/data# mkdir -pv /apps/dubbo/consumer
root@skywalking-node3:/data# java -javaagent:/data/skywalking-agent/skywalking-agent.jar -jar /apps/dubbo/consumer/dubbo-
client.jar
部署dubboadmin(172.31.2.163-JDK8):
root@skywalking-zookeeper:/apps# java -version
openjdk version "1.8.0_352"
OpenJDK Runtime Environment (build 1.8.0_352-8u352-ga-1~22.04-b08)
OpenJDK 64-Bit Server VM (build 25.352-b08, mixed mode)
root@skywalking-zookeeper:/apps# tar xvf apache-tomcat-8.5.84.tar.gz
root@skywalking-zookeeper:/apps# cd /apps/apache-tomcat-8.5.84/webapps/
root@skywalking-zookeeper:/apps/apache-tomcat-8.5.84/webapps# rm -rf ./*
root@skywalking-zookeeper:/apps/apache-tomcat-8.5.84/webapps# unzip dubboadmin.war
root@skywalking-zookeeper:/apps/apache-tomcat-8.5.84/webapps# vim dubboadmin/WEB-INF/dubbo.properties
dubbo.registry.address=zookeeper://172.31.2.163:2181
dubbo.admin.root.password=root
dubbo.admin.guest.password=guest
复制代码


实现 skywalking 的钉钉告警

skywalking 告警-钉钉:
root@skywalking-server:~# vim /apps/skywalking/config/alarm-settings.yml
rules: #定义rule规则
service_cpm_rule: #唯一的规则名称,必须以_rule结尾
# Metrics value need to be long, double or int
metrics-name: service_cpm #指标名称
op: ">" #操作符,>, >=, <, <=, ==
threshold: 1 #指标阈值
# The length of time to evaluate the metrics
period: 2 #评估指标的间隔周期
# How many times after the metrics match the condition, will trigger alarm
count: 1 #匹配成功多少次就会触发告警
# How many times of checks, the alarm keeps silence after alarm triggered, default as same as period.
#silence-period: 3
silence-period: 2 #触发告警后的静默时间
message: dubbo-provider service_cpm 大于1了 #告警信息
dingtalkHooks:
textTemplate: |-
{
"msgtype": "text",
"text": {
"content": "Apache SkyWalking Alarm: \n %s."
}
}
webhooks:
- url: https://oapi.dingtalk.com/robot/send?access_token=3f773a20ef885659112b0d49086ca60d575562a2b1f113fbe215703366bb66f9 #注意钉钉关键字
root@skywalking-server:~# systemctl restart skywalking.service
复制代码

发布于: 刚刚阅读数: 5
用户头像

赤色闪电

关注

还未添加个人签名 2018-05-30 加入

还未添加个人简介

评论

发布
暂无评论
运维进阶训练营 -W08H_运维_赤色闪电_InfoQ写作社区