Promethues operate blackbox(http/tcp/dns/icmp探测)

2023-10-17 23:59

本文主要是介绍Promethues operate blackbox(http/tcp/dns/icmp探测),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Promethues operate blackbox(http/tcp/dns/icmp探测)

由于grafana dashboard市场下载的blackbox不太好用,我做了简单修改,效果如下:

在这里插入图片描述

prometheus配置

由于prometheus operator采用servicemonitor或者probe方式来对blackbox进行数据采集的时候均存在一定的问题,所以对于这部分scrap配置,采用手动配置了

[root@k8s-master-1 prometheus-operator]# cat prometheus-server.yaml 
---
apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:name: servernamespace: monitor
spec:image: prom/prometheus:v2.36.2nodeSelector: kubernetes.io/hostname: "k8s-master-1"serviceMonitorSelector:matchLabels:application: "prometheus"probeSelector:matchLabels:application: "prometheus"serviceAccountName: prometheus-serveradditionalScrapeConfigs:name: blackboxkey: blackbox-config.yamlstorage:volumeClaimTemplate: #如果配置了这个,prometheus-server的存储就会保存在这里spec:accessModes:- ReadWriteOnceresources:requests:storage: 10Gi
---
apiVersion: v1    
kind: Service    
metadata:    name: prometheus-server    namespace: monitor    labels:    application: "prometheus-server"    
spec:    selector:    prometheus: server    type: NodePort    ports:    - name: metrics    port: 9090    targetPort: 9090    protocol: TCP    nodePort: 39090   

blackbox配置

