之前在macos系统测试安装psql和kong,但是实际环境中,大部分是部署在linux服务器上。下面记录了在centos7上部署postgresql和kong的总结以及遇到的一些问题的解决。

查看centos版本:

$ cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)

部署版本:

kong: v0.13.1

postgresql: v10.4 (注意:psql版本必须与kong版本对应)

安装依赖包

安装gcc编译环境

$ sudo yum install -y gcc gcc-c++

pcre安装

pcre(Perl Compatible Regular Expressions) 是一个 Perl 库,包括 perl 兼容的正则表达式,nginx 的 http 库使用 pcre 解析正则表达式。
$ sudo yum install -y pcre pcre-devel

zlib安装

zlib 库提供多种压缩和加压缩的方式。
$ sudo yum install -y zlib zlib-devel

openssl安装

openssl 是一个请打的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议

$ sudo yum install -y openssl openssl-devel

postgresql 部署

PostgreSQL是完全由社区驱动的开源项目,由全世界超过1000名贡献者所维护。它提供了单个完整功能的版本。可靠性是PostgreSQL的最高优先级。Kong 默认使用 postgresql 作为数据库。
这里安装kong的版本是0.13,对应的psql版本需要在v10+,否则启动kong会报下面的错:
$  /usr/local/bin/kong start
2018/06/08 12:07:55 [warn] postgres database 'kong' is missing migration: (response-transformer) 2016-05-04-160000_resp_trans_schema_changes
Error: /usr/local/share/lua/5.1/kong/cmd/start.lua:34: [postgres error] the current database schema does not match this version of Kong. Please run `kong migrations up` to update/initialize the database schema. Be aware that Kong migrations should only run from a single node, and that nodes running migrations concurrently will conflict with each other and might corrupt your database schema!

安装psql-10

$ sudo yum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-latest-x86_64/pgdg-centos10-10-2.noarch.rpm

$ sudo  yum install -y postgresql10-server postgresql10-contrib

初始化数据库

$ sudo /usr/pgsql-10/bin/postgresql-10-setup initdb
Initializing database ... OK

设置成centos7开机自启动

sudo systemctl enable postgresql-10.service

启动postgresql服务

# 启动服务
$ sudo systemctl start postgresql-10.service
# 查看psql运行状态
$ sudo systemctl status postgresql-10.service
● postgresql-10.service - PostgreSQL 10 database serverLoaded: loaded (/usr/lib/systemd/system/postgresql-10.service; disabled; vendor preset: disabled)Active: active (running) since Fri 2018-06-08 12:22:17 CST; 16s agoDocs: https://www.postgresql.org/docs/10/static/Process: 12951 ExecStartPre=/usr/pgsql-10/bin/postgresql-10-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)Main PID: 12957 (postmaster)CGroup: /system.slice/postgresql-10.service├─12957 /usr/pgsql-10/bin/postmaster -D /var/lib/pgsql/10/data/├─12959 postgres: logger process├─12961 postgres: checkpointer process├─12962 postgres: writer process├─12963 postgres: wal writer process├─12964 postgres: autovacuum launcher process├─12965 postgres: stats collector process└─12966 postgres: bgworker: logical replication launcherJun 08 12:22:17 172-18-38-219 systemd[1]: Starting PostgreSQL 10 database server...
Jun 08 12:22:17 172-18-38-219 postmaster[12957]: 2018-06-08 12:22:17.798 CST [12957] LOG:  listeni...432
Jun 08 12:22:17 172-18-38-219 postmaster[12957]: 2018-06-08 12:22:17.798 CST [12957] LOG:  could n...ess
Jun 08 12:22:17 172-18-38-219 postmaster[12957]: 2018-06-08 12:22:17.798 CST [12957] HINT:  Is ano...ry.
Jun 08 12:22:17 172-18-38-219 postmaster[12957]: 2018-06-08 12:22:17.801 CST [12957] LOG:  listeni...32"
Jun 08 12:22:17 172-18-38-219 postmaster[12957]: 2018-06-08 12:22:17.808 CST [12957] LOG:  listeni...32"
Jun 08 12:22:17 172-18-38-219 postmaster[12957]: 2018-06-08 12:22:17.825 CST [12957] LOG:  redirec...ess
Jun 08 12:22:17 172-18-38-219 postmaster[12957]: 2018-06-08 12:22:17.825 CST [12957] HINT:  Future...g".
Jun 08 12:22:17 172-18-38-219 systemd[1]: Started PostgreSQL 10 database server.
Hint: Some lines were ellipsized, use -l to show in full.

