Pinpoint–基础–3.3–安装部署–pinpoint安装–docker部署
前提
使用hd用户登陆
完成基础环境搭建
https://blog.csdn.net/zhou920786312/article/details/118212302
代码位置
https://gitee.com/DanShenGuiZu/learnDemo/tree/master/pinpoint-learn/demo1
1、下载 pinpoint
# 下载地址: https://github.com/pinpoint-apm/pinpoint/releases/tag/v2.3.3
pinpoint-web-boot-2.3.3.jar
pinpoint-collector-boot-2.3.3.jar
pinpoint-agent-2.3.3.tar.gz
2、pinpoint 服务端
2.1、pinpoint-collector
- 默认端口:
- 8081,我这改为5551
- 9994
- 9995
- 9996
- 配置文件:application.yml
2.2.1、代码
hosts
111.111.111.111 zookeeper.hd.com
application.yml
server:
port: 5551
docker-entrypoint.sh
#!/bin/bash
# 虚拟机参数
JAVA_OPTS=
if [ -n "${JAVA_JVM_OPTS1}" ] ; then
JAVA_OPTS="${JAVA_OPTS} ${JAVA_JVM_OPTS1}"
fi
if [ -n "${JAVA_JVM_OPTS2}" ] ; then
JAVA_OPTS="${JAVA_OPTS} ${JAVA_JVM_OPTS2}"
fi
# 配置zookeeper地址
JAVA_OPTS="${JAVA_OPTS} -Dpinpoint.zookeeper.address=zookeeper.hd.com"
# 配置host
cat /home/hd/other/hosts >> /etc/hosts
# 打印配置参数
echo "JVM启动参数:"${JAVA_OPTS}
java -server ${JAVA_OPTS} -jar /home/hd/server.jar
Dockerfile
FROM registry.hd.com:5000/cheng_guang/hd_jdk:1.0
# 创建者
MAINTAINER feizhou <www.feizhou.com.cn>
# 内存参数
ENV JAVA_JVM_OPTS1=-Xms1024m
ENV JAVA_JVM_OPTS2=-Xmx2048m
COPY docker-entrypoint.sh /usr/local/bin/
COPY server/config/* /home/hd/config/
COPY server/pinpoint-collector-boot-2.3.3.jar /home/hd/server.jar
COPY other/* /home/hd/other/
EXPOSE 5551
EXPOSE 9994
EXPOSE 9995
EXPOSE 9996
ENTRYPOINT ["bash","docker-entrypoint.sh"]
WORKDIR /home/hd
shell.sh
#!/bin/bash
#
# 容器 脚本,有启动,重启,停止功能
# 端口
port1=5551
registry_docker="registry_docker_detail"
# 镜像名称
image_tag="image_tag_detail"
# 容器 名称
container_name="container_name_detail"
image_version=$registry_docker$container_name:$image_tag
# 容器id
container_id=
# 启动
start() {
# 获取容器id
get_container_id
# 如果容器id存在,且对应的文件夹也存在
if [ "$container_id" != "" ]; then
echo "$container_name 正在运行"
else
echo "启动:$container_name"
docker_run
fi
}
# 停止
stop() {
# 获取容器id
get_container_id
# 如果容器id存在,且对应的文件夹也存在
if [ "$container_id" != "" ]; then
# 杀死容器id
docker rm -f $container_id
# 睡眠3秒,单位微秒
sleep 3s
echo "$container_name 已停止"
else
echo "$container_name 未运行"
fi
}
# 重启
restart() {
stop
start
}
# 运行状态
status() {
get_container_id
if [ "$container_id" != "" ]; then
echo "$container_name 正在运行"
docker inspect $container_name
else
echo "$container_name 已停止"
fi
}
# 获取容器id
get_container_id() {
container_id=`docker ps -a |grep "$container_name" | grep -v grep| awk '{print $1}'`
}
docker_run() {
mkdir -p /home/hd/shell/$container_name/log
docker run -d --network=host --name $container_name \
-v /home/hd/shell/$container_name/log/:/home/hd/log/ \
--restart=unless-stopped $image_version
}
# 启动参数
case "$1" in
start)
echo "------------------------执行启动------------------------"
start
;;
stop)
echo "------------------------执行停止------------------------"
stop
;;
restart)
echo "------------------------执行重启------------------------"
restart
;;
status)
echo "------------------------执行查看------------------------"
status
;;
*)
echo $"参数提示: $0 {start|stop|restart|status}"
esac
.gitlab-ci.yml
#image: registry.cn-hangzhou.aliyuncs.com/choerodon-tools/cibase:0.7.0
# 变量说明
# CI_PROJECT_NAME 项目名称,auth-center
# CI_PROJECT_ID GitLab CI在内部使用的当前项目的唯一ID
# CI_COMMIT_REF_NAME 分支名称
# CI_COMMIT_SHA commit的版本号
# DOCKER_USER docker账号
# DOCKER_PWD docker密码
# DOCKER_REGISTRY 仓库
# time 提交时间错
# 定义变量
variables:
# GIT_CHECKOUT 全局设置为 false,这样所有阶段都不下载git代码
GIT_CHECKOUT: "false"
# docker 服务名称
docker_name: "pinpoint-collector"
# 缓存文件目录
cache_dir: "/home/gitlab-runner/cache/${CI_PROJECT_NAME}-${CI_PROJECT_ID}-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA}"
cache_dir_docker: ${cache_dir}/docker
image_name: ${DOCKER_REGISTRY}/${HARBOR_PROJECT_NAME}/${CI_PROJECT_NAME}
registry_docker_detail: ${DOCKER_REGISTRY}\/${HARBOR_PROJECT_NAME}\/
stages:
- build-app
- build-docker-images
- server-restart
- server-stop
- clean-cache
# 拷贝文件到指定目录
build-app:
stage: build-app
variables:
# 下载git代码
GIT_CHECKOUT: "true"
script:
# 构建临时目录
- mkdir -p ${cache_dir_docker}
- echo ${cache_dir_docker}
# 拷贝项目中的docker目录到临时文件中
- cp -fr ./docker/* ${cache_dir_docker}
- cp -fr ./shell/* ${cache_dir}
- chmod +x ${cache_dir}/shell.sh
only:
- tags
- develop
- master
- /^release-.*$/
- /^hotfix-.*$/
- /^feature-.*$/
- develop-zf-v1
# 构建镜像
build-docker-images:
stage: build-docker-images
script:
# 修改权限
- chmod +x ${cache_dir_docker}/docker-entrypoint.sh
# 镜像标签
- image_tag=${CI_COMMIT_REF_NAME}$(date +%Y%m%d-%H%M%S)
# 镜像版本
- image_version=${image_name}:$image_tag
# 镜像版本说明文件
- echo $image_version >> ${cache_dir}/image_version
- sed -i "s/image_tag_detail/${image_tag}/g" $cache_dir/shell.sh
- sed -i "s/registry_docker_detail/${registry_docker_detail}/g" $cache_dir/shell.sh
- sed -i "s/container_name_detail/${CI_PROJECT_NAME}/g" $cache_dir/shell.sh
# 登陆
- docker login -u ${DOCKER_USER} -p ${DOCKER_PWD} ${DOCKER_REGISTRY}
# 构建镜像
- docker build -f ${cache_dir_docker}/Dockerfile -t $image_version ${cache_dir_docker}
# 推送镜像
- docker push $image_version
# 停止服务
server-stop:
stage: server-stop
script:
- /home/hd/shell/$docker_name/shell.sh stop
# 手动执行
when: manual
# 启动服务
server-restart:
stage: server-restart
script:
# 推送脚本
- mkdir -p /home/hd/shell/$docker_name
- cp $cache_dir/shell.sh /home/hd/shell/$docker_name
- "docker login -u ${DOCKER_USER} -p ${DOCKER_PWD} ${DOCKER_REGISTRY} && /home/hd/shell/$docker_name/shell.sh restart"
# 手动执行
when: manual
# 清空缓存
clean-cache:
stage: clean-cache
script:
- rm -rf ${cache_dir_docker}/
when: always
2.2.2、核心代码
2.2、pinpoint-web
- 默认端口:8080,我这改为5552
- 配置文件:application.yml
2.3.1、代码
大部分代码都和2.2.1一样,下面我只会列出核心代码
2.3.2、核心代码
2.3.3、查看
http://111.111.102.183:5552/main
3、pinpoint 客户端
PinPoint-Agent需要与被测应用安装在一起
3.1、代码
3.2.1、Dockerfile
COPY pinpoint/pinpoint-agent-2.3.3.tar.gz /home/hd/pinpoint-agent-2.3.3.tar.gz
RUN tar -xzf pinpoint-agent-2.3.3.tar.gz &&\
mv pinpoint-agent-2.3.3 /pt-agent &&\
rm -f pinpoint-agent-2.3.3.tar.gz
3.2.2、docker-entrypoint.sh
if [[ $PINPOINT_ENABLE_PINPOINT == "true" ]]; then
sed -i "s/127.0.0.1/${PINPOINT_COLLECTOR_IP}/g" /pt-agent/profiles/release/pinpoint.config
sed -i "s/module=GRPC/module=THRIFT/g" /pt-agent/profiles/release/pinpoint.config
sed -i "s/rate=20/rate=${PINPOINT_SAMPLING_RATE}/g" /pt-agent/profiles/release/pinpoint.config
echo "profiler.collector.span.port=${PINPOINT_SPAN_PORT}">>/pt-agent/profiles/release/pinpoint.config
echo "profiler.collector.stat.port=${PINPOINT_STAT_PORT}">>/pt-agent/profiles/release/pinpoint.config
echo "profiler.collector.tcp.port=${PINPOINT_TCP_PORT}">>/pt-agent/profiles/release/pinpoint.config
echo "=================pinpoint enabled==================="
echo " collectorIP: ${PINPOINT_COLLECTOR_IP}"
echo " agentId: ${PINPOINT_POD_IP}"
echo " applicationName: ${PINPOINT_APPLICATION_NAME}"
JAVA_AGENT="-javaagent:/pt-agent/pinpoint-bootstrap.jar -Dpinpoint.agentId=${PINPOINT_POD_IP} -Dpinpoint.applicationName=${PINPOINT_APPLICATION_NAME}"
fi
java -server ${JAVA_OPTS} $JAVA_AGENT -jar /home/hd/server.jar
3.2、启动后