Centos7にKongを構築する

APIを実装することになったので、OSS のAPI Gateway 「Kong」を構築した際の手順。お役に立てれば幸いです。
Centos7バージョン
# cat /etc/centos-release
CentOS Linux release 7.6.1810 (Core)
Kongインストール
こちらの公式手順に従う
1 2 3 4 5 6 7 8 9 10 11 |
sudo yum update -y ## wgetはすでに入っているのでインストールはしない sudo yum install -y wget wget https://bintray.com/kong/kong-rpm/rpm -O bintray-kong-kong-rpm.repo export major_version=`grep -oE '[0-9]+\.[0-9]+' /etc/redhat-release | cut -d "." -f1` sed -i -e 's/baseurl.*/&\/centos\/'$major_version''/ bintray-kong-kong-rpm.repo sudo mv bintray-kong-kong-rpm.repo /etc/yum.repos.d/ sudo yum update -y sudo yum install -y kong |
DB作成
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
## PostgreSQLはインストール済み su - postgres bash$ psql ## ユーザーとテーブル作成とパスワード設定 設定しないと後述してるがエラーになる postgres=#CREATE USER kong; CREATE DATABASE kong OWNER kong; postgres=# ALTER USER kong WITH PASSWORD 'パスワード設定'; ## 抜ける \q ## 確認 bash$ psql -l <出力結果> 名前 | 所有者 | エンコーディング | 照合順序 | Ctype(変換演算子) | アクセス権限 -----------+----------+------------------+----------+-------------------+----------------------- kong | kong | UTF8 | C | C | |
Kong起動
先にDBの設定を行っておかないと後述の通りエラーになる
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
## 設定ファイル作成 cd /etc/kong cp kong.conf.default kong.conf <設定> database = postgres # Determines which of PostgreSQL or Cassandra # this node will use as its datastore. # Accepted values are `postgres`, # `cassandra`, and `off`. pg_host = 127.0.0.1 # Host of the Postgres server. pg_port = 5432 # Port of the Postgres server. pg_timeout = 5000 # Defines the timeout (in ms), for connecting, # reading and writing. pg_user = kong # Postgres user. pg_password = 設定したパスワード # Postgres user's password. pg_database = kong # The database name to connect to. |
起動します。
1 2 3 4 5 6 7 8 9 10 11 |
## migrations kong migrations bootstrap ## 警告がでるので設定しておく ulimit -n 4096 ## 起動 kong start ## 確認 curl -i http://localhost:8001/ |
JSONが取得できれていれば完了
migrations実行時にエラー「Error: missing password, required for connect」が出た場合は下記を参考にして下さい。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
## 公式手順に従う sudo yum install epel-release sudo yum install kong-1.3.0.*.noarch.rpm --nogpgcheck sudo yum update -y sudo yum install -y wget wget https://bintray.com/kong/kong-rpm/rpm -O bintray-kong-kong-rpm.repo export major_version=`grep -oE '[0-9]+\.[0-9]+' /etc/redhat-release | cut -d "." -f1` sed -i -e 's/baseurl.*/&\/centos\/'$major_version''/ bintray-kong-kong-rpm.repo sudo mv bintray-kong-kong-rpm.repo /etc/yum.repos.d/ sudo yum update -y sudo yum install -y kong ## postgres CREATE USER kong; CREATE DATABASE kong OWNER kong; kong migrations bootstrap Error: missing password, required for connect エラー発生 ## デバック kong migrations bootstrap -v ## ユーザーkongにパスワードがないからっぽい su - postgres -bash-4.2$ psql psql (11.5) "help" でヘルプを表示します。 postgres=# ALTER USER kong WITH PASSWORD 'パスワード設定'; ## 設定ファイル作成 cd /etc/kong cp kong.conf.default kong.conf <設定> database = postgres # Determines which of PostgreSQL or Cassandra # this node will use as its datastore. # Accepted values are `postgres`, # `cassandra`, and `off`. pg_host = 127.0.0.1 # Host of the Postgres server. pg_port = 5432 # Port of the Postgres server. pg_timeout = 5000 # Defines the timeout (in ms), for connecting, # reading and writing. pg_user = kong # Postgres user. pg_password = 設定したパスワード # Postgres user's password. pg_database = kong # The database name to connect to. |
以上で問題なし
-
前の記事
Windows Server2016 FTP接続がグローバルIPを指定すると接続できない 2019.10.09
-
次の記事
さくらサーバーでhtmlファイルでPHPを動作させる方法 2019.10.10
コメントを書く