- k8s安装skywalking
[root@master skping]
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: skywalking-oap-server
name: skywalking-oap-server
namespace: ops-share
spec:
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app: skywalking-oap-server
template:
metadata:
creationTimestamp: null
labels:
app: skywalking-oap-server
spec:
containers:
- env:
- name: SW_STORAGE
value: elasticsearch7
- name: SW_STORAGE_ES_CLUSTER_NODES
value: '192.168.14.27:9200'
image: 'apache/skywalking-oap-server:8.5.0-es7'
imagePullPolicy: IfNotPresent
securityContext:
privileged: true
name: skywalking-oap-server
ports:
- containerPort: 1234
protocol: TCP
- containerPort: 11800
protocol: TCP
- containerPort: 12800
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
---
apiVersion: v1
kind: Service
metadata:
name: skywalking-oap-server
namespace: ops-share
labels:
app: skywalking-oap-server
spec:
type: ClusterIP
ports:
- name: http1
protocol: TCP
port: 1234
targetPort: 1234
- name: http2
protocol: TCP
port: 11800
targetPort: 11800
- name: http3
protocol: TCP
port: 12800
targetPort: 12800
selector:
app: skywalking-oap-server
[root@master skping]
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: skywalking-ui
name: skywalking-ui
namespace: ops-share
spec:
replicas: 1
selector:
matchLabels:
app: skywalking-ui
template:
metadata:
creationTimestamp: null
labels:
app: skywalking-ui
spec:
containers:
- env:
- name: SW_OAP_ADDRESS
value: 'skywalking-oap-server.ops-share:12800'
image: 'apache/skywalking-ui:8.5.0'
imagePullPolicy: IfNotPresent
name: skywalking-ui
ports:
- containerPort: 8080
name: http
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
---
apiVersion: v1
kind: Service
metadata:
name: skywalking-ui
namespace: ops-share
labels:
app: skywalking-ui
spec:
type: NodePort
ports:
- name: http
protocol: TCP
port: 8080
targetPort: http
selector:
app: skywalking-ui
- 启动
kubectl ns create ops-share
kubectl apply -f ./
kubectl get pod,svc -n ops-share
-
访问ip+端口
-
golang代码接入skywalking
#cat test.go
package main
import (
"fmt"
"github.com/SkyAPM/go2sky"
v3 "github.com/SkyAPM/go2sky-plugins/gin/v3"
"github.com/SkyAPM/go2sky/reporter"
"github.com/gin-gonic/gin"
"net/http"
"time"
)
func main() {
r := gin.Default()
rp, err := reporter.NewGRPCReporter("192.168.14.27:11800", reporter.WithCheckInterval(time.Second))
if err != nil{
fmt.Println("NewGRPCReporter failed!")
return
}
tracer, err := go2sky.NewTracer("demo2", go2sky.WithReporter(rp))
if err != nil{
fmt.Println("NewTracer failed!")
return
}
go2sky.SetGlobalTracer(tracer)
r.Use(v3.Middleware(r, tracer))
r.GET("/",test)
r.Run(":7070")
}
func test(c *gin.Context) {
span,ctx, _ :=go2sky.GetGlobalTracer().CreateLocalSpan(c.Request.Context(),go2sky.WithOperationName("demo2-test"))
if span!=nil{
span.Log(time.Now(),"start demo2-test")
defer span.End()
}
fmt.Println(fmt.Sprintf("traceid:%s spaneId:%d, test 7070",go2sky.TraceID(ctx),go2sky.SpanID(ctx)))
c.String(http.StatusOK, "test 7070")
}
#cat test2.go
package main
import (
"context"
"crypto/tls"
"fmt"
"github.com/SkyAPM/go2sky"
v3 "github.com/SkyAPM/go2sky-plugins/gin/v3"
"github.com/SkyAPM/go2sky/reporter"
"github.com/gin-gonic/gin"
"io/ioutil"
"net/http"
"time"
)
func main() {
r := gin.Default()
rp, err := reporter.NewGRPCReporter("192.168.14.27:11800", reporter.WithCheckInterval(time.Second))
if err != nil {
fmt.Println("NewGRPCReporter failed!")
return
}
tracer, err := go2sky.NewTracer("demo1", go2sky.WithReporter(rp))
if err != nil {
fmt.Println("NewTracer failed!")
return
}
go2sky.SetGlobalTracer(tracer)
r.Use(v3.Middleware(r, tracer))
r.GET("/", test)
r.Run(":8085")
}
func test(c *gin.Context) {
span, ctx, _ := go2sky.GetGlobalTracer().CreateLocalSpan(c.Request.Context(), go2sky.WithOperationName("demo1-test"))
if span != nil {
defer span.End()
}
fmt.Println(fmt.Sprintf("traceid:%s spaneId:%d, test 8085",go2sky.TraceID(ctx),go2sky.SpanID(ctx)))
HttpRequest(ctx)
c.String(http.StatusOK, "test 8085")
}
func HttpRequest(ctx context.Context) {
url := "http://localhost:7070/"
request, _ := http.NewRequest(http.MethodGet, url, nil)
span, _ := go2sky.GetGlobalTracer().CreateExitSpan(ctx, "httpRequest", url, func(headerKey, headerValue string) error {
request.Header.Set(headerKey, headerValue)
return nil
})
defer span.End()
span.Log(time.Now(), "start "+url)
request = request.WithContext(ctx)
client := http.Client{Transport: &http.Transport{DisableKeepAlives: true, TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}}
response, err := client.Do(request)
if err != nil {
span.Error(time.Now(), fmt.Sprintf("%v", err))
} else {
defer response.Body.Close()
responseByte, _ := ioutil.ReadAll(response.Body)
span.Log(time.Now(), "response:"+string(responseByte))
fmt.Println(fmt.Sprintf("traceid:%s spaneId:%d, response%s", go2sky.TraceID(ctx), go2sky.SpanID(ctx), string(responseByte)))
}
}
- 启动go服务
go run test.go
go run test2.go
-
访问ip+8085地址
-
多请求一点数据让skywalking数据展示出来
for i in {1..100};do sleep 2; hey -n 100 -m get http://192.168.10.100:8085 ;done
- php-fpm容器接入skywalking
docker pull skyapm/skywalking-php:v4.2.0-7.2-fpm-alpine
docker run -itd -p 8080:8080 skyapm/skywalking-php:v4.2.0-7.2-fpm-alpine bash
docker exec -it id bash
cd /usr/local/etc/php/conf.d/
cat ext-skywalking.ini
[skywalking]
extension=skywalking.so
skywalking.app_code = hello_skywalking
skywalking.enable = 1
skywalking.version = 8
skywalking.grpc = 192.168.14.27:11800
#skywalking.error_handler_enable = 0
#skywalking.sample_n_per_3_secs = -1
#skywalking.instance_name = ""
cd /var/www/html
cat 2.php
<?php
$url = 'http://192.168.10.100:8085/';
echo file_get_contents($url);
?>
-
重启docker php-fpm容器并访问8080/2.php
页面显示test 8085 因为访问的8085的接口
-
查看skywalking是否监控到了php