微服务spring-cloud 链路追踪skywalking6.x引入

1、准备工做java

环境:web

1.jdk1.8,高于不支持spring

2.elasticsearch6.5.4搜索引擎:apache

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.4.tar.gzbootstrap

解压:tar -zxvf elasticsearch-6.5.4.tar.gzvim

配置:bash

vim elasticsearch-6.5.4/config/elasticsearch.yml服务器

修改如下内容app

cluster.name: myskywalkingwebapp

path.data: /opt/data/es/data

path.logs: /opt/data/es/logs

bootstrap.memory_lock: false

bootstrap.system_call_filter: false

network.host: 127.0.0.1    #推荐本机IP,

http.port: 9200

启动es

2、安装skywalking服务端

1.官网下载:http://skywalking.apache.org/

#wget http://mirror.bit.edu.cn/apache/skywalking/6.1.0/apache-skywalking-apm-6.1.0.tar.gz 

#解压:tar -zxvf apache-skywalking-apm-6.1.0.tar.gz 

2.修改webapp端口由默认8080,改为13800:

cd /home/wshop/skywalking/apache-skywalking-apm-bin/webapp

vi webapp.yml

server:
  port: 13800

3.修改es配置

cd /home/wshop/skywalking/apache-skywalking-apm-bin/config

vi application.yml

4.启动

cd /home/wshop/skywalking/apache-skywalking-apm-bin/bin

./startup.sh

将启动两个服务:收集器11800端口和监控ui界面13800端口

访问:http://192.168.60.235:13800/

说明服务端已经启动成功;

3、客户端引入:

192.168.60.235:11800属于收集器

本地服务器,只要对应上"skywalking-agent.jar"

其余服务只要将agent目录复制过去,而后启动对应该服务接口,即能进行监控;

相应jar工程,在启动脚本前增长“ -javaagent:/home/wshop/skywalking/apache-skywalking-apm-bin/agent/skywalking-agent.jar -Dskywalking.agent.service_name=${APPNAME} -Dskywalking.collector.backend_service=192.168.60.235:11800”  便可。

完整客户端run脚本

#!/bin/bash
#########################################################################
# File Name: run.sh
# Function:
# Author: Mason
# Version: V1.0
# Created Time: 28/1/2019 11:41:48
#########################################################################

# chkconfig: - 98 33
# description: Starts and stops the java project daemon \
#              used to provide some java jar packet services.

source /etc/profile

# base env parameters setting
BASEDIR=$(dirname $(readlink -f $0))
APPNAME=user-manager
VERSION=1.0.0
PORT=8710

JAVAOPT="-Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256M"


# define some functions
get_pid(){
        PID=$(ps -ef|grep ${APPNAME} |grep "java" |grep -v grep |awk '{print $2}')
}

start(){
        if [ -z ${PID} ];then
                nohup java ${JAVAOPT} -Dlogging.config=${BASEDIR}/logback-spring.xml -D$APPNAME -javaagent:/home/wshop/skywalking/apache-skywalking-apm-bin/agent/skywalking-agent.jar -Dskywalking.agent.service_name=${APPNAME} -Dskywalking.collector.backend_service=192.168.60.235:11800  -jar ${BASEDIR}/${APPNAME}-${VERSION}.jar --spring.config.location=${BASEDIR}/application.yml,/home/wshop/service/config/bootstrap.yml &>/dev/null &

                inter=1
                time=10
                i=0
                while ((i < time));do
                        get_pid
                        #if [ $(netstat -lntup|grep -c $PID) -le 1 ];then
                    if((i>(time-2)));then
                if [ ${PID} ];then
                    echo "${APPNAME} started OK."
                    break
                else
                    sleep ${inter}
                    let i++
                fi
            else
                sleep ${inter}
                let i++
            fi
                done
                if ((i == time));then
                        echo "${APPNAME} started FAIL in $((inter*time)) second!"
                        exit 1
                fi
        else
                echo "${APPNAME} is still running with pid ${PID}!"
                exit 1
        fi
}

stop(){
        if [ ! -z ${PID} ];then
                kill -9 ${PID} && echo "${APPNAME} was killed."
        else
                echo "${APPNAME} is not running!"
                exit 0
        fi
}

restart(){
        stop
        start
}

status(){
        if [ ! -z ${PID} ];then
                echo "${APPNAME} is running with pid ${PID}"
        else
                echo "${APPNAME} is not running."
        fi
}

# the main program started get_pid case "$1" in   start)         start         ;;   stop)         stop         ;;   restart)         restart         ;;   status)         status         ;;   *)         echo $"Usage: $0 {start|stop|restart|status}"         exit 2 esac exit $?

相关文章
相关标签/搜索