What is Kong

Kong is an API gateway that forwards API traffic between clients and (micro) services. Below is a comparison of the technical architecture before and after using Kong:

Install Kong on Centos

Kong can be installed on multiple platforms. This article uses Centos as an example.

Downloading software Packages

Centos6:bintray.com/kong/kong-r… Centos7:bintray.com/kong/kong-r…

The installation

'sudo yum install kong-1.3.0.*.noarch. RPM --nogpgcheck'Copy the code

Configure Kong

Database-free mode

Kong can run with or without a database.

Configure the database in /etc/kong/kong.conf:

``database = off                  # Determines which of PostgreSQL or Cassandra
                                # this node will use as its datastore.
                                # Accepted values are `postgres`,
                                # `cassandra`, and `off`.`` 
Copy the code

Select a folder and generate the configuration:

`kong config init` 
Copy the code

The kong.yml file is generated in the current directory.

There are database schemas

When using database mode, it is easy to cooperate with Konga management Service. Kong supports PostgreSQL 9.5+ and Cassandra 3.x.x as its data store.

We use PostgreSQL.

Configure the database in /etc/kong/kong.conf:

``database = postgres             # Determines which of PostgreSQL or Cassandra
                                # this node will use as its datastore.
                                # Accepted values are `postgres`,
                                # `cassandra`, and `off`.Pg_host = 127.0.0.1# Host of the Postgres server.
pg_port = 5432                  # Port of the Postgres server.
pg_timeout = 5000               # Defines the timeout (in ms), for connecting,
                                # reading and writing.

pg_user = kong                  # Postgres user.
pg_password =                   # Postgres user's password.
pg_database = kong              # The database name to connect to.`` 
Copy the code

Perform database migration:

`kong migrations bootstrap [-c /path/to/kong.conf]` 
Copy the code

Output:

Bootstrapping database...
migrating core on database 'kong'...
core migrated up to: 000_base (executed)
core migrated up to: 003_100_to_110 (executed)
core migrated up to: 004_110_to_120 (executed)
core migrated up to: 005_120_to_130 (executed)
core migrated up to: 006_130_to_140 (executed)
core migrated up to: 007_140_to_150 (executed)
core migrated up to: 008_150_to_200 (executed)
core migrated up to: 009_200_to_210 (executed)
core migrated up to: 010_210_to_211 (executed)
core migrated up to: 011_212_to_213 (executed)
core migrated up to: 012_213_to_220 (executed)
core migrated up to: 013_220_to_230 (executed)
migrating rate-limiting on database 'kong'...
rate-limiting migrated up to: 000_base_rate_limiting (executed)
rate-limiting migrated up to: 003_10_to_112 (executed)
rate-limiting migrated up to: 004_200_to_210 (executed)
migrating hmac-auth on database 'kong'...
hmac-auth migrated up to: 000_base_hmac_auth (executed)
hmac-auth migrated up to: 002_130_to_140 (executed)
hmac-auth migrated up to: 003_200_to_210 (executed)
migrating oauth2 on database 'kong'...
oauth2 migrated up to: 000_base_oauth2 (executed)
oauth2 migrated up to: 003_130_to_140 (executed)
oauth2 migrated up to: 004_200_to_210 (executed)
oauth2 migrated up to: 005_210_to_211 (executed)
migrating ip-restriction on database 'kong'...
ip-restriction migrated up to: 001_200_to_210 (executed)
migrating jwt on database 'kong'...
jwt migrated up to: 000_base_jwt (executed)
jwt migrated up to: 002_130_to_140 (executed)
jwt migrated up to: 003_200_to_210 (executed)
migrating basic-auth on database 'kong'...
basic-auth migrated up to: 000_base_basic_auth (executed)
basic-auth migrated up to: 002_130_to_140 (executed)
basic-auth migrated up to: 003_200_to_210 (executed)
migrating key-auth on database 'kong'...
key-auth migrated up to: 000_base_key_auth (executed)
key-auth migrated up to: 002_130_to_140 (executed)
key-auth migrated up to: 003_200_to_210 (executed)
migrating session on database 'kong'...
session migrated up to: 000_base_session (executed)
session migrated up to: 001_add_ttl_index (executed)
migrating acl on database 'kong'...
acl migrated up to: 000_base_acl (executed)
acl migrated up to: 002_130_to_140 (executed)
acl migrated up to: 003_200_to_210 (executed)
acl migrated up to: 004_212_to_213 (executed)
migrating response-ratelimiting on database 'kong'...
response-ratelimiting migrated up to: 000_base_response_rate_limiting (executed)
migrating bot-detection on database 'kong'...
bot-detection migrated up to: 001_200_to_210 (executed)
migrating acme on database 'kong'...
acme migrated up to: 000_base_acme (executed)
41 migrations processed
41 executed
Database is up-to-date
Copy the code

Start the Kong

Generate a configuration file:

`cp /etc/kong/kong.conf.default /etc/kong/kong.conf` 
Copy the code

Activation:

`kong start -c /etc/kong/kong.conf` 
Copy the code

Check whether the operation is normal

`curl -i http://localhost:8001/` 
Copy the code

Normal output:

'HTTP/1.1 200 OK Date: Thu, 18 Mar 2021 03:34:10 GMT Content-Type: Application /json; charset=utf-8 Connection: keep-alive Access-Control-Allow-Origin: * Content-Length: 10596 X-Kong-Admin-Latency: 3 Server: kong / 2.3.3 {"plugins": {"enabled_in_cluster": []."available_on_server": {"grpc-web":true."correlation-id":true."pre-function":true."cors":true."rate-limiting":true."loggly":true."hmac-auth":true."zipkin":true."request-size-limiting":true."azure-functions":true."request-transformer":true."oauth2":true."response-transformer":true."ip-restriction":true."statsd":true."jwt":true."proxy-cache":true."basic-auth":true."key-auth":true."http-log":true."session":true."datadog":true."tcp-log":true."prometheus":true."post-function":true."ldap-auth":true."acl":true."grpc-gateway":true."file-log":true."syslog":true."udp-log":true."response-ratelimiting":true."aws-lambda":true."bot-detection":true."acme":true."request-termination":true}},"tagline":"Welcome to kong"."configuration": {"pluginserver...... `Copy the code

This piece of JSON is Kong’s health data.

Original link: www.sdk.cn/details/voY…

SDK is a neutral communities, there are a variety of front knowledge, has the rich API, developers have a love of learning artificial intelligence, have humor developers take you learn python, there will be the next hot HongMeng, when various elements together, let us together to build professional, fun and imaginative valuable developer community, Help developers realize their self-worth!