kong cluster deployment

kong cluster deployment

Attached official cluster reference document
https://docs.konghq.com/1.2.x/clustering/

(1) Installing kong on multiple servers

Prepare the server environment for centos7, the first server for centos6, install kong, and execute the following code:

$ sudo yum update -y
 $ sudo yum install -y wget
 $ wget https://bintray.com/kong/kong-rpm/rpm -O bintray-kong-kong-rpm.repo
 $ export major_version=`grep -oE '[0-9]+\.[0-9]+' /etc/redhat-release | cut -d "." -f1`
 $ sed -i -e 's/baseurl.*/&\/centos\/'$major_version''/ bintray-kong-kong-rpm.repo
 $ sudo mv bintray-kong-kong-rpm.repo /etc/yum.repos.d/
 $ sudo yum update -y
 $ sudo yum install -y kong

Successful installation results are as follows:

Modify kong's configuration file kong.conf
The location is ect/kong. The modification is as follows

(2) Migrating kong data from centos6

Execute the following code:

kong migrations bootstrap [-c /path/to/kong.conf]

The results are as follows:

Overlay the kong document partially with the custom plug-in
Start kong and set up kong management address to open to the outside world


Accessing kong of centos7 through kong admin ui

(3) Comparing the consistency of kong data between two servers

Check to see if the information is consistent with kong on centos6, where the screenshot only shows service information


The first screenshot is kong on centos7 and the second is kong on centos6. The ip addresses of the two servers are in the upper right corner. The comparison data are consistent.
Add a service to kong on centos6 as follows:

Refresh kong service information on centos7 as follows:

The services added on centos6 were successfully added to centos7, and centos7 kong was successfully deployed.
Now we can expand any number of node nodes horizontally, as long as they connect to the same database (or cluster), and if kong wants to be an entry to the outside world, we can forward these kong nodes as upstream of the reverse proxy through nginx. Reference link https://blog.csdn.net/tr1912/article/details/81603674

(4) Nginx kong load balancing configuration

upstream kong {
   # Load balancing algorithm, based on the minimum number of connections
   least_conn;
   server 192.168.43.132:8000;
   server 192.168.43.111:8000;
}

server {
   # These ports need to be modified to the actual situation.
   Listen 8088;
   #include snippets/ssl-api.example.com.conf;
   #include snippets/ssl-params.conf;
   # https needs to disable gzip for security reasons
   # But in some scenarios, you don't need to disable it
   # gzip off;
   gzip on;
   # Set the minimum number of bytes allowed to compress pages
   gzip_min_length 1000;
   gzip_buffers 4 16k;
   gzip_http_version 1.1;
   # 1-9, default 1, the larger the value, the higher the compression rate, the more CPU occupied, the longer the time
   gzip_comp_level 3;
   gzip_vary on;
   # Disable gzip compression for IE 6
   gzip_disable "MSIE [1-6]\.";
   gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/javascript "application/javascript; charset=utf-8" application/xml application/xml+rss application/json "application/json; charset=utf-8" fo
nt/ttf font/otf image/svg+xml;

   # Set the maximum allowable POST data volume. If the submitted file exceeds this value, 413 errors will occur.
   client_max_body_size 20m;
   keepalive_timeout 15;

   # The version number of nginx is not displayed
   server_tokens off;

   ## Individual nginx logs
   access_log  /var/log/nginx/access.log;
   error_log   /var/log/nginx/error.log;

   # You can't use ^~here because the string is followed by a regular expression.
   # Match only those that match the rules, and all others return 404
   location / {
       # This command sets the server in headers to be used by the backend website of the nginx agent
       proxy_set_header Host $http_host;
       proxy_redirect off;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Scheme $scheme;
       proxy_pass http://kong;
       expires -1;
   }

   # Home page returns 404
   location = / {
       return 404;
   }
}

(5) Test connection


Successful configuration

Keywords: Nginx sudo yum RPM

Added by JeDi58 on Thu, 25 Jul 2019 13:04:02 +0300