Kong是一個使用了lua-nginx-module運行在Nginx之上的Lua應用。Kong是一個成熟的API網關解決方案。API 網關,即API Gateway,是大型分佈式系統中,爲了保護內部服務而設計的一道屏障,能夠提供高性能、高可用的 API託管服務,從而幫助服務的開發者便捷地對外提供服務,而不用考慮安全控制、流量控制、審計日誌等問題,統一在網關層將安全認證,流量控制,審計日誌,黑白名單等實現。網關的下一層,是內部服務,內部服務只需開發和關注具體業務相關的實現。網關能夠提供API發佈、管理、維護等主要功能。開發者只須要簡單的配置操做便可把本身開發的服務發佈出去,同時置於網關的保護之下。 php
參考文檔:
https://konghq.com/ (kong官網)
https://www.pocketdigi.com/bo...
https://www.postgresql.org/ (postgresql官網)
http://www.postgres.cn/index....
環境:
環境:Centos7
配置:2c4g
權限:root
注意:請勿使用"yum install kong-community-edition"安裝Kong,必須指定版本號!"yum install kong-community-edition-0.14.1.*.noarch.rpm --nogpgcheck"
# 配置完yum庫以後卸載以前安裝的Postgresql yum erase postgresql* # 刪除遺留的數據 rm -rf /var/lib/pgsql
下載RPM(PostgreSQL YUM源),找到對應的版本 CentOS 7 - x86_64node
# 安裝yum源 yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm # 安裝PostgreSQL yum install postgresql96-server postgresql96-contrib
# 初始化數據庫 /usr/pgsql-9.6/bin/postgresql96-setup initdb
# PostgreSQL 使用systemctl做爲服務託管 service postgresql-9.6 start/stop/restart/reload # 或是 systemctl start/stop/restart/status postgresql-9.6 # 設置開機自啓 systemctl enable postgresql-9.6
# 卸載PostgreSQL yum erase postgresql96
PostgreSQL數據庫默認會建立一個Linux系統用戶postgres,經過passwd命令能夠設置密碼。nginx
# 建立postgres數據庫帳號 su postgres psql ALTER USER postgres WITH PASSWORD '123456'; \q su root
將listen_addresses前的#去掉,並將 listen_addresses = 'localhost' 改爲 listen_addresses = '*';git
#------------------------------------------------------------------------------ # CONNECTIONS AND AUTHENTICATION #------------------------------------------------------------------------------ # - Connection Settings - # 放開IP的限制 listen_addresses = '*' # what IP address(es) to listen on;
將IPv4區下的127.0.0.1/32修改成0.0.0.0/0; 將ident修改成md5github
# TYPE DATABASE USER ADDRESS METHOD # "local" is for Unix domain socket connections only local all all peer local all all md5 # IPv4 local connections: ### 假如Kong用戶設置了密碼,須要配置MD5認證 host all all 127.0.0.1/32 md5 ### 允許遠程向Navicat客戶端訪問 host all all 0.0.0.0/0 md5 # IPv6 local connections: host all all ::1/128 ident
#爲postgres用戶增長work分組 sudo usermod -a -G work postgres # 添加kong數據庫帳戶及數據庫 createuser -s -e kong createdb -E UTF8 -O kong kong # 添加kong系統用戶名 sudo adduser kong # 可選 爲kong系統用戶設置密碼 sudo passwd kong
# 建立postgres數據庫帳號 su postgres psql ALTER USER kong WITH PASSWORD '123456'; \q exit
官網文檔:Kong Installsql
# 新建Kong的yum reposit vi /etc/yum.repos.d/kong-community-edition.repo # 輸入內容 [kong-community-edition] name=kong-community-edition baseurl=https://kong.bintray.com/kong-community-edition-rpm/centos/7 gpgcheck=0 repo_gpgcheck=0 enabled=1
# 安裝epel yum install epel-release # 安裝Kong yum localinstall https://bintray.com/kong/kong-community-edition-rpm/download_file?file_path=centos/7/kong-community-edition-0.14.1.el7.noarch.rpm
# 建立配置 cp kong.conf.default kong.conf vim /etc/kong/kong.conf # 修改數據庫配置 database = postgres # Determines which of PostgreSQL or Cassandra pg_host = 127.0.0.1 # The PostgreSQL host to connect to. pg_port = 5432 # The port to connect to. pg_user = kong # The username to authenticate if required. pg_password = 123456 # The password to authenticate if required. pg_database = kong # The database name to connect to.
kong migrations up [-c /path/to/kong.conf]
kong start [-c /path/to/kong.conf] # 非root權限用戶啓動方式 chmod -R 777 /usr/local/kong chmod -R 777 /usr/local/share/lua/5.1
curl -i http://localhost:8001/
官方文檔:Kong Dashboard Install數據庫
# kong Dashboard是nodejs寫的 sudo yum install nodejs
# Install Kong Dashboard npm install -g kong-dashboard # Start Kong Dashboard kong-dashboard start --kong-url http://kong:8001 # Start Kong Dashboard on a custom port kong-dashboard start \ --kong-url http://kong:8001 \ --port [port] # Start Kong Dashboard with basic auth kong-dashboard start \ --kong-url http://kong:8001 \ --basic-auth user1=password1 user2=password2 # See full list of start options kong-dashboard start --help