微服務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 $?

相關文章
相關標籤/搜索