基于kong的开发指南
1.安装docker
附上docker安装文档和基本使用教程:https://www.runoob.com/docker/ubuntu-docker-install.html
2.安装kongdb
2.1下载镜像
docker pull registry.cn-beijing.aliyuncs.com/hantang2/staticngnix:kongdb
2.2创建容器
docker run -dt --name kongdb --network host -p 5342:5342 f9f91d1533eb
3.安装kong
3.1下载镜像
docker pull registry.cn-beijing.aliyuncs.com/hantang2/imgshare:777.77.10
3.2添加配置文件
mkdir ~/kconf //1.创建一个目录
cd ~/kconf //2.进入目录
vim servers.conf //3.创建并打开server.conf
server{
server_name kong_prometheus_exporter;
listen 0.0.0.0:9542; # can be any other port as well
access_log off;
location /metrics {
default_type text/plain;
content_by_lua_block {
local prometheus = require "kong.plugins.prometheus.exporter"
prometheus:collect()
}
}
location /nginx_status {
internal;
stub_status;
}
}
# Health check server
server {
server_name kong_health_check;
listen 0.0.0.0:9001; # can be any other port as well
access_log off;
location /health {
return 200;
}
}
#4 将该这个配置文件内容粘贴到servers.conf文件中
3.3创建容器(注意~/kconf配置文件的路径)
docker run -d --name kong --network host -e "KONG_DATABASE=postgres" -e "KONG_PG_HOST=127.0.0.1" -e "KONG_PG_DATABASE=kong" -e "KONG_PG_USER=kong" -e "KONG_PG_PASSWORD=123456" -e "KONG_PG_PORT=5432" -e "KONG_NGINX_HTTP_INCLUDE=/kong/servers.conf" -e "KONG_PROXY_ACCESS_LOG=/dev/stdout" -e "KONG_ADMIN_ACCESS_LOG=/dev/stdout" -e "KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl" -p 8000:8000 -p 8443:8443 -p 8001:8001 -p 8444:8444 -v ~/kconf:/kong f1cf0e9017b5
4.安装konga
4.1拉取镜像
docker pull pantsel/konga
4.2创建容器
docker run -d --name konga --network host -e "DB_DATABASE=konga" -e "DB_USER=konga" -e "DB_PASSWORD=konga" -e "DB_PORT=5432" -e "DB_HOST=127.0.0.1" -e "NODE_ENV=development" -p 1337:1337 e3251e50022b
4.3检验是否启动
在开发机器访问http://××××××:1337打开控制台
5.用docker安装MySQL
5.1拉取镜像
docker pull mysql:5.6 //这里以5.6版本为例
5.2创建容器
docker run -itd --name mysql5.6 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:5.6
6.安装redis
6.1拉取镜像
docker pull redis
6.2创建配置文件
mkdir ~/redisconf //1.创建一个目录
cd ~/redisconf //2.进入目录
vim redis.conf //3.创建并打开redis.conf
//4.将下面文件内容粘贴到redis.conf文件中
//5.修改redis.conf文件中的bind参数,改为你的工作机器地址(本机为127.0.0.1)
# Redis configuration file example.
#
# Note that in order to read the configuration file, Redis must be
# started with the file path as first argument:
#
# ./redis-server /path/to/redis.conf
# Note on units: when memory size is needed, it is possible to specify
# it in the usual form of 1k 5GB 4M and so forth:
#
# 1k => 1000 bytes
# 1kb => 1024 bytes
# 1m => 1000000 bytes
# 1mb => 1024*1024 bytes
# 1g => 1000000000 bytes
# 1gb => 1024*1024*1024 bytes
#
# units are case insensitive so 1GB 1Gb 1gB are all the same.
################################## INCLUDES ###################################
# Include one or more other config files here. This is useful if you
# have a standard template that goes to all Redis servers but also need
# to customize a few per-server settings. Include files can include
# other files, so use this wisely.
#
# Notice option "include" won't be rewritten by command "CONFIG REWRITE"
# from admin or Redis Sentinel. Since Redis always uses the last processed
# line as value of a configuration directive, you'd better put includes
# at the beginning of this file to avoid overwriting config change at runtime.
#
# If instead you are interested in using includes to override configuration
# options, it is better to use include as the last line.
#
# include /path/to/local.conf
# include /path/to/other.conf
################################## MODULES #####################################
# Load modules at startup. If the server is not able to load modules
# it will abort. It is possible to use multiple loadmodule directives.
#
# loadmodule /path/to/my_module.so
# loadmodule /path/to/other_module.so
################################## NETWORK #####################################
# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 loopback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 192.168.4.119
# Protected mode is a layer of security protection, in order to avoid that
# Redis instances left open on the internet are accessed and exploited.
#
# When protected mode is on and if:
#
# 1) The server is not binding explicitly to a set of addresses using the
# "bind" directive.
# 2) No password is configured.
#
# The server only accepts connections from clients connecting from the
# IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain
# sockets.
#
# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
protected-mode yes
# Accept connections on the specified port, default is 6379 (IANA #815344).
# If port 0 is specified Redis will not listen on a TCP socket.
port 6379
# TCP listen() backlog.
#
# In high requests-per-second environments you need an high backlog in order
# to avoid slow clients connections issues. Note that the Linux kernel
# will silently truncate it to the value of /proc/sys/net/core/somaxconn so
# make sure to raise both the value of somaxconn and tcp_max_syn_backlog
# in order to get the desired effect.
tcp-backlog 511
# Unix socket.
#
# Specify the path for the Unix socket that will be used to listen for
# incoming connections. There is no default, so Redis will not listen
# on a unix socket when not specified.
#
# unixsocket /tmp/redis.sock
# unixsocketperm 700
# Close the connection after a client is idle for N seconds (0 to disable)
timeout 0
# TCP keepalive.
#
# If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
# of communication. This is useful for two reasons:
#
# 1) Detect dead peers.
# 2) Take the connection alive from the point of view of network
# equipment in the middle.
#
# On Linux, the specified value (in seconds) is the period used to send ACKs.
# Note that to close the connection the double of the time is needed.
# On other kernels the period depends on the kernel configuration.
#
# A reasonable value for this option is 300 seconds, which is the new
# Redis default starting with Redis 3.2.1.
tcp-keepalive 300