Postgresql配置

执行完初始化任务之后,postgresql 会自动创建和生成两个用户和一个数据库:
linux 系统用户 postgres:管理数据库的系统用户;
  postgresql 用户 postgres:数据库超级管理员;
  数据库 postgres:用户 postgres 的默认数据库;
  密码由于是默认生成的,需要在系统中修改一下。

修改初始密码

$ passwd postgres
Changing password for user postgres.
New password:
BAD PASSWORD: The password contains the user name in some form
Retype new password:
passwd: all authentication tokens updated successfully.

创建用户

为了安全以及满足 Kong 初始化的需求,需要在建立一个 postgre 用户 kong 和对应的 linux 用户 kong,并新建数据库 kong。

# 新建 linux kong 用户
$ sudo adduser kong# 使用管理员账号登录 psql 创建用户和数据库
# 切换 postgres 用户
# 切换 postgres 用户后,提示符变成 `-bash-4.3$`
$ su postgres# 进入psql控制台,此时会进入到控制台(系统提示符变为'postgres=#')
bash-4.3$ psql
could not change directory to "/root": Permission denied
psql (10.4)
Type "help" for help.#为管理员用户postgres修改密码,之前改过了这里就不用改了
postgres=# password postgres#建立新的数据库用户(和之前建立的系统用户要一样)
postgres=# create user kong with password 'kong';
CREATE ROLE#为新用户建立数据库
postgres=# create database kong owner kong;
CREATE DATABASE#把新建的数据库权限赋予 kong
postgres=# grant all privileges on database kong to kong;
GRANT#退出控制台
postgres=# \q
bash-4.3$

注意:在 psql 控制台下执行命令,一定记得在命令后添加分号。

而且postgresql的用户要和系统用户一样:

$ cat /etc/passwd
...
postgres:x:26:26:PostgreSQL Server:/var/lib/pgsql:/bin/bash
kong:x:1002:1002::/home/kong:/bin/bash

问题一:

用命令行登录,在root账户下登录postgresql 数据库会提示权限问题:

$ psql -U kong -d kong -h 127.0.0.1 -p 5432
psql: FATAL:  Ident authentication failed for user "kong"

原因是postgres没有配置对外访问策略。

认证权限配置文件为 /var/lib/pgsql/10/data/pg_hba.conf
常见的四种身份验证为:
trust:凡是连接到服务器的,都是可信任的。只需要提供psql用户名,可以没有对应的操作系统同名用户;
  password 和 md5:对于外部访问,需要提供 psql 用户名和密码。对于本地连接,提供 psql 用户名密码之外,还需要有操作系统访问权。(用操作系统同名用户验证)password 和 md5 的区别就是外部访问时传输的密码是否用 md5 加密;
  ident:对于外部访问,从 ident 服务器获得客户端操作系统用户名,然后把操作系统作为数据库用户名进行登录对于本地连接,实际上使用了peer;
  peer:通过客户端操作系统内核来获取当前系统登录的用户名,并作为psql用户名进行登录。
psql 用户必须有同名的操作系统用户名。并且必须以与 psql 同名用户登录 linux 才可以登录 psql 。想用其他用户(例如 root )登录 psql,修改本地认证方式为 trust 或者 password 即可。
$ vim /var/lib/pgsql/10/data/pg_hba.conf# 增加如下两条配置
# IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all 0.0.0.0/0 trust

问题二:
通过本地连接会提示拒绝连接,因为pgsql 默认只能通过本地访问,需要开启远程访问。
修改配置文件  var/lib/pgsql/10/data/postgresql.conf ,将 listen_address 设置为 '*'
$ vim var/lib/pgsql/10/data/postgresql.conf
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------# - Connection Settings -listen_addresses = '*'             # what IP address(es) to listen on;

修改以上两个配置文件后,重启postgresql服务:

