kong 負載均衡

首先建立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"nginx

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;
}

}api

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

kong 負載均衡

相關文章
相關標籤/搜索