β

CentOS下安装kong API网关服务

苹果园子 125 阅读
API

kong 官网

https://getkong.org/install/centos/

# wget https://github.com/Mashape/kong/releases/download/0.10.3/kong-0.10.3.el6.noarch.rpm
# rpm -iv kong-0.10.3.el6.noarch.rpm
# kong version
0.10.3

修改kong配置
# cp /etc/kong/kong.conf.default /etc/kong/kong.conf

prefix = /usr/local/kong/
log_level = notice
proxy_access_log = logs/access.log
proxy_error_log = logs/error.log
admin_access_log = logs/admin_access.log
admin_error_log = logs/error.log
proxy_listen = 0.0.0.0:8000
proxy_listen_ssl = 0.0.0.0:8443
admin_listen = 0.0.0.0:8001
nginx_worker_processes = auto
nginx_daemon = on
mem_cache_size = 128m

database = postgres
pg_host = 127.0.0.1
pg_port = 5432
pg_user = kong
pg_password = kong
pg_database = kong

更多配置说明:https://getkong.org/docs/0.10.x/configuration/

安装postgresql数据库
https://www.postgresql.org/download/linux/redhat/

# yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-centos96-9.6-3.noarch.rpm
# yum install postgresql96
# yum install postgresql96-server
# service postgresql-9.6 initdb
# chkconfig postgresql-9.6 on

修改数据库配置
# vi /var/lib/pgsql/9.6/data/postgresql.conf

hba_file = ‘/var/lib/pgsql/9.6/data/pg_hba.conf’
listen_addresses = ‘*’
port = 5432

# vi /var/lib/pgsql/9.6/data/pg_hba.conf
host all all 127.0.0.1/32 trust

权限说明参考 https://www.depesz.com/2007/10/04/ident/
trust
password
md5
ident
reject
权限有问题,会报以下错误
Error: /usr/local/share/lua/5.1/kong/cmd/start.lua:21: [postgres error] could not get current migrations: [postgres error] FATAL: Ident authentication failed for user “kong”

# service postgresql-9.6 start
# sudo su – postgres
-bash-4.1$ psql
psql (9.6.3)
Type “help” for help.

postgres=# \password postgres
Enter new password: postgres
Enter it again:
postgres=# CREATE USER kong;
CREATE ROLE
postgres=# CREATE DATABASE kong OWNER kong;
CREATE DATABASE
postgres=# GRANT ALL PRIVILEGES ON DATABASE kong to kong;
GRANT
postgres=# \password kong
Enter new password: kong
Enter it again:
postgres=# \q

postgresql其他一些方法使用参考 http://www.ruanyifeng.com/blog/2013/12/getting_started_with_postgresql.html

启动kong会报以下提示,提前做下优化
ulimit is currently set to “1024”. For better performance set it to at least “4096” using “ulimit -n”

# vi /etc/security/limits.conf

* soft nofile 51200
* hard nofile 102400
* soft noproc 51200
* hard noproc 102400

# ulimit -SHn 51200

启动kong,会初始一些数据配置
# kong start

# curl -i -X POST \
> –url http://localhost:8001/apis/ \
> –data ‘name=example-api’ \
> –data ‘hosts=example.com’ \
> –data ‘upstream_url=http://httpbin.org’

HTTP/1.1 201 Created
Date: Thu, 15 Jun 2017 07:41:39 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.10.3

{

“http_if_terminated”:true,

“id”:”0d2bb519-bdd9-4c75-86e7-5ba9bc895e50″,

“retries”:5,

“preserve_host”:false,

“created_at”:1497512500000,

“upstream_connect_timeout”:60000,

“upstream_url”:”http:\/\/httpbin.org”,

“upstream_read_timeout”:60000,

“https_only”:false,”upstream_send_timeout”:60000,

“strip_uri”:true,

“name”:”example-api”,

“hosts”:[“example.com”]

}

# curl -i -X GET \
–url http://localhost:8000/ip \
–header ‘Host: example.com’

API
作者:苹果园子
此苹果非彼苹果
原文地址:CentOS下安装kong API网关服务, 感谢原作者分享。

发表评论