$ sudo systemctl restart postgresql-10.service$ psql -U kong -d kong -h 127.0.0.1 -p 5432
psql (10.4)
Type "help" for help.kong=> \lList of databasesName    |  Owner   | Encoding  | Collate | Ctype |   Access privileges
-----------+----------+-----------+---------+-------+-----------------------kong      | kong     | SQL_ASCII | C       | C     | =Tc/kong             +|          |           |         |       | kong=CTc/kongpostgres  | postgres | SQL_ASCII | C       | C     |template0 | postgres | SQL_ASCII | C       | C     | =c/postgres          +|          |           |         |       | postgres=CTc/postgrestemplate1 | postgres | SQL_ASCII | C       | C     | =c/postgres          +|          |           |         |       | postgres=CTc/postgres
(4 rows)kong=>

相关postgres命令参考:postgres常见命令

kong部署

kong这块按照官网的方法不成功,最终下载了rpm包安装成功的。

安装kong

$ sudo yum install kong-community-edition-0.13.1.el7.noarch.rpm
...
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transactionInstalling : kong-community-edition-0.13.1-1.noarch                                               1/1Verifying  : kong-community-edition-0.13.1-1.noarch                                               1/1Installed:kong-community-edition.noarch 0:0.13.1-1Complete!

修改 kong 的配置文件

默认配置文件位于 /etc/kong/kong.conf.default
sudo cp /etc/kong/kong.conf.default /etc/kong/kong.conf
将之前安装配置好的 postgresql 信息填入 kong 配置文件中:
$ sudo vi /etc/kong/kong.conf
#------------------------------------------------------------------------------
# DATASTORE
#------------------------------------------------------------------------------# Kong will store all of its data (such as APIs, consumers and plugins) in
# either Cassandra or PostgreSQL.
#
# All Kong nodes belonging to the same cluster must connect themselves to the
# same database.database = postgres              # Determines which of PostgreSQL or Cassandra# this node will use as its datastore.# Accepted values are `postgres` and# `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              # The database name to connect to.ssl = off                       # 如果不希望开放 8443 的 ssl 访问可关闭

初始化数据库表

