搭建skywalking需要用到三个镜像:
elasticsearch:用来存储数据
skywalking-oap-server:Skywalking服务器
skywalking-ui :Skywalking的UI界面
下载镜像
docker pull elasticsearch:7.9.0
docker pull apache/skywalking-oap-server:8.9.1
docker pull apache/skywalking-ui:8.9.1
Docker 单独镜像安装
安装elasticsearch
本机创建持久化目录,官方推荐
mkdir -p /Users/admin/Documents/data/elasticsearch/data
mkdir -p /Users/admin/Documents/data/elasticsearch/logs
持久化启动elasticsearch
安装elasticsearch并挂载文件
docker run -d --name=es7 \
--restart=always \
-p 9200:9200 -p 9300:9300 \
-e "discovery.type=single-node" \
-v /Users/admin/Documents/data/elasticsearch/data:/usr/share/elasticsearch/data \
-v /Users/admin/Documents/data/elasticsearch/logs:/usr/share/elasticsearch/logs \
elasticsearch:7.9.0
查看启动情况
docker ps -a
查看镜像日志
docker logs -f es7
验证ES
浏览器访问:http://localhost:9200/,返回:
{
"name" : "a0455020b01a",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "AFy_WI-iQa63pVug9XIUXQ",
"version" : {
"number" : "7.9.0",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "a479a2a7fce0389512d6a9361301708b92dff667",
"build_date" : "2020-08-11T21:36:48.204330Z",
"build_snapshot" : false,
"lucene_version" : "8.6.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
安装skywalking-oap
需要先安装好es才能安装opa
启动 skywalking-oap
docker run --name oap --restart=always -d \
-e TZ=Asia/Shanghai \
-p 12800:12800 \
-p 11800:11800 \
--link es7:es7 \
-e SW_STORAGE=elasticsearch7 \
-e SW_STORAGE_ES_CLUSTER_NODES=es7:9200 \
apache/skywalking-oap-server:8.9.0
-e TZ=Asia/Shanghai
:指定时区。
--link es7:es7
:关联es7容器,通过容器名字来解决ip会发生变更的问题。
-e SW_STORAGE=elasticsearch
:设置环境变量,指定存储方式。
-e SW_STORAGE_ES_CLUSTER_NODES=es7:9200
:设置环境变量,指定ES的地址
登录容器
docker exec -it oap bash
安装skywalking-ui
启动UI
docker run -d --name skywalking-ui \
--restart=always \
-e TZ=Asia/Shanghai \
-p 8088:8080 \
--link oap:oap \
-e SW_OAP_ADDRESS=oap:12800 \
apache/skywalking-ui:8.9.0
访问UI:http://localhost:8088/
[图片上传失败...(image-3cce25-1651322607264)]
docker-compose 安装
编写docker-compose.yml文件
https://github.com/apache/skywalking/tree/master/docker 官网有示例docker-compose.yml
文件,我们只需要下载下来修改下即可。
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
version: '3.8'
services:
elasticsearch:
# image: docker.elastic.co/elasticsearch/elasticsearch-oss:${ES_VERSION}
image: elasticsearch:7.9.0
container_name: elasticsearch
# --restart=always : 开机启动,失败也会一直重启;
# --restart=on-failure:10 : 表示最多重启10次
restart: always
ports:
- "9200:9200"
- "9300:9300"
healthcheck:
test: [ "CMD-SHELL", "curl --silent --fail localhost:9200/_cluster/health || exit 1" ]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
environment:
- discovery.type=single-node
# 锁定物理内存地址,防止elasticsearch内存被交换出去,也就是避免es使用swap交换分区,频繁的交换,会导致IOPS变高;
- bootstrap.memory_lock=true
# 设置时区
- TZ=Asia/Shanghai
# - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
oap:
image: apache/skywalking-oap-server:8.9.1
container_name: oap
restart: always
# 设置依赖的容器
depends_on:
elasticsearch:
condition: service_healthy
# 关联ES的容器,通过容器名字来找到相应容器,解决IP变动问题
links:
- elasticsearch
# 端口映射
ports:
- "11800:11800"
- "12800:12800"
# 监控检查
healthcheck:
test: [ "CMD-SHELL", "/skywalking/bin/swctl ch" ]
# 每间隔30秒执行一次
interval: 30s
# 健康检查命令运行超时时间,如果超过这个时间,本次健康检查就被视为失败;
timeout: 10s
# 当连续失败指定次数后,则将容器状态视为 unhealthy,默认 3 次。
retries: 3
# 应用的启动的初始化时间,在启动过程中的健康检查失效不会计入,默认 0 秒。
start_period: 10s
environment:
# 指定存储方式
SW_STORAGE: elasticsearch
# 指定存储的地址
SW_STORAGE_ES_CLUSTER_NODES: elasticsearch:9200
SW_HEALTH_CHECKER: default
SW_TELEMETRY: prometheus
TZ: Asia/Shanghai
# JAVA_OPTS: "-Xms2048m -Xmx2048m"
ui:
image: apache/skywalking-ui:8.9.1
container_name: skywalking-ui
restart: always
depends_on:
oap:
condition: service_healthy
links:
- oap
ports:
- "8088:8080"
environment:
SW_OAP_ADDRESS: http://oap:12800
TZ: Asia/Shanghai
启动容器
切换到docker-compose.yml
文件下,然后执行一下命令:
docker-compose up -d
查看启动镜像
docker-compose ps
浏览器验证
下载agent
下载源码包,然后解压取agent目录
https://archive.apache.org/dist/skywalking/8.9.1/
或
https://skywalking.apache.org/downloads/
解压获得agent.jar
。修改conf配置文件
将地址改为skywalking地址
agent.service_name=${SW_AGENT_NAME:Your_ApplicationName}
agent.instance_name=${SW_AGENT_INSTANCE_NAME:}
collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES:127.0.0.1:11800}
- 启动文件配置agent
-javaagent:/skywalking-agent/skywalking-agent.jar -Dskywalking.agent.service_name=demoskywalking -Dskywalking.collector.backend_service=127.0.0.1:11800
[图片上传失败...(image-bc0076-1651322607265)]
jar包方式
java -javaagent:/skywalking-agent/agent/skywalking-agent.jar
-Dskywalking.agent.service_name=app-service
-Dskywalking.collector.backend_service=127.0.0.1:11800
-jar app-service.jar &