1. 安装
curl -Lo kong-2.5.0.amd64.rpm $( rpm --eval "https://download.konghq.com/gateway-2.x-centos-%{centos_ver}/Packages/k/kong-2.5.0.el%{centos_ver}.amd64.rpm")
sudo yum install kong-2.5.0.amd64.rpm
2. 安装 postgresql10
安装
PostgreSQL
请参考centos7安装PostgreSQL
KONG
使用PostgreSQL 9.5+ 或 Cassandra 3.x.x 作为数据存储。这里使用 PostgreSQL
。
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm -y
yum install postgresql10 -y
yum install postgresql10-server -y
/usr/pgsql-10/bin/postgresql-10-setup initdb
systemctl enable postgresql-10
systemctl start postgresql-10
3. 配置数据库
需要事先准备好。创建一个名为 kong 的用户,并且创建一个名为 kong 的数据库。
$ sudo -s -u postgres
psql
CREATE USER kong WITH PASSWORD '123456';
CREATE DATABASE kong OWNER kong;
GRANT ALL PRIVILEGES ON DATABASE kong to kong;
\q # 退出
postgresql 默认只能使用postgres 用户,这里修改一下, 方便其他用户都可以登录。
vim /var/lib/pgsql/10/data/pg_hba.conf
# 找到下面的行,修改成 trust
host all all 127.0.0.1/32 trust
systemctl restart postgresql-10
4.数据库配置
cp /etc/kong/kong.conf.default /etc/kong/kong.conf
编辑 /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.
#pg_schema = # The database schema to use. If unspecified,
# Kong will respect the `search_path` value of
# your PostgreSQL instance.
配置完后,运行下面的命令
kong migrations bootstrap -c /etc/kong/kong.conf
5.启动 KONG
--vv
可以打印更多的启动日志
kong start -c /etc/kong/kong.conf --vv
检查 KONG 是否正确运行
curl -i http://localhost:8001/
或者
kong health
[root@zjwoo src]# kong health
nginx.......running
Kong is healthy at /usr/local/kong
[root@zjwoo src]# curl -i http://localhost:8001/
HTTP/1.1 200 OK
Date: Thu, 12 Aug 2021 03:02:06 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Access-Control-Allow-Origin: *
Content-Length: 11093
X-Kong-Admin-Latency: 382
Server: kong/2.5.0
{"node_id":"be92c546-f2f0-4e86-99d9-0bf29f925b64","hostname":"zjwoo","tagline":"Welcome to kong","plugins":{"available_on_server":{"statsd":true,"bot-detection":true,"aws-lambda":true,"request-termination":true,"azure-functions":true,"zipkin":true,"pre-function":true,"post-function":true,"oauth2":true,"tcp-log":true,"session":true,"acme":true,"grpc-web":true,"grpc-gateway":true,"hmac-auth":true,"basic-auth":true,"ip-restriction":true,"request-transformer":true,"response-transformer":true,"request-size-limiting":true,"rate-limiting":true,"response-ratelimiting":true,"syslog":true,"loggly":true,"datadog":true,"ldap-auth":true,"jwt":true,"acl":true,"correlation-id":true,"cors":true,"key-auth":true,"http-log":true,"file-log":true,"udp-log":true,"proxy-cache":true,"prometheus":true},"enabled_in_cluster":[]},"lua_version":"LuaJIT 2.1.0-beta3","pids":{"workers":[31918],"master":31917},"configuration":{"client_ssl_cert_default":"/usr/local/kong/ssl/kong-default.crt","client_ssl_cert_key_default":"/usr/local/kong/ssl/kong-default.key","admin_ssl_cert_default":"/usr/local/kong/ssl/admin-kong-default.crt","admin_ssl_cert_key_default":"/usr/local/kong/ssl/admin-kong-default[root@zjwoo src]# ^C
[root@zjwoo src]# curl -i http://localhost:8000/
HTTP/1.1 404 Not Found
Date: Thu, 12 Aug 2021 03:02:13 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Content-Length: 48
X-Kong-Response-Latency: 0
Server: kong/2.5.0
{"message":"no Route matched with those values"}[root@zjwoo src]# ^C
[root@zjwoo src]# ^C
[root@zjwoo src]# ^C
[root@zjwoo src]# curl -i http://localhost:8001/
HTTP/1.1 200 OK
Date: Thu, 12 Aug 2021 03:02:18 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Access-Control-Allow-Origin: *
Content-Length: 11093
X-Kong-Admin-Latency: 1
Server: kong/2.5.0
{"node_id":"be92c546-f2f0-4e86-99d9-0bf29f925b64","hostname":"zjwoo","tagline":"Welcome to kong","plugins":{"available_on_server":{"statsd":true,"bot-detection":true,"aws-lambda":true,"request-termination":true,"azure-functions":true,"zipkin":true,"pre-function":true,"post-function":true,"oauth2":true,"tcp-log":true,"session":true,"acme":true,"grpc-web":true,"grpc-gateway":true,"hmac-auth":true,"basic-auth":true,"ip-restriction":true,"request-transformer":true,"response-transformer":true,"request-size-limiting":true,"rate-limiting":true,"response-ratelimiting":true,"syslog":true,"loggly":true,"datadog":true,"ldap-auth":true,"jwt":true,"acl":true,"correlation-id":true,"cors":true,"key-auth":true,"http-log":true,"file-log":true,"udp-log":true,"proxy-cache":true,"prometheus":true},"enabled_in_cluster":[]},"lua_version":"LuaJIT 2.1.0-beta3","pids":{"workers":[31918],"master":31917},"configuration":{"client_ssl_cert_default":"/usr/loca[root@zjwoo src]# kong health
nginx.......running
Kong is healthy at /usr/local/kong
[root@zjwoo src]# curl -i http://localhost:8001/
HTTP/1.1 200 OK
Date: Thu, 12 Aug 2021 03:04:13 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Access-Control-Allow-Origin: *
Content-Length: 11093
X-Kong-Admin-Latency: 1
Server: kong/2.5.0
{"node_id":"be92c546-f2f0-4e86-99d9-0bf29f925b64","hostname":"zjwoo","tagline":"Welcome to kong","plugins":{"available_on_server":{"statsd":true,"bot-detection":true,"aws-lambda":true,"request-termination":true,"azure-functions":true,"zipkin":true,"pre-function":true,"post-function":true,"oauth2":true,"tcp-log":true,"session":true,"acme":true,"grpc-web":true,"grpc-gateway":true,"hmac-auth":true,"basic-auth":true,"ip-restriction":true,"request-transformer":true,"response-transformer":true,"request-size-limiting":true,"rate-limiting":true,"response-ratelimiting":true,"syslog":true,"loggly":true,"datadog":true,"ldap-auth":true,"jwt":true,"acl":true,"correlation-id":true,"cors":true,"key-auth":true,"http-log":true,"file-log":true,"udp-log":true,"proxy-cache":true,"prometheus":true},"enabled_in_cluster":[]},"lua_version":"LuaJIT 2.1.0-beta3","pids":{"workers":[31918],"master":31917},"configuration":{"client_ssl_cert_default":"/usr/local/kong/ssl/kong-default.crt","client_ssl_cert_key_default":"/usr/local/kong/ssl/kong-default.key","admin_ssl_cert_default":"/usr/local/kong/ssl/admin-kong-default.crt","admin_ssl_cert_key_default":"/usr/local/kong/ssl/admin-kong-default.key","admin_ssl_cert_default_ecdsa":"/usr/local/kong/ssl/admin-kong-default-ecdsa.crt","admin_ssl_cert_key_default_ecdsa":"/usr/local/kong/ssl/admin-kong-default-ecdsa.key","ssl_cipher_suite":"intermediate","ssl_ciphers":"ECDHE-ECDSA-A[root@zjwoo src]# curl -i http://localhost:8001/
HTTP/1.1 200 OK
Date: Thu, 12 Aug 2021 03:04:17 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Access-Control-Allow-Origin: *
Content-Length: 11093
X-Kong-Admin-Latency: 1
Server: kong/2.5.0
{"node_id":"be92c546-f2f0-4e86-99d9-0bf29f925b64","hostname":"zjwoo","tagline":"Welcome to kong","plugins":{"available_on_server":{"statsd":true,"bot-detection":true,"aws-lambda":true,"request-termination":true,"azure-functions":true,"zipkin":true,"pre-function":true,"post-function":true,"oauth2":true,"tcp-log":true,"session":true,"acme":true,"grpc-web":true,"grpc-gateway":true,"hmac-auth":true,"basic-auth":true,"ip-restriction":true,"request-transformer":true,"response-transformer":true,"request-size-limiting":true,"rate-limiting":true,"response-ratelimiting":true,"syslog":true,"loggly":true,"datadog":true,"ldap-auth":true,"jwt":true,"acl":true,"correlation-id":true,"cors":true,"key-auth":true,"http-log":true,"file-log":true,"udp-log":true,"proxy-cache":true,"prometheus":true},"enabled_in_cluster":[]},"lua_version":"LuaJIT 2.1.0-beta3","pids":{"workers":[31918],"master":31917},"configuration":{"client_ssl_cert_default":"/usr/local/kong/ssl/kong-default.crt","client_ssl_cert_key_default":"/usr/local/kong/ssl/kong-default.key","admin_ssl_cert_default":"/usr/local/kong/ssl/admin-kong-default.crt","admin_ssl_cert_key_default":"/usr/local/kong/ssl/admin-kong-default.key","admin_ssl_cert_default_ecdsa":"/usr/local/kong/ssl/admin-kong-default-ecdsa.crt","admin_ssl_cert_key_default_ecdsa":"/usr/local/kong/ssl/admin-kong-default-ecdsa.key","ssl_cipher_suite":"intermediate","ssl_ciphers":"ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384","lua_package_path":"./?.lua;./?/init.lua;","status_ssl_cert_default_ecdsa":"/usr/local/kong/ssl/status-kong-default-ecdsa.crt","status_ssl_cert_key_default_ecdsa":"/usr/local/kong/ssl/status-kong-default-ecdsa.key","prefix":"/usr/local/kong","lua_package_cpath":"","port_maps":{},"proxy_listen":["0.0.0.0:8000 reuseport backlog=16384","0.0.0.0:8443 http2 ssl reuseport backlog=16384"],"admin_listen":["127.0.0.1:8001 reuseport backlog=16384","127.0.0.1:8444 http2 ssl reuseport backlog=16384"],"status_listen":["off"],"stream_listen":["off"],"cluster_listen":["0.0.0.0:8005"],"admin_ssl_cert":["/usr/local/kong/ssl/admin-kong-default.crt","/usr/local/kong/ssl/admin-kong-default-ecdsa.crt"],"admin_ssl_cert_key":["/usr/local/kong/ssl/admin-kong-default.key","/usr/local/kong/ssl/admin-kong-default-ecdsa.key"],"status_ssl_cert":{},"status_ssl_cert_key":{},"db_resurrect_ttl":30,"nginx_user":"kong kong","nginx_main_user":"kong kong","nginx_daemon":"on","nginx_main_daemon":"on","cluster_v2":false,"nginx_main_worker_processes":"auto","plugins":["bundled"],"real_ip_header":"X-Real-IP","nginx_proxy_real_ip_header":"X-Real-IP","real_ip_recursive":"off","nginx_proxy_real_ip_recursive":"off","client_max_body_size":"0","nginx_http_client_max_body_size":"0","client_body_buffer_size":"8k","nginx_http_client_body_buffer_size":"8k","headers":["server_tokens","latency_tokens"],"pg_password":"******","pg_ssl":false,"pg_ssl_verify":false,"pg_max_concurrent_queries":0,"pg_semaphore_timeout":60000,"pg_ro_ssl":false,"pg_ro_ssl_verify":false,"nginx_main_directives":[{"name":"daemon","value":"on"},{"name":"user","value":"kong kong"},{"name":"worker_processes","value":"auto"},{"name":"worker_rlimit_nofile","value":"auto"}],"cassandra_contact_points":["127.0.0.1"],"cassandra_port":9042,"pluginserver_names":{},"cassandra_ssl":false,"cassandra_ssl_verify":false,"cassandra_write_consistency":"ONE","nginx_upstream_directives":{},"nginx_proxy_directives":[{"name":"real_ip_header","value":"X-Real-IP"},{"name":"real_ip_recursive","value":"off"}],"nginx_status_directives":{},"cassandra_read_consistency":"ONE","nginx_stream_directives":[{"name":"lua_shared_dict","value":"stream_prometheus_metrics 5m"},{"name":"lua_ssl_protocols","value":"TLSv1.1 TLSv1.2 TLSv1.3"},{"name":"ssl_dhparam","value":"/usr/local/kong/ssl/ffdhe2048.pem"},{"name":"ssl_prefer_server_ciphers","value":"off"},{"name":"ssl_protocols","value":"TLSv1.2 TLSv1.3"},{"name":"ssl_session_tickets","value":"on"},{"name":"ssl_session_timeout","value":"1d"}],"cassandra_lb_policy":"RequestRoundRobin","nginx_supstream_directives":{},"go_pluginserver_exe":"/usr/local/bin/go-pluginserver","nginx_sproxy_directives":{},"cassandra_refresh_frequency":60,"cassandra_repl_strategy":"SimpleStrategy","upstream_keepalive_pool_size":60,"cassandra_repl_factor":1,"cassandra_data_centers":["dc1:2","dc2:3"],"cassandra_schema_consensus_timeout":60000,"nginx_err_logs":"/usr/local/kong/logs/error.log","ssl_protocols":"TLSv1.1 TLSv1.2 TLSv1.3","nginx_http_ssl_protocols":"TLSv1.2 TLSv1.3","nginx_stream_ssl_protocols":"TLSv1.2 TLSv1.3","ssl_prefer_server_ciphers":"on","nginx_http_ssl_prefer_server_ciphers":"off","nginx_stream_ssl_prefer_server_ciphers":"off","ssl_dhparam":"ffdhe2048","nginx_http_ssl_dhparam":"ffdhe2048","upstream_keepalive_idle_timeout":60,"kong_env":"/usr/local/kong/.kong_env","ssl_cert_csr_default":"/usr/local/kong/ssl/kong-default.csr","nginx_stream_ssl_session_tickets":"on","ssl_cert_default":"/usr/local/kong/ssl/kong-default.crt","nginx_http_ssl_session_timeout":"1d","ssl_cert_key_default":"/usr/local/kong/ssl/kong-default.key","proxy_access_log":"logs/access.log","ssl_cert_default_ecdsa":"/usr/local/kong/ssl/kong-default-ecdsa.crt","proxy_stream_access_log":"logs/access.log basic","ssl_cert_key_default_ecdsa":"/usr/local/kong/ssl/kong-default-ecdsa.key","admin_access_log":"logs/admin_access.log","admin_error_log":"logs/error.log","status_access_log":"off","status_error_log":"logs/status_error.log","log_level":"notice","nginx_optimizations":true,"lua_ssl_trusted_certificate":{},"lua_ssl_verify_depth":1,"lua_ssl_protocols":"TLSv1.1 TLSv1.2 TLSv1.3","nginx_http_lua_ssl_protocols":"TLSv1.1 TLSv1.2 TLSv1.3","nginx_stream_lua_ssl_protocols":"TLSv1.1 TLSv1.2 TLSv1.3","db_update_propagation":0,"stream_listeners":{},"cluster_control_plane":"127.0.0.1:8005","cluster_mtls":"shared","cluster_data_plane_purge_delay":1209600,"cluster_ocsp":"off","untrusted_lua":"sandbox","untrusted_lua_sandbox_requires":{},"untrusted_lua_sandbox_environment":{},"nginx_main_worker_rlimit_nofile":"auto","nginx_events_worker_connections":"auto","nginx_events_multi_accept":"on","ssl_cert":["/usr/local/kong/ssl/kong-default.crt","/usr/local/kong/ssl/kong-default-ecdsa.crt"],"database":"postgres","enabled_headers":{"Via":true,"Server":true,"X-Kong-Upstream-Latency":true,"server_tokens":true,"latency_tokens":true,"X-Kong-Admin-Latency":true,"X-Kong-Proxy-Latency":true,"X-Kong-Upstream-Status":false,"X-Kong-Response-Latency":true},"nginx_admin_client_max_body_size":"10m","nginx_admin_client_body_buffer_size":"10m","nginx_http_lua_regex_match_limit":"100000","client_ssl":false,"db_cache_ttl":0,"pg_host":"127.0.0.1","mem_cache_size":"128m","trusted_ips":{},"upstream_keepalive_max_requests":100,"pg_database":"kong","nginx_stream_ssl_session_timeout":"1d","proxy_error_log":"logs/error.log","proxy_stream_error_log":"logs/error.log","status_ssl_cert_key_default":"/usr/local/kong/ssl/status-kong-default.key","ssl_cert_key":["/usr/local/kong/ssl/kong-default.key","/usr/local/kong/ssl/kong-default-ecdsa.key"],"pg_user":"kong","nginx_kong_stream_conf":"/usr/local/kong/nginx-kong-stream.conf","kic":false,"nginx_conf":"/usr/local/kong/nginx.conf","admin_acc_logs":"/usr/local/kong/logs/admin_access.log","db_update_frequency":5,"pg_port":5432,"nginx_stream_ssl_dhparam":"ffdhe2048","host_ports":{},"status_listeners":{},"nginx_http_ssl_session_tickets":"on","cluster_listeners":[{"http2":false,"proxy_protocol":false,"deferred":false,"reuseport":false,"backlog=%d+":false,"ip":"0.0.0.0","bind":false,"port":8005,"ssl":false,"listener":"0.0.0.0:8005"}],"error_default_type":"text/plain","cassandra_timeout":60000,"proxy_ssl_enabled":true,"proxy_listeners":[{"http2":false,"proxy_protocol":false,"deferred":false,"reuseport":true,"ip":"0.0.0.0","bind":false,"listener":"0.0.0.0:8000 reuseport backlog=16384","backlog=16384":true,"ssl":false,"port":8000},{"http2":true,"proxy_protocol":false,"deferred":false,"reuseport":true,"ip":"0.0.0.0","bind":false,"listener":"0.0.0.0:8443 ssl http2 reuseport backlog=16384","backlog=16384":true,"ssl":true,"port":8443}],"pg_timeout":60000,"role":"traditional","lua_socket_pool_size":30,"nginx_admin_directives":[{"name":"client_body_buffer_size","value":"10m"},{"name":"client_max_body_size","value":"10m"}],"worker_state_update_frequency":5,"worker_consistency":"strict","go_plugins_dir":"off","nginx_worker_processes":"auto","nginx_events_directives":[{"name":"multi_accept","value":"on"},{"name":"worker_connections","value":"auto"}],"nginx_http_directives":[{"name":"client_body_buffer_size","value":"8k"},{"name":"client_max_body_size","value":"0"},{"name":"lua_regex_match_limit","value":"100000"},{"name":"lua_shared_dict","value":"prometheus_metrics 5m"},{"name":"lua_ssl_protocols","value":"TLSv1.1 TLSv1.2 TLSv1.3"},{"name":"ssl_dhparam","value":"/usr/local/kong/ssl/ffdhe2048.pem"},{"name":"ssl_prefer_server_ciphers","value":"off"},{"name":"ssl_protocols","value":"TLSv1.2 TLSv1.3"},{"name":"ssl_session_tickets","value":"on"},{"name":"ssl_session_timeout","value":"1d"}],"cassandra_keyspace":"kong","nginx_http_upstream_directives":{},"nginx_http_status_directives":{},"loaded_plugins":{"statsd":true,"bot-detection":true,"aws-lambda":true,"request-termination":true,"jwt":true,"acl":true,"correlation-id":true,"cors":true,"oauth2":true,"tcp-log":true,"session":true,"acme":true,"http-log":true,"key-auth":true,"hmac-auth":true,"basic-auth":true,"ip-restriction":true,"request-transformer":true,"response-transformer":true,"request-size-limiting":true,"rate-limiting":true,"response-ratelimiting":true,"syslog":true,"loggly":true,"datadog":true,"ldap-auth":true,"prometheus":true,"proxy-cache":true,"udp-log":true,"file-log":true,"grpc-gateway":true,"grpc-web":true,"post-function":true,"pre-function":true,"zipkin":true,"azure-functions":true},"db_cache_warmup_entities":["services"],"cassandra_username":"kong","stream_proxy_ssl_enabled":false,"admin_ssl_enabled":true,"status_ssl_enabled":false,"admin_listeners":[{"http2":false,"proxy_protocol":false,"deferred":false,"reuseport":true,"ip":"127.0.0.1","bind":false,"listener":"127.0.0.1:8001 reuseport backlog=16384","backlog=16384":true,"ssl":false,"port":8001},{"http2":true,"proxy_protocol":false,"deferred":false,"reuseport":true,"ip":"127.0.0.1","bind":false,"listener":"127.0.0.1:8444 ssl http2 reuseport backlog=16384","backlog=16384":true,"ssl":true,"port":8444}],"nginx_pid":"/usr/local/kong/pids/nginx.pid","nginx_acc_logs":"/usr/local/kong/logs/access.log","dns_resolver":{},"dns_hostsfile":"/etc/hosts","nginx_kong_conf":"/usr/local/kong/nginx-kong.conf","dns_error_ttl":1,"dns_not_found_ttl":30,"dns_stale_ttl":4,"dns_order":["LAST","SRV","A","CNAME"],"dns_no_sync":false,"ssl_session_timeout":"1d","anonymous_reports":true,"ssl_session_tickets":"on","status_ssl_cert_default":"/usr/local/kong/ssl/status-kong-default.crt"},"timers":{"pending":9,"running":0},"version":"2.5.0"}
停止 Kong
kong stop
来源
kong 专题目录
Kong nginx-01 CentOS7 图文安装
CentOS Installation
centos7安装kong网关
kong的端口简介以及如何远程连接kong的管理端口
Kong API Gateway 管理API详解