$ kong migrations up -c  /etc/kong/kong.conf
migrating core for database kong
core migrated up to: 2015-01-12-175310_skeleton
core migrated up to: 2015-01-12-175310_init_schema
core migrated up to: 2015-11-23-817313_nodes
core migrated up to: 2016-02-29-142793_ttls
core migrated up to: 2016-09-05-212515_retries
core migrated up to: 2016-09-16-141423_upstreams
core migrated up to: 2016-12-14-172100_move_ssl_certs_to_core
core migrated up to: 2016-11-11-151900_new_apis_router_1
core migrated up to: 2016-11-11-151900_new_apis_router_2
core migrated up to: 2016-11-11-151900_new_apis_router_3
core migrated up to: 2016-01-25-103600_unique_custom_id
core migrated up to: 2017-01-24-132600_upstream_timeouts
core migrated up to: 2017-01-24-132600_upstream_timeouts_2
core migrated up to: 2017-03-27-132300_anonymous
core migrated up to: 2017-04-18-153000_unique_plugins_id
core migrated up to: 2017-04-18-153000_unique_plugins_id_2
core migrated up to: 2017-05-19-180200_cluster_events
core migrated up to: 2017-05-19-173100_remove_nodes_table
core migrated up to: 2017-06-16-283123_ttl_indexes
core migrated up to: 2017-07-28-225000_balancer_orderlist_remove
core migrated up to: 2017-10-02-173400_apis_created_at_ms_precision
core migrated up to: 2017-11-07-192000_upstream_healthchecks
core migrated up to: 2017-10-27-134100_consistent_hashing_1
core migrated up to: 2017-11-07-192100_upstream_healthchecks_2
core migrated up to: 2017-10-27-134100_consistent_hashing_2
core migrated up to: 2017-09-14-121200_routes_and_services
core migrated up to: 2017-10-25-180700_plugins_routes_and_services
migrating response-transformer for database kong
response-transformer migrated up to: 2016-05-04-160000_resp_trans_schema_changes
migrating ip-restriction for database kong
ip-restriction migrated up to: 2016-05-24-remove-cache
migrating statsd for database kong
statsd migrated up to: 2017-06-09-160000_statsd_schema_changes
migrating jwt for database kong
jwt migrated up to: 2015-06-09-jwt-auth
jwt migrated up to: 2016-03-07-jwt-alg
jwt migrated up to: 2017-05-22-jwt_secret_not_unique
jwt migrated up to: 2017-07-31-120200_jwt-auth_preflight_default
jwt migrated up to: 2017-10-25-211200_jwt_cookie_names_default
migrating cors for database kong
cors migrated up to: 2017-03-14_multiple_orgins
migrating basic-auth for database kong
basic-auth migrated up to: 2015-08-03-132400_init_basicauth
basic-auth migrated up to: 2017-01-25-180400_unique_username
migrating key-auth for database kong
key-auth migrated up to: 2015-07-31-172400_init_keyauth
key-auth migrated up to: 2017-07-31-120200_key-auth_preflight_default
migrating ldap-auth for database kong
ldap-auth migrated up to: 2017-10-23-150900_header_type_default
migrating hmac-auth for database kong
hmac-auth migrated up to: 2015-09-16-132400_init_hmacauth
hmac-auth migrated up to: 2017-06-21-132400_init_hmacauth
migrating datadog for database kong
datadog migrated up to: 2017-06-09-160000_datadog_schema_changes
migrating tcp-log for database kong
tcp-log migrated up to: 2017-12-13-120000_tcp-log_tls
migrating acl for database kong
acl migrated up to: 2015-08-25-841841_init_acl
migrating response-ratelimiting for database kong
response-ratelimiting migrated up to: 2015-08-03-132400_init_response_ratelimiting
response-ratelimiting migrated up to: 2016-08-04-321512_response-rate-limiting_policies
response-ratelimiting migrated up to: 2017-12-19-120000_add_route_and_service_id_to_response_ratelimiting
migrating request-transformer for database kong
request-transformer migrated up to: 2016-05-04-160000_req_trans_schema_changes
migrating rate-limiting for database kong
rate-limiting migrated up to: 2015-08-03-132400_init_ratelimiting
rate-limiting migrated up to: 2016-07-25-471385_ratelimiting_policies
rate-limiting migrated up to: 2017-11-30-120000_add_route_and_service_id
migrating oauth2 for database kong
oauth2 migrated up to: 2015-08-03-132400_init_oauth2
oauth2 migrated up to: 2016-07-15-oauth2_code_credential_id
oauth2 migrated up to: 2016-12-22-283949_serialize_redirect_uri
oauth2 migrated up to: 2016-09-19-oauth2_api_id
oauth2 migrated up to: 2016-12-15-set_global_credentials
oauth2 migrated up to: 2017-04-24-oauth2_client_secret_not_unique
oauth2 migrated up to: 2017-10-19-set_auth_header_name_default
oauth2 migrated up to: 2017-10-11-oauth2_new_refresh_token_ttl_config_value
oauth2 migrated up to: 2018-01-09-oauth2_pg_add_service_id
62 migrations ran

启动kong服务

$ kong start
Kong started

服务已经正常启动

