gpt4 book ai didi

node.js - Google计算引擎书架教程: npm ERR!网络读取ECONNRESET

转载 作者:太空宇宙 更新时间:2023-11-04 02:03:01 25 4
gpt4 key购买 nike

我目前正在学习 GCE 书架教程,这让我最头疼:https://cloud.google.com/nodejs/tutorials/bookshelf-on-compute-engine

我被困在这一步:

To see the application running, go to http://[YOUR_INSTANCE_IP]:8080,

where [YOUR_INSTANCE_IP] is the external IP address of your instance.

当我尝试通过端口 8080 在外部 IP 上查看我的应用程序时,没有任何反应。

我可以确认防火墙规则已正确应用,并且我的虚拟机实例显示了正确的网络标记。

我查看了串行日志,意识到启动脚本存在问题,因为实例无法克隆 git 存储库。

所以我改变了

git 克隆 https://source.developers.google.com/p/$PROJECTID/opt/app

git 克隆 https://source.developers.google.com/p/d3-barchart/r/repo/opt/app

(startup-script.sh 的其余部分在这里:)

#! /bin/bash
# Copyright 2017, Google, Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# [START startup]
set -v

# Talk to the metadata server to get the project id
PROJECTID=$(curl -s "http://metadata.google.internal/computeMetadata/v1/project/project-id" -H "Metadata-Flavor: Google")

# Install logging monitor. The monitor will automatically pick up logs sent to
# syslog.
# [START logging]
curl -s "https://storage.googleapis.com/signals-agents/logging/google-fluentd-install.sh" | bash
service google-fluentd restart &
# [END logging]

# Install dependencies from apt
apt-get update
apt-get install -yq ca-certificates git nodejs build-essential supervisor

# Install nodejs
mkdir /opt/nodejs
curl https://nodejs.org/dist/v4.2.2/node-v4.2.2-linux-x64.tar.gz | tar xvzf - -C /opt/nodejs --strip-components=1
ln -s /opt/nodejs/bin/node /usr/bin/node
ln -s /opt/nodejs/bin/npm /usr/bin/npm

# Get the application source code from the Google Cloud Repository.
# git requires $HOME and it's not set during the startup script.
export HOME=/root
git config --global credential.helper gcloud.sh
git clone https://source.developers.google.com/p/d3-barchart/r/repo /opt/app

# Install app dependencies
cd /opt/app/7-gce
npm install

# Create a nodeapp user. The application will run as this user.
useradd -m -d /home/nodeapp nodeapp
chown -R nodeapp:nodeapp /opt/app

# Configure supervisor to run the node app.
cat >/etc/supervisor/conf.d/node-app.conf << EOF
[program:nodeapp]
directory=/opt/app/7-gce
command=npm start
autostart=true
autorestart=true
user=nodeapp
environment=HOME="/home/nodeapp",USER="nodeapp",NODE_ENV="production"
stdout_logfile=syslog
stderr_logfile=syslog
EOF

supervisorctl reread
supervisorctl update

# Application should now be running under supervisor
# [END startup]

即使我的虚拟机实例现在可以正确克隆 git 存储库,它现在也会收到 ECONNRESET 错误:

