1.1 搭建skywalking需要用到三个镜像

2022-09-08 11:17:58 浏览数 (1)

本文为joshua317原创文章,转载请注明:转载自joshua317博客 https://www.joshua317.com/article/264

操作系统:CentOS7.4

一、镜像准备

1.1 搭建skywalking需要用到三个镜像

elasticsearch:用来存储数据

skywalking-oap-server:Skywalking服务器

skywalking-ui :Skywalking的UI界面

1.2 下载镜像

代码语言:javascript复制
docker pull elasticsearch:7.9.0
docker pull apache/skywalking-oap-server:8.9.1
docker pull apache/skywalking-ui:8.9.1

1.3 查看镜像

代码语言:javascript复制
docker images

二、方式一:单独镜像安装

2.1 安装elasticsearch

2.1.1 本机创建持久化目录,官方推荐

代码语言:javascript复制
mkdir -p /data/elasticsearch7/data
mkdir -p /data/elasticsearch7/logs

2.1.2 持久化启动elasticsearch,安装elasticsearch并挂载文件

代码语言:javascript复制
docker run -itd 
--name=es7 
--restart=always 
-p 9200:9200 -p 9300:9300 
-e "discovery.type=single-node" 
-v /data/elasticsearch7/data:/usr/share/elasticsearch/data 
-v /data/elasticsearch7/logs:/usr/share/elasticsearch/logs 
elasticsearch:7.9.0

2.1.3 查看启动情况

代码语言:javascript复制
docker ps -a

2.1.4 查看镜像日志

代码语言:javascript复制
docker logs -f es7

2.1.5 验证ES

浏览器访问:http://192.168.3.176:9200/,返回:

代码语言:javascript复制
{
name: "ac1504b16770",
cluster_name: "docker-cluster",
cluster_uuid: "k06cLZkBSjiO6aYVKBtfYQ",
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"
}

2.2 安装skywalking-oap

注意:需要先安装好es才能安装oap

2.2.1 持久化启动 skywalking-oap

代码语言:javascript复制
docker run  -itd 
--name skywalking-oap 
--restart=always 
-e TZ=Asia/Shanghai 
-p 12800:12800 
-p 11800:11800 
--link es7:es7 
-e SW_STORAGE=elasticsearch 
-e SW_STORAGE_ES_CLUSTER_NODES=es7:9200 
apache/skywalking-oap-server:8.9.1

-e TZ=Asia/Shanghai:指定时区。

--link es7:es7:关联es7容器,通过容器名字来解决ip会发生变更的问题。

-e SW_STORAGE=elasticsearch:设置环境变量,指定存储方式。

-e SW_STORAGE_ES_CLUSTER_NODES=es7:9200:设置环境变量,指定ES的地址

2.2.2 登录容器

代码语言:javascript复制
docker exec -it skywalking-oap bash

2.3 安装skywalking-ui

2.3.1 持久化启动 skywalking-ui

代码语言:javascript复制
docker run -itd --name skywalking-ui 
--restart=always 
-e TZ=Asia/Shanghai 
-p 8080:8080 
--link skywalking-oap:skywalking-oap 
-e SW_OAP_ADDRESS=skywalking-oap:12800 
apache/skywalking-ui:8.9.1

2.4 浏览器验证

访问UI:http://192.168.3.176:8080/

三、方式二:docker-compose 安装

3.1 编写docker-compose.yml文件

https://github.com/apache/skywalking/tree/master/docker

官网有示例docker-compose.yml文件,我们只需要下载下来修改下即可。

代码语言:javascript复制
# 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: elasticsearch:7.9.0
    container_name: es7
    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: skywalking-oap
    restart: always
    # 设置依赖的容器
    depends_on:
      elasticsearch:
        condition: service_healthy
    # 关联ES的容器,通过容器名字来找到相应容器,解决IP变动问题
    links:
      - es7
    # 端口映射
    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: es7: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:
      - skywalking-oap
    ports:
      - "8080:8080"
    environment:
      SW_OAP_ADDRESS: http://skywalking-oap:12800
      TZ: Asia/Shanghai

3.2 启动容器

切换到docker-compose.yml文件所在的目录下,然后执行一下命令:

代码语言:javascript复制
docker-compose up -d

3.3 查看启动镜像

代码语言:javascript复制
docker-compose ps

3.4 浏览器验证

访问网址 http://192.168.3.176:8080/

四、java服务接入skywalking

4.1 下载agent

下载源码包,然后解压取agent目录 https://archive.apache.org/dist/skywalking/8.9.1/ 或 https://skywalking.apache.org/downloads/ 解压获得agent.jar

4.2 jar包方式(推荐)

代码语言:javascript复制
java -javaagent:/data/skywalking-agent/agent/skywalking-agent.jar
-Dskywalking.agent.service_name=my-app-service
-Dskywalking.collector.backend_service=192.168.3.176:11800
-jar my-app-service.jar &

本文为joshua317原创文章,转载请注明:转载自joshua317博客 https://www.joshua317.com/article/264

0 人点赞