API gateway 之 kong 安裝 (二)


 

一、系統環境

[root@kong ~]# service iptables status
iptables: Firewall is not running.
[root@kong ~]# getenforce
Disabled
[root@kong ~]# cat /etc/system-release
CentOS release 6.7 (Final)
[root@kong ~]# uname -a
Linux kong 2.6.32-573.el6.x86_64 #1 SMP Thu Jul 23 15:44:03 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

 

二、kong的安裝

    根據kong的官網文檔進行安裝  官網:https://konghq.com/install/

  1、yum源配置

[root@kong ~]# cat /etc/yum.repos.d/bintray-kong-kong-community-edition-rpm.repo
[bintraybintray-kong-kong-community-edition-rpm]
name=bintray-kong-kong-community-edition-rpm
baseurl=https://kong.bintray.com/kong-community-edition-rpm/centos/6
gpgcheck=0
repo_gpgcheck=0
enabled=1

 

  2、安裝kong  默認安裝的 kong-0.10.4-1.noarch,官網已經更新到了0.13.x了,也可以手動下載最新版的rpm包安裝

[root@kong ~]# yum install -y kong

  如果安裝是報如下錯誤,就在/etc/yum.conf 配置文件 sslverify=false后,重新執行上面命令

https://kong.bintray.com/kong-community-edition-rpm/centos/6/kong-community-edition-0.10.4.el6.noarch.rpm: [Errno 14] Peer cert cannot be verified or peer cert invalid

 

  3、安裝 kong 需要的數據庫,默認選擇的是postgreSQL,kong支持2種數據庫存儲(postgreSQL 和 Cassandra 

    postgreSQL官網:https://www.postgresql.org/download/

    Cassandra官網:http://cassandra.apache.org/download/

    

    這里我們以postgreSQL為例進行安裝

    a、配置yum源

      https://www.postgresql.org/download/linux/redhat/

yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-6-x86_64/pgdg-centos10-10-2.noarch.rpm

yum install postgresql10

yum install postgresql10-server

service postgresql-10 initdb
chkconfig postgresql-10 on

 

    b、修改postgreSQL配置文件

      /var/lib/pgsql/10/data/postgresql.conf

listen_addresses = 'localhost'

替換成如下:

listen_addresses = '*'

      /var/lib/pgsql/10/data/pg_hba.conf

host    all             all             127.0.0.1/32            ident

換成如下:

host    all             all             127.0.0.1/32            trust

 

    c、啟動postgreSQL

service postgresql-10 start

 

    d、創建kong需要的庫、授權  並 把相關的數據寫入庫

[root@base ~]# su - postgres
-bash-4.1$ psql
psql (8.4.20, server 10.3)
WARNING: psql version 8.4, server version 10.0.
         Some psql features might not work.
Type "help" for help.

postgres=# CREATE USER kong; CREATE DATABASE kong OWNER kong;
CREATE ROLE
CREATE DATABASE
postgres=# quit
postgres-# \q
-bash-4.1$ exit
logout
[root@base ~]# kong migrations up
...................
response-ratelimiting migrated up to: 2016-08-04-321512_response-rate-limiting_policies
migrating acl for database kong
acl migrated up to: 2015-08-25-841841_init_acl
32 migrations ran

 

    e、修改普通用戶描述符,至少4096

ulimit -HSn 65535
echo "ulimit -HSn 65535" >> /etc/rc.local

 

  4、啟動 kong

[root@base ~]# kong start
Kong started

[root@base ~]# netstat -lntp|grep nginx
tcp        0      0 0.0.0.0:8000                0.0.0.0:*                   LISTEN      3984/nginx          
tcp        0      0 0.0.0.0:8001                0.0.0.0:*                   LISTEN      3984/nginx          
tcp        0      0 0.0.0.0:8443                0.0.0.0:*                   LISTEN      3984/nginx          
tcp        0      0 0.0.0.0:8444                0.0.0.0:*                   LISTEN      3984/nginx

[root@base ~]# curl -i -X GET http://localhost:8001/
HTTP/1.1 200 OK
Date: Thu, 05 Apr 2018 08:22:56 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.10.4

{"timers":{"running":0,"pending":5},"configuration":{"admin_error_log":"logs\/error.log","cassandra_lb_policy":"RoundRobin","admin_access_log":"logs\/admin_access.log","ca ..................
..............................

 

三、Kong UI管理工具

  安裝說明:https://github.com/PGBI/kong-dashboard

 

  1、安裝kong管理工具的環境依賴  nodejs 及 npm

    nodejs 及 npm安裝教程:https://nodejs.org/en/download/package-manager/#enterprise-linux-and-fedora

curl --silent --location https://rpm.nodesource.com/setup_9.x | sudo bash -

yum -y install nodejs

 

  2、使用 npm 安裝 kong-dashboard

npm install -g kong-dashboard
nohup kong-dashboard start --kong-url http://192.168.1.128:8001 &


也可以基於basic 認證,在登錄是要求輸入密碼

nohup kong-dashboard start --kong-url http://192.168.1.128:8001 --basic-auth admin=123456 &

 

  3、訪問 kong-dashboard   http://192.168.1.128:8080 (輸入剛剛配置的賬號密碼)

 

 

四、Kong 桌面管理工具

  Kong 桌面管理工具:https://github.com/ajaysreedhar/kongdash 有linux版本,windows版本,mac版本。

 

  下載地址:https://github.com/ajaysreedhar/kongdash/releases/download/v0.3.0/kongdash-0.3.0-ia32.exe

 

  訪問地址:http://192.168.1.128:8001/

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM