Kong系列-02-CentOS 7下Kong 1.4.2安装

x33g5p2x  于2021-12-21 转载在 其他  
字(12.2k)|赞(0)|评价(0)|浏览(481)

先安装PostgreSQL,请参见CentOS下PostgreSQL 12 安装。然后为Kong初始化数据库。

  1. su - postges
  2. su: user postges does not exist
  3. [root@kong postgresql]# su - postgres
  4. 上一次登录:日 12 15 08:17:06 CST 2019pts/0
  5. -bash-4.2$ psql
  6. 用户 postgres 的口令:
  7. psql (12.1)
  8. 输入 "help" 来获取帮助信息.
  9. postgres=# CREATE USER kong WITH PASSWORD '1111';
  10. CREATE ROLE
  11. postgres=# CREATE DATABASE kong OWNER kong;
  12. CREATE DATABASE
  13. postgres=# GRANT ALL PRIVILEGES ON DATABASE kong TO kong;
  14. GRANT
  15. postgres=# \q
  16. -bash-4.2$ psql -U kong -d kong -h 127.0.0.1 -p 5432
  17. 用户 kong 的口令:
  18. psql (12.1)
  19. 输入 "help" 来获取帮助信息.
  20. kong=> \q
  21. -bash-4.2$ exit
  22. 登出

下载rpm包,https://bintray.com/kong/kong-rpm/centos/view/files/centos/7#files/centos/7。

安装所需工具。

  1. yum install -y gcc pcre-devel zlib-devel openssl-devel
  2. vi /etc/security/limits.conf
  3. * soft nofile 4096
  4. #重启生效
  5. reboot

安装Kong。

  1. mkdir kong
  2. cd kong
  3. #将下载的文件上传到此目录。
  4. yum install -y epel-release
  5. yum install -y kong-1.4.2.el7.amd64.rpm --nogpgcheck

配置Kong。

  1. cp /etc/kong/kong.conf.default /etc/kong/kong.conf
  2. vi /etc/kong/kong.conf
  3. ......
  4. admin_listen = 0.0.0.0:8001, 0.0.0.0:8444 ssl
  5. ......
  6. database = postgres # Determines which of PostgreSQL or Cassandra
  7. # this node will use as its datastore.
  8. # Accepted values are `postgres`,
  9. # `cassandra`, and `off`.
  10. pg_host = 127.0.0.1 # Host of the Postgres server.
  11. pg_port = 5432 # Port of the Postgres server.
  12. #pg_timeout = 5000 # Defines the timeout (in ms), for connecting,
  13. # reading and writing.
  14. pg_user = kong # Postgres user.
  15. pg_password = 1111 # Postgres user's password.
  16. pg_database = kong # The database name to connect to.
  17. ......
  18. kong check
  19. configuration at /etc/kong/kong.conf is valid

初始化Kong,Kong会向数据库写入初始化数据。

  1. kong migrations bootstrap

启动Kong。

  1. kong start
  2. Kong started
  3. kong health
  4. nginx.......running
  5. Kong is healthy at /usr/local/kong

Kong的8001为管理端口,8000为Proxy端口,如果都能访问,表示Kong安装成功。

  1. curl http://localhost:8001 -s | python -m json.tool
  2. {
  3. "configuration": {
  4. "admin_acc_logs": "/usr/local/kong/logs/admin_access.log",
  5. "admin_access_log": "logs/admin_access.log",
  6. "admin_error_log": "logs/error.log",
  7. "admin_listen": [
  8. "0.0.0.0:8001",
  9. "0.0.0.0:8444 ssl"
  10. ],
  11. "admin_listeners": [
  12. {
  13. "bind": false,
  14. "deferred": false,
  15. "http2": false,
  16. "ip": "0.0.0.0",
  17. "listener": "0.0.0.0:8001",
  18. "port": 8001,
  19. "proxy_protocol": false,
  20. "reuseport": false,
  21. "ssl": false,
  22. "transparent": false
  23. },
  24. {
  25. "bind": false,
  26. "deferred": false,
  27. "http2": false,
  28. "ip": "0.0.0.0",
  29. "listener": "0.0.0.0:8444 ssl",
  30. "port": 8444,
  31. "proxy_protocol": false,
  32. "reuseport": false,
  33. "ssl": true,
  34. "transparent": false
  35. }
  36. ],
  37. "admin_ssl_cert": "/usr/local/kong/ssl/admin-kong-default.crt",
  38. "admin_ssl_cert_default": "/usr/local/kong/ssl/admin-kong-default.crt",
  39. "admin_ssl_cert_key": "/usr/local/kong/ssl/admin-kong-default.key",
  40. "admin_ssl_cert_key_default": "/usr/local/kong/ssl/admin-kong-default.key",
  41. "admin_ssl_enabled": true,
  42. "anonymous_reports": true,
  43. "cassandra_consistency": "ONE",
  44. "cassandra_contact_points": [
  45. "127.0.0.1"
  46. ],
  47. "cassandra_data_centers": [
  48. "dc1:2",
  49. "dc2:3"
  50. ],
  51. "cassandra_keyspace": "kong",
  52. "cassandra_lb_policy": "RequestRoundRobin",
  53. "cassandra_port": 9042,
  54. "cassandra_refresh_frequency": 60,
  55. "cassandra_repl_factor": 1,
  56. "cassandra_repl_strategy": "SimpleStrategy",
  57. "cassandra_schema_consensus_timeout": 60000,
  58. "cassandra_ssl": false,
  59. "cassandra_ssl_verify": false,
  60. "cassandra_timeout": 60000,
  61. "cassandra_username": "kong",
  62. "client_body_buffer_size": "8k",
  63. "client_max_body_size": "0",
  64. "client_ssl": false,
  65. "client_ssl_cert_default": "/usr/local/kong/ssl/kong-default.crt",
  66. "client_ssl_cert_key_default": "/usr/local/kong/ssl/kong-default.key",
  67. "database": "postgres",
  68. "db_cache_ttl": 0,
  69. "db_cache_warmup_entities": [
  70. "services",
  71. "plugins"
  72. ],
  73. "db_resurrect_ttl": 30,
  74. "db_update_frequency": 5,
  75. "db_update_propagation": 0,
  76. "dns_error_ttl": 1,
  77. "dns_hostsfile": "/etc/hosts",
  78. "dns_no_sync": false,
  79. "dns_not_found_ttl": 30,
  80. "dns_order": [
  81. "LAST",
  82. "SRV",
  83. "A",
  84. "CNAME"
  85. ],
  86. "dns_resolver": {},
  87. "dns_stale_ttl": 4,
  88. "enabled_headers": {
  89. "Server": true,
  90. "Via": true,
  91. "X-Kong-Admin-Latency": true,
  92. "X-Kong-Proxy-Latency": true,
  93. "X-Kong-Response-Latency": true,
  94. "X-Kong-Upstream-Latency": true,
  95. "X-Kong-Upstream-Status": false,
  96. "latency_tokens": true,
  97. "server_tokens": true
  98. },
  99. "error_default_type": "text/plain",
  100. "headers": [
  101. "server_tokens",
  102. "latency_tokens"
  103. ],
  104. "kong_env": "/usr/local/kong/.kong_env",
  105. "loaded_plugins": {
  106. "acl": true,
  107. "aws-lambda": true,
  108. "azure-functions": true,
  109. "basic-auth": true,
  110. "bot-detection": true,
  111. "correlation-id": true,
  112. "cors": true,
  113. "datadog": true,
  114. "file-log": true,
  115. "hmac-auth": true,
  116. "http-log": true,
  117. "ip-restriction": true,
  118. "jwt": true,
  119. "key-auth": true,
  120. "kubernetes-sidecar-injector": true,
  121. "ldap-auth": true,
  122. "loggly": true,
  123. "oauth2": true,
  124. "post-function": true,
  125. "pre-function": true,
  126. "prometheus": true,
  127. "proxy-cache": true,
  128. "rate-limiting": true,
  129. "request-size-limiting": true,
  130. "request-termination": true,
  131. "request-transformer": true,
  132. "response-ratelimiting": true,
  133. "response-transformer": true,
  134. "session": true,
  135. "statsd": true,
  136. "syslog": true,
  137. "tcp-log": true,
  138. "udp-log": true,
  139. "zipkin": true
  140. },
  141. "log_level": "notice",
  142. "lua_package_cpath": "",
  143. "lua_package_path": "./?.lua;./?/init.lua;",
  144. "lua_socket_pool_size": 30,
  145. "lua_ssl_verify_depth": 1,
  146. "mem_cache_size": "128m",
  147. "nginx_acc_logs": "/usr/local/kong/logs/access.log",
  148. "nginx_admin_directives": {},
  149. "nginx_conf": "/usr/local/kong/nginx.conf",
  150. "nginx_daemon": "on",
  151. "nginx_err_logs": "/usr/local/kong/logs/error.log",
  152. "nginx_http_directives": [
  153. {
  154. "name": "ssl_protocols",
  155. "value": "TLSv1.1 TLSv1.2 TLSv1.3"
  156. },
  157. {
  158. "name": "lua_shared_dict",
  159. "value": "prometheus_metrics 5m"
  160. }
  161. ],
  162. "nginx_http_ssl_protocols": "TLSv1.1 TLSv1.2 TLSv1.3",
  163. "nginx_http_status_directives": {},
  164. "nginx_http_upstream_directives": [
  165. {
  166. "name": "keepalive_timeout",
  167. "value": "60s"
  168. },
  169. {
  170. "name": "keepalive_requests",
  171. "value": "100"
  172. },
  173. {
  174. "name": "keepalive",
  175. "value": "60"
  176. }
  177. ],
  178. "nginx_http_upstream_keepalive": "60",
  179. "nginx_http_upstream_keepalive_requests": "100",
  180. "nginx_http_upstream_keepalive_timeout": "60s",
  181. "nginx_kong_conf": "/usr/local/kong/nginx-kong.conf",
  182. "nginx_kong_stream_conf": "/usr/local/kong/nginx-kong-stream.conf",
  183. "nginx_optimizations": true,
  184. "nginx_pid": "/usr/local/kong/pids/nginx.pid",
  185. "nginx_proxy_directives": {},
  186. "nginx_sproxy_directives": {},
  187. "nginx_stream_directives": {},
  188. "nginx_worker_processes": "auto",
  189. "origins": {},
  190. "pg_database": "kong",
  191. "pg_host": "127.0.0.1",
  192. "pg_max_concurrent_queries": 0,
  193. "pg_password": "******",
  194. "pg_port": 5432,
  195. "pg_semaphore_timeout": 60000,
  196. "pg_ssl": false,
  197. "pg_ssl_verify": false,
  198. "pg_timeout": 60000,
  199. "pg_user": "kong",
  200. "plugins": [
  201. "bundled"
  202. ],
  203. "prefix": "/usr/local/kong",
  204. "proxy_access_log": "logs/access.log",
  205. "proxy_error_log": "logs/error.log",
  206. "proxy_listen": [
  207. "0.0.0.0:8000",
  208. "0.0.0.0:8443 http2 ssl"
  209. ],
  210. "proxy_listeners": [
  211. {
  212. "bind": false,
  213. "deferred": false,
  214. "http2": false,
  215. "ip": "0.0.0.0",
  216. "listener": "0.0.0.0:8000",
  217. "port": 8000,
  218. "proxy_protocol": false,
  219. "reuseport": false,
  220. "ssl": false,
  221. "transparent": false
  222. },
  223. {
  224. "bind": false,
  225. "deferred": false,
  226. "http2": true,
  227. "ip": "0.0.0.0",
  228. "listener": "0.0.0.0:8443 ssl http2",
  229. "port": 8443,
  230. "proxy_protocol": false,
  231. "reuseport": false,
  232. "ssl": true,
  233. "transparent": false
  234. }
  235. ],
  236. "proxy_ssl_enabled": true,
  237. "real_ip_header": "X-Real-IP",
  238. "real_ip_recursive": "off",
  239. "router_consistency": "strict",
  240. "router_update_frequency": 1,
  241. "service_mesh": false,
  242. "ssl_cert": "/usr/local/kong/ssl/kong-default.crt",
  243. "ssl_cert_csr_default": "/usr/local/kong/ssl/kong-default.csr",
  244. "ssl_cert_default": "/usr/local/kong/ssl/kong-default.crt",
  245. "ssl_cert_key": "/usr/local/kong/ssl/kong-default.key",
  246. "ssl_cert_key_default": "/usr/local/kong/ssl/kong-default.key",
  247. "ssl_cipher_suite": "modern",
  248. "ssl_ciphers": "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256",
  249. "ssl_preread_enabled": true,
  250. "status_access_log": "off",
  251. "status_error_log": "logs/status_error.log",
  252. "status_listen": [
  253. "off"
  254. ],
  255. "status_listeners": {},
  256. "stream_listen": [
  257. "off"
  258. ],
  259. "stream_listeners": {},
  260. "trusted_ips": {},
  261. "upstream_keepalive": 60
  262. },
  263. "hostname": "kong",
  264. "lua_version": "LuaJIT 2.1.0-beta3",
  265. "node_id": "ac7df796-7fb4-4e89-86d4-3f8ad5a93f6e",
  266. "plugins": {
  267. "available_on_server": {
  268. "acl": true,
  269. "aws-lambda": true,
  270. "azure-functions": true,
  271. "basic-auth": true,
  272. "bot-detection": true,
  273. "correlation-id": true,
  274. "cors": true,
  275. "datadog": true,
  276. "file-log": true,
  277. "hmac-auth": true,
  278. "http-log": true,
  279. "ip-restriction": true,
  280. "jwt": true,
  281. "key-auth": true,
  282. "kubernetes-sidecar-injector": true,
  283. "ldap-auth": true,
  284. "loggly": true,
  285. "oauth2": true,
  286. "post-function": true,
  287. "pre-function": true,
  288. "prometheus": true,
  289. "proxy-cache": true,
  290. "rate-limiting": true,
  291. "request-size-limiting": true,
  292. "request-termination": true,
  293. "request-transformer": true,
  294. "response-ratelimiting": true,
  295. "response-transformer": true,
  296. "session": true,
  297. "statsd": true,
  298. "syslog": true,
  299. "tcp-log": true,
  300. "udp-log": true,
  301. "zipkin": true
  302. },
  303. "enabled_in_cluster": []
  304. },
  305. "prng_seeds": {
  306. "pid: 1272": 115238374918,
  307. "pid: 1284": 559859622153
  308. },
  309. "tagline": "Welcome to kong",
  310. "timers": {
  311. "pending": 6,
  312. "running": 0
  313. },
  314. "version": "1.4.2"
  315. }
  316. curl -i http://localhost:8000
  317. HTTP/1.1 404 Not Found
  318. Date: Sun, 15 Dec 2019 04:33:54 GMT
  319. Content-Type: application/json; charset=utf-8
  320. Connection: keep-alive
  321. Content-Length: 48
  322. X-Kong-Response-Latency: 2
  323. Server: kong/1.4.2
  324. {"message":"no Route matched with those values"}

相关文章