Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Kong introduction

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Overview

Kong is an API gateway that forwards API traffic between clients and (micro) services, extending functionality through plug-ins.

Kong's official website, https://konghq.com/kong

Kong's official Github site: https://github.com/kong/kong

Kong has two main components:

Kong Server: a nginx-based server that receives API requests.

Apache Cassandra: used to store operational data.

Kong's data store supports two components, Cassandra and PostgreSQL.

The official GUI tool recommended by Kong is called Kong-Dashboard, but it is not very friendly.

Kong also has a tool for GUI called KongA,GitHub address is https://github.com/pantsel/konga.

You can scale the Kong service horizontally by adding more Kong Server machines and distribute requests to those machines through front-end load balancers. According to the documentation, two Cassandra nodes are sufficient to support most cases, but if the network is very crowded, consider adding more nodes as appropriate.

One of the most attractive features of Kong for the open source community is the ability to extend existing functionality through plug-ins that are executed during the life cycle of the API request response cycle. The plug-in is written in Lua, and Kong has the following basic functions: HTTP basic authentication, key authentication, CORS (Cross-origin Resource Sharing, cross-domain resource sharing), TCP, UDP, file log, API request flow limit, request forwarding and nginx monitoring.

The Kong package can be run on some Linux distributions (including CentOS, RHEL, Debian, Ubuntu), Mac OS X and Docker, Kubernetes, AWS-cloud, and Google-Cloud, both locally and on cloud servers.

In addition to the free open source version, Mashape also offers a paid enterprise version, which includes technical support, usage training services, and API analytics plug-ins.

Rpm-based installation

The installation is currently based on CentOS 7.

The current latest version of Kong is 1.3.0.

The download package can be downloaded from the official address

Https://bintray.com/kong/kong-rpm/download_file?file_path=centos/7/kong-1.3.0.el7.amd64.rpm

You can also download it using the yum repository

Modify the baseurl path of the repo file of yum repository as follows:

Baseurl= https://kong.bintray.com/kong-rpm/centos/7

We next use the epel source of yum for installation.

Install rpm package yum install epel-releaseyum install kong-1.3.0.*.noarch.rpm-- nogpgcheck installation data store database

Kong may or may not have a database during operation.

If you want to use the database, you need to use the kong.conf configuration file to configure how to launch the database as a data store, as well as the corresponding routing or Kong agent.

If you do not need to use a data database, you specify a kong.yml declarative configuration file in the kong.conf file as the data store file.

Kong supports PostgreSQL 9.5 + and Cassandra 3.xx as his data storage database.

If you use a database:

If you use PostgreSQL, you need to initialize a database and a user, for example:

CREATE USER kong; CREATE DATABASE kong OWNER kong

Now run Kong migrations

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

If you do not use the database:

If you want to run Kong in db-free mode, you should first generate a declarative configuration file. Use the following command to generate a normal kong.yml under the current folder

Kong config init

After generating the kong.yml file, edit your kong.conf file and set the following parameters:

Database = offdeclarative_config = / path/to/kong.yml launch kongkong start [- c / path/to/kong.conf]

If you want to stop, use the following command to stop

Kong stop

The overload command is

Kong reload uses Kong

Kong runs on local port 8001 by default

Curl-I http://localhost:8001/ installs Kong using database based on Docker

You can then quickly connect to the Kong container and its database container.

Create a Docker network

You need to create a custom network, run container discovery and communicate with each other, and then create a network named kong-net, or you can use another name.

Docker network create kong-net starts the database

If you want to use a Cassandra container

Docker run-d-name kong-database\-network=kong-net\-p 9042 cassandra:3

If you want to use a PostgreSQL container

Docker run-d-name kong-database\-network=kong-net\-p 5432pur5432\-e "POSTGRES_USER=kong"\-e "POSTGRES_DB=kong"\ postgres:9.6 initialize the database

Run migrations using a transient Kong container

Docker run-- rm\-- network=kong-net\-e "KONG_DATABASE=postgres"\-e "KONG_PG_HOST=kong-database"\-e "KONG_CASSANDRA_CONTACT_POINTS=kong-database"\ kong:latest kong migrations bootstrap

