安装chrome

创建yum源

# cd /etc/yum.repos.d/
# vim google-chrome.repo

创建yum源信息

[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

安装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的完整版本号

下载之后解压压缩包:

# unzip chromedriver_linux64.zip

给chromeDriver文件夹赋予权限:

# chmod +x /usr/chromedriver/chromedriver

安装Xvfb

安装说明

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

安装Xvfb

# yum install Xvfb -y
# 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 Nov 18 14:25 chrome -> /etc/alternatives/google-chrome
lrwxrwxrwx 1 root root 20 Nov 18 14:25 google-chrome -> /usr/bin/xvfb-chrome
lrwxrwxrwx 1 root root 32 Jun 28 18:39 google-chrome-stable -> /opt/google/chrome/google-chrome
-rwxr-xr-x 1 root root 422 Nov 18 14:24 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

此时再次查看映射关系,如下所示:

lrwxrwxrwx 1 root root 31 Nov 18 14:36 chrome -> /etc/alternatives/google-chrome
lrwxrwxrwx 1 root root 20 Nov 18 14:36 google-chrome -> /usr/bin/xvfb-chrome
lrwxrwxrwx 1 root root 32 Jun 28 18:21 google-chrome-stable -> /opt/google/chrome/google-chrome
-rwxr-xr-x 1 root root 422 Nov 18 14:36 xvfb-chrome

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

options.addArguments("--headless")

centos7安装chrome+chromeDriver+Xvfb的更多相关文章

  1. CentOS-yum安装chrome+chromeDriver+xvfb

    安装chrome 创建yum源文件 $ vim /etc/yum.repos.d/google-chrome.repo [google-chrome] name=google-chrome baseu ...

  2. centos7安装chrome及加载poatman开发插件

    为什么要安装chrome?因为centos7的默认浏览器firefox的实在是不习惯,上面占了太多,本来显示器就不大... 好了,首先下载chome的rpm安装包(如果需要的可以留言,我有备份) 然后 ...

  3. CentOS7 安装chrome浏览器

    本篇文章主要记录如何在CentOS7.0上安装chrome. 1.配置yum下载源: 在目录 /etc/yum.repos.d/ 下新建文件 google-chrome.repo, 并且在该文件中添加 ...

  4. 【转载】CentOS7 安装Chrome浏览器

    本篇文章主要记录如何在CentOS7.0上安装Chrome浏览器. 方法1: Google官方源在国内可能无法正常访问,故而添加Fedora中文社区提供的镜像源: sudo wget http://r ...

  5. CentOS7 安装Chrome

    1. 下载Chrome浏览器的rpm包 https://www.chrome64bit.com/index.php/google-chrome-64-bit-for-linux 2. 安装Chrome ...

  6. centos7安装chrome的历程(fedora同)

    安装 首先是下载,地址奉上:http://www.google.cn/chrome/browser/desktop/index.html,选择64 bit .rpm (适用于 Fedora/openS ...

  7. Linux Centos7安装chrome浏览器

    参考:https://blog.csdn.net/u010472499/article/details/72327963 1. 配置yum源 在目录 /etc/yum.repos.d/ 下新建文件 g ...

  8. centos7安装chrome浏览器

    1.配置yum下载源: 在目录 /etc/yum.repos.d/ 下新建文件 google-chrome.repo, 并且在该文件中添加如下内容: [google-chrome]name=googl ...

  9. CentOS7安装Chrome

    1. 进入官网:https://www.google.cn/intl/zh-CN/chrome/2. 点击下载3. 直接安装:sudo yum localinstall google-chrome-s ...

随机推荐

  1. Web网站实现用户认证访问(加密访问)

    Web网站实现用户认证访问,有效减少流量的访问,具体的实现步骤如下: 我们使用httpd作为测试对象,体现安装好httpd服务,并且可以在浏览器访问测试首页(可以关闭防火墙:如果不关闭防火墙,则需要开 ...

  2. Java 单例模式:懒加载(延迟加载)和即时加载

    引言 在开发中,如果某个实例的创建需要消耗很多系统资源,那么我们通常会使用惰性加载机制(或懒加载.延时加载),也就是说只有当使用到这个实例的时候才会创建这个实例,这个好处在单例模式中得到了广泛应用.这 ...

  3. 结合JVM 浅谈Java 类加载器(Day_03)

    所谓错过,不是错了,而是过了. 什么是JAVA类加载? Class对象由JVM自动产生,每当一个类被加载时,JVM就自动为其生成一个Class对象,通过Class对象可以获得类的相关信息.将类信息读取 ...

  4. Nginx/LVS/HAProxy对比分析

    Nginx/LVS/HAProxy简单介绍: Nginx:专为性能优化而开发,性能是其最重要的考量,实现上非常注重效率 .它支持内核Poll模型,能经受高负载的考验,有报告表明能支持高达 50,000 ...

  5. 第5讲 | 从物理层到MAC层:如何在宿舍里自己组网玩联机游戏?

    第一层(物理层) 水晶头要做交叉线,用的就是所谓的 1-3.2-6 交叉接法. 有一个叫做 Hub 的东西,也就是集线器.这种设备有多个口,可以将宿舍里的多台电脑连接起来.但是,和交换机不同,集线器没 ...

  6. Wrong——Python

    1.向MySQL中插入时间(年月日时分秒),在时分秒处报错.在年月日与时分秒中间有个空格.解决办法:在sql语句中时间用一个" "包起来就可以了.. 2.在Ubuntu的cront ...

  7. 20192113 2020-2021-2 《Python程序设计》实验二报告

    20192113 2020-2021-2 <Python程序设计>实验二报告 课程:<Python程序设计> 班级: 1921 姓名: 衣丽莎 学号:20192113 实验教师 ...

  8. [源码解析] 深度学习分布式训练框架 Horovod (1) --- 基础知识

    [源码解析] 深度学习分布式训练框架 Horovod --- (1) 基础知识 目录 [源码解析] 深度学习分布式训练框架 Horovod --- (1) 基础知识 0x00 摘要 0x01 分布式并 ...

  9. Python+Selenium自动化-模拟键盘操作

    Python+Selenium自动化-模拟键盘操作   0.导入键盘类Keys() selenium中的Keys()类提供了大部分的键盘操作方法:通过send_keys()方法来模拟键盘上的按键. # ...

  10. zk客户端及锁的使用

    1.生成zk客户端对象 private CuratorFramework buildClient() { logger.info("zookeeper registry center ini ...