安装chrome

创建yum源文件

$ vim /etc/yum.repos.d/google-chrome.repo

[google-chrome]
name=google-chrome
baseurl=http://dl.google.com/linux/chrome/rpm/stable/$basearch
enabled=1
gpgcheck=1
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub

停用更新-参考官网

如要阻止 Chrome 浏览器自动更新,请执行下列一项操作:

  • 在安装 Chrome 浏览器之前先创建一个空白存储区:
    $ sudo touch /etc/default/google-chrome
  • 在 /etc/default/google-chrome 中添加下列一行内容:
    repo_add_once=false

安装google-chrome

$ yum -y install google-chrome-stable --nogpgcheck

chrome安装路径

使用上述步骤安装完成之后,chrome的安装路径在/opt/google/chrome目录下

安装chromeDriver

查看chrome版本

$ google-chrome -version

下载对应版本的chromeDriver

https://npm.taobao.org/mirrors/chromedriver/查询与chrome版本对应的chromeDriver版本,大版本对应即可,如当前chrome最新的版本是78.0.3904.97,只需要查找与78对应的chromeDriver版本即可。

找到对应的版本后,在linux上使用以下命令下载chromeDriver压缩包:

$ mkdir /usr/chromedriver

$ cd /usr/chromedriver

$ wget https://npm.taobao.org/mirrors/chromedriver/version/chromedriver_linux64.zip

version即为chromeDriver的完整版本号

下载之后解压压缩包:(安装命令:yum install unzip -y)

$ unzip chromedriver_linux64.zip

给chromeDriver文件夹赋予权限:

$ chmod +x /usr/chromedriver/chromedriver

安装Xvfb

安装说明

安装此软件的原因是在centos上,chromeDriver必须使用无头模式,当有不使用无头模式的需求时就需要安装此软件,否则chromeDriver无法正确启动chrome

安装Xvfb

$ yum install Xvfb -y

$ yum install libXfont

$ yum install xorg-x11-fonts* -y

在/usr/bin/目录下创建xvfb-chrome文件

$ vim /usr/bin/xvfb-chrome

在xvfb-chrome文件中输入以下内容

#!/bin/bash 

