[root@ar414.com ~] yum -y install java
2.安装 chromehtml
#使用下面的命令,在root用户下就能够安装最新的 Google Chrome [root@ar414.com ~] yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
3.安装 seleniumjava
4.安装 chromedriverlinux
chromedriver_linux64.zip
5.将下载的文件解压,放在以下位置chrome
[root@ar414.com ~] unzip ./chromedriver_linux64.zip [root@ar414.com ~] mv ./chromedriver /usr/bin/chromedriver
6.给予执行权限vim
[root@ar414.com ~] vim /usr/bin/xvfb-chrome
7.安装 XVFBapi
[root@ar414.com ~] yum install Xvfb -y [root@ar414.com ~] yum install xorg-x11-fonts* -y
8.新建在/usr/bin/ 一个名叫 xvfb-chrom 的文件写入如下内容浏览器
#!/bin/bash _kill_procs() { kill -TERM $chrome wait $chrome kill -TERM $xvfb } Setup a trap to catch SIGTERM and relay it to child processes rap _kill_procs SIGTERM VFB_WHD=${XVFB_WHD:-1280x720x16} Start Xvfb vfb :99 -ac -screen 0 $XVFB_WHD -nolisten tcp & vfb=$! xport DISPLAY=:99 chrome --no-sandbox --disable-gpu$@ & chrome=$! wait $chrome wait $xvfb
9.添加执行权限安全
chmod +x /usr/bin/xvfb-chrome
10.查看当前映射关系bash
[root@ar414.com ~] ll /usr/bin/ | grep chrom -rwxr-xr-x 1 root root 7874704 Mar 20 14:55 chromedriver lrwxrwxrwx 1 root root 31 Mar 20 00:24 google-chrome -> /etc/alternatives/google-chrome lrwxrwxrwx 1 root root 32 Mar 20 14:30 google-chrome-stable -> /opt/google/chrome/google-chrome
11.更改Chrome启动的软链接网络
[root@ar414.com ~] ln -s /etc/alternatives/google-chrome /usr/bin/chrome [root@ar414.com ~] rm -rf /usr/bin/google-chrome [root@ar414.com ~] ln -s /usr/bin/xvfb-chrome /usr/bin/google-chrome
12.查看修改后的映射关系
[root@ar414.com ~] ll /usr/bin/ | grep chrom -rwxr-xr-x 1 root root 7874704 Mar 20 14:55 chromedriver lrwxrwxrwx 1 root root 31 Mar 20 00:24 chrome -> /etc/alternatives/google-chrome lrwxrwxrwx 1 root root 22 Mar 20 00:11 google-chrome -> /usr/bin/xvfb-chromium lrwxrwxrwx 1 root root 32 Mar 20 14:30 google-chrome-stable -> /opt/google/chrome/google-chrome -rwxr-xr-x 1 root root 432 Mar 20 00:09 xvfb-chrome
13.后台运行selenium服务
#Tip:通常我线上环境都会用supervisor守护进程来保证服务一直处于运行状态,在遇到程序异常、报错等状况能够马上重启,继续提供服务,有时间会写一个supervisor的实战文章 [root@ar414.com ~] nohup java -jar selenium-server-standalone-3.141.59.jar &