做这个:
0. 运行 sudo apt update
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
Run Code Online (Sandbox Code Playgroud)
2. 在 Puppeteer 应用程序的 launch() 部分设置 --no-sandbox 参数(仅当您以 root/root 的 cron 运行时才需要)
const browser = await puppeteer.launch({headless: true, args: ['--no-sandbox']})
Run Code Online (Sandbox Code Playgroud)
E:正如 Niko 所指出的,--no-sandbox打开您的服务器以接受来自抓取工具访问的网站的恶意攻击。看起来其他地方有一些 SO 问题发布了实施起来并不可怕的替代方案。我喜欢大卫在这里的回答,这似乎表明即使在 2021 年--no-sandbox在某些情况下仍然是必要的邪恶。
E2:见下面的答案。看起来在 2021 年我们也必须安装libgbm-dev
通过 SSH 连接到服务器:
\n安装应用程序:
\nsudo apt-get 更新
\nsudo apt-get install -y libgbm-dev
\nsudo 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 libxtst6 ca-证书字体解放 libappindicator1 libnss3 lsb-release xdg-utils获取
\n须藤安装卷曲
\n卷曲-sL https://deb.nodesource.com/setup_14.x | 须藤-E bash-
\nsudo apt安装nodejs
\nsudo apt安装git
\ngit config --global user.name“你的名字”
\ngit config --global user.email“您的电子邮件”
\ngit clone “你的项目 git url”
\ncd“你的项目文件夹”
\n尼普我
\nnpm 启动
\n如果您需要在一台 VPS 服务器上运行多个应用程序 - 谷歌工具“Screen”
\n