gpt4 book ai didi

google-compute-engine - GCE : How do you create a forwarding rule from port 80 external to port 5555 internal

转载 作者:行者123 更新时间:2023-12-04 03:51:09 24 4
gpt4 key购买 nike

我是第一次使用谷歌计算引擎。我想设置一个网络负载平衡器(带有静态ip),该端口在端口80上监听,但转发到在端口5555上监听的后端服务器。我发现的所有示例均显示将80转发至80,这对我的情况。

引用:https://cloud.google.com/compute/docs/load-balancing/network/forwarding-rules

谢谢

最佳答案

经过大量的阅读和测试,我找到了一个解决方案,该解决方案允许GCE将请求代理到另一个端口上的内部端口。要转发到其他端口,我必须设置代理,ServerPools,UrlMaps等,因此设置要比基本的网络转发复杂得多。

##############################
# Setting up API port forwarding from external 80 to internal 5555
export INTERNAL_PORT=5555 #The port number that api is running on.
export EXTERNAL_PORT=80 #The port number that will be exposed externally by the proxy

export ZONE=us-central1-b
export NETWORK=mynetwork

export INSTANCE_GRP="api-us"
export HEALTH_CHECK="api-basic-check"
export HEALTH_CHECK_CHECKPATH="/isok"
export BK_SRV_SERVICE="api-srv"
export PROXY_NAME="api-proxy"
export URLMAP_NAME="api-urlmap"
export HTTP_FW_NAME="api-http-fw-rule"
export ADDRESS_NAME="api-external-ip"

export BACKEND_SRV01="apiserver01"

gcloud preview instance-groups --zone $ZONE create $INSTANCE_GRP --network $NETWORK
gcloud preview instance-groups --zone $ZONE instances \
--group $INSTANCE_GRP add $BACKEND_SRV01
#The load balancing service by default looks for a service with a key of http.
gcloud preview instance-groups --zone $ZONE add-service $INSTANCE_GRP \
--port $INTERNAL_PORT --service http

gcloud compute http-health-checks create $HEALTH_CHECK \
--check-interval 5s --healthy-threshold 2 \
--port $INTERNAL_PORT --timeout 3s --unhealthy-threshold 4 \
--request-path $HEALTH_CHECK_CHECKPATH

gcloud compute backend-services create $BK_SRV_SERVICE \
--http-health-check $HEALTH_CHECK
gcloud compute backend-services add-backend $BK_SRV_SERVICE \
--group $INSTANCE_GRP --zone $ZONE

gcloud compute url-maps create $URLMAP_NAME --default-service $BK_SRV_SERVICE
gcloud compute target-http-proxies create $PROXY_NAME --url-map $URLMAP_NAME

#create a static address to expose externally so that we can keep it if we remove the proxy.
gcloud compute addresses create $ADDRESS_NAME --global
export IP=`gcloud compute addresses describe $ADDRESS_NAME --global --format json | jq --raw-output '.address'`

gcloud compute forwarding-rules create $HTTP_FW_NAME --global \
--target-http-proxy $PROXY_NAME --port-range $EXTERNAL_PORT --address $IP

echo $IP # This is the IP to use for DNS etc...

关于google-compute-engine - GCE : How do you create a forwarding rule from port 80 external to port 5555 internal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28495237/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com