You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by me...@apache.org on 2020/02/09 09:19:54 UTC
[incubator-apisix] branch master updated: CLI: `bin/apisix` to
support the SO_REUSEPORT (#1085)
This is an automated email from the ASF dual-hosted git repository.
membphis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 60b2493 CLI: `bin/apisix` to support the SO_REUSEPORT (#1085)
60b2493 is described below
commit 60b2493f5b781462a442b58f7f0385412945aae9
Author: Yousa <sn...@gmail.com>
AuthorDate: Sun Feb 9 17:19:45 2020 +0800
CLI: `bin/apisix` to support the SO_REUSEPORT (#1085)
Fix #342
---
.gitignore | 3 +++
.travis/check-nginxconf.sh | 29 +++++++++++++++++++++++++++++
.travis/linux_apisix_luarocks_runner.sh | 23 +++++++++++++++--------
bin/apisix | 12 ++++++------
conf/config.yaml | 1 +
5 files changed, 54 insertions(+), 14 deletions(-)
diff --git a/.gitignore b/.gitignore
index e74c4e6..880525d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -56,3 +56,6 @@ client_body_temp
utils/lj-releng
.idea/
*.iml
+
+# .travis
+!.travis/*.sh
diff --git a/.travis/check-nginxconf.sh b/.travis/check-nginxconf.sh
new file mode 100644
index 0000000..ba8e4b7
--- /dev/null
+++ b/.travis/check-nginxconf.sh
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+#check whether the 'reuseport' is in nginx.conf .
+matched=`grep -E "listen.*reuseport" conf/nginx.conf | wc -l`
+if [ $matched -eq 0 ]; then
+ echo "failed: nginx.conf file is missing reuseport configuration"
+ exit 1
+else
+ echo "passed: nginx.conf file contains reuseport configuration"
+fi
+
+exit 0
diff --git a/.travis/linux_apisix_luarocks_runner.sh b/.travis/linux_apisix_luarocks_runner.sh
index 8a494ff..9327a47 100755
--- a/.travis/linux_apisix_luarocks_runner.sh
+++ b/.travis/linux_apisix_luarocks_runner.sh
@@ -43,20 +43,27 @@ script() {
sudo mkdir -p /usr/local/apisix/deps
sudo PATH=$PATH ./utils/install-apisix.sh install
- sudo apisix help
- sudo apisix init
- sudo apisix start
- sudo apisix stop
+ sudo PATH=$PATH apisix help
+ sudo PATH=$PATH apisix init
+ sudo PATH=$PATH apisix start
+ sudo PATH=$PATH apisix stop
sudo PATH=$PATH ./utils/install-apisix.sh remove
# install APISIX by luarocks
sudo luarocks install rockspec/apisix-master-0.rockspec
- sudo apisix help
- sudo apisix init
- sudo apisix start
- sudo apisix stop
+ sudo PATH=$PATH apisix help
+ sudo PATH=$PATH apisix init
+ sudo PATH=$PATH apisix start
+ sudo PATH=$PATH apisix stop
+
+ # make init
+ # 'make init' operates scripts and related configuration files in the current directory
+ # The 'apisix' command is a command in the /usr/local/apisix,
+ # and the configuration file for the operation is in the /usr/local/apisix/conf
+ sudo PATH=$PATH make init
+ sudo PATH=$PATH bash .travis/check-nginxconf.sh
sudo luarocks remove rockspec/apisix-master-0.rockspec
}
diff --git a/bin/apisix b/bin/apisix
index 69b7453..eea31ef 100755
--- a/bin/apisix
+++ b/bin/apisix
@@ -129,10 +129,10 @@ stream {
server {
{% for _, port in ipairs(stream_proxy.tcp or {}) do %}
- listen {*port*};
+ listen {*port*} {% if enable_reuseport then %} reuseport {% end %};
{% end %}
{% for _, port in ipairs(stream_proxy.udp or {}) do %}
- listen {*port*} udp;
+ listen {*port*} udp {% if enable_reuseport then %} reuseport {% end %};
{% end %}
preread_by_lua_block {
@@ -261,15 +261,15 @@ http {
{% end %}
server {
- listen {* node_listen *};
+ listen {* node_listen *} {% if enable_reuseport then %} reuseport {% end %};
{% if ssl.enable then %}
- listen {* ssl.listen_port *} ssl {% if ssl.enable_http2 then %} http2 {% end %};
+ listen {* ssl.listen_port *} ssl {% if ssl.enable_http2 then %} http2 {% end %} {% if enable_reuseport then %} reuseport {% end %};
{% end %}
{% if enable_ipv6 then %}
- listen [::]:{* node_listen *};
+ listen [::]:{* node_listen *} {% if enable_reuseport then %} reuseport {% end %};
{% if ssl.enable then %}
- listen [::]:{* node_ssl_listen *} ssl {% if ssl.enable_http2 then %} http2 {% end %};
+ listen [::]:{* node_ssl_listen *} ssl {% if ssl.enable_http2 then %} http2 {% end %} {% if enable_reuseport then %} reuseport {% end %};
{% end %}
{% end %} {% -- if enable_ipv6 %}
diff --git a/conf/config.yaml b/conf/config.yaml
index 57efc2a..0e24d5c 100644
--- a/conf/config.yaml
+++ b/conf/config.yaml
@@ -21,6 +21,7 @@ apisix:
enable_admin_cors: true # Admin API support CORS response headers.
enable_debug: false
enable_dev_mode: false # Sets nginx worker_processes to 1 if set to true
+ enable_reuseport: true # Enable nginx SO_REUSEPORT switch if set to true.
enable_ipv6: true
config_center: etcd # etcd: use etcd to store the config value
# yaml: fetch the config value from local yaml file `/your_path/conf/apisix.yaml`