前置条件:安装好jdk11,linux服务器(centos7.9),go版本(我的是1.18,1.21都可以)
1.下载skywalking

2.下载agent源码

3.下载的两个文件传到服务器
4.启动skywalking
/apache-skywalking-apm-bin/bin/startup.sh
出现这个说明成功了:

有问题可以查日志:"apache-skywalking-apm-bin/logs/"
UI的端口是8080,防火墙放开端口,直接 "ip:8080" 即可访问
5.编译go-agent
cd apache-skywalking-go-0.5.0
# 如果没有make环境,直接yum install make
make build
编译需要点时间,成功如下:

6.编写go程序
日志有几个是支持的,例如logrus、zap
Go
package main
import (
_ "github.com/apache/skywalking-go"
"github.com/sirupsen/logrus"
"go.uber.org/zap"
"net/http"
)
func main() {
logger, _ := zap.NewProduction()
defer logger.Sync()
http.HandleFunc("/hello", func(writer http.ResponseWriter, request *http.Request) {
writer.Write([]byte("Hello World"))
logrus.Infof("send messages!")
logger.Info("send messages!!!!!!!")
})
err := http.ListenAndServe(":8000", nil)
if err != nil {
panic(err)
}
}
7.编译启动程序
Go
# 这个地方需要使用 -a参数
go build -toolexec="编译好的二进制" -a -o main .
# 例如
# go build -toolexec="/home/dev_tools/apache-skywalking-go-0.5.0/bin/skywalking-go-agent-0.5.0-linux-amd64" -a -o main .
Go
# 执行程序
./main
浏览器点击 ip:8000/hello
UI( ip:8080)能看到链路追踪
