KONG安装使用说明 系统版本:ubuntu14 1、下载安装包 $ wget https://github.com/Mashape/kong/releases/download/0.8.3/kong-0.8.3.trusty_all.deb 2、安装依赖 $ sudo apt-get update $ sudo apt-get install openjdk-7-jdk $ sudo apt-get install netcat openssl libpcre3 dnsmasq procps $ sudo dpkg -i kong-0.8.3.*.deb 3、安装数据库 安装CASSANDRA 2.2.X 下载地址: $ wget http://mirrors.hust.edu.cn/apache/cassandra/2.1.15/apache-cassandra-2.1.15-bin.tar.gz 解压: $ tar zxvf apache-cassandra-2.1.15-bin.tar.gz 移动: $ sudo mv apache-cassandra-2.1.15-bin /usr/local/cassandra-2.1.15 执行: $ /usr/local/cassandra-2.1.15/bin/cassandra 4、修改配置 $ sudo vi /etc/kong/kong.yml 设置 cluster_listen: "127.0.0.1:7946" 5、启动kong $ kong start 5、运行kong $ curl 127.0.0.1:8001 6、添加API $ curl -i -X POST \ --url http://localhost:8001/apis/ \ --data 'name=simlogin' \ --data 'upstream_url=http://uc.ttq.dev/index.php/ttk/auth/simlogin' \ --data 'request_path=/simlogin' \ --data 'request_host=uc.ttq.dev' url:kong固定地址 request_path:请求路径 upstream_url:真实路径 7、访问API http://172.168.6.211:8000/simlogins?login_account=18022222223&channel=ttk&type=pc 172.168.6.211:8000(Kong服务器地址) simlogins (request_path) 8、Key验证 配置key $ curl -X POST http://kong:8001/apis/{api}/plugins \ --data "name=key-auth" 例子: $ curl -X POST http://localhost:8001/apis/simlogin/plugins --data 'name=key-auth' 返回值: { "api_id": "95ec4e23-0d19-4c38-a974-8f5643876eb0", "id": "5e711b42-23f8-4f79-a7b1-91b0bd779c69", "created_at": 1472110325000, "enabled": true, "name": "key-auth", "config": { "key_names": ["apikey"], "hide_credentials": false } } 创建调用账户 $ curl -X POST http://kong:8001/consumers/ \ --data "username=<USERNAME>" \ --data "custom_id=<CUSTOM_ID>" 例子: $ curl -X POST http://localhost:8001/consumers/ \ --data "username=login_user" --data "custom_id=000002" 返回值: { "custom_id": "000002", "username": "login_user", "created_at": 1472110450000, "id": "9267ff99-3732-4150-a727-ced409699e27" } 设置key $ curl -X POST http://kong:8001/consumers/{consumer}/key-auth 例子: $ curl -X POST http://localhost:8001/consumers/9267ff99-3732-4150-a727-ced409699e27/key-auth \ --data "key=ksdpemc514d" 返回值: { "key": "ksdpemc514d", "consumer_id": "9267ff99-3732-4150-a727-ced409699e27", "created_at": 1472110618000, "id": "005a8a0b-61ce-4085-8300-4c9790c9599c" } http调用 http://kong:8000/simlogins?apikey=ksdpemc514d //参数和实际接口参数一样 8、IP限定 $ curl -X POST http://kong:8001/apis/{api}/plugins \ --data "name=ip-restriction" \ --data "config.whitelist=54.13.21.1, 143.1.0.0/24" 例子: $ curl -X POST http://localhost:8001/apis/login/plugins \ --data "name=ip-restriction" \ --data "config.whitelist=172.168.6.210" 返回值: { "api_id": "f7eb3785-2e6f-477c-bac6-4b078a7a7cf2", "id": "ec1666af-66f5-45f4-8059-619b93d1299a", "created_at": 1472191585000, "enabled": true, "name": "ip-restriction", "config": { "whitelist": ["172.168.6.210"] } } 9、删除扩展 $ curl -i -X DELETE kong:8001/plugins/{pluginsid} 例子: $ curl -i -X DELETE localhost:8001/plugins/f1ef7f24-a5b3-40c7-8c23-75860bdf9fb3 返回值: HTTP/1.1 204 No Content Date: Fri, 26 Aug 2016 06:04:44 GMT Connection: keep-alive Access-Control-Allow-Origin: * Server: kong/0.8.3 10、安装ui 注:比较麻烦,而且也不稳定 安装mongoDB $ sudo apt-get install mongodb mongodb-clients mongodb-dev mongodb-server 安装nodejs $ sudo weget https://nodejs.org/dist/v4.5.0/node-v4.5.0.tar.gz //nodejs $ sudo tar zxvf node-v4.5.0.tar.gz $ sudo ./configure $ sudo make && make install 安装npm $ sudo weget https://npm.taobao.org/mirrors/npm/v3.9.6.tar.gz //npm $ sudo tar zxvf v3.9.6.tar.gz $ sudo ./configure $ sudo make && make install 安装bower 1、$ sudo npm i -g bower 2、$ git clone https://github.com/lestoni/dashy.git 3、$ sudo bower install 4、修改bower.json "validator": "https://github.com/yairEO/validator.git#^1.0.6 5、配置config/index.js 6、$ npm start 7、http://localhost:7500
转载于:https://www.cnblogs.com/herry52/p/5828938.html