使用nginx-push-stream-module

首先需要下载或者克隆插件,地址在https://github.com/wandenberg/nginx-push-stream-module。如果是和nginx一起安装只需要在configure时加上--add-module=模块路径即可,下面说一下配置方式。

  安装后需要在nginx的配置文件nginx.conf或者其他包含的配置文件中做如下配置:

在http段加入

#最大共享内存
push_stream_shared_memory_size                100m;
#频道最大长度
push_stream_max_channel_id_length             200;
#每个频道缓存的最大消息数量
push_stream_max_messages_stored_per_channel   20;
#消息生命周期(分钟)
push_stream_message_ttl                       5m;

添加一个虚拟主机(server)配置如下

    server {
	listen 8080;
	server_name     127.0.0.1;
	location /pub {
		push_stream_publisher admin;
		push_stream_channels_path $arg_id;
		push_stream_store_messages on;
	}
	location ~ /sub/(.*) {
		push_stream_subscriber;
		push_stream_channels_path $1;
		push_stream_last_received_message_time      "$arg_time";
		push_stream_last_received_message_tag       "$arg_tag";
		push_stream_header_template "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta http-equiv=\"Cache-Control\" content=\"no-store\">\r\n<meta http-equiv=\"Cache-Control\" content=\"no-cache\">\r\n<meta http-equiv=\"Pragma\" content=\"no-cache\">\r\n<meta http-equiv=\"Expires\" content=\"Thu, 1 Jan 1970 00:00:00 GMT\">\r\n<script type=\"text/javascript\">\r\nwindow.onError = null;\r\ntry{ document.domain = (window.location.hostname.match(/^(\d{1,3}\.){3}\d{1,3}$/)) ? window.location.hostname : window.location.hostname.split('.').slice(-1 * Math.max(window.location.hostname.split('.').length - 1, (window.location.hostname.match(/(\w{4,}\.\w{2}|\.\w{3,})$/) ? 2 : 3))).join('.');}catch(e){}\r\nparent.PushStream.register(this);\r\n</script>\r\n</head>\r\n<body>";
        	push_stream_message_template "<script>p(~id~,'~channel~','~text~');</script>";
		push_stream_footer_template "</body></html>";
		default_type "text/html; charset=utf-8";
		push_stream_ping_message_interval 10s;
	}
	location ~ /ev/(.*) {
		push_stream_subscriber eventsource;
		push_stream_channels_path $1;
		push_stream_last_received_message_time      "$arg_time";
		push_stream_last_received_message_tag       "$arg_tag";
		push_stream_message_template "{\"id\":~id~,\"channel\":\"~channel~\",\"text\":\"~text~\",\"tag\":\"~tag~\",\"time\":\"~time~\"}";
		push_stream_ping_message_interval 10s;
	}
	location ~ /ws/(.*) {
		push_stream_subscriber websocket;
		push_stream_channels_path $1;
		push_stream_last_received_message_time      "$arg_time";
		push_stream_last_received_message_tag       "$arg_tag";
		push_stream_message_template "{\"id\":~id~,\"channel\":\"~channel~\",\"text\":\"~text~\",\"tag\":\"~tag~\",\"time\":\"~time~\"}";
		push_stream_ping_message_interval 10s;
	}
	location ~ /lp/(.*) {
		push_stream_subscriber long-polling;
		push_stream_channels_path $1;
		push_stream_last_received_message_time      "$arg_time";
		push_stream_last_received_message_tag       "$arg_tag";
		push_stream_message_template "{\"id\":~id~,\"channel\":\"~channel~\",\"text\":\"~text~\",\"tag\":\"~tag~\",\"time\":\"~time~\"}";
		push_stream_longpolling_connection_ttl 30s;
	}

  }

然后重新载入nginx的配置,可以在Linux命令下使用curl做如下测试(其中ch1代表频道)

#发布信息:
curl http://localhost:8080/pub?id=ch1 -d "test message"
#订阅信息:
curl http://localhost:8080/lp/ch1
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Tengine是一个基于Nginx的Web服务器,它具有高性能和可扩展性。引用[1]提到了使用nginx-module-vts来使用nginx prometheus模块。这个模块允许我们收集和监控Nginx服务器的性能指标,并将其暴露给Prometheus进行监控。 为了部署Tengine和nginx-module-vts,首先需要下载Tengine和nginx-module-vts的源代码。可以通过执行以下命令来下载它们: ``` git clone https://github.com/alibaba/tengine git clone https://github.com/vozlt/nginx-module-vts ``` 然后安装所需的依赖项,如zlib和openssl。可以使用以下命令在CentOS上安装它们: ``` yum -y install zlib* openssl openssl-devel ``` 接下来,我们需要构建Tengine并添加nginx-module-vts模块。可以按照以下步骤进行: ``` cd tengine ./configure --add-module=/root/software/nginx-module-vts --prefix=/usr/local/nginx --user=nginx --group=nginx --with-stream --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_v2_module --with-http_ssl_module make make install ``` 这将构建并安装Tengine,同时添加了nginx-module-vts模块。 关于Tengine的配置,引用提到了安装第三方模块的方法。如果要安装支持四层和七层的健康检查和数据监控功能,可以使用以下命令: ``` ./configure --add-module=.../ngx_healthcheck_module/ --add-module=.../nginx-module-vts --add-module=.../nginx-module-sts --add-module=.../nginx-module-stream-sts ``` 这些功能的具体安装方法在之前的文章中已经有说明,这里就不再赘述。 总结起来,Tengine是一个基于Nginx的高性能Web服务器,而nginx-module-vts是一个用于收集和监控Nginx服务器性能指标的模块。通过按照以上步骤下载、构建和配置Tengine以及添加nginx-module-vts模块,我们可以实现对Nginx服务器的监控和性能指标收集。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值