$ sudo apt install redis 100 [09:23:03] [sudo] password for guohao: Reading package lists... Done Building dependency tree... Done Reading state information... Done redis is already the newest version (5:6.0.16-1ubuntu1). The following package was automatically installed and is no longer required: openjdk-11-jre Use 'sudo apt autoremove' to remove it. 0 upgraded, 0 newly installed, 0 to remove and 17 not upgraded.
test the redis
1 2 3 4 5
$ redis-cli -h localhost localhost:6379> set a test OK localhost:6379> get a "test"
diff --git a/conf/config-default.yaml b/conf/config-default.yaml index e40dc174..3d8dd4c4 100755 --- a/conf/config-default.yaml +++ b/conf/config-default.yaml @@ -73,15 +73,15 @@ apisix: # radixtree_uri_with_parameter: similar to radixtree_uri but match URI with parameters. See https://github.com/api7/lua-resty-radixtree/#parameters-in-path for more details. ssl: radixtree_sni # radixtree_sni: match route by SNI
- # stream_proxy: # TCP/UDP L4 proxy - # only: true # Enable L4 proxy only without L7 proxy. - # tcp: - # - addr: 9100 # Set the TCP proxy listening ports. - # tls: true - # - addr: "127.0.0.1:9101" - # udp: # Set the UDP proxy listening ports. - # - 9200 - # - "127.0.0.1:9201" + stream_proxy: # TCP/UDP L4 proxy + only: true # Enable L4 proxy only without L7 proxy. + tcp: + - addr: 9100 # Set the TCP proxy listening ports. + tls: true + - addr: "127.0.0.1:9101" + udp: # Set the UDP proxy listening ports. + - 9200 + - "127.0.0.1:9201"
# dns_resolver: # If not set, read from `/etc/resolv.conf` # - 1.1.1.1 @@ -141,7 +141,7 @@ nginx_config: # Config for render the template to generate n # user: root # Set the execution user of the worker process. This is only # effective if the master process runs with super-user privileges. error_log: logs/error.log # Location of the error log. - error_log_level: warn # Logging level: info, debug, notice, warn, error, crit, alert, or emerg. + error_log_level: debug # Logging level: info, debug, notice, warn, error, crit, alert, or emerg. worker_processes: auto # Automatically determine the optimal number of worker processes based
create proxy
create a proxy and enable the limit-conn plugin with conn 1.
$ make reload [09:24:37] [ info ] reload -> [ Start ] /home/guohao/apisix/bin/apisix reload /usr/local/openresty//luajit/bin/luajit ./apisix/cli/apisix.lua reload Warning! Current maximum number of open file descriptors [1024] is not greater than 1024, please increase user limits by execute 'ulimit -n <new user limits>' , otherwise the performance is low. [ info ] reload -> [ Done ]
test the proxy
test the stream proxy
1 2 3 4 5 6 7 8 9
$ 2023/07/10 18:35:08 [info] 40958#1379024: *542041 [lua] timers.lua:39: run timer[plugin#server-info], context: ngx.timer 2023/07/10 18:35:08 [info] 40956#1379020: *541986 client disconnected, bytes from/to client:47/171634, bytes from/to upstream:171634/47 2023/07/10 18:35:08 [info] 40956#1379020: *541986 stream [lua] init.lua:1114: stream_log_phase(): enter stream_log_phase while proxying connection, client: 127.0.0.1, server: 127.0.0.1:9101, upstream: "127.0.0.1:6379", bytes from/to client:47/171634, bytes from/to upstream:171634/0 2023/07/10 18:35:08 [debug] 40956#1379020: *541986 stream [lua] init.lua:125: phase_func(): request latency is nil 2023/07/10 18:35:09 [info] 40958#1379024: *542073 [lua] timers.lua:39: run timer[plugin#server-info], context: ngx.timer [09:24:53] localhost:9101> set key test OK localhost:9101> get key "test"
... 2023/07/10 18:30:34 [error] 40018#1373140: *526473 failed to run log_by_lua*: ...ohao/workspace/apisix/apisix/plugins/limit-conn/init.lua:122: attempt to perform arithmetic on field 'request_time' (a nil value) stack traceback: ...ohao/workspace/apisix/apisix/plugins/limit-conn/init.lua:122: in function 'phase_func' /Users/guohao/workspace/apisix/apisix/plugin.lua:1134: in function 'run_plugin' /Users/guohao/workspace/apisix/apisix/init.lua:1116: in function 'stream_log_phase' log_by_lua(nginx.conf:113):2: in main chunk while prereading client data, client: 127.0.0.1, server: 127.0.0.1:9101 2023/07/10 18:30:35 [info] 40020#1373151: *526570 [lua] timers.lua:39: run timer[plugin#server-info], context: ngx.timer
At present, the reason for the two differences is unknown, and it takes time to look at the code.