1. docker-compose installation and download
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
2. Introduction to APM components https://blog.csdn.net/u013613428/article/details/86667240
https://blog.csdn.net/weixin_45784983/article/details/109285319
3. APM-Server deployment, installation and usage examples
- Write the docker-es-kibana.yml file. The file is located at: /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
- elasticsearch.yml file configuration, the file location: /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"] #本地只有一个节点,无法正常启动,先注释
- Run es and kibana
assign permissions to the es directory and enter the directory: /data/log
After es is started, a node will be generated. Because it does not exist before starting, it will report that it has no permissions after starting, so it needs to be executed again, and then docker restarts 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
- Create a new apm directory under /data/log, enter the apm directory and edit the file: apm-server.yml
to modify the address of 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
Execute the command cd /data/log/apm in the apm directory
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
- Add apm plugin to kibana
7. Download the guest 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. Start the client java to access the apm service
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 &