安装使用SkyWalking先看这篇文章,地址:https://www.cnblogs.com/sanduzxcvbnm/p/15829781.html

使用SkyWalking监控nginx借助的是nginx的lua模块,若没有则需要重新编译安装nginx,在这里直接使用openresty,这个自带就已经有lua模块了

wget https://openresty.org/package/centos/openresty.repo && mv openresty.repo /etc/yum.repos.d/ && yum makecache
yum -y install openresty systemctl start openresty.service && systemctl enable openresty.service

下载SkyWalking Nginx LUA

地址:https://skywalking.apache.org/downloads/

下载后的文件是:skywalking-nginx-lua-0.6.0.tar.gz







解压缩skywalking-nginx-lua-0.6.0.tar.gz文件到nginx的conf目录下

nginx的conf目录以实际情况为准,解压后的文件夹是:skywalking-nginx-lua-0.6.0

tar -zxv -f skywalking-nginx-lua-0.6.0.tar.gz -C /usr/local/openresty/nginx/conf/

使用官方提供的nignx配置文件进行配置演示

官方参考文档地址:https://github.com/apache/skywalking-nginx-lua

官方参考配置:

http {
lua_package_path "/Path/to/.../skywalking-nginx-lua/lib/?.lua;;"; # Buffer represents the register inform and the queue of the finished segment
lua_shared_dict tracing_buffer 100m; # Init is the timer setter and keeper
# Setup an infinite loop timer to do register and trace report.
init_worker_by_lua_block {
local metadata_buffer = ngx.shared.tracing_buffer -- Set service name
metadata_buffer:set('serviceName', 'User Service Name')
-- Instance means the number of Nginx deployment, does not mean the worker instances
metadata_buffer:set('serviceInstanceName', 'User Service Instance Name')
-- type 'boolean', mark the entrySpan include host/domain
metadata_buffer:set('includeHostInEntrySpan', false)
-- set ignoreSuffix, If the operation name(HTTP URI) of the entry span includes suffixes in this set, this segment would be ignored. Multiple values should be separated by a comma(',').
-- require("skywalking.util").set_ignore_suffix(".jpg,.jpeg,.js,.css,.png,.bmp,.gif,.ico,.mp3,.mp4,.svg") -- set random seed
require("skywalking.util").set_randomseed()
require("skywalking.client"):startBackendTimer("http://127.0.0.1:12800") # 这儿应该是12800,不是8080,官方文档写的有问题 -- If there is a bug of this `tablepool` implementation, we can
-- disable it in this way
-- require("skywalking.util").disable_tablepool() skywalking_tracer = require("skywalking.tracer")
} server {
listen 8090; location /ingress {
default_type text/html; rewrite_by_lua_block {
------------------------------------------------------
-- NOTICE, this should be changed manually
-- This variable represents the upstream logic address
-- Please set them as service logic name or DNS name
--
-- Currently, we can not have the upstream real network address
------------------------------------------------------
skywalking_tracer:start("upstream service")
-- If you want correlation custom data to the downstream service
-- skywalking_tracer:start("upstream service", {custom = "custom_value"})
} -- Target upstream service
proxy_pass http://127.0.0.1:8080/backend; body_filter_by_lua_block {
if ngx.arg[2] then
skywalking_tracer:finish()
end
} log_by_lua_block {
skywalking_tracer:prepareForReport()
}
}
}
}

在解压的skywalking-nginx-lua-0.6.0/examples路径下有一个skywalking官方提供的nginx.conf配置文件,用这个文件替换安装openresty后的那个默认nginx.conf文件,然后再修改这个文件。

主要是修改lua_package_path参数,也就是引用的lua文件路径和访问skywalking后端服务的端口号



然后启动nginx服务,使用命令:curl http://127.0.0.1:8090/ingress,结果如下:

# curl 127.0.0.1:8090/ingress
<p>Backend service for testing only.</p>
<p>Backend sw8 received headers: 1-ZjhlNjNjYjMtMDU3Yy00ZDQ4LWEwNmItMDVhYWU4ZDQ5MzUz-MzZjNjY3ZmMtMjZjMi00MjQ0LWEzOTctODZjNWZkOTZlZmQz-1-VXNlciBTZXJ2aWNlIE5hbWU=-VXNlciBTZXJ2aWNlIEluc3RhbmNlIE5hbWU=-L3RpZXIyL2xi-YmFja2VuZCBzZXJ2aWNl</p>

