DigitalOcean API + cloud-config - 安装 Node v14
DigitalOcean API + cloud-config - install Node v14
我想立即调用 Digital Ocean create droplet API 创建一个安装了 NodeJS v14 的 droplet。我调用了 API,获取 IP,使用 SSH 登录,但没有安装任何东西。不确定我做错了什么或者如何调试它。
我的API请求:
curl --location --request POST 'https://api.digitalocean.com/v2/droplets' \
--header 'Authorization: Bearer $TOKEN' \
--header 'Content-Type: application/json' \
--data-raw '{
"names": [
"test"
],
"region": "nyc3",
"size": "s-1vcpu-1gb",
"image": "ubuntu-21-10-x64",
"ssh_keys": [
"my-key-fingerprint"
],
"backups": false,
"ipv6": true,
"user_data": "#cloud-config\n\npackage_update: true\npackage_upgrade: false\npackage_reboot_if_required: false\n\nruncmd:\n - '\''curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash'\''\n - '\''source .bashrc'\''\n - '\''nvm install v14.19.0'\''",
"private_networking": null,
"volumes": null,
"tags": [
"test"
]
}'
如果我在 ssh shell 中手动输入以下 3 个内容,那么它会很好地安装节点:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
source .bashrc
nvm install v14.19.0
您应该检查 Droplet 的日志以确定发生了什么:
more /var/log/cloud-init-output.log
对于您的脚本:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
=> Downloading nvm from git to '/.nvm'
=> Compressing and cleaning up git repository
=> Profile not found. Tried ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile.
=> Create one of them and run this script again
OR
=> Append the following lines to the correct file yourself:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
=> Close and reopen your terminal to start using nvm or run the following to use it now:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
/var/lib/cloud/instance/scripts/runcmd: 3: source: not found
/var/lib/cloud/instance/scripts/runcmd: 4: nvm: not found
2022-02-13 17:57:03,777 - cc_scripts_user.py[WARNING]: Failed to run module scripts-user (scripts in /var/lib/cloud/instance/scripts)
2022-02-13 17:57:03,778 - util.py[WARNING]: Running module scripts-user (<module 'cloudinit.config.cc_scripts_user' from '/usr/lib/python3/dist-packages/cloudinit/config/cc_scripts_user.py'>) failed
我想立即调用 Digital Ocean create droplet API 创建一个安装了 NodeJS v14 的 droplet。我调用了 API,获取 IP,使用 SSH 登录,但没有安装任何东西。不确定我做错了什么或者如何调试它。
我的API请求:
curl --location --request POST 'https://api.digitalocean.com/v2/droplets' \
--header 'Authorization: Bearer $TOKEN' \
--header 'Content-Type: application/json' \
--data-raw '{
"names": [
"test"
],
"region": "nyc3",
"size": "s-1vcpu-1gb",
"image": "ubuntu-21-10-x64",
"ssh_keys": [
"my-key-fingerprint"
],
"backups": false,
"ipv6": true,
"user_data": "#cloud-config\n\npackage_update: true\npackage_upgrade: false\npackage_reboot_if_required: false\n\nruncmd:\n - '\''curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash'\''\n - '\''source .bashrc'\''\n - '\''nvm install v14.19.0'\''",
"private_networking": null,
"volumes": null,
"tags": [
"test"
]
}'
如果我在 ssh shell 中手动输入以下 3 个内容,那么它会很好地安装节点:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
source .bashrc
nvm install v14.19.0
您应该检查 Droplet 的日志以确定发生了什么:
more /var/log/cloud-init-output.log
对于您的脚本:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
=> Downloading nvm from git to '/.nvm'
=> Compressing and cleaning up git repository
=> Profile not found. Tried ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile.
=> Create one of them and run this script again
OR
=> Append the following lines to the correct file yourself:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
=> Close and reopen your terminal to start using nvm or run the following to use it now:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
/var/lib/cloud/instance/scripts/runcmd: 3: source: not found
/var/lib/cloud/instance/scripts/runcmd: 4: nvm: not found
2022-02-13 17:57:03,777 - cc_scripts_user.py[WARNING]: Failed to run module scripts-user (scripts in /var/lib/cloud/instance/scripts)
2022-02-13 17:57:03,778 - util.py[WARNING]: Running module scripts-user (<module 'cloudinit.config.cc_scripts_user' from '/usr/lib/python3/dist-packages/cloudinit/config/cc_scripts_user.py'>) failed