bingooyong / note

1 stars 1 forks source link

Mac下Kong的安装与使用 #16

Open bingooyong opened 5 years ago

bingooyong commented 5 years ago

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

[TOC]

Mac下Kong的安装与使用(kong-0.12.2)

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

安装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

编译安装 luarocks

./configure \
   --lua-suffix=jit \
   --with-lua=/usr/local/openresty/luajit \
   --with-lua-include=/usr/local/openresty/luajit/include/luajit-2.1

安装 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

在 Mac OS 安装

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;
在 Centos7 安装 postgresql 9.6 [rpm](https://yum.postgresql.org/repopackages.php)
yum install -y https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm
yum install -y postgresql96-server postgresql96-contrib
# 初始化数据库
/usr/pgsql-9.6/bin/postgresql96-setup initdb
# 设置开机启动
systemctl enable postgresql-9.6.service
# 启动数据库
systemctl start postgresql-9.6.service
# 配置远程访问
vi /var/lib/pgsql/9.6/data/postgresql.conf

安装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:/opt/soft/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 

kong-1.2.2 问题3:

这是因为没有安装openssl或者openssl文件位于其它目录中,如果是用brew命令安装的openssl,可以用brew info openssl找到openssl文件路径:

Error: Failed installing dependency: https://luarocks.org/luasec-0.7-1.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
  No file openssl/ssl.h in /include
You may have to install OPENSSL in your system and/or pass OPENSSL_DIR or OPENSSL_INCDIR to the luarocks command.

解决办法:

➜  ~ brew info openssl
openssl: stable 1.0.2s (bottled) [keg-only]
......
openssl is keg-only, which means it was not symlinked into /usr/local,
because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.

If you need to have openssl first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl/include"
......

OPENSSL_DIR明确指定OPENSSL目录就可以了,如下:

luarocks make OPENSSL_DIR=/usr/local/opt/openssl CRYPTO_DIR=/usr/local/opt/openssl

luarocks

清理历史安装包

luarocks purge --tree=/usr/local
luarocks list