docker-compose部署单点apm链路追踪

一.docker-compose 安装下载

1、登入 GitHub ,找到对应版本
curl -L https://github.com/docker/compose/releases/download/1.27.4/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

2、将下载后的文件放到 /usr/local/bin 目录下,并添加执行权限
chmod +x /usr/local/bin/docker-compose

二.APM组件介绍 https://blog.csdn.net/u013613428/article/details/86667240
https://blog.csdn.net/weixin_45784983/article/details/109285319

三,APM-Server 部署安装及使用示例

  1. 编写 docker-es-kibana.yml 文件,该文件所在位置:/data/log
version: '2.2'
services:
  es01:
    image: elasticsearch:7.8.0
    container_name: es01
    environment:
      - bootstrap.memory_lock=true
      - discovery.type=single-node
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - /data/log/es/data:/usr/share/elasticsearch/data
      - /data/logs/es/plugins:/usr/share/elasticsearch/plugins
      - /data/log/es/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
    ports:
      - 9200:9200
    networks:
      - elastic

  kib01:
    image: kibana:7.8.0
    container_name: kib01
    ports:
      - 5601:5601
    environment:
      ELASTICSEARCH_URL: http://es01:9200
      ELASTICSEARCH_HOSTS: http://es01:9200
    networks:
      - elastic

volumes:
  data01:
    driver: local

networks:
  elastic:
    driver: bridge
  1. elasticsearch.yml 文件配置,该文件所在位置:/data/log/es
cluster.name: es-docker-cluster
# 节点名称
node.name: es01
# 绑定host,0.0.0.0代表当前节点的ip
network.host: 0.0.0.0
# 设置其它节点和该节点交互的ip地址,如果不设置它会自动判断,值必须是个真实的ip地址(本机ip)
#network.publish_host: 192.168.200.135
# 设置对外服务的http端口,默认为9200
http.port: 9200
# 设置节点间交互的tcp端口,默认是9300
transport.tcp.port: 9300
# 是否支持跨域,默认为false
http.cors.enabled: true
# 当设置允许跨域,默认为*,表示支持所有域名,如果我们只是允许某些网站能访问,那么可以使用正则表达式。比如只允许本地地址。 /https?:\/\/localhost(:[0-9]+)?/
http.cors.allow-origin: "*"
# 表示这个节点是否可以充当主节点
node.master: true
# 是否充当数据节点
node.data: true
# 所有主从节点ip:port
#discovery.seed_hosts: ["192.168.200.135:9300"]  #本地只有一个节点,无法正常启动,先注释
# 这个参数决定了在选主过程中需要 有多少个节点通信  预防脑裂 N/2+1
discovery.zen.minimum_master_nodes: 1
#初始化主节点
#cluster.initial_master_nodes: ["es-node-1"]  #本地只有一个节点,无法正常启动,先注释
  1. 运行es 、kibana
    分配权限给es目录,进入目录: /data/log
    es启动之后会生成一个node,因为这个启动前没有,启动后会报没有权限,所以要重新执行下 ,然后docker重启es
    chmod 777 /data/log/es/**
# 进入 /data/log
cd /data/log

# 分配权限
chmod 777 es/**

# 启动 es kibana

docker-compose  -f docker-es-kibana.yml up -d
  1. 在/data/log 下新建 apm目录,进入apm目录编辑文件:apm-server.yml
    修改 output.elasticsearch 的地址
apm-server:
  host: "0.0.0.0:8200"
#queue:
  #mem:
    # Max number of events the queue can buffer.
    #events: 4096

#setup.template.pattern: "apm-%{[observer.version]}-*"
#setup.template.overwrite: false
#setup.template.settings:
  #index:
    #number_of_shards: 1
    #codec: best_compression
    #number_of_routing_shards: 30
    #mapping.total_fields.limit: 2000

output.elasticsearch:
  hosts: ["43.155.85.161:9200"]

  # Number of workers per Elasticsearch host.
  #worker: 1

  indices:
    - index: "apm-%{[observer.version]}-sourcemap"
      when.contains:
        processor.event: "sourcemap"

    - index: "apm-%{[observer.version]}-error-%{+yyyy.MM.dd}"
      when.contains:
        processor.event: "error"

    - index: "apm-%{[observer.version]}-transaction-%{+yyyy.MM.dd}"
      when.contains:
        processor.event: "transaction"

    - index: "apm-%{[observer.version]}-span-%{+yyyy.MM.dd}"
      when.contains:
        processor.event: "span"

    - index: "apm-%{[observer.version]}-metric-%{+yyyy.MM.dd}"
      when.contains:
        processor.event: "metric"

    - index: "apm-%{[observer.version]}-onboarding-%{+yyyy.MM.dd}"
      when.contains:
        processor.event: "onboarding"

  #max_retries: 3
  #bulk_max_size: 50
  #backoff.max: 60s
  #timeout: 90

#logging.level: info
#logging.to_syslog: true
#logging.metrics.enabled: false
#logging.metrics.period: 30s
#logging.to_files: true
#logging.files:
  #path: /var/log/apm-server
  #name: apm-server
  #rotateeverybytes: 10485760 # = 10MB
  #keepfiles: 7
  #permissions: 0600
  #interval: 0
#logging.json: false

#http.enabled: false
#http.host: localhost
#http.port: 5066
  1. 在apm目录下执行命令
    cd /data/log/apm
docker run -d --name=apm-server --user=apm-server --volume="$(pwd)/apm-server.yml:/usr/share/apm-server/apm-server.yml:ro" -p 8200:8200 docker.io/elastic/apm-server:7.9.0

  1. 在kibana添加apm插件

docker-compose部署单点apm链路追踪_第1张图片
docker-compose部署单点apm链路追踪_第2张图片
docker-compose部署单点apm链路追踪_第3张图片
7.下载客https://repo1.maven.org/maven2/co/elastic/apm/elastic-apm-agent/
在这里插入图片描述

wget https://repo1.maven.org/maven2/co/elastic/apm/elastic-apm-agent/1.31.0/elastic-apm-agent-1.31.0.jar

8.启动客户端java接入apm服务

nohup java -javaagent:/opt/apm/elastic-apm-agent-1.32.0.jar -Delastic.apm.service_name=osale-admin-seller -Delastic.apm.server_url=http://43.155.85.161:8200 -Delastic.apm.application_packages=osale-admin-seller -jar osale-admin-seller-0.0.1-SNAPSHOT.jar --server.port=8080 2>&1 &

在这里插入图片描述
docker-compose部署单点apm链路追踪_第4张图片

你可能感兴趣的:(docker,elasticsearch,java)