In the above example, you need to modify your KONG_DATABASE parameters yourself.

Start Kong

When migration has been executed and the database is ready, start the Kong container to connect to the database container, such as:

Docker run-d-- name kong\-- network=kong-net\-e "KONG_DATABASE=postgres"\-e "KONG_PG_HOST=kong-database"\-e "KONG_CASSANDRA_CONTACT_POINTS=kong-database"\-e "KONG_PROXY_ACCESS_LOG=/dev/stdout"\-e "KONG_ADMIN_ACCESS_LOG=/dev/stdout"\-e "KONG_PROXY_ERROR_LOG=/dev/" Stderr "\-e" KONG_ADMIN_ERROR_LOG=/dev/stderr "\-e" KONG_ADMIN_LISTEN=0.0.0.0:8001 0.0.0.0 ssl 8444 "\-p 8000 Kong 8000\-p 8443 Kong 8443\-p 8001 ssl 8001\-p 844415 8444\ kong:latest use Kong

Kong runs on 8001

Curl-I http://localhost:8001/ no-data base mode to create Docker network

You need to create a custom network, run container discovery and communicate with each other, and then create a network named kong-net, or you can use another name.

Docker network create kong-net

In the mode without database, it is not necessary to create a dedicated network, but it can be better used to add other content, such as the speed limit plug-in supported by the Redis cluster.

Create Docker Volum

For the purposes of this guide, the Docker volume is a folder within the host. You can map it to a folder in the container, and we give the volume a name, kong-vol.

Docker volume create kong-vol

Use the following command to view the mount point path of the volume

$docker volume inspect kong-vol [{"CreatedAt": "2019-05-28T12:40:09Z", "Driver": "local", "Labels": {}, "Mountpoint": "/ var/lib/docker/volumes/kong-vol/_data", "Name": "kong-vol", "Options": {} "Scope": "local"}]

Record the path to MountPoint, which will be used below.

Initialize configuration file

Modify the configuration file according to the specification that claims to be the configuration file, add the necessary configuration items, such as serveice, route, plugins, consumer, etc., save the configuration file under the path of MountPoint, this article will be placed in / var/lib/docker/volumes/kong-vol/_data/kong.yml

Start Kong in no database mode

Start Kong with the following command, mount the data volume with the-v parameter, and specify the necessary environment variables with the-e parameter.

$docker run-d-name kong\-network=kong-net\-v "kong-vol:/usr/local/kong/declarative"\-e "KONG_DATABASE=off"\-e "KONG_DECLARATIVE_CONFIG=/usr/local/kong/declarative/kong.yml"\-e "KONG_PROXY_ACCESS_LOG=/dev/stdout"\-e "KONG_ADMIN_ACCESS_LOG=/dev/stdout"\ -e "KONG_PROXY_ERROR_LOG=/dev/stderr"\-e "KONG_ADMIN_ERROR_LOG=/dev/stderr"\-e "KONG_ADMIN_LISTEN=0.0.0.0:8001 0.0.0.0 ssl 8444 "\-p 8000 Kong 8000\-p 8443 Kong 8443\-p 8001 ssl 8001\-p 844415 8444\ kong:latest use Kong

After Kong starts, you can use it, and you can access Kong in the following ways

Curl-I http://localhost:8001/

For example, get a list of service

Default port for curl-I http://localhost:8001/servicesKong

Kong is fine. After startup, the following ports will be listened by default.

8000 Kong listens for incoming HTTP requests from the client and forwards them to the upstream service. : 8443 Kong listens for traffic from HTTPS. The behavior of this port is similar to: 8000. It is only used to monitor HTTPS requests without forwarding function. This port can be closed in the configuration file. API 8001 Admin API is used to configure the listening service of Kong. : 8444 Admin API listens for HTTPS traffic. Summary

This article describes what Kong is and how to install it under CentOS and Docker. Kong is an application component of OpenResty. If you want to install Kong from source code, you need to install OpenResty first. For more information, please see Compile Source.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report