$ curl 127.0.0.1:8001
{"plugins":{"enabled_in_cluster":[],"available_on_server":{"response-transformer":true,"correlation-id":true,"statsd":true,"jwt":true,"cors":true,"basic-auth":true,"key-auth":true,"ldap-auth":true,"http-log":true,"oauth2":true,"hmac-auth":true,"acl":true,"datadog":true,"tcp-log":true,"ip-restriction":true,"request-transformer":true,"file-log":true,"bot-detection":true,"loggly":true,"request-size-limiting":true,"syslog":true,"udp-log":true,"response-ratelimiting":true,"aws-lambda":true,"runscope":true,"rate-limiting":true,"request-termination":true}},"tagline":"Welcome to kong","configuration":{"error_default_type":"text\/plain","client_ssl":false,"lua_ssl_verify_depth":1
....

转载于:https://www.cnblogs.com/zhoujie/p/kong5.html

centos7部署posgresql和kong总结相关推荐

  1. centos losf 安装_Linux Centos7部署环境安装-CentOS

    Linux Centos7部署环境安装-CentOS Centos7部署环境安装及Linux常用命令 centos系统下各文件夹的作用 centos7修改系统默认语言 centos7安装rz/sz命令 ...

  2. centos-7部署docker

    centos-7部署docker 由于工作需要搭建一个ELK日志分析系统,查找了一些资料,想用docker部署.以前使用过docker镜像,拉取漏洞环境,好像是在ubuntu部署的,但那个虚拟机找不到 ...

  3. CentOS7部署Nginx

    CentOS7部署Nginx 1.准备工作 Nginx的安装依赖于以下三个包,意思就是在安装Nginx之前首先必须安装一下的三个包,注意安装顺序如下: 1 SSL功能需要openssl库,直接通过yu ...

  4. Centos7部署轻量级自动化运维工具pssh (亲测)

    下载pssh安装包 [root@localhost ~]# wget https://files.pythonhosted.org/packages/60/9a/8035af3a7d3d1617ae2 ...

  5. centos7 查看oracle运行日志_Linux(CentOS7)部署系列---常规应用部署方案

    前言 作为Java开发者,部署war包应用到Linux系统时常常会犯怵,一个是对Linux命令不是很熟悉,还有一个就是在Linux安装诸如JDK.Tomcat.MySQL.Redis等一知半解导致的, ...

  6. 使用Centos7部署静态网站

    使用Centos7部署静态网站 我在配置过程中参阅了一些博主的文章,收益很大,在此列出: [CentOS7快速上手]4.Nginx安装&配置 - Ken的杂谈 在centOs 上搭建nginx ...

  7. 阿里云centos7部署:nginx+uwsgi+django+vue

    基础环境 阿里云centos7 部署架构 nginx + uwsgi nginx提供静态文件服务和反向代理: uwsgi充当Web服务器: 部署过程 修改项目的配置文件,配置收集静态文件之后存放的目录 ...

  8. Centos7部署个人wiki(bookstack)踩坑版

    Centos7部署个人wiki(bookstack) 安装epel-release 安装nginx,启动并设置自启(如有请忽略) 下载php-fpm以及所需依赖组件 配置php 更改php-fpm配置 ...

  9. Aria2 Centos7部署

    Aria2 Centos7部署 配置Epel源 https://developer.aliyun.com/mirror/epel?spm=a2c6h.13651102.0.0.3e221b11IziK ...

最新文章

  1. 13个Pandas奇技淫巧
  2. python填写excel-python——向Excel读取或写入数据
  3. PayPal宣布退出虚拟货币组织Libra协会
  4. DIP第九章习题解答
  5. java uppercase方法_java-方法引用
  6. 分布式面试 - 为什么要进行系统拆分?
  7. CSDN上传资源时一直提示 请填写资源tag
  8. 服务器图片加载慢_页面提高性能利器_懒加载
  9. Linux学习笔记016---CentOS7虚拟机设置使用静态IP上网_配置集群的时候可以用
  10. Codeforces Round 1 - 10总结 【@Abandon】
  11. 铁甲雄心机器人建造成本_铁甲雄心最强机器人
  12. gdi win7奔溃_gdiplus.dll 32/64位
  13. 看看“电子招投标平台”是如何识破“围标串标”的,看完少走弯路
  14. 初识Tracepro及基本操作说明
  15. 雷蛇鼠标 雷云3 驱动无法启动 Razer Syncapse 3 Failed to start
  16. java护眼的颜色_爱护眼睛,从IDEA开始,护眼色设置走起-护眼设置
  17. 出中的意思是什么_从里出来是什么意思
  18. 魔术命令python_魔术命令_利用Python进行数据分析_红黑联盟读书频道
  19. c语言模拟开关题目,8x16 模拟开关阵列芯片 CH446Q.PDF
  20. 痞子衡嵌入式:浅析IAR下调试信息输出机制之硬件UART外设

热门文章

  1. Hybrid Skeleton Driven Surface Registration for Temporally Consistent Volumetric Video
  2. 3.6 - Maya Commands: setAttr
  3. 用卷积神经网络识别实际田间条件下茶叶病虫害(自然环境下拍摄的数据集不用太多预处理)
  4. 按clear按钮清空两个文本框的内容,按copy按钮时将Source文本框的内容复制到Target文本框,按close按钮结束程序的运行
  5. oracle10g 64位安装包下载地址,Oracle10g下载地址--多平台下的32位和64位
  6. vue 使用echart图表 随屏幕放大缩小_哈特(HART)475手操器使用教程
  7. 【Python数据分析】数据挖掘建模——分类与预测——决策树
  8. 深度学习项目:歌词的自动生成
  9. html打开软件连接的代码,《前端开发从零学起》Lesson.7 HTML中超链接的使用方法...
  10. mysql执行语句_MySQL查看实时执行的SQL语句