Mac下Kong的安装与使用

title: Mac下Kong的安装与使用
date: 2018-03-08 16:02:59
tags: Kong

安装,由于使用homebrew各种报错,最后直接使用源码安装

  • 安装openresty

Mac OS X (macOS) 用户安装过程中由于pcre和openssl可能出错,直接使用brew单独安装 http://openresty.org/cn/installation.html

brew update
brew install pcre openssl

安装成功后使用list查询安装路径

brew list pcre openssl
​
/usr/local/Cellar/pcre/8.41/bin/pcre-config
/usr/local/Cellar/pcre/8.41/bin/pcregrep
/usr/local/Cellar/pcre/8.41/bin/pcretest
/usr/local/Cellar/pcre/8.41/include/ (6 files)
/usr/local/Cellar/pcre/8.41/lib/libpcre.1.dylib
/usr/local/Cellar/pcre/8.41/lib/libpcre16.0.dylib
/usr/local/Cellar/pcre/8.41/lib/libpcre32.0.dylib
/usr/local/Cellar/pcre/8.41/lib/libpcrecpp.0.dylib
/usr/local/Cellar/pcre/8.41/lib/libpcreposix.0.dylib
/usr/local/Cellar/pcre/8.41/lib/pkgconfig/ (5 files)
/usr/local/Cellar/pcre/8.41/lib/ (10 other files)
/usr/local/Cellar/pcre/8.41/share/doc/ (64 files)
/usr/local/Cellar/pcre/8.41/share/man/ (103 files)
/usr/local/Cellar/openssl/1.0.2n/.bottle/etc/ (8 files)
/usr/local/Cellar/openssl/1.0.2n/bin/c_rehash
/usr/local/Cellar/openssl/1.0.2n/bin/openssl
/usr/local/Cellar/openssl/1.0.2n/include/openssl/ (75 files)
/usr/local/Cellar/openssl/1.0.2n/lib/libcrypto.1.0.0.dylib
/usr/local/Cellar/openssl/1.0.2n/lib/libssl.1.0.0.dylib
/usr/local/Cellar/openssl/1.0.2n/lib/engines/ (12 files)
/usr/local/Cellar/openssl/1.0.2n/lib/pkgconfig/ (3 files)
/usr/local/Cellar/openssl/1.0.2n/lib/ (4 other files)
/usr/local/Cellar/openssl/1.0.2n/share/man/ (1680 files)

安装 luarocks

brew install lua
brew link luarocks
​
git clone git://github.com/diegonehab/luasocket.git
cd luasocket
make macosx
sudo make install

安装openresty

wget https://openresty.org/download/openresty-1.11.2.5.tar.gz
tar xzf openresty-1.11.2.5.tar.gz
cd openresty-1.11.2.5
​
./configure \
  --with-cc-opt="-I/usr/local/Cellar/openssl/1.0.2o_1/include/ -I/usr/local/Cellar/pcre/8.41/include/" \
  --with-ld-opt="-L/usr/local/Cellar/openssl/1.0.2o_1/lib/ -L/usr/local/Cellar/pcre/8.41/lib/" \
  -j8\
  --with-pcre-jit \
  --with-ipv6 \
  --with-http_realip_module \
  --with-http_ssl_module \
  --with-http_stub_status_module \
  --with-http_v2_module
​
make -j8
make install
  • 安装postgresql

brew install postgresql
initdb /usr/local/var/postgres -E utf8
pg_ctl -D /usr/local/var/postgres -l logfile start
/usr/local/bin/psql -d postgres
​
#初始化kong的用户和数据库
CREATE USER kong; CREATE DATABASE kong OWNER kong;
  • 安装kong

wget https://codeload.github.com/Kong/kong/tar.gz/0.12.2 -O kong-0.12.2.tar.gz
tar xzf kong-0.12.2.tar.gz
sudo make
sudo make install
  • 设置环境变量

我这里是直接改了zsh的环境变量,不用zsh的可以改~/.bash_profile

vi ~/.zsh_profile
export PATH="$PATH:/usr/local/openresty/bin"
export PATH="$PATH:/Users/YourName/dev/kong-0.12.2/kong-0.12.2/bin"
  • 启动kong

#初始化
kong migrations up
#启动
kong start
  • 测试kong

⋊> ~ curl -i http://localhost:8001/                                                                                                                                                                                                                              
HTTP/1.1 200 OK
Date: Thu, 08 Mar 2018 08:49:08 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.12.2

PS:

  1. Kong

  2. openresty

 

问题1:

/usr/include/sys/resource.h:204:2: error: unknown type name 'uint64_t'

解决办法:

mv /usr/local/include /usr/local/include.old
brew install llvm

问题2:

Error: Failed installing dependency: https://luarocks.org/luasec-0.6-2.src.rock - Could not find header file for OPENSSL
  No file openssl/ssl.h in /usr/local/include
  No file openssl/ssl.h in /usr/include

解决办法:

cd /usr/local/include 
ln -s ../opt/openssl/include/openssl 

你可能感兴趣的:(Mac下Kong的安装与使用)