一: 安裝openssl和pcre
yum -y install pcre-devel openssl openssl-devel
安裝git
yum install git -y
安裝gcc
yum install gcc -y
安裝: lua
wget http://luajit.org/download/LuaJIT-2.0.5.tar.gz
tar -xvf LuaJIT-2.0.5.tar.gz
cd LuaJIT-2.0.5
make install
二: 下載安裝 openresty
wget https://openresty.org/download/openresty-1.13.6.2.tar.gz
tar -xvf openresty-1.13.6.2.tar.gz
cd openresty-1.13.6.2
./configure --with-pcre-jit --with-http_ssl_module --with-http_realip_module --with-http_stub_status_module --with-http_v2_module
gmake install
三:luarocks
wget http://luarocks.github.io/luarocks/releases/luarocks-3.0.3.tar.gz
tar -xvf luarocks-3.0.3.tar.gz
cd luarocks-3.0.3
./configure
make install
四:安裝數據庫
yum 安裝了 PostgreSQL
yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-redhat-repo-42.0-11.noarch.rpm
yum install postgresql96
yum install postgresql96-server
初始化數據庫
/usr/pgsql-9.6/bin/postgresql96-setup initdb
終端顯示:
Initializing database ... OK
創建用戶組和用戶:
創建用戶組:sudo groupadd postgresql
創建用戶:sudo useradd -gpostgresql postgresql
設置postgresql-9開機自啓
systemctl enable postgresql-9.6
終端顯示:Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-9.6.service to /usr/lib/systemd/system/postgresql-9.6.service.
啓動postgresql服務
systemctl start postgresql-9.6
------------創建數據庫------------
切換到剛纔帶創建的postgres用戶
su - postgres
psql
創建用戶kong的數據庫名稱爲kong,密碼爲kong的數據庫實例
CREATE USER kong WITH PASSWORD 'kong'; CREATE DATABASE kong OWNER kong;
終端顯示:
CREATE ROLE
CREATE DATABASE
退出
\q
還需要設置下數據庫訪問權限
vi /var/lib/pgsql/9.6/data/pg_hba.conf
修改爲:
host all all 127.0.0.1/32 trust
修改配置
vi /var/lib/pgsql/9.6/data/postgresql.conf
修改以下配置
port = 5432
修改爲:pg_password=kong
重啓動PostgreSQL數據庫
systemctl restart postgresql-9.6
五:安裝kong
下載kong2.0.4(https://docs.konghq.com/install)
將源碼copy到服務器
執行安裝rpm
rpm -ivh kong-2.0.4.el7.amd64.rpm
檢查是否安裝成功--
kong version
[root@hecs-x-xlarge-2-linux-20200604174817 home]# kong version
2.0.4
六:kong啓動
先修改kong配置文件名字
mv /etc/kong/kong.conf.default /etc/kong/kong.conf
在 /etc/kong/ 文件創建kong.conf 內容如下
vim/etc/kong/kong.conf
prefix = /usr/data/kong/
proxy_listen = 0.0.0.0:8000, 0.0.0.0:8443 ssl
admin_listen = 127.0.0.1:8001
database = postgres # Determines which of PostgreSQL or Cassandra
pg_host = 127.0.0.1 # The PostgreSQL host to connect to.
pg_port = 5432 # The port to connect to.
pg_user = kong # The username to authenticate if required.
pg_password =kong # The password to authenticate if required.
pg_database = kong
保存後退出
執行 kong migrations bootstrap
啓動kong
kong start
檢查配置:
curl -i -X GET http://localhost:8001/終端顯示:
HTTP / 1.1 200 OK
Date: Sun, 28 Jun 2020 05: 42: 50 GMT
Content - Type: application / json;
charset = utf - 8
Connection: keep - alive
Access - Control - Allow - Origin: *
Server: kong / 2.0 .4
Content - Length: 8308
X - Kong - Admin - Latency: 112
{
"plugins": {
"enabled_in_cluster": [],
"available_on_server": {
"correlation-id": true,
"pre-function": true,
"cors": true,
"ldap-auth": true,
"loggly": true,
"hmac-auth": true,
"zipkin": true,
"request-size-limiting": true,
"azure-functions": true,
"request-transformer": true,
"oauth2": true,
"response-transformer": true,
"ip-restriction": true,
"statsd": true,
"jwt": true,
"proxy-cache": true,
"basic-auth": true,
"key-auth": true,
"http-log": true,
"datadog": true,
"tcp-log": true,
"rate-limiting": true,
"post-function": true,
"prometheus": true,
"acl": true,
"syslog": true,
"file-log": true,
"acme": true,
"udp-log": true,
"response-ratelimiting": true,
"aws-lambda": true,
"session": true,
"bot-detection": true,
"request-termination": true
}
},
"tagline": "Welcome to kong",
"configuration": {
"plugins": ["bundled"],
"admin_listen": ["127.0.0.1:8001"],
"proxy_access_log": "logs\/access.log",
"prefix": "\/usr\/local\/kong",
"nginx_conf": "\/usr\/local\/kong\/nginx.conf",
"cassandra_username": "kong",
"nginx_events_directives": [{
"value": "auto",
"name": "worker_connections"
}, {
"value": "on",
"name": "multi_accept"
}],
"dns_resolver": {},
"nginx_upstream_keepalive_requests": "100",
"nginx_http_upstream_directives": [{
"value": "100",
"name": "keepalive_requests"
}, {
"value": "60s",
"name": "keepalive_timeout"
}, {
"value": "60",
"name": "keepalive"
}],
"nginx_main_daemon": "on",
"stream_proxy_ssl_enabled": false,
"nginx_acc_logs": "\/usr\/local\/kong\/logs\/access.log",
"pg_semaphore_timeout": 60000,
"proxy_listen": ["0.0.0.0:8000", "0.0.0.0:8443 ssl"],
"client_ssl_cert_default": "\/usr\/local\/kong\/ssl\/kong-default.crt",
"go_pluginserver_exe": "\/usr\/local\/bin\/go-pluginserver",
"dns_no_sync": false,
"db_update_propagation": 0,
"stream_listen": ["off"],
"nginx_err_logs": "\/usr\/local\/kong\/logs\/error.log",
"cassandra_port": 9042,
"headers": ["server_tokens", "latency_tokens"],
"nginx_http_client_max_body_size": "0",
"status_listen": ["off"],
"cassandra_lb_policy": "RequestRoundRobin",
"cluster_control_plane": "127.0.0.1:8005",
"nginx_http_ssl_prefer_server_ciphers": "off",
"pg_database": "kong",
"nginx_http_client_body_buffer_size": "8k",
"admin_acc_logs": "\/usr\/local\/kong\/logs\/admin_access.log",
"cassandra_refresh_frequency": 60,
"nginx_pid": "\/usr\/local\/kong\/pids\/nginx.pid",
"nginx_main_worker_rlimit_nofile": "auto",
"admin_access_log": "logs\/admin_access.log",
"proxy_listeners": [{
"listener": "0.0.0.0:8000",
"proxy_protocol": false,
"reuseport": false,
"backlog=%d+": false,
"deferred": false,
"ssl": false,
"ip": "0.0.0.0",
"port": 8000,
"http2": false,
"bind": false
}, {
"listener": "0.0.0.0:8443 ssl",
"proxy_protocol": false,
"reuseport": false,
"backlog=%d+": false,
"deferred": false,
"ssl": true,
"ip": "0.0.0.0",
"port": 8443,
"http2": false,
"bind": false
}],
"db_cache_warmup_entities": ["services", "plugins"],
"enabled_headers": {
"latency_tokens": true,
"X-Kong-Response-Latency": true,
"Server": true,
"X-Kong-Admin-Latency": true,
"X-Kong-Upstream-Status": false,
"Via": true,
"X-Kong-Proxy-Latency": true,
"server_tokens": true,
"X-Kong-Upstream-Latency": true
},
"nginx_http_ssl_protocols": "TLSv1.2 TLSv1.3",
"db_cache_ttl": 0,
"nginx_events_multi_accept": "on",
"admin_ssl_cert_default": "\/usr\/local\/kong\/ssl\/admin-kong-default.crt",
"pg_ssl": false,
"status_access_log": "off",
"cluster_listeners": [{
"listener": "0.0.0.0:8005",
"proxy_protocol": false,
"reuseport": false,
"backlog=%d+": false,
"deferred": false,
"ssl": false,
"ip": "0.0.0.0",
"port": 8005,
"http2": false,
"bind": false
}],
"kong_env": "\/usr\/local\/kong\/.kong_env",
"cassandra_schema_consensus_timeout": 60000,
"log_level": "notice",
"admin_ssl_cert_key_default": "\/usr\/local\/kong\/ssl\/admin-kong-default.key",
"real_ip_recursive": "off",
"cassandra_repl_factor": 1,
"ssl_cipher_suite": "intermediate",
"router_consistency": "strict",
"pg_port": 5432,
"cassandra_keyspace": "kong",
"ssl_cert_default": "\/usr\/local\/kong\/ssl\/kong-default.crt",
"nginx_http_ssl_session_timeout": "1d",
"nginx_upstream_directives": [{
"value": "100",
"name": "keepalive_requests"
}, {
"value": "60s",
"name": "keepalive_timeout"
}, {
"value": "60",
"name": "keepalive"
}],
"role": "traditional",
"admin_ssl_enabled": false,
"trusted_ips": {},
"nginx_events_worker_connections": "auto",
"nginx_supstream_directives": {},
"ssl_cert_key": "\/usr\/local\/kong\/ssl\/kong-default.key",
"pg_user": "kong",
"pg_password": "******",
"ssl_ciphers": "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384",
"nginx_admin_directives": {},
"nginx_upstream_keepalive_timeout": "60s",
"nginx_http_directives": [{
"value": "0",
"name": "client_max_body_size"
}, {
"value": "off",
"name": "ssl_prefer_server_ciphers"
}, {
"value": "8k",
"name": "client_body_buffer_size"
}, {
"value": "TLSv1.2 TLSv1.3",
"name": "ssl_protocols"
}, {
"value": "on",
"name": "ssl_session_tickets"
}, {
"value": "1d",
"name": "ssl_session_timeout"
}, {
"value": "prometheus_metrics 5m",
"name": "lua_shared_dict"
}],
"pg_host": "127.0.0.1",
"nginx_kong_stream_conf": "\/usr\/local\/kong\/nginx-kong-stream.conf",
"ssl_cert_csr_default": "\/usr\/local\/kong\/ssl\/kong-default.csr",
"go_plugins_dir": "off",
"cluster_listen": ["0.0.0.0:8005"],
"dns_order": ["LAST", "SRV", "A", "CNAME"],
"dns_error_ttl": 1,
"nginx_sproxy_directives": {},
"nginx_http_upstream_keepalive_timeout": "60s",
"pg_timeout": 60000,
"nginx_http_upstream_keepalive_requests": "100",
"database": "postgres",
"nginx_upstream_keepalive": "60",
"nginx_worker_processes": "auto",
"nginx_http_status_directives": {},
"lua_package_path": ".\/?.lua;.\/?\/init.lua;",
"router_update_frequency": 1,
"upstream_keepalive": 60,
"pg_max_concurrent_queries": 0,
"proxy_ssl_enabled": true,
"nginx_http_upstream_keepalive": "60",
"lua_socket_pool_size": 30,
"mem_cache_size": "128m",
"db_resurrect_ttl": 30,
"cassandra_data_centers": ["dc1:2", "dc2:3"],
"cassandra_consistency": "ONE",
"client_max_body_size": "0",
"admin_error_log": "logs\/error.log",
"nginx_main_directives": [{
"value": "on",
"name": "daemon"
}, {
"value": "auto",
"name": "worker_rlimit_nofile"
}, {
"value": "auto",
"name": "worker_processes"
}],
"dns_not_found_ttl": 30,
"nginx_http_ssl_session_tickets": "on",
"cassandra_ssl": false,
"db_update_frequency": 5,
"cassandra_repl_strategy": "SimpleStrategy",
"status_error_log": "logs\/status_error.log",
"nginx_status_directives": {},
"kic": false,
"dns_stale_ttl": 4,
"nginx_kong_conf": "\/usr\/local\/kong\/nginx-kong.conf",
"real_ip_header": "X-Real-IP",
"dns_hostsfile": "\/etc\/hosts",
"admin_listeners": [{
"listener": "127.0.0.1:8001",
"proxy_protocol": false,
"reuseport": false,
"backlog=%d+": false,
"deferred": false,
"ssl": false,
"ip": "127.0.0.1",
"port": 8001,
"http2": false,
"bind": false
}],
"nginx_optimizations": true,
"ssl_cert": "\/usr\/local\/kong\/ssl\/kong-default.crt",
"nginx_proxy_real_ip_recursive": "off",
"nginx_proxy_real_ip_header": "X-Real-IP",
"cassandra_ssl_verify": false,
"client_ssl": false,
"cassandra_timeout": 60000,
"nginx_main_worker_processes": "auto",
"proxy_error_log": "logs\/error.log",
"client_ssl_cert_key_default": "\/usr\/local\/kong\/ssl\/kong-default.key",
"nginx_daemon": "on",
"anonymous_reports": true,
"status_listeners": {},
"ssl_cert_key_default": "\/usr\/local\/kong\/ssl\/kong-default.key",
"pg_ssl_verify": false,
"cassandra_contact_points": ["127.0.0.1"],
"client_body_buffer_size": "8k",
"lua_package_cpath": "",
"stream_listeners": {},
"error_default_type": "text\/plain",
"loaded_plugins": {
"session": true,
"pre-function": true,
"cors": true,
"ldap-auth": true,
"loggly": true,
"hmac-auth": true,
"zipkin": true,
"request-size-limiting": true,
"azure-functions": true,
"request-transformer": true,
"oauth2": true,
"response-transformer": true,
"syslog": true,
"statsd": true,
"jwt": true,
"proxy-cache": true,
"basic-auth": true,
"key-auth": true,
"http-log": true,
"datadog": true,
"tcp-log": true,
"correlation-id": true,
"post-function": true,
"bot-detection": true,
"acl": true,
"ip-restriction": true,
"file-log": true,
"rate-limiting": true,
"udp-log": true,
"response-ratelimiting": true,
"aws-lambda": true,
"prometheus": true,
"acme": true,
"request-termination": true
},
"nginx_stream_directives": [{
"value": "stream_prometheus_metrics 5m",
"name": "lua_shared_dict"
}],
"nginx_proxy_directives": [{
"value": "X-Real-IP",
"name": "real_ip_header"
}, {
"value": "off",
"name": "real_ip_recursive"
}],
"lua_ssl_verify_depth": 1
},
"version": "2.0.4",
"node_id": "71292a47-2477-4d6f-80f6-12eb87252a1b",
"lua_version": "LuaJIT 2.1.0-beta3",
"prng_seeds": {
"pid: 25373": 239131502205,
"pid: 25360": 131371902618,
"pid: 25372": 118213580162
},
"timers": {
"pending": 9,
"running": 0
},
"hostname": "hecs-x-large-2-linux-20200628091636"
}
安裝完畢。