首先创建upstream
curl -i -X POST --url http://localhost:8001/upstreams/ -d "name=user_service_upstream"
之后添加后端服务
curl -i -X POST --url http://localhost:8001/upstreams/user_service_upstream/targets -d "target=192.168.195.129:80"
curl -i -X POST --url http://localhost:8001/upstreams/user_service_upstream/targets -d "target=192.168.195.130:80"
查看upstream 里面的target
curl -i -X GET --url http://localhost:8001/upstreams/user_service_upstream/targets/
添加到api
curl -i -X POST --url http://localhost:8001/apis/ -d "name=user_service_lb" -d "hosts=www.test.com" -d "upstream_url=http://user_service_upstream"

ps -ef | grep nginx
cd /usr/local/openresty/nginx/conf/
vi nginx.conf
在最后添加
include vhosts/*.conf;
注:大括号里面
mkdir vhosts
cd vhosts/
vi nginx.conf
server {
listen 80;
server_name www.test.com;

location / {
    proxy_pass http://www.test.com:8000;
}

}

/usr/local/openresty/nginx/sbin/nginx -t
/usr/local/openresty/nginx/sbin/nginx
vi /etc/hosts
192.168.195.128 www.test.com

kong 负载均衡_第1张图片