[root@k8s-master-1 blackbox]# cat blackbox.yaml 
apiVersion: v1
kind: ConfigMap
metadata:name: blackbox-confignamespace: monitor
data:blackbox.yml: |-modules:http_2xx:                          # http 检测模块  Blockbox-Exporter 中所有的探针均是以 Module 的信息进行配置prober: httptimeout: 15shttp:valid_http_versions: ["HTTP/1.1", "HTTP/2"]   valid_status_codes: [200,301,302]method: GETpreferred_ip_protocol: "ip4"   # 选用IPV4follow_redirects: true         # 跟进重定向tcp_connect:                       # TCP模块prober: tcptimeout: 15sdns_tcp:                           # tcp探测DNSprober: dnsdns:transport_protocol: "tcp"      # 默认是 udppreferred_ip_protocol: "ip4"   # 默认是 ip6query_name: "kubernetes.default.svc.cluster.local" # 利用这个域名来检查 dns 服务器query_type: "A"                                    # 如果是 kube-dns ,一定要加入这个,因为不支持Ipv6icmp:prober: icmpicmp:preferred_ip_protocol: "ip4"
---
apiVersion: apps/v1
kind: Deployment
metadata:name: blackboxnamespace: monitor
spec:replicas: 1selector:matchLabels:app: blackboxtemplate:metadata:labels:app: blackboxspec:nodeName: k8s-master-1containers:- image: prom/blackbox-exporter:v0.21.1name: blackboxargs:- --config.file=/etc/blackbox_exporter/blackbox.yml- --log.level=info - --web.listen-address=:9115ports:- name: httpcontainerPort: 9115volumeMounts:- name: configmountPath: /etc/blackbox_exporterdnsPolicy: ClusterFirstvolumes:- name: configconfigMap:name: blackbox-config
---
apiVersion: v1
kind: Service
metadata:name: blackboxnamespace: monitorlabels:app: blackbox
spec:selector:app: blackboxtype: NodePortports:- name: httpport: 9115targetPort: 9115nodePort: 39115
---
#apiVersion: v1
#kind: Secret
#metadata:
#  name: blackbox
#  namespace: monitor
#stringData: 
#  blackbox.yaml: | 
#  - job_name: "icmp-check"  # 这样写会出问题
#    metrics_path: /probe
#    params:
#      module: icmp
#    static_configs:
#    - targets:
#      - 192.168.0.10
#      - 192.168.0.11
---
# 使用这种方式进行黑盒监控时多个target只抓取了第一个target,原因暂时未找到,生成的scrp_url=10.70.0.128:9115/probe?module=tcp_connect&target=192.168.0.10:22&target=192.168.0.11:22""
# issues https://github.com/prometheus-operator/prometheus-operator/issues/2821#apiVersion: monitoring.coreos.com/v1   
#kind: ServiceMonitor
#metadata:
#  name: blackbox
#  namespace: monitor
#  labels:
#    application: "prometheus"
#spec:
#  namespaceSelector:
#    matchNames: ["monitor"]
#  selector:
#    matchLabels:
#      app: blackbox
#  endpoints:
#  - interval: "15s"
#    path: /probe
#    port: http
#    scheme: HTTP
#    params:
#      module:
#      - tcp_connect
#      target:
#      - 192.168.0.10:22
#      - 192.168.0.11:22
#    relabelings: 
#    - sourceLabels: [__address__]
#      targetLabel: __param_target
#    - sourceLabels: [__param_target]
#      targetLabel: instance
#    - targetLabel: __address__
#      replacement: blackbox.monitor.svc.cluster.local:9115
---
# 这种太重复了,会导致生成很多instance,需要对标签进行处理,后续二个job 需进行标签聚合,太麻烦了
#apiVersion: monitoring.coreos.com/v1
#kind: Probe
#metadata:
#  name: blackbox-tcp-check
#  namespace: monitor
#  labels:
#    application: "prometheus"
#spec:
#  jobName: tcp-check
#  module: tcp_connect
#  prober:
#    url: blackbox.monitor.svc.cluster.local:9115
#  targets:
#    staticConfig:
#      static:
#      - 192.168.0.10:22
#      - 192.168.0.11:22
#  metricRelabelings:
#  - sourceLabels: [__address__]
#    targetLabel: instance
---
#apiVersion: monitoring.coreos.com/v1
#kind: Probe
#metadata:
#  name: blackbox-icmp-check
#  namespace: monitor
#  labels:
#    application: "prometheus"
#spec:
#  jobName: icmp-check
#  module: icmp
#  prober:
#    url: blackbox.monitor.svc.cluster.local:9115
#  targets:
#    staticConfig:
#      static:
#      - 192.168.0.10
#      - 192.168.0.11
#  metricRelabelings:
#  - sourceLabels: [__address__]  # 基于IP保证后续instance一致
#    targetLabel: instanc
[root@k8s-master-1 blackbox]# cat blackbox-config.yaml 
- job_name: "ICMP-CHECK"    metrics_path: /probe params:    module: - icmp    static_configs:    - targets:    - 192.168.0.10    - 192.168.0.11labels:blackbox: icmprelabel_configs:- source_labels: [__address__]                         # 为params赋值target=[__address__],调整向blackbox请求的URL参数target_label: __param_target- target_label: __address__                            # 让prometheus去blackbox抓取信息replacement: blackbox.monitor.svc.cluster.local:9115- source_labels: [__param_target]                      # 將 instace 的值修改成 target 的值target_label: instance
- job_name: "TCP-CHECK"    metrics_path: /probe params:    module: - tcp_connect   static_configs:    - targets:    - 192.168.0.10:22    - 192.168.0.11:22- 192.168.0.10:3306- 192.168.0.10:6443- 192.168.0.10:1250- 192.168.0.10:2380- 192.168.0.11:2380- 192.168.0.10:2049- 192.168.0.10:111labels:blackbox: tcprelabel_configs:- source_labels: [__address__]   target_label: __param_target- target_label: __address__     replacement: blackbox.monitor.svc.cluster.local:9115- source_labels: [__param_target] 
#    regex: "(.*):(.*)"                                   # 聚合instance,将其与第一个job为一类,丢弃端口,grafana不做聚合,放弃这种方式
#    replacement: $1target_label: instance
- job_name: "HTTP-CHECK"    metrics_path: /probe params:    module: - http_2xx    static_configs:    - targets:    - http://www.baidu.com- http://www.huya.com- http://www.douyu.com- http://www.bilibili.comlabels:blackbox: http_2xxrelabel_configs:- source_labels: [__address__]     target_label: __param_target- target_label: __address__         replacement: blackbox.monitor.svc.cluster.local:9115- source_labels: [__param_target]    target_label: instance
- job_name: "DNS-CHECK"    metrics_path: /probe params:    module: - dns_tcpstatic_configs:    - targets:    - 10.0.0.10                                           # K8S集群内DNS服务器labels:blackbox: dnsrelabel_configs:- source_labels: [__address__]     target_label: __param_target- target_label: __address__         replacement: blackbox.monitor.svc.cluster.local:9115- source_labels: [__param_target]    target_label: instance

