这里我们采用企业中主流的skywalking6.X系列。
服务器规划
生成至少两台虚拟机
141节点
141节点docker方式安装skywalking。
154节点
初始化java、mvn、git、docker环境。
官网地址
根据官网地址选择TAG版本后,进入docker目录中,修改docker-compose.yml文件内容
https://github.com/apache/skywalking
6.6.0版本地址
https://github.com/apache/skywalking/tree/v6.6.0/docker
docker-compose.yml
version: '3.3'
services:
elasticsearch:
image: elasticsearch:7.5.1
container_name: elasticsearch
restart: always
ports:
- 9200:9200
environment:
discovery.type: single-node
TZ: Asia/Shanghai
ulimits:
memlock:
soft: -1
hard: -1
oap:
image: apache/skywalking-oap-server:6.6.0-es7
container_name: oap
depends_on:
- elasticsearch
links:
- elasticsearch
restart: always
ports:
- 11800:11800
- 12800:12800
environment:
SW_STORAGE: elasticsearch # 指定ES版本
SW_STORAGE_ES_CLUSTER_NODES: elasticsearch:9200
TZ: Asia/Shanghai
ui:
image: apache/skywalking-ui:6.6.0
container_name: ui
depends_on:
- oap
links:
- oap
restart: always
ports:
- 8080:8080
environment:
SW_OAP_ADDRESS: oap:12800
TZ: Asia/Shanghai
ES测试
http://192.168.198.141:1 9200/
skywalking测试
http://192.168.198.141:8080/
skywalking集成war包
tomcat8下载
官网下载地址:
https://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.57/bin/apache-tomcat-
8.5.57.tar.gz
skywalking客户端配置
将skywalking源码包上传154节点/opt目录中
cd /opt
tar zxf apache-skywalking-apm-6.6.0.tar.gz
mv apache-skywalking-apm-bin/ skywalking
rm -rf apache-skywalking-apm-6.6.0.tar.gz
springmvc项目
idea配置
idea开发工具mvn工程。使用springMVC+jsp方式。需要进行war包配置。需要将web目录重新更名为webapp并将webapp目录复制到maven工程指定的src/main/中。
pom.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>springmvcdemo2</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<spring.version>5.0.5.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>skywalking-springmvc</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<!-- 指定端口 -->
<port>8082</port>
<!-- 请求路径 -->
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>
</project>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-web.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.controller</url-pattern>
</servlet-mapping>
</web-app>
applicationContext-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/springcontext.xsd">
<context:component-scan base-package="com.lagou.controller"/>
</beans>
HelloController
@Controller
@RequestMapping("/hello")
//注意访问项目URL地址为:hello/sayHello.controller
public class HelloController {
@RequestMapping("/sayHello")
@ResponseBody
public String sayHello(String name){
return "hello skywalking";
}
}
index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>skywaling springmv war</title>
</head>
<body>
hello skywaling springmv war!!!
</body>
</html>
运行测试
本地idea开发工具中运行项目
mvn clean tomcat7:run
测试index页面
http://localhost:8082
测试URL地址
http://localhost:8082/hello/sayHello.controller
打包项目
mvn clean package
配置agent
首先我们复制一份agent,防止与其他应用程序使用的agent冲突
cd /opt/skywalking
cp -r agent agent_springmvc
cd /opt/skywalking/agent_springmvc/config
vi agent.config
我们在配置中找到这么一行:
agent.service_name=${SW_AGENT_NAME:Your_ApplicationName}
这里的配置含义是可以读取到SW_AGENT_NAME配置属性,如果该配置没有指定,那么默认名称为Your_ApplicationName。这里我们把Your_ApplicationName替换成skywalking_springmvc
agent.service_name=${SW_AGENT_NAME:skywalking_springmvc}
配置tomcat
将apache-tomcat-8.5.57.tar.gz上传154节点/opt目录中
cd /opt
tar zxf apache-tomcat-8.5.57.tar.gz
mv apache-tomcat-8.5.57 tomcat8
rm -rf apache-tomcat-8.5.57.tar.gz
将war包复制到webapps目录
cd /data
mv /data/skywalking-springmvc.war /opt/tomcat8/webapps/
集成skywalking
在catalina.sh文件顶部添加skywalking集成配置
vi /opt/tomcat8/bin/catalina.sh
CATALINA_OPTS="$CATALINA_OPTS -
javaagent:/opt/skywalking/agent_springmvc/skywalking-agent.jar -
Dskywalking.collector.backend_service=192.168.198.141:11800"; export
CATALINA_OPTS
启动tomcat
启动tomcat8
cd /opt/tomcat8/bin
./startup.sh
http://192.168.198.154:8080/
http://192.168.198.154:8080/skywalking-springmvc/
http://192.168.198.154:8080/skywalking-springmvc/hello/sayHello.controller
停止tomcat8
./shutdown.sh
网友评论