如何以root用户身份在Ubuntu Server上运行节点Puppeteer应用程序

时间:2018-10-07 05:21:24

标签: node.js ubuntu npm vps puppeteer

我正在尝试运行使用npm软件包Puppeteer的节点应用程序来抓取网站,使用将root作为默认用户登录身份的VPS。

它永远都行不通。我总是不得不花半个小时的时间来寻找解决方案……再也没有了。

3 个答案:

答案 0 :(得分:3)

通过 SSH 连接到服务器

  1. 打开你的终端
  2. 输入:ssh root@[服务器ip]
  3. 如果这是您第一次连接到服务器,您将收到安全提示。输入“是”
  4. 填写您的密码:[password]
  5. 您现在应该连接到您的服务器

安装应用

sudo apt-get 更新

sudo apt-get install -y libgbm-dev

sudo apt install -y gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libcertlspreleases 字体 >

sudo apt install curl

curl -sL https://deb.nodesource.com/setup_10.x |须藤 -E bash -

sudo apt 安装 nodejs

git config --global user.name "你的名字"

git config --global user.email "你的邮箱"

git clone "你的项目 git url"

cd "你的项目文件夹"

npm 我

npm 启动


如果您需要在一台 VPS 服务器上运行多个应用程序 - 谷歌工具“屏幕”

答案 1 :(得分:1)

执行以下操作:

1。安装libx内容

sudo apt-get install libpangocairo-1.0-0 libx11-xcb1 libxcomposite1 libxcursor1 libxdamage1 libxi6 libxtst6 libnss3 libcups2 libxss1 libxrandr2 libgconf2-4 libasound2 libatk1.0-0 libgtk-3-0

2。在Puppeteer应用程序的launch()部分中设置--no-sandbox参数(仅当您以root / root的cron身份运行时才需要)

const browser = await puppeteer.launch({headless: true, args: ['--no-sandbox']})

答案 2 :(得分:0)

安装 libgbm 后,一切正常! 希望能帮到你

    sudo apt-get update
    sudo apt-get install -y libgbm-dev