创建prometheus资源需要的additionalScrapeConfigs:kubectl create secret generic blackbox --from-file=blackbox-config.yaml -n monitor

prometheus检查

在这里插入图片描述

导入grafana配置

{"annotations": {"list": [{"builtIn": 1,"datasource": {"type": "datasource","uid": "grafana"},"enable": true,"hide": true,"iconColor": "rgba(0, 211, 255, 1)","name": "Annotations & Alerts","target": {"limit": 100,"matchAny": false,"tags": [],"type": "dashboard"},"type": "dashboard"}]},"description": "Quick overview of values from blackbox exporters","editable": true,"fiscalYearStartMonth": 0,"gnetId": 11529,"graphTooltip": 0,"id": 3,"iteration": 1656837727417,"links": [],"liveNow": false,"panels": [{"columns": [],"datasource": {"type": "prometheus","uid": "wt9lNze7z"},"fontSize": "100%","gridPos": {"h": 8,"w": 11,"x": 0,"y": 0},"id": 103,"links": [],"repeatDirection": "h","scroll": true,"showHeader": true,"sort": {"col": 4,"desc": false},"styles": [{"alias": "Time","align": "auto","dateFormat": "YYYY-MM-DD HH:mm:ss","pattern": "Time","type": "hidden"},{"alias": "1=UP, 0=DOWN","align": "auto","colorMode": "row","colors": ["rgba(245, 54, 54, 0.9)","rgba(245, 54, 54, 0.9)","rgba(50, 172, 45, 0.97)"],"dateFormat": "YYYY-MM-DD HH:mm:ss","decimals": 0,"pattern": "Value","thresholds": ["0","1"],"type": "number","unit": "short"},{"alias": "","align": "auto","colors": ["rgba(245, 54, 54, 0.9)","rgba(237, 129, 40, 0.89)","rgba(50, 172, 45, 0.97)"],"dateFormat": "YYYY-MM-DD HH:mm:ss","decimals": 2,"pattern": "__name__","thresholds": [],"type": "hidden","unit": "short"},{"alias": "","align": "auto","colors": ["rgba(245, 54, 54, 0.9)","rgba(237, 129, 40, 0.89)","rgba(50, 172, 45, 0.97)"],"decimals": 2,"pattern": "/.*/","thresholds": [],"type": "number","unit": "short"}],"targets": [{"expr": "probe_success","format": "table","instant": true,"intervalFactor": 1,"refId": "A"}],"title": "黑盒监控汇总数据","transform": "table","type": "table-old"},{"columns": [],"datasource": {"type": "prometheus","uid": "wt9lNze7z"},"fontSize": "100%","gridPos": {"h": 8,"w": 13,"x": 11,"y": 0},"id": 109,"links": [],"scroll": true,"showHeader": true,"sort": {"col": 3,"desc": false},"styles": [{"alias": "Time","align": "auto","dateFormat": "YYYY-MM-DD HH:mm:ss","pattern": "Time","type": "hidden"},{"alias": "Time Left","align": "auto","colorMode": "row","colors": ["rgba(245, 54, 54, 0.9)","rgba(237, 129, 40, 0.89)","rgba(50, 172, 45, 0.97)"],"dateFormat": "YYYY-MM-DD HH:mm:ss","decimals": 0,"pattern": "Value","thresholds": ["0","2592000"],"type": "number","unit": "s"},{"alias": "","align": "auto","colors": ["rgba(245, 54, 54, 0.9)","rgba(237, 129, 40, 0.89)","rgba(50, 172, 45, 0.97)"],"decimals": 2,"pattern": "/.*/","thresholds": [],"type": "number","unit": "short"}],"targets": [{"expr": "probe_ssl_earliest_cert_expiry-time()","format": "table","instant": true,"intervalFactor": 1,"legendFormat": "{{instance}}","refId": "A"}],"title": "SSL证书过期情况","transform": "table","type": "table-old"},{"datasource": {"type": "prometheus","uid": "wt9lNze7z"},"fieldConfig": {"defaults": {"color": {"mode": "palette-classic"},"custom": {"axisLabel": "","axisPlacement": "auto","barAlignment": 0,"drawStyle": "line","fillOpacity": 0,"gradientMode": "none","hideFrom": {"legend": false,"tooltip": false,"viz": false},"lineInterpolation": "smooth","lineWidth": 3,"pointSize": 5,"scaleDistribution": {"type": "linear"},"showPoints": "never","spanNulls": false,"stacking": {"group": "A","mode": "none"},"thresholdsStyle": {"mode": "off"}},"mappings": [],"thresholds": {"mode": "absolute","steps": [{"color": "green","value": null},{"color": "red","value": 80}]},"unit": "short"},"overrides": []},"gridPos": {"h": 8,"w": 24,"x": 0,"y": 8},"id": 107,"links": [],"options": {"legend": {"calcs": ["max","min"],"displayMode": "table","placement": "right"},"tooltip": {"mode": "multi","sort": "desc"}},"pluginVersion": "8.5.1","targets": [{"datasource": {"type": "prometheus","uid": "wt9lNze7z"},"expr": "probe_duration_seconds","format": "time_series","intervalFactor": 1,"legendFormat": "{{instance}}","refId": "A"}],"title": "探测耗时","type": "timeseries"},{"datasource": {"type": "prometheus","uid": "wt9lNze7z"},"fieldConfig": {"defaults": {"color": {"mode": "palette-classic"},"custom": {"axisLabel": "","axisPlacement": "auto","barAlignment": 0,"drawStyle": "line","fillOpacity": 0,"gradientMode": "none","hideFrom": {"legend": false,"tooltip": false,"viz": false},"lineInterpolation": "smooth","lineStyle": {"fill": "solid"},"lineWidth": 3,"pointSize": 5,"scaleDistribution": {"type": "linear"},"showPoints": "never","spanNulls": true,"stacking": {"group": "A","mode": "none"},"thresholdsStyle": {"mode": "off"}},"mappings": [],"thresholds": {"mode": "absolute","steps": [{"color": "green","value": null},{"color": "red","value": 80}]},"unit": "short"},"overrides": []},"gridPos": {"h": 6,"w": 24,"x": 0,"y": 16},"id": 119,"links": [],"options": {"legend": {"calcs": ["min"],"displayMode": "list","placement": "bottom"},"tooltip": {"mode": "multi","sort": "none"}},"pluginVersion": "8.5.1","targets": [{"datasource": {"type": "prometheus","uid": "wt9lNze7z"},"expr": "probe_success{blackbox=\"dns\"}","format": "time_series","intervalFactor": 1,"legendFormat": "{{instance}}","refId": "A"}],"title": "DNS探测","type": "timeseries"},{"datasource": {"type": "prometheus","uid": "wt9lNze7z"},"fieldConfig": {"defaults": {"color": {"mode": "palette-classic"},"custom": {"axisLabel": "","axisPlacement": "auto","barAlignment": 0,"drawStyle": "line","fillOpacity": 0,"gradientMode": "none","hideFrom": {"legend": false,"tooltip": false,"viz": false},"lineInterpolation": "smooth","lineWidth": 3,"pointSize": 5,"scaleDistribution": {"type": "linear"},"showPoints": "never","spanNulls": true,"stacking": {"group": "A","mode": "none"},"thresholdsStyle": {"mode": "off"}},"mappings": [],"thresholds": {"mode": "absolute","steps": [{"color": "green","value": null},{"color": "red","value": 80}]},"unit": "short"},"overrides": [{"__systemRef": "hideSeriesFrom","matcher": {"id": "byNames","options": {"mode": "exclude","names": ["192.168.0.11"],"prefix": "All except:","readOnly": true}},"properties": [{"id": "custom.hideFrom","value": {"legend": false,"tooltip": false,"viz": true}}]}]},"gridPos": {"h": 6,"w": 24,"x": 0,"y": 22},"id": 115,"links": [],"options": {"legend": {"calcs": ["min"],"displayMode": "list","placement": "bottom"},"tooltip": {"mode": "multi","sort": "none"}},"pluginVersion": "8.5.1","targets": [{"datasource": {"type": "prometheus","uid": "wt9lNze7z"},"editorMode": "code","exemplar": false,"expr": "probe_success{blackbox=\"icmp\"}","format": "time_series","instant": false,"intervalFactor": 1,"legendFormat": "{{instance}}","range": true,"refId": "A"}],"title": "网络探测","type": "timeseries"},{"datasource": {"type": "prometheus","uid": "wt9lNze7z"},"fieldConfig": {"defaults": {"color": {"mode": "palette-classic"},"custom": {"axisLabel": "","axisPlacement": "auto","barAlignment": 0,"drawStyle": "line","fillOpacity": 0,"gradientMode": "none","hideFrom": {"legend": false,"tooltip": false,"viz": false},"lineInterpolation": "smooth","lineStyle": {"fill": "solid"},"lineWidth": 3,"pointSize": 5,"scaleDistribution": {"type": "linear"},"showPoints": "never","spanNulls": true,"stacking": {"group": "A","mode": "none"},"thresholdsStyle": {"mode": "off"}},"mappings": [],"thresholds": {"mode": "absolute","steps": [{"color": "green","value": null},{"color": "red","value": 80}]},"unit": "short"},"overrides": []},"gridPos": {"h": 6,"w": 24,"x": 0,"y": 28},"id": 113,"links": [],"options": {"legend": {"calcs": ["min"],"displayMode": "list","placement": "bottom"},"tooltip": {"mode": "multi","sort": "none"}},"pluginVersion": "8.5.1","targets": [{"datasource": {"type": "prometheus","uid": "wt9lNze7z"},"expr": "probe_success{blackbox=\"tcp\"}","format": "time_series","intervalFactor": 1,"legendFormat": "{{instance}}","refId": "A"}],"title": "端口探测","type": "timeseries"},{"datasource": {"type": "prometheus","uid": "wt9lNze7z"},"fieldConfig": {"defaults": {"color": {"mode": "palette-classic"},"custom": {"axisLabel": "","axisPlacement": "auto","barAlignment": 0,"drawStyle": "line","fillOpacity": 0,"gradientMode": "none","hideFrom": {"legend": false,"tooltip": false,"viz": false},"lineInterpolation": "smooth","lineWidth": 3,"pointSize": 5,"scaleDistribution": {"type": "linear"},"showPoints": "auto","spanNulls": false,"stacking": {"group": "A","mode": "none"},"thresholdsStyle": {"mode": "off"}},"mappings": [],"thresholds": {"mode": "absolute","steps": [{"color": "green","value": null},{"color": "red","value": 80}]}},"overrides": []},"gridPos": {"h": 6,"w": 24,"x": 0,"y": 34},"id": 117,"links": [],"options": {"legend": {"calcs": ["min"],"displayMode": "list","placement": "bottom"},"tooltip": {"mode": "single","sort": "none"}},"pluginVersion": "8.5.1","targets": [{"datasource": {"type": "prometheus","uid": "wt9lNze7z"},"expr": "probe_success{blackbox=\"http_2xx\"}","format": "time_series","intervalFactor": 1,"legendFormat": "{{instance}}","refId": "A"}],"title": "站点探测","type": "timeseries"}],"refresh": "30s","schemaVersion": 36,"style": "dark","tags": ["blackbox","prometheus"],"templating": {"list": [{"auto": true,"auto_count": 10,"auto_min": "10s","current": {"selected": false,"text": "auto","value": "$__auto_interval_interval"},"hide": 2,"label": "Interval","name": "interval","options": [{"selected": true,"text": "auto","value": "$__auto_interval_interval"},{"selected": false,"text": "5s","value": "5s"},{"selected": false,"text": "10s","value": "10s"},{"selected": false,"text": "30s","value": "30s"},{"selected": false,"text": "1m","value": "1m"},{"selected": false,"text": "10m","value": "10m"},{"selected": false,"text": "30m","value": "30m"},{"selected": false,"text": "1h","value": "1h"},{"selected": false,"text": "6h","value": "6h"},{"selected": false,"text": "12h","value": "12h"},{"selected": false,"text": "1d","value": "1d"},{"selected": false,"text": "7d","value": "7d"},{"selected": false,"text": "14d","value": "14d"},{"selected": false,"text": "30d","value": "30d"}],"query": "5s,10s,30s,1m,10m,30m,1h,6h,12h,1d,7d,14d,30d","refresh": 2,"skipUrlSync": false,"type": "interval"},{"current": {"selected": false,"text": "All","value": "$__all"},"datasource": {"type": "prometheus","uid": "wt9lNze7z"},"definition": "","hide": 2,"includeAll": true,"multi": true,"name": "targets","options": [],"query": {"query": "label_values(probe_success, instance)","refId": "Prometheus-targets-Variable-Query"},"refresh": 1,"regex": "","skipUrlSync": false,"sort": 0,"tagValuesQuery": "","tagsQuery": "","type": "query","useTags": false}]},"time": {"from": "now-5m","to": "now"},"timepicker": {"refresh_intervals": ["5s","10s","30s","1m","5m","15m","30m","1h","2h","1d"],"time_options": ["5m","15m","1h","6h","12h","24h","2d","7d","30d"]},"timezone": "","title": "Blackbox Exporter Quick Overview-1","uid": "xtkCtBkiz2","version": 28,"weekStart": ""
}