对照nginx.conf文件分析刚才使用的命令,可以得到如下结果:

1.访问127.0.0.1:8090/ingress对应的是nginx.conf配置文件中的server {listen 8090;}location /ingress {}配置

2.这个location /ingress {}配置中实际访问使用的是:proxy_pass http://127.0.0.1:8090/tier2/lb;,把接受过来的请求转发给这个服务了。

3.分析proxy_pass http://127.0.0.1:8090/tier2/lb;,对应的是 server {listen 8090;}location /tier2/lb配置

4.这个配置再把请求转发给proxy_pass http://127.0.0.1:8090/backend;,这个服务对应的是 server {listen 8090;}location /backend配置

5.这个配置的内容如下,正好是请求curl http://127.0.0.1:8090/ingress后得到的相应结果。

content_by_lua_block {
ngx.say("<p>Backend service for testing only.</p>")
ngx.say("<p>Backend sw8 received headers: " .. ngx.req.get_headers()["sw8"] .. "</p>")
}

根据实际情况修改nginx.conf文件

skywalking官方提供的nginx.conf文件可以作为测试分析使用,实际使用的话可以直接在原有nginx.conf文件的基础上新增加上需要的配置即可。

nginx.conf实际配置

http {
lua_package_path "/usr/local/openresty/nginx/conf/skywalking-nginx-lua-0.6.0/lib/?.lua;;"; # 根据实际情况修改这个路径,跟上面解压缩后的路径保持一致,(lib目录下还有子目录,子目录下才是lua文件)
lua_shared_dict tracing_buffer 100m; init_worker_by_lua_block {
local metadata_buffer = ngx.shared.tracing_buffer
metadata_buffer:set('serviceName', 'httpnginx') # 修改一下名称
metadata_buffer:set('serviceInstanceName', 'httpInstancenginx') # 修改一下名称
metadata_buffer:set('includeHostInEntrySpan', false)
require("skywalking.util").set_randomseed()
require("skywalking.client"):startBackendTimer("http://127.0.0.1:12800") # 修改成连接skywalking后端服务的地址和端口(我这都是在一台主机上)
skywalking_tracer = require("skywalking.tracer")
} ....... # 静态文件示例,没有后端服务
server {
listen 80;
server_name localhost;
access_log logs/host.access.log main; location / {
default_type text/html;
root html;
index index.html index.htm; # 如下内容直接新增
rewrite_by_lua_block {
skywalking_tracer:start("listennginx") # 修改一下名称
} body_filter_by_lua_block {
if ngx.arg[2] then
skywalking_tracer:finish()
end
}
log_by_lua_block {
skywalking_tracer:prepareForReport()
}
}
} # 有后端服务的示例
server {
listen 80;
server_name localhost; location /ingress { # ingress根据实际情况修改
default_type text/html;
rewrite_by_lua_block {
skywalking_tracer:start("upstream service")
} proxy_pass http://127.0.0.1:8000/xxx; # 反向代理的后端服务和端口等根据实际情况修改 body_filter_by_lua_block {
if ngx.arg[2] then
skywalking_tracer:finish()
end
} log_by_lua_block {
skywalking_tracer:prepareForReport()
}
}
} }

效果

以静态文件示例,没有后端服务为例

用浏览器访问这个主机的80端口,出现的是openresty默认页面,此时查看skywalking页面

故意访问一个不存在的页面或路径