_kill_procs() { 
kill -TERM $chrome 
wait $chrome 
kill -TERM $xvfb 


# Setup a trap to catch SIGTERM and relay it to child processes 
trap _kill_procs SIGTERM 

XVFB_WHD=${XVFB_WHD:-1280x720x16} 

# Start Xvfb 
Xvfb :99 -ac -screen 0 $XVFB_WHD -nolisten tcp & 
xvfb=$! 

export DISPLAY=:99 

chrome --no-sandbox --disable-gpu$@ & 
chrome=$! 

wait $chrome 
wait $xvfb

添加执行权限

$ chmod +x /usr/bin/xvfb-chrome

查看当前的映射关系

$ ll /usr/bin/ | grep chrom

映射关系如下所示:

lrwxrwxrwx 1 root root 31 Apr 8 17:12 google-chrome -> /etc/alternatives/google-chrome
lrwxrwxrwx 1 root root 32 Apr 8 17:12 google-chrome-stable -> /opt/google/chrome/google-chrome
-rwxr-xr-x 1 root root 370 Apr 8 18:12 xvfb-chrome

更改chrome启动的软连接

$ ln -s /etc/alternatives/google-chrome /usr/bin/chrome

$ rm -rf /usr/bin/google-chrome

$ ln -s /usr/bin/xvfb-chrome /usr/bin/google-chrome

此时再次查看映射关系

$ ll /usr/bin/ | grep chrom

如下所示:

lrwxrwxrwx 1 root root 31 Apr 8 18:13 chrome -> /etc/alternatives/google-chrome
lrwxrwxrwx 1 root root 20 Apr 8 18:13 google-chrome -> /usr/bin/xvfb-chrome
lrwxrwxrwx 1 root root 32 Apr 8 17:12 google-chrome-stable -> /opt/google/chrome/google-chrome
-rwxr-xr-x 1 root root 370 Apr 8 18:12 xvfb-chrome

注:以上步骤操作完成后即可在centos环境下使用非无头浏览器,此时chromeDriver创建时不能再添加以下参数:

options.addArguments("--headless")

 

CentOS-yum安装chrome+chromeDriver+xvfb的更多相关文章

  1. centos7安装chrome+chromeDriver+Xvfb

    安装chrome 创建yum源 # cd /etc/yum.repos.d/ # vim google-chrome.repo 创建yum源信息 [google-chrome] name=google ...

  2. 如何在linux CentOS 上安装chrome 谷歌浏览器?

    获得linux命令的root权限:http://blog.csdn.net/mddy2001/article/details/76521101. 更改密码在终端中输入:sudo passwd root ...

  3. centos yum 安装 mongodb 以及php扩展

    centos yum 安装 mongodb 以及php扩展 投稿:hebedich 字体:[增加 减小] 类型:转载 MongoDB是一个基于分布式文件存储的数据库.由C++语言编写.旨在为WEB应用 ...

  4. 【转】CentOS yum安装和卸载软件的使用方法

    在CentOS yum安装和卸载软件的使用方法安装方法安装一个软件时.   CentOS yum -y install httpd安装多个相类似的软件时   CentOS yum -y install ...

  5. [转帖]Centos7 yum安装Chrome浏览器

    Centos7 yum安装Chrome浏览器 https://www.cnblogs.com/ianduin/p/8727333.html以及https://blog.csdn.net/libaine ...

  6. CentOS yum 安装LAMP PHP5.4版本

    CentOS yum 安装LAMP PHP5.4版本 [日期:2015-06-04] 来源:Linux社区  作者:rogerzhanglijie [字体:大 中 小]     Linux系统版本:C ...

  7. CentOS yum安装mcrypt

    CentOS yum安装mcrypt   本篇排错的前提是只想用yum安装,不想使用源码包编译安装. php依赖一下包:   #yum install libmcrypt libmcrypt-deve ...

  8. CentOS yum安装mcrypt详细图解教程

    CentOS yum安装mcrypt详细图解教程 在Linux的发行版CentOS 6.3 系统下,LAMP(Linux+Apache+Mysql+php)环境搭建好后发现PHPMyadmin提示 “ ...

  9. centos yum 安装php5.6

    centos yum 安装php5.6 卸载 php之前的版本: yum remove -y php-common 配置源 CentOS 6.5的源 rpm -Uvh http://ftp.iij.a ...

随机推荐

  1. 攻防世界-WEB-新手练习区

    附:|>>>攻防世界-WEB-高手进阶区<<<|

  2. python rpc 的实现

    所谓RPC,是远程过程调用(Remote Procedure Call)的简写,网上解释很多,简单来说,就是在当前进程调用其他进程的函数时,体验就像是调用本地写的函数一般.本文实现的是在本地调用远端的 ...

  3. VMware虚拟机CentOS磁盘扩容

    版本信息: VMware Workstation 15 Pro  15.5.2 build-15785246, CentOS7 原虚拟机默认20G,安装东西多了,磁盘空间不够用, docker mys ...

  4. GO学习-(24) Go语言操作Redis

    Go语言操作Redis 在项目开发中redis的使用也比较频繁,本文介绍了Go语言中go-redis库的基本使用. Redis介绍 Redis是一个开源的内存数据库,Redis提供了多种不同类型的数据 ...

  5. GO学习-(6) Go语言基础之运算符

    Go语言基础之运算符 运算符用于在程序运行时执行数学或逻辑运算. 运算符 Go 语言内置的运算符有: 算术运算符 关系运算符 逻辑运算符 位运算符 赋值运算符 算数运算符 运算符 描述 + 相加 - ...

  6. GO学习-(2) 从零开始搭建Go语言开发环境

    从零开始搭建Go语言开发环境 一步一步,从零搭建Go语言开发环境. 安装Go语言及搭建Go语言开发环境 下载 下载地址 Go官网下载地址:https://golang.org/dl/ Go官方镜像站( ...

  7. .Net Core Api发布时报502.5 [The Application process failed to Start]问题的解决原因

       碰到这样的错误,在网上找了很久很久.我自己在部署的时候已经把Core 部署需要的环境包在服务器安装好了.还会报这个错,然后在网上找的安装了一个系统补丁包!安装之后还是不行.最后我把服务器重启了一 ...

  8. 人工智能AI Boosting HMC Memory Chip

    人工智能AI Boosting HMC Memory Chip Innosilicon的AI Boosting HMC存储芯片适用于高速,高带宽和高性能存储领域,例如AI边缘,数据中心,自动化等. H ...

  9. HiCar人-车-家全场景智慧互联

    HiCar人-车-家全场景智慧互联 (HUAWEI HiCar Smart Connection)解决方案,具备如下特点: 安全交互:以安全为前提的极简交互(Safety) 无感互联:手机/IoT 设 ...

  10. TensorRT深度学习训练和部署图示

    TensorRT深度学习训练和部署 NVIDIA TensorRT是用于生产环境的高性能深度学习推理库.功率效率和响应速度是部署的深度学习应用程序的两个关键指标,因为它们直接影响用户体验和所提供服务的 ...