这篇关于Promethues operate blackbox(http/tcp/dns/icmp探测)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/228821

相关文章

BUUCTF靶场[web][极客大挑战 2019]Http、[HCTF 2018]admin

目录   [web][极客大挑战 2019]Http 考点:Referer协议、UA协议、X-Forwarded-For协议 [web][HCTF 2018]admin 考点:弱密码字典爆破 四种方法:   [web][极客大挑战 2019]Http 考点:Referer协议、UA协议、X-Forwarded-For协议 访问环境 老规矩,我们先查看源代码

【Linux】应用层http协议

一、HTTP协议 1.1 简要介绍一下HTTP        我们在网络的应用层中可以自己定义协议,但是,已经有大佬定义了一些现成的,非常好用的应用层协议,供我们直接使用,HTTP(超文本传输协议)就是其中之一。        在互联网世界中,HTTP(超文本传输协议)是一个至关重要的协议,他定义了客户端(如浏览器)与服务器之间如何进行通信,以交换或者传输超文本(比如HTML文档)。

如何确定 Go 语言中 HTTP 连接池的最佳参数?

确定 Go 语言中 HTTP 连接池的最佳参数可以通过以下几种方式: 一、分析应用场景和需求 并发请求量: 确定应用程序在特定时间段内可能同时发起的 HTTP 请求数量。如果并发请求量很高,需要设置较大的连接池参数以满足需求。例如,对于一个高并发的 Web 服务,可能同时有数百个请求在处理,此时需要较大的连接池大小。可以通过压力测试工具模拟高并发场景,观察系统在不同并发请求下的性能表现,从而