使用SkyWalking监控nginx (以openresty为例)的更多相关文章

  1. 用Nginx+Lua(OpenResty)开发高性能Web应用

    在互联网公司,Nginx可以说是标配组件,但是主要场景还是负载均衡.反向代理.代理缓存.限流等场景:而把Nginx作为一个Web容器使用的还不是那么广泛.Nginx的高性能是大家公认的,而Nginx开 ...

  2. Nginx+Lua(OpenResty)开发高性能Web应用

    使用Nginx+Lua(OpenResty)开发高性能Web应用 博客分类: 跟我学Nginx+Lua开发 架构 ngx_luaopenresty 在互联网公司,Nginx可以说是标配组件,但是主要场 ...

  3. zabbix监控nginx连接状态(转)

    zabbix监控nginx zabbix可以监控nginx的状态,关于一个服务的状态可以查看服务本身的状态(版本号.是否开启),还应该关注服务能力(例如以nginx的负载效果:连接数.请求数和句柄数) ...

  4. 使用Nginx+Lua(OpenResty)开发高性能Web应用

    摘自(http://jinnianshilongnian.iteye.com/blog/2280928) 在互联网公司,Nginx可以说是标配组件,但是主要场景还是负载均衡.反向代理.代理缓存.限流等 ...

  5. 【zabbix告警监控】配置zabbix监控nginx服务

    zabbix监控nginx,nginx需要添加--with-http_stub_status模块 使用zabbix监控nginx,首先nginx需要配置开启ngx_status.但是我这边nginx安 ...

  6. Nginx、OpenResty和Kong的基本概念与使用方法

    Nginx.OpenResty和Kong的基本概念与使用方法 2018年10月10日 22:46:08 李佶澳 阅读数 322更多 分类专栏: kubernetes   版权声明:本文为博主原创文章, ...

  7. Nginx+lua+openresty精简系列

    1. CentOS系统安装openresty 你可以在你的 CentOS 系统中添加 openresty 仓库,这样就可以便于未来安装或更新我们的软件包(通过 yum update 命令).运行下面的 ...

  8. Zabbix 监控 Nginx(四)

    简介: 如何使用 Zabbix 监控 Nginx 状态 ? 1.获取 Nginx 状态( HTTP Stub Status ) [root@localhost ~]# /apps/product/ng ...

  9. Python 监控nginx服务是否正常

    Python 监控nginx服务是否正常 #!/usr/bin/env python import os, sys, time from time import strftime while True ...

随机推荐

  1. throws关键字_异常处理的第一种方式(交给别人处理)和try_catch_异常处理的第二种方式(自己处理)

    throws关键字:异常处理的第一种方式,交给别人处理 作用: 当方法内部抛出异常对象的时候,那么我们就必须处理这个异常对象 可以使用throws关键字处理异常对象, 会把异常对象声明抛出给方法的调用 ...

  2. 【一知半解】synchronied

    synchronized是什么 synchronized是java同步锁,同一时刻多个线程对同一资源进行修改时,能够保证同一时刻只有一个线程获取到资源并对其进行修改,因此保证了线程安全性. synch ...

  3. APISpace万券齐发,API采购大放价

    Eolink APISpace 是 Eolink 旗下专业的API 数据交易平台,上面拥有海量的API,开发者可以根据需求自由选择. 环境天气 全国天气预报,支持全国以及全球多个城市的天气查询,包含国 ...

  4. 项目配置yaml

    springboot的一些配置 #当循环调用时,就会报错 spring.main.allow-circular-references=true #配置mvc是需要使用一个@EnableWebMvc,不 ...

  5. Linux、Ubuntu常用命令

    # 文件解压缩 # zip压缩目录(附带目录权限) zip -q -r html.zip /home/html 压缩目录 tar -zcvf pack.tar.gz pack/ #打包压缩为一个.gz ...

  6. 蔚来杯2022牛客暑期多校训练营5 ABCDFGHK

    比赛链接 A 题解 知识点:图论,dp. 暴力建图,连接所有点的双向通路,除了原点是单向的,并且把路径长度作为权值. 随后,从原点出发(\(f[0] = 0\),其他点负无穷,保证从原点出发),按照权 ...

  7. Mybatis的使用(4)

    1:解决实体类成员变量和数据库表中字段名称不一致的问题: 方法1:在写sql语句时,给表中的列名起别名,名字和实体类名称一样 方法2:使用resultMap来解决: 例如:实体类中成员变量为id,na ...

  8. C# 虚方法、抽象方法

    一.虚方法(virtual) 作用:当有一个定义在类中的函数需要在继承类中实现时,可以使用虚方法. 示例: class Person { public virtual void XXX() { Con ...

  9. while 循环、do- while 循环 和 for 循环之间的那点事

    C语言自学之三种循环比较 使用循环计算1-2+3-4+5-6+--100的值?    在编辑器中给出了三种循环体结构的部分代码,请选择合适的循环结构补全代码实现此功能.    运行结果为: sum=- ...

  10. python包合集-cffi

    一.cffi cffi是连接Python与c的桥梁,可实现在Python中调用c文件.cffi为c语言的外部接口,在Python中使用该接口可以实现在Python中使用外部c文件的数据结构及函数. 二 ...