Install Kong
Kong install 방법은 다양한 운영체제 환경에 따라 설치 방법을 가이드 하고 있다.
https://konghq.com/install/
https://docs.konghq.com/install/docker/
https://docs.konghq.com/install/kubernetes/
https://docs.konghq.com/install/centos/
https://docs.konghq.com/install/redhat/
CentOS 설치
RPM 패키지를 다운로드
https://bintray.com/kong/kong-community-edition-rpm/download_file?file_path=centos/6/kong-community-edition-0.14.1.el6.noarch.rpm
https://bintray.com/kong/kong-community-edition-rpm/download_file?file_path=centos/7/kong-community-edition-0.14.1.el7.noarch.rpm
YUM Repository 다운로드
https://bintray.com/kong/kong-community-edition-rpm
baseurl=https://kong.bintray.com/kong-community-edition-rpm/centos/6
or
baseurl=https://kong.bintray.com/kong-community-edition-rpm/centos/7
1.KONG 다운로드
$ sudo yum install epel-release
$ sudo yum install kong-community-edition-0.14.1.*.noarch.rpm --nogpgcheck
2. KONG 설치
sudo yum install kong-community-edition-0.14.1.*.noarch.rpm --nogpgcheck
rpm -Uvh kong-community-edition-1.0.0rc1.el7.noarch.rpm # 1.0 버전으로 설치
3. 데이터베이스 준비하기
데이터베이스에 연결할 수 있도록 Kong을 구성 하십시오. Kong은 데이터 저장소로 PostgreSQL 9.5+ 와 Cassandra 3.xx 를 모두 지원합니다 .
아래와 같이 데이터 베이스를 만들어야 하는데 할 일이 많습니다.
> 4. 데이터베이스 설치~5. 데이터베이스 설정를 하시고 여기를 다시 보세요
[root@localhost data]# sudo -u postgres psql
psql (9.6.10)
Type "help" for help.
postgres=# CREATE USER kongapi with PASSWORD 'kongapi';
CREATE ROLE
postgres=# CREATE DATABASE kongdb OWNER kongapi;
CREATE DATABASE
postgres=# GRANT ALL PRIVILEGES ON DATABASE "kongdb" to kongapi;
GRANT
4. pgsql 데이터베이스 설치
wget https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-centos96-9.6-3.noarch.rpm
rpm -Uvh pgdg-centos96-9.6-3.noarch.rpm
yum -y install postgresql96 postgresql96-server postgresql96-devel postgresql96-libs
5. 데이터베이스 설정
PGSQL 기본 설정은 /var/lib/pgsql/data에 데이터 파일이 생성된다. 아래와 같이 다른 디렉토리로 이동하기 위한 설정을 하였다.
5.1 centos7 기동 스크립트를 수정
Edit /usr/lib/systemd/system/postgresql.service
> Environment=PGPORT=5432
> - Environment=PGDATA=/var/lib/pgsql/data
> + Environment=PGDATA=/data/PgData/data
mkdir -p /data/PgData/data
chown -R postgres:postgres /data/PgData
5.2 Install Initdb
export PGDATA=/data/PgData/data
/usr/pgsql-9.6/bin/initdb
./postgresql96-setup initdb
# postgresql-setup initdb # pgsql 9.2
5.3 Postgres 접근 환경 설정
원격의 서버에서 접근하기 위해 아래와 같은 설정이 필요하다.
## Config Access ###########
[edit pg_hba.conf]
# host all all 127.0.0.1/32 ident
# + host all all 192.168.56.0/24 md5
[edit postgresql.conf]
# + listen_addresses = '*'
# - #listen_addresses = 'localhost' # what IP address(es) to listen on
5.4 데몬 설정 후 기동하기
#### for 9.6 ###
systemctl start postgresql-9.6
systemctl stop postgresql-9.6
systemctl status postgresql-9.6
systemctl enable postgresql-9.6
systemctl disable postgresql-9.6
#### for 9.2 ###
systemctl start postgresql
systemctl stop postgresql
systemctl status postgresql
5.5 접속 상태 확인하기
다음과 같이 실행하여 접속이 되는지 확인한다.
[root@localhost data]# systemctl start postgresql-9.6
[root@localhost data]# systemctl status postgresql-9.6
[root@localhost data]# netstat -antp | grep 5432
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN 15939/postmaster
tcp6 0 0 :::5432 :::* LISTEN 15939/postmaster
0.0.0.0:5432 : 외부에서 5432 port 로 접속 가능하도록 되었음을 확인 한다.
su - postgres
psql -U kongapi -h 192.168.56.102 -d kongdb
6. kong 설정하기
cp /etc/kong/kong.conf.default /etc/kong/kong.conf
[Edit /etc/kong/kong.conf]
database = postgres
pg_host = 192.168.56.101 # The PostgreSQL host to connect to.
pg_port = 5432 # The port to connect to.
pg_user = kongapi # The username to authenticate if required.
pg_password = kongapi # The password to authenticate if required.
pg_database = kongdb # The database name to connect to.
7. kong 구동하기
kong 기동을 위한 환경 초기화 를 위해 다음과 같이 실행하면 데이터베이스를 생성한다.
# kong migrations bootstrap
# kong check
configuration at /etc/kong/kong.conf is valid
# kong start
아래와 같이 에러가 나는 경우는 /etc/security/limits.conf를 수정후 재부팅 하거나 ulimit -n 10240 으로 임시적인 해결이 가능하다.
[root@localhost kong]# kong start
2018/09/25 02:12:56 [warn] ulimit is currently set to "1024". For better performance set it to at least "4096" using "ulimit -n"
Kong started
Edit /etc/security/limits.conf
#<domain> <type> <item> <value>
#
+ * hard nofile 10240
+ * soft nofile 10240
+ * hard nproc 10000
+ * soft nproc 10000
ulimit -n 10240
[root@localhost kong]# ulimit -a
open files (-n) 1024 -> 10240으로 수정하려면 재부팅을 하거나 ulimit -n 10240 으로 해결한다.