【Go】go连接clickhouse使用TCP协议

离开你是傻是对是错 是看破是软弱 这结果是爱是恨或者是什么 如果是种解脱 怎么会还有眷恋在我心窝 那么爱你为什么                      🎵 黄品源/莫文蔚《那么爱你为什么》 package mainimport ("context""fmt""log""time""github.com/ClickHouse/clickhouse-go/v2")func main(

Anaconda 中遇到CondaHTTPError: HTTP 404 NOT FOUND for url的问题及解决办法

最近在跑一个开源项目遇到了以下问题,查了很多资料都大(抄)同(来)小(抄)异(去)的,解决不了根本问题,费了很大的劲终于得以解决,记录如下: 1、问题及过程: (myenv) D:\Workspace\python\XXXXX>conda install python=3.6.13 Solving environment: done.....Proceed ([y]/n)? yDownloa

2024.9.8 TCP/IP协议学习笔记

1.所谓的层就是数据交换的深度,电脑点对点就是单层,物理层,加上集线器还是物理层,加上交换机就变成链路层了,有地址表,路由器就到了第三层网络层,每个端口都有一个mac地址 2.A 给 C 发数据包,怎么知道是否要通过路由器转发呢?答案:子网 3.将源 IP 与目的 IP 分别同这个子网掩码进行与运算****,相等则是在一个子网,不相等就是在不同子网 4.A 如何知道,哪个设备是路由器?答案:在 A

图解TCP三次握手|深度解析|为什么是三次

写在前面 这篇文章我们来讲解析 TCP三次握手。 TCP 报文段 传输控制块TCB:存储了每一个连接中的一些重要信息。比如TCP连接表,指向发送和接收缓冲的指针,指向重传队列的指针,当前的发送和接收序列等等。 我们再来看一下TCP报文段的组成结构 TCP 三次握手 过程 假设有一台客户端,B有一台服务器。最初两端的TCP进程都是处于CLOSED关闭状态,客户端A打开链接,服务器端

构建高性能WEB之HTTP首部优化

0x00 前言 在讨论浏览器优化之前,首先我们先分析下从客户端发起一个HTTP请求到用户接收到响应之间,都发生了什么?知己知彼,才能百战不殆。这也是作为一个WEB开发者,为什么一定要深入学习TCP/IP等网络知识。 0x01 到底发生什么了? 当用户发起一个HTTP请求时,首先客户端将与服务端之间建立TCP连接,成功建立连接后,服务端将对请求进行处理,并对客户端做出响应,响应内容一般包括响应

Golang支持平滑升级的HTTP服务

前段时间用Golang在做一个HTTP的接口,因编译型语言的特性,修改了代码需要重新编译可执行文件,关闭正在运行的老程序,并启动新程序。对于访问量较大的面向用户的产品,关闭、重启的过程中势必会出现无法访问的情况,从而影响用户体验。 使用Golang的系统包开发HTTP服务,是无法支持平滑升级(优雅重启)的,本文将探讨如何解决该问题。 一、平滑升级(优雅重启)的一般思路 一般情况下,要实现平滑

Java http请求示例

使用HttpURLConnection public static String httpGet(String host) {HttpURLConnection connection = null;try {URL url = new URL(host);connection = (HttpURLConnection) url.openConnection();connection.setReq