[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 &