工作结构图
安装 配置 postgre
- ip 10.42.0.210
- docker环境
- postgre 9.6
- postgre 下载地址
https://www.postgresql.org/download/
安装
yum install -y https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm
yum install -y postgresql96
yum install -y postgresql96-server
- docker 环境不要使用 systemctl 报dbus问题 初始化数据库
su - postgres
/usr/pgsql-9.6/bin/initdb /var/lib/pgsql/9.6/data/
启动 postgre服务
/usr/pgsql-9.6/bin/pg_ctl -D /var/lib/pgsql/9.6/data/ -l logfile start
设置postgre 服务
vi /var/lib/pgsql/9.6/data/pg_hba.conf
末尾添加收信主机
host all all 10.42.0.203/32 trust
host all all 10.42.0.208/32 trust
host all all 10.42.0.206/32 trust
host all all 10.42.0.207/32 trust
host all all 10.42.0.212/32 trust
host all all 10.42.0.213/32 trust
保存重启 pg
/usr/pgsql-9.6/bin/pg_ctl -D /var/lib/pgsql/9.6/data/ -l logfile restart
创建 kong用户
CREATE USER kong; CREATE DATABASE kong OWNER kong;
安装 配置 kong
- 容器ip 10.42.0.206 ,10.42.0.207 10.42.0.208
- 当前操作容器ip 10.42.0.206
- kong 下载地址
https://docs.konghq.com/install/centos/?_ga=2.195692393.458761176.1533519250-2014745959.1533189884
wget https://bintray.com/kong/kong-community-edition-rpm/download_file?file_path=centos/7/kong-community-edition-0.14.0.el7.noarch.rpm -o kong.rpm
rpm -ivh kong.rpm
初始化kong配置文件
cp /etc/kong/kong.conf.default /etc/kong/kong.conf
设置kong配置文件 设置 proxy_listen
proxy_listen = 0.0.0.0:80, 0.0.0.0:443 ssl
集群配置
pg_host = 10.42.0.210
pg_port = 5432
pg_user = kong
pg_password =
pg_database = kong
db_update_frequency = 5
db_update_propagation = 0
db_cache_ttl = 0
第一台机器数据库初始化
kong migrations up -c /etc/kong/kong.conf
启动kong
kong start -c /etc/kong/kong.conf
10.42.0.207 10.42.0.208 复制同样的 kong 配置文件 然后直接启动
配置服务
测试环境
- 商品管理
curl -X POST http://localhost:8001/services/ --data 'name=test_p_service' --data 'host=p.test.xxx.com'
- 基础信息
curl -X POST http://localhost:8001/services/ --data 'name=test_m_service' --data 'host=m.test.xxx.com'
- 订单服务
curl -X POST http://localhost:8001/services/ --data 'name=test_o_service' --data 'host=o.test.xxx.com'
配置路由
- 商品管理
curl -X POST http://localhost:8001/routes/ --data 'paths[]=/api/p-service' --data 'service.id=f18c8de7-b637-4e98-ae2c-a85934f904f4' --data 'hosts[]=api.test.xxx.com''
- 基础信息
curl -X POST http://localhost:8001/routes/ --data 'paths[]=/api/m-service' --data 'service.id=301d78c5-7f5c-4c52-b74d-df71979feb48' --data 'hosts[]=api.test.xxx.com'
- 订单服务
curl -X POST http://localhost:8001/routes/ --data 'paths[]=/api/o-service' --data 'service.id=aa5ed98c-6fb3-43e8-b564-3d33dbf592fa' --data 'hosts[]=api.test.xxx.com'
前端nginx 配置
- ip 10.42.0.211 nginx 添加 upstream
upstream kong {
server 10.42.0.206;
server 10.42.0.207;
server 10.42.0.208;
}
include vhosts/*.conf;
api.test.xxx.com.conf 测试环境 nginx配置
server {
listen 80;
server_name api.test.xxx.com;
#access_log /tmp/kong.log kong;
location / {
proxy_pass http://kong;
proxy_set_header Host 'api.test.xxx.com';
}
}
@jingdor.com