Jul 24 21:52:59 my-app-instance startup-script: INFO startup-script: # Get the application source code from the Google Cloud Repository.
Jul 24 21:52:59 my-app-instance startup-script: INFO startup-script: # git requires $HOME and it's not set during the startup script.
Jul 24 21:52:59 my-app-instance startup-script: INFO startup-script: export HOME=/root
Jul 24 21:52:59 my-app-instance startup-script: INFO startup-script: git config --global credential.helper gcloud.sh
Jul 24 21:52:59 my-app-instance startup-script: INFO startup-script: git clone https://source.developers.google.com/p/d3-barchart/r/repo /opt/app
Jul 24 21:52:59 my-app-instance startup-script: INFO startup-script: Cloning into '/opt/app'...
Jul 24 21:53:02 my-app-instance startup-script: INFO startup-script: # Install app dependencies
Jul 24 21:53:02 my-app-instance startup-script: INFO startup-script: cd /opt/app/7-gce
Jul 24 21:53:02 my-app-instance startup-script: INFO startup-script: npm install
Jul 24 21:53:04 my-app-instance startup-script: INFO startup-script: npm WARN deprecated jade@1.11.0: Jade has been renamed to pug, please install the latest version of pug instead of jade
Jul 24 21:53:05 my-app-instance startup-script: INFO startup-script: npm WARN engine @google-cloud/nodejs-repo-tools@1.4.15: wanted: {"node":">=6"} (current: {"node":"4.2.2","npm":"2.14.7"})
Jul 24 21:53:21 my-app-instance startup-script: INFO startup-script: npm WARN deprecated transformers@2.1.0: Deprecated, use jstransformer
Jul 24 21:53:50 my-app-instance startup-script: INFO startup-script: npm WARN optional dep failed, continuing fsevents@1.1.2
Jul 24 21:54:06 my-app-instance startup-script: INFO startup-script: npm WARN deprecated node-uuid@1.4.8: Use uuid module instead
Jul 24 21:54:20 my-app-instance startup-script: INFO startup-script: npm ERR! Linux 3.16.0-4-amd64
Jul 24 21:54:20 my-app-instance startup-script: INFO startup-script: npm ERR! argv "/opt/nodejs/bin/node" "/usr/bin/npm" "install"
Jul 24 21:54:20 my-app-instance startup-script: INFO startup-script: npm ERR! node v4.2.2
Jul 24 21:54:20 my-app-instance startup-script: INFO startup-script: npm ERR! npm v2.14.7
Jul 24 21:54:20 my-app-instance startup-script: INFO startup-script: npm ERR! code ECONNRESET
Jul 24 21:54:20 my-app-instance startup-script: INFO startup-script: npm ERR! errno ECONNRESET
Jul 24 21:54:20 my-app-instance startup-script: INFO startup-script: npm ERR! syscall read
Jul 24 21:54:20 my-app-instance startup-script: INFO startup-script: npm ERR! network read ECONNRESET
Jul 24 21:54:20 my-app-instance startup-script: INFO startup-script: npm ERR! network This is most likely not a problem with npm itself
Jul 24 21:54:20 my-app-instance startup-script: INFO startup-script: npm ERR! network and is related to network connectivity.
Jul 24 21:54:20 my-app-instance startup-script: INFO startup-script: npm ERR! network In most cases you are behind a proxy or have bad network settings.
Jul 24 21:54:20 my-app-instance startup-script: INFO startup-script: npm ERR! network
Jul 24 21:54:20 my-app-instance startup-script: INFO startup-script: npm ERR! network If you are behind a proxy, please make sure that the
Jul 24 21:54:20 my-app-instance startup-script: INFO startup-script: npm ERR! network 'proxy' config is set properly. See: 'npm help config'

说实话,我不知道这是否是我无法在外部 IP 上查看我的应用程序的原因,但目前,这是我唯一发现错误的地方。如何解决这个问题?

最佳答案

需要检查的一件事是您的防火墙规则中打开了哪些端口。 HTTP 的默认端口是 80,https 的默认端口是 443。

转到防火墙规则并查看允许哪些端口访问您的外部 IP 地址。要到达那里,请先单击 GCP 控制台左上角的汉堡包,然后:

网络 --> 防火墙规则

现在,查看您为 HTTP 访问打开的端口。您可以调整服务器以监听端口 80 或添加防火墙规则以监听 tcp:80。确保您的虚拟机已添加到创建新规则的网络(因此请确保将规则添加到默认网络)。

说实话,Dev-Ops 教程并没有做太多的指导,而且往往会省略很多步骤。

关于node.js - Google计算引擎书架教程: npm ERR!网络读取ECONNRESET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45291444/

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