适用CentOS/RedHat类操作系统
一、版本信息
- Kong: 2.0.1
注意:Kong的安装包里自带OpenResty,不需要单独安装Openresty
二、安装
在线安装RPM
sudo yum install -y wget
wget https://bintray.com/kong/kong-rpm/rpm -O bintray-kong-kong-rpm.repo
export major_version=`grep -oE '[0-9]+\.[0-9]+' /etc/redhat-release | cut -d "." -f1`
sed -i -e 's/baseurl.*/&\/centos\/'$major_version''/ bintray-kong-kong-rpm.repo
sudo mv bintray-kong-kong-rpm.repo /etc/yum.repos.d/
sudo yum install -y kong
离线安装RPM
sudo yum install -y wget
wget https://bintray.com/kong/kong-rpm/rpm -O bintray-kong-kong-rpm.repo
export major_version=`grep -oE '[0-9]+\.[0-9]+' /etc/redhat-release | cut -d "." -f1`
sed -i -e 's/baseurl.*/&\/centos\/'$major_version''/ bintray-kong-kong-rpm.repo
sudo mv bintray-kong-kong-rpm.repo /etc/yum.repos.d/
sudo yum install -y yum-utils
sudo yumdownloader kong-2.0.1
sudo yum install -y kong
三、检查是否安装成功
- 查看Kong版本信息
kong version
- 使用DB-less模式启动Kong
cp /etc/kong/kong.conf.default /etc/kong/kong.conf
sed -i "/^#database/i\database = off" /etc/kong/kong.conf
kong start
curl http://127.0.0.1:8001
四、运行目录
- /usr/local/kong Kong的运行目录
- /usr/local/kong/pids/nginx.pid nginx-master进程号
- /usr/local/kong/logs/access.log 数据口的访问日志文件
- /usr/local/kong/logs/admin_access.log 管理口的访问日志
- /usr/local/kong/logs/error.log 错误日志
五、监听端口
-
数据口:8000
curl http://127.0.0.1:8000/
-
管理口:8001
curl http://127.0.0.1:8001/
六、查看连接数统计
# curl http://127.0.01:8001/status 2>/dev/null | jq .server
{
"connections_writing": 1,
"total_requests": 13,
"connections_handled": 13,
"connections_accepted": 13,
"connections_reading": 0,
"connections_active": 1,
"connections_waiting": 0
}
七、查看内存统计
# curl http://127.0.01:8001/status 2>/dev/null | jq .memory
{
"workers_lua_vms": [
{
"http_allocated_gc": "0.05 MiB",
"pid": 1310
}
],
"lua_shared_dicts": {
"kong_rate_limiting_counters": {
"allocated_slabs": "0.08 MiB",
"capacity": "12.00 MiB"
},
"kong_locks": {
"allocated_slabs": "0.06 MiB",
"capacity": "8.00 MiB"
},
"kong_healthchecks": {
"allocated_slabs": "0.04 MiB",
"capacity": "5.00 MiB"
},
"kong_cluster_events": {
"allocated_slabs": "0.04 MiB",
"capacity": "5.00 MiB"
......
八、日志文件自动切割
cat > /etc/logrotate.d/kong <<EOF
/usr/local/kong/logs/*.log {
daily
missingok
rotate 30
compress
delaycompress
dateext
notifempty
create root root
sharedscripts
postrotate
[ -f /usr/local/kong/pids/nginx.pid ] && kill -USR1 `cat /usr/local/kong/pids/nginx.pid`
endscript
}
EOF
九、监控指标
- 连接数
- 内存
- 错误日志
网友评论