HOME
  Security
   Software
    Hardware
  
FPGA
  CPU
   Android
    Raspberry Pi
  
nLite
  Xcode
   etc.
    ALL
  
LINK
BACK
 

2017/10/20

Raspberry Pi Raspbian Jessieで PhantomJS 2.1.1をビルドする方法、OpenSSL 1.0.1t Raspberry Pi Raspbian Jessieで PhantomJS 2.1.1をビルドする方法、OpenSSL 1.0.1t

(ラズパイに Phantom.js 2.1.1の最新版をコンパイルしてインストールして Webサイトをスクレイピング)

Tags: [Raspberry Pi], [電子工作]





● Raspberry Pi 3 Model Bを遂に購入

 Raspberry Pi3 Model B RPI2 RPI3

 大人気の CPUボードの Raspberry Piに WiFiと Bluetoothが搭載されたモデルが新発売となりました。
 以前から Raspberry Pi 2を買おうかどうか迷っていましたが、Raspberry Pi 3 Model Bの発売を機に購入を決意してラズベリアンになる事にしました。

 ※ ラズパイの OS Raspbianはバージョンが上がる毎に過去の版と OSの内部の作りが変わり、過去に書かれた製作記事(例えば Raspbian Wheezyの時代の記事)がそのままではエラーが出たりして動かない事が有ります。
 ※ 当方のホームページのラズパイ記事は全て Raspberry Pi 3 Model Bと Raspbian Jessieの組み合わせで動作確認をしております。
(ただし、将来的に新しい Raspbian OSが出た場合に、当方の Raspbian Jessieを基にした内容がそのままでは動かない可能性が有ります。)
 ※ 2017/08/16から Raspbian OSは Raspbian Jessieから Raspbian Stretchに変わりました。
 ※ 2019/06/20から Raspbian OSは Raspbian Stretchから Raspbian Busterに変わりました。

Download Raspbian for Raspberry Pi

ちなみに、歴代のバージョンと名称は
Debianコードネーム年月備考(参考)Ubuntuでの該当名称
Debian 11Bullseye2021/08/14~2021/11からラズパイにリリースFocal Fossa 20.04 LTS ?
Debian 10Buster2019/06/20~2019/06からラズパイ4対応Bionic 18.04 LTS
Debian 9Stretch2017/08/16~2018/03からラズパイ3B+対応Xenial 16.04 LTS
Debian 8Jessie2015~2016/02からラズパイ3対応Trusty 14.04 LTS
Debian 7Wheezy2013~2016
Debian 6.0Squeeze2011~2014
Debian GNU/Linux 5.0Lenny2009~2012


● PhantomJS 2.1.1

 スクレイピングやら Webの自動巡回やらが可能。JavaScriptで記述する。

PhantomJS
 PhantomJS is a headless WebKit scriptable with a JavaScript API.
 It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG.

● PhantomJS関連アプリ

SlimerJS - A scriptable browser for Web developers
npm install slimerjs
/home/pi
└── slimerjs@0.10.3

CasperJS - Navigation scripting & testing for PhantomJS and SlimerJS
npm install casperjs
/home/pi
└── casperjs@1.1.4


● PhantomJS 2.1.1のビルドが面倒な人用にバイナリをアップロードしました。

 Raspberry Piで動く PhantomJS 2.1.1のバイナリを GitHubにアップロードしました。面倒なコンパイルが不要で、すぐに PhantomJSを動作させる事ができます。

FREEWING-JP/phantomjs - PhantomJS 2.1.1 for Raspberry Pi

 詳しくは下記にまとめました。

2017/10/20
Raspbianで最新版の Phantom.js 2.1.1のビルド済みバイナリを導入して速攻で簡単に動かす方法
Raspbianで最新版の Phantom.js 2.1.1のビルド済みバイナリを導入して速攻で簡単に動かす方法

  ラズパイで PhantomJS 2.1.1のバイナリをインストールする方法、ビルド不要で簡単導入


● Raspberry Pi 3の Raspbian Jessie 2017-07最終版で PhantomJS 2.1.1をビルドする方法

 このページの内容は 2017年 7月版 Raspbian Jessieで動作を確認しています。
 ※最新の Raspbian Stretch版でもビルドができました。
$ uname -a
Linux raspberrypi 4.9.35-v7+ #1014 SMP Fri Jun 30 14:47:43 BST 2017 armv7l GNU/Linux

$ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 8.0 (jessie)
Release:        8.0
Codename:       jessie


● PhantomJS 2.1.1をビルドするには SDカード容量が 16GB以上の物が必要

 SDカード容量が 8GBの場合は最初のソースリストのダウンロード時に「ディスクフル」で駄目です。
 SDカードのオススメはこちら。

 Raspberry Piで安定して使える相性の無い microSDカードのまとめ

2016/09/10
Raspberry Pi 3で安定して使える相性の無い最適な microSDカードの種類のまとめ
Raspberry Pi 3で安定して使える相性の無い最適な microSDカードの種類のまとめ

  ラズパイ3で安定して使える microSDカードを購入する Teamと SanDiskは絶対に買わない


● Raspbianと OpenSSLのバージョンの関係

 Raspbian Jessie = OpenSSL 1.0.1t、3 May 2016
Debian jessie - パッケージ: openssl (1.0.1t-1+deb8u6)
パッケージ: libssl1.0.0 (1.0.1t-1+deb8u6)

 Raspbian Stretch = OpenSSL 1.1.0f、25 May 2017
Debian stretch - パッケージ: openssl (1.1.0f-3)
パッケージ: libssl1.1 (1.1.0f-3)
ソースパッケージ: openssl1.0 (1.0.2l-2)

 ※ PhantomJSのコンパイルには OpenSSL 1.0.2以下が必要です。
 ※ OpenSSLの 1.0.2までと 1.1以降とは中身がかなり違うので Raspbian Stretch = OpenSSL 1.1.0fの場合は通常の手順ではビルドできません。
 ※ PhantomJS以外のアプリでも OpenSSL 1.1.0の非互換性により「ビルドができない」問題が有ります。


● How to build PhantomJS 2.1.1 on Raspberry Pi 3 with Raspbian Jessie 2017-07

 How to build PhantomJS 2.1.1 on Raspberry Pi 3 with Raspbian Jessie 2017-07
 ラズパイ3の Raspbian JessieでPhantomJS 2.1.1をソースファイルからビルドする方法。

Phantom JSのビルド手順

Requirements
Hardware requirements
 RAM: at least 4 GB
 Disk space: at least 3 GB
 CPU: 1.8 GHz, 4 cores or more
※メモリが 1GBのラズパイ3でもビルドできました。
PhantomJS is still a web browser, albeit headless.
 Thus, building it from source takes a long time
 (mainly due to thousands of files in the WebKit module).
 Estimated build time for a 4-core system is 30 minutes.
PhantomJSはヘッドレスですが、まだ Webブラウザです。
 したがって、ソースからのビルドには長い時間がかかります
 (主に、WebKitモジュールのファイルが数千あるためです)。
 4コアシステムの場合、ビルドに要する時間は 30分です。

 ※ ラズパイ3で 1コアでビルドで 7時間程度(--jobs 1の時、仮想メモリ 100MB)
 ※ ラズパイ3で 2コアでビルドで 4時間程度(--jobs 2の時、仮想メモリ 2GB)
 ※ ラズパイ3で 3コアでビルドで 3時間40分程度(--jobs 3の時、仮想メモリ 2GB)
# Swap領域はデフォルトの 100MBのまま
free -h
#              total       used       free     shared    buffers     cached
# Mem:          923M       279M       643M        13M        17M       165M
# -/+ buffers/cache:        96M       826M
# Swap:          99M         0B        99M

# その他のメモリ関連のコマンド
top -n 1
# Tasks: 156 total,   1 running, 155 sleeping,   0 stopped,   0 zombie
# %Cpu(s):  1.8 us,  1.3 sy,  0.0 ni, 94.4 id,  2.4 wa,  0.0 hi,  0.0 si,  0.0 st
# KiB Mem:    945512 total,   286656 used,   658856 free,    18404 buffers
# KiB Swap:   102396 total,        0 used,   102396 free.   169392 cached Mem
#
#   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
#  1179 pi        20   0    5104   2512   2144 R  16.8  0.3   0:00.06 top
#     1 root      20   0   22820   3960   2792 S   0.0  0.4   0:02.65 systemd

vmstat
# procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
#  r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
#  0  0      0 658872  18400 169364    0    0   239     5  678  200  2  1 94  3  0
# Raspbian Jessie 2017-07 OpenSSL 1.0.1t
# お決まりの手順
sudo apt-get update

# OpenSSLのバージョンを確認
openssl version
# OpenSSL 1.0.1t  3 May 2016

# PhantomJSのビルドに必要な依存関係のあるバイナリ類をインストールする
sudo apt-get -y install git build-essential g++ flex bison gperf ruby perl libsqlite3-dev libfontconfig1-dev libicu-dev libfreetype6 libssl-dev libpng-dev libjpeg-dev

● Gitから PhantomJSのソースファイルを取得(その1 通常フル版)
 git cloneで phantomjsのソースリストを取得します。
ariya/phantomjs - Scriptable Headless WebKit http://phantomjs.org
cd
# git cloneで phantomjsのソースリストを取得する
git clone git://github.com/ariya/phantomjs.git
cd phantomjs
 git cloneが 99%で止まってしまう場合は下記の様に細切れに git cloneします。
cd
# git cloneで phantomjsのソースリストを取得する
# --single-branch --depth=1を指定して gitコマンドの処理の負荷を軽減?する?
git clone git://github.com/ariya/phantomjs.git -b master --single-branch --depth=1
cd phantomjs
# 各ブランチを細切れに指定して取得する事で gitコマンドの処理の負荷を軽減?する?
git fetch origin 1.4:refs/remotes/origin/1.4
git fetch origin 1.6.0:refs/remotes/origin/1.6.0
git fetch origin 1.9.0:refs/remotes/origin/1.9.0
git fetch origin 2.0.0:refs/remotes/origin/2.0.0
git fetch origin 2.1.1:refs/remotes/origin/2.1.1

● Gitから PhantomJSのソースファイルを取得(その2 時間短縮版)
cd
git clone git://github.com/ariya/phantomjs.git -b 2.1.1 --single-branch --depth=1
cd phantomjs

 以下は共通手順
# Raspbian Jessie 2017-07 OpenSSL 1.0.1t build PhantomJS 2.1.1
# checkout 2.1.1で phantomjsの 2.1.1を指定する
git checkout 2.1.1

# git fetchでソースリスト(2.1.1)を取得する(念の為実行する)
git fetch

git show -q
# commit d9cda3dcd26b0e463533c5cc96e39c0f39fc32c1
# Author: Ariya Hidayat <ariya.hidayat@gmail.com>
# Date:   Sun Jan 24 10:19:22 2016 -0800

# ビルドに必要な他のモジュールをダウンロードする
git submodule init
git submodule update

# build.pyで PhantomJSをビルドする
# -cで最初の「ビルドに時間掛かるよ~」の警告に同意する
# --jobs 1はコンパイルに使用する CPUの数
python ./build.py -c --jobs 1

# 7時間程度待つ(ラズパイ3で --jobs 1)
# 後述の様に --jobs 2でコンパイルに使用する CPUを 2個にすれば 4時間でビルドできるのでそちらをオススメ。

# phantomjs -vで PhantomJSのバージョンを確認する
./bin/phantomjs -v
# 2.1.1

ls -l ./bin
# -rwxr-xr-x 1 pi pi 50013804 Oct 27 05:05 phantomjs

readelf -A ./bin/phantomjs
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "6"
  Tag_CPU_arch: v6
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-1
  Tag_FP_arch: VFPv2
  Tag_ABI_PCS_wchar_t: 4
  Tag_ABI_FP_rounding: Needed
  Tag_ABI_FP_denormal: Needed
  Tag_ABI_FP_exceptions: Needed
  Tag_ABI_FP_number_model: IEEE 754
  Tag_ABI_align_needed: 8-byte
  Tag_ABI_align_preserved: 8-byte, except leaf SP
  Tag_ABI_enum_size: int
  Tag_ABI_HardFP_use: SP and DP
  Tag_ABI_VFP_args: VFP registers
  Tag_CPU_unaligned_access: v6


● PhantomJSで Web画面をキャプチャする JavaScriptのサンプル
PhantomJS Screen Capture

github.js
var page = require('webpage').create();
page.open('https://github.com/', function() {
  page.render('github.png');
  phantom.exit();
});

./phantomjs github.js
ReferenceError: Can't find variable: Promise
  https://assets-cdn.github.com/assets/frameworks-90ee08465df40055dba1b6cdf1a92989e00c4f07d805bcbb1c183bf3cc9edaf4.js:1 in o
ReferenceError: Can't find variable: Promise
  https://assets-cdn.github.com/assets/frameworks-90ee08465df40055dba1b6cdf1a92989e00c4f07d805bcbb1c183bf3cc9edaf4.js:1 in o

 PhantomJSでキャプチャした Web画像
・github.png、PhantomJSでキャプチャした Web画像
github.png、PhantomJSでキャプチャした Web画像
 ※ 減色、リサイズ、トリミングをしています。元画像は 360KB 1304x6880dot 24bit


● ラズパイ3で PhantomJS 2.1.1をビルドするのに必要な時間を調べてみた。

 追試でラズパイ3でのビルド時間を正確に計測してみた。
python ./build.py -c --jobs 1
 でコンパイルに CPUコアを 1個だけ使用の場合。
 結果: 420分 = 7時間
# dateコマンドで日時を保存する
date >BUILD_START
# timeコマンドでコマンドの実行時間を計測する
time python ./build.py -c --jobs 1
date >BUILD_END
# dateコマンドの日時を表示する
cat BUILD_START
cat BUILD_END

#==== 420分 = 7時間
real    420m3.266s
user    401m27.690s
sys     16m29.570s

cat BUILD_START
# Sat 28 Oct 00:46:12 UTC 2017
cat BUILD_END
# Sat 28 Oct 07:46:17 UTC 2017


● PhantomJS 2.1.1

$ ./bin/phantomjs -v
2.1.1

$ ./bin/phantomjs --help
Usage:
   phantomjs [switchs] [options] [script] [argument [argument [...]]]

Options:
  --cookies-file=<val>                 Sets the file name to store the persistent cookies
  --config=<val>                       Specifies JSON-formatted configuration file
  --debug=<val>                        Prints additional warning and debug message: 'true' or 'false' (default)
  --disk-cache=<val>                   Enables disk cache: 'true' or 'false' (default)
  --disk-cache-path=<val>              Specifies the location for the disk cache
  --ignore-ssl-errors=<val>            Ignores SSL errors (expired/self-signed certificate errors): 'true' or 'false' (default)
  --load-images=<val>                  Loads all inlined images: 'true' (default) or 'false'
  --local-url-access=<val>             Allows use of 'file:///' URLs: 'true' (default) or 'false'
  --local-storage-path=<val>           Specifies the location for local storage
  --local-storage-quota=<val>          Sets the maximum size of the local storage (in KB)
  --offline-storage-path=<val>         Specifies the location for offline storage
  --offline-storage-quota=<val>        Sets the maximum size of the offline storage (in KB)
  --local-to-remote-url-access=<val>   Allows local content to access remote URL: 'true' or 'false' (default)
  --max-disk-cache-size=<val>          Limits the size of the disk cache (in KB)
  --output-encoding=<val>              Sets the encoding for the terminal output, default is 'utf8'
  --remote-debugger-port=<val>         Starts the script in a debug harness and listens on the specified port
  --remote-debugger-autorun=<val>      Runs the script in the debugger immediately: 'true' or 'false' (default)
  --proxy=<val>                        Sets the proxy server, e.g. '--proxy=http://proxy.company.com:8080'
  --proxy-auth=<val>                   Provides authentication information for the proxy, e.g. ''-proxy-auth=username:password'
  --proxy-type=<val>                   Specifies the proxy type, 'http' (default), 'none' (disable completely), or 'socks5'
  --script-encoding=<val>              Sets the encoding used for the starting script, default is 'utf8'
  --script-language=<val>              Sets the script language instead of detecting it: 'javascript'
  --web-security=<val>                 Enables web security, 'true' (default) or 'false'
  --ssl-protocol=<val>                 Selects a specific SSL protocol version to offer. Values (case insensitive): TLSv1.2, TLSv1.1, TLSv1.0, TLSv1 (same as v1.0), SSLv3, or ANY. Default is to offer all that Qt thinks are secure (SSLv3 and up). Not all values may be supported, depending on the system OpenSSL library.
  --ssl-ciphers=<val>                  Sets supported TLS/SSL ciphers. Argument is a colon-separated list of OpenSSL cipher names (macros like ALL, kRSA, etc. may not be used). Default matches modern browsers.
  --ssl-certificates-path=<val>        Sets the location for custom CA certificates (if none set, uses environment variable SSL_CERT_DIR. If none set too, uses system default)
  --ssl-client-certificate-file=<val>  Sets the location of a client certificate
  --ssl-client-key-file=<val>          Sets the location of a clients' private key
  --ssl-client-key-passphrase=<val>    Sets the passphrase for the clients' private key
  --webdriver=<val>                    Starts in 'Remote WebDriver mode' (embedded GhostDriver): '[[<IP>:]<PORT>]' (default '127.0.0.1:8910')
  --webdriver-logfile=<val>            File where to write the WebDriver's Log (default 'none') (NOTE: needs '--webdriver')
  --webdriver-loglevel=<val>           WebDriver Logging Level: (supported: 'ERROR', 'WARN', 'INFO', 'DEBUG') (default 'INFO') (NOTE: needs '--webdriver')
  --webdriver-selenium-grid-hub=<val>  URL to the Selenium Grid HUB: 'URL_TO_HUB' (default 'none') (NOTE: needs '--webdriver')
  -w,--wd                              Equivalent to '--webdriver' option above
  -h,--help                            Shows this message and quits
  -v,--version                         Prints out PhantomJS version

Any of the options that accept boolean values ('true'/'false') can also accept 'yes'/'no'.

Without any argument, PhantomJS will launch in interactive mode (REPL).

Documentation can be found at the web site, http://phantomjs.org.


● ラズパイ3で PhantomJS 2.1.1をビルドするのに必要な時間を調べてみた。

 追試でラズパイ3でのビルド時間を正確に計測してみた。
python ./build.py -c --jobs 2
 でコンパイルに CPUコアを 2個だけ使用の場合。
 結果: 途中でハングやメモリ不足で中断して計測不能(SWAP領域は 100MBのまま)
# dateコマンドで日時を保存する
date >BUILD_START
# timeコマンドでコマンドの実行時間を計測する
time python ./build.py -c --jobs 2
date >BUILD_END
# dateコマンドの日時を表示する
cat BUILD_START
cat BUILD_END

 途中の下記の場所でラズパイがハングした。(2回実験して 2回とも)
.obj/inspector/InspectorAllInOne.o inspector/InspectorAllInOne.cpp

 ハングの後、電源を入れなおして再起動して続行。
time python ./build.py -c --jobs 2

virtual memory exhausted: Cannot allocate memory
Makefile.WebCore.Target:135993: recipe for target '.obj/inspector/InspectorAllInOne.o' failed
make[2]: *** [.obj/inspector/InspectorAllInOne.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: Leaving directory '/home/pi/phantomjs/src/qt/qtwebkit/Source/WebCore'
Makefile.WebCore:68: recipe for target 'sub-Target-pri-make_first-ordered' failed
make[1]: *** [sub-Target-pri-make_first-ordered] Error 2
make[1]: Leaving directory '/home/pi/phantomjs/src/qt/qtwebkit/Source/WebCore'
Makefile:177: recipe for target 'sub-Source-WebCore-WebCore-pro-make_first-ordered' failed
make: *** [sub-Source-WebCore-WebCore-pro-make_first-ordered] Error 2

ERROR: Failed to build PhantomJS! Building Qt WebKit failed.
 コンパイラがメモリ不足のエラーを出して停止

$ free -h
             total       used       free     shared    buffers     cached
Mem:          923M        53M       870M       564K       1.6M        26M
-/+ buffers/cache:        24M       898M
Swap:          99M        12M        87M

● --jobs 2でビルド中の freeコマンドの結果
python ./build.py -c --jobs 2
 を実行中に別のターミナルから freeコマンドで確認

pi@raspberrypi:~ $ free -h
             total       used       free     shared    buffers     cached
Mem:          923M       850M        73M       9.7M        28M       498M
-/+ buffers/cache:       323M       600M
Swap:          99M       3.7M        96M

● ラズパイの仮想メモリの SWAP領域を広げれば --jobs 2でも大丈夫かも

 でも、SWAP領域を広げても仮想メモリのアクセスが遅いから、「ビルドを通す事」には意味が有るけど、「ビルド時間を短縮する事」には意味が無いと思います。
 (追試で検証したら 7時間が 4時間に短縮されたので CPU処理時間のメリットが仮想メモリ(SDカード)への I/Oアクセス速度のデメリットを上回りました。)

/etc/dphys-swapfile
 ファイルの
CONF_SWAPSIZE=100
 を書き換える。単位は MB単位。

sudo nano /etc/dphys-swapfile
CONF_SWAPSIZE=2048

# コマンドラインでサクッと実行して書き換える場合
sudo sed -i -e "s/^CONF_SWAPSIZE=.*/CONF_SWAPSIZE=2048/g" /etc/dphys-swapfile

# 2GB超を割り当てたい場合は、下記の CONF_MAXSWAPの箇所を有効にして書き換える。
#CONF_MAXSWAP=2048
 を書き換える。

sudo service dphys-swapfile stop
sudo service dphys-swapfile start
 または
sudo service dphys-swapfile restart
 で dphys-swapfileサービスを再起動する。
 再起動時にスワップファイルを更新するので 2GBを設定した場合は時間が掛かる。

$ free -h
             total       used       free     shared    buffers     cached
Mem:          923M       883M        39M       6.2M       4.6M       830M
-/+ buffers/cache:        48M       875M
Swap:         2.0G         0B       2.0G

# 仮想メモリに 2GB超のスワップ領域を割り当てた場合の例
CONF_SWAPSIZE=2148
CONF_MAXSWAP=2148

$ free -h
             total       used       free     shared    buffers     cached
Mem:          923M       881M        41M       6.2M       4.9M       828M
-/+ buffers/cache:        48M       874M
Swap:         2.1G         0B       2.1G
 上記の仮想メモリに 2.1GBを設定した後に実行してみるテスト。
time python ./build.py -c --jobs 2

 コンパイルできた!
make[1]: Leaving directory '/home/pi/phantomjs/src'

real    25m7.389s
user    39m48.190s
sys     1m27.370s

$ ls -l ./bin/
-rwxr-xr-x 1 pi pi 50013804 Oct 29 02:30 phantomjs

$ ./bin/phantomjs -v
2.1.1


●空きメモリ領域について補足

 ラズパイが画面表示に使用する VRAMのサイズを減らす方法も有ります。
 デフォルトの 64MBから 16MBにする事で、使用可能なメモリ領域を 48MBも増やせます。

Memory options in config.txt - GPU_MEM
 Minimum value is 16 .
 Maximum value is 944 .
 The default value is 64 .
cat /boot/config.txt | grep gpu_mem
# /boot/config.txtの最後に gpu_mem=16の行を追加

sudo nano /boot/config.txt
gpu_mem=16

# コマンドラインでサクッと実行して書き換える場合
sudo bash -c "echo gpu_mem=16>> /boot/config.txt"
sudo sed -i -e "s/^gpu_mem=.*/gpu_mem=16/g" /boot/config.txt

●上記を踏まえて --jobs 2で再リベンジ

 結果: 243分 = 4時間(SWAP領域を 2GBに設定)
free -h
#              total       used       free     shared    buffers     cached
# Mem:          923M       192M       731M        12M       9.7M       147M
# -/+ buffers/cache:        34M       888M
# Swap:          99M         0B        99M

sudo sed -i -e "s/^CONF_SWAPSIZE=.*/CONF_SWAPSIZE=2048/g" /etc/dphys-swapfile

sudo bash -c "echo gpu_mem=16>> /boot/config.txt"
sudo sed -i -e "s/^gpu_mem=.*/gpu_mem=16/g" /boot/config.txt

sudo apt-get update
sudo reboot

#---
free -h
#              total       used       free     shared    buffers     cached
# Mem:          970M       936M        34M       6.5M       7.2M       881M
# -/+ buffers/cache:        48M       922M
# Swap:         2.0G         0B       2.0G

sudo apt-get -y install wget git build-essential g++ flex bison gperf ruby perl libsqlite3-dev libfontconfig1-dev libicu-dev libfreetype6 libssl-dev libpng-dev libjpeg-dev

free -h
#              total       used       free     shared    buffers     cached
# Mem:          970M       924M        46M       6.5M        19M       838M
# -/+ buffers/cache:        66M       904M
# Swap:         2.0G         0B       2.0G

cd
git clone git://github.com/ariya/phantomjs.git -b master --single-branch --depth=1
cd phantomjs
git fetch origin 1.4:refs/remotes/origin/1.4
git fetch origin 1.6.0:refs/remotes/origin/1.6.0
git fetch origin 1.9.0:refs/remotes/origin/1.9.0
git fetch origin 2.0.0:refs/remotes/origin/2.0.0
git fetch origin 2.1.1:refs/remotes/origin/2.1.1
git checkout 2.1.1
git fetch
git submodule init
git submodule update

date >BUILD_START
# --jobs 2で CPUコア 2個指定
time python ./build.py -c --jobs 2
date >BUILD_END
cat BUILD_START
cat BUILD_END

# SWAP領域を 100MBに戻す
sudo sed -i -e "s/^CONF_SWAPSIZE=.*/CONF_SWAPSIZE=100/g" /etc/dphys-swapfile

● --jobs 2で無事にビルド完了

 なんと 243分の 4時間で完了しました。
 と言う訳で、PhantomJSのビルドは、SWAPを設定してでも CPUを 2個使用したビルドの方が有利と言う結論になりました。
 SWAPの読み書きにボトルネックが有っても CPUの処理時間の方がそれを上回る効果が有ると言う事ですね。
 420分が 243分で 42%程度の効果。
make[1]: Leaving directory '/home/pi/phantomjs/src'

real    243m5.174s
user    442m50.870s
sys     18m49.030s

pi@raspberrypi:~/phantomjs $ date >BUILD_END
pi@raspberrypi:~/phantomjs $ cat BUILD_START
Sun 29 Oct 03:22:51 UTC 2017
pi@raspberrypi:~/phantomjs $ cat BUILD_END
Sun 29 Oct 07:25:57 UTC 2017

pi@raspberrypi:~/phantomjs $ ls -l ./bin/
total 48844
-rwxr-xr-x 1 pi pi 50013804 Oct 29 07:25 phantomjs

pi@raspberrypi:~/phantomjs $ free -h
             total       used       free     shared    buffers     cached
Mem:          970M       387M       583M       276K        16M       324M
-/+ buffers/cache:        45M       925M
Swap:         2.0G        12M       2.0G


● 3コアでのコンパイルに挑戦

 X Window System(GUIデスクトップ)も停止して使用可能なメインメモリ容量を稼ぎます。

●実験的に --jobs 3でビルド
free -h
#              total       used       free     shared    buffers     cached
# Mem:          923M       380M       543M        19M        21M       257M
# -/+ buffers/cache:       101M       822M
# Swap:          99M         0B        99M

# ラズパイの仮想メモリの SWAP領域を 2GBに広げる
sudo sed -i -e "s/^CONF_SWAPSIZE=.*/CONF_SWAPSIZE=2048/g" /etc/dphys-swapfile
cat /etc/dphys-swapfile | grep CONF_SWAPSIZE
sudo service dphys-swapfile restart

#  VRAMのサイズを 64MBから 16MBに減らす
sudo bash -c "echo gpu_mem=16>> /boot/config.txt"
sudo sed -i -e "s/^gpu_mem=.*/gpu_mem=16/g" /boot/config.txt

# ラズパイの X Window Systemを無効化してメモリ使用量を減らす
sudo systemctl set-default multi-user.target
systemctl list-units | grep lightdm
sudo systemctl disable lightdm

# 緑色の ACT LEDの動作がハートビート(心臓の鼓動)になり一定間隔で点滅する。
# ハングした場合は点滅しなくなるので考えているのかハングしているのかの区別がつく。
sudo bash -c "echo dtparam=act_led_trigger=heartbeat >> /boot/config.txt"

# 再起動で設定を反映させる
sudo reboot


#---
free -h
#              total       used       free     shared    buffers     cached
# Mem:          970M        95M       875M       6.6M       9.6M        49M
# -/+ buffers/cache:        36M       934M
# Swap:         2.0G         0B       2.0G

sudo apt-get -y install wget git build-essential g++ flex bison gperf ruby perl libsqlite3-dev libfontconfig1-dev libicu-dev libfreetype6 libssl-dev libpng-dev libjpeg-dev

cd
git clone git://github.com/ariya/phantomjs.git -b master --single-branch --depth=1
cd phantomjs
git fetch origin 1.4:refs/remotes/origin/1.4
git fetch origin 1.6.0:refs/remotes/origin/1.6.0
git fetch origin 1.9.0:refs/remotes/origin/1.9.0
git fetch origin 2.0.0:refs/remotes/origin/2.0.0
git fetch origin 2.1.1:refs/remotes/origin/2.1.1
git checkout 2.1.1
git fetch
git submodule init
git submodule update

date >BUILD_START
# --jobs 3で CPUコア 3個指定
time python ./build.py -c --jobs 3
date >BUILD_END
cat BUILD_START
cat BUILD_END

# SWAP領域を 100MBに戻す
sudo sed -i -e "s/^CONF_SWAPSIZE=.*/CONF_SWAPSIZE=100/g" /etc/dphys-swapfile

● --jobs 3で無事にビルド完了

 216分と言う事で 2コアと比べて 24分の短縮となりました。
 2コアと 3コアのビルド時間は 1コアから 2コアの様な劇的な効果は有りませんでした。
 240分が 216分で 10%程度の効果。
make[1]: Leaving directory '/home/pi/phantomjs/src'

real    216m34.153s
user    485m51.940s
sys     21m57.350s
pi@raspberrypi:~/phantomjs $ date >BUILD_END
pi@raspberrypi:~/phantomjs $ cat BUILD_START
Mon 30 Oct 12:42:38 UTC 2017
pi@raspberrypi:~/phantomjs $ cat BUILD_END
Mon 30 Oct 16:19:12 UTC 2017

pi@raspberrypi:~/phantomjs $ free -h
             total       used       free     shared    buffers     cached
Mem:          970M       388M       582M       400K        18M       324M
-/+ buffers/cache:        46M       924M
Swap:         2.0G        18M       2.0G


● -cが無い場合の最初に表示と確認を求められる「ビルドに時間掛かるよ~」の警告文
----------------------------------------
               WARNING
----------------------------------------

Building PhantomJS from source takes a very long time, anywhere from 30 minutes
to several hours (depending on the machine configuration). It is recommended to
use the premade binary packages on supported operating systems.

For details, please go the the web site: http://phantomjs.org/download.html.

Do you want to continue (Y/n)?


● PhantomJSの build.pyのヘルプ
$ python ./build.py --help
usage: build.py [-h] [-r] [-d] [-j JOBS] [-c] [-n] [-s]
                [--qmake-args QMAKE_ARGS]
                [--webkit-qmake-args WEBKIT_QMAKE_ARGS]
                [--phantomjs-qmake-args PHANTOMJS_QMAKE_ARGS]
                [--qt-config QT_CONFIG] [--git-clean-qtbase]
                [--git-clean-qtwebkit] [--skip-qtbase]
                [--skip-configure-qtbase] [--skip-qtwebkit]
                [--skip-configure-qtwebkit] [--skip-git]

Build PhantomJS from sources.

optional arguments:
  -h, --help            show this help message and exit
  -r, --release         Enable compiler optimizations.
  -d, --debug           Build with debug symbols enabled.
  -j JOBS, --jobs JOBS  How many parallel compile jobs to use. Defaults to 4.
  -c, --confirm         Silently confirm the build.
  -n, --dry-run         Only print what would be done without actually
                        executing anything.
  -s, --silent          Reduce output during compilation.

advanced options:
  --qmake-args QMAKE_ARGS
                        Additional arguments that will be passed to all QMake
                        calls.
  --webkit-qmake-args WEBKIT_QMAKE_ARGS
                        Additional arguments that will be passed to the Qt
                        WebKit QMake call.
  --phantomjs-qmake-args PHANTOMJS_QMAKE_ARGS
                        Additional arguments that will be passed to the
                        PhantomJS QMake call.
  --qt-config QT_CONFIG
                        Additional arguments that will be passed to Qt Base
                        configure.
  --git-clean-qtbase    Run git clean in the Qt Base folder. ATTENTION: This
                        will remove all untracked files!
  --git-clean-qtwebkit  Run git clean in the Qt WebKit folder. ATTENTION: This
                        will remove all untracked files!
  --skip-qtbase         Skip Qt Base completely and do not build it. Only
                        enable this option when Qt Base was built previously
                        and no update is required.
  --skip-configure-qtbase
                        Skip configure step of Qt Base, only build it. Only
                        enable this option when the environment has not
                        changed and only an update of Qt Base is required.
  --skip-qtwebkit       Skip Qt WebKit completely and do not build it. Only
                        enable this option when Qt WebKit was built previously
                        and no update is required.
  --skip-configure-qtwebkit
                        Skip configure step of Qt WebKit, only build it. Only
                        enable this option when neither the environment nor Qt
                        Base has changed and only an update of Qt WebKit is
                        required.
  --skip-git            Skip all actions that require Git. For use when
                        building from a tarball release.


● Jessieでビルドした PhantomJSのバイナリは Stretchでは動かない

 Raspbian Jessie = OpenSSL 1.0.1t 3 May 2016
 Raspbian Stretch = OpenSSL 1.1.0f 25 May 2017
$ ./phantomjs2
./phantomjs2: error while loading shared libraries: libssl.so.1.0.0: cannot open shared object file: No such file or directory
 Jessieでビルドした PhantomJSのバイナリは Stretchでは動きまへん。。


● How to build PhantomJS 2.1.1 on Raspberry Pi 3 with Raspbian Stretch 2017-09

 Raspbian Stretch = OpenSSL 1.1.0f 25 May 2017
 ラズパイ3の Raspbian StretchでPhantomJS 2.1.1をソースファイルからビルドする方法

2017/10/20
Raspberry Pi Raspbian Stretchで PhantomJS 2.1.1をビルドする方法、OpenSSL 1.1の罠
Raspberry Pi Raspbian Stretchで PhantomJS 2.1.1をビルドする方法、OpenSSL 1.1の罠

  ラズパイに Phantom.js 2.1.1の最新版をコンパイルしてインストールして Webサイトをスクレイピング


● Git clone stuck at 99%

 Gitコマンドで cloneした時に 99%で止まったままになる。
pi@raspberrypi:~/qq $ git clone git://github.com/ariya/phantomjs.git
Cloning into 'phantomjs'...
remote: Counting objects: 64456, done.
Receiving objects:  99% (64432/64456), 10.04 MiB | 884.00 KiB/s
 ※ 99%で止まったままになる。
pi@raspberrypi:~/phantomjs $ git fetch origin 2.0.0:refs/remotes/origin/2.0.0
remote: Counting objects: 26764, done.
remote: Compressing objects: 100% (17685/17685), done.
Receiving objects:  99% (26686/26764), 90.96 MiB | 139.00 KiB/s
 ※ 99%で止まったままになる。

git clone hangs forever on github
GIT_TRACE=1 GIT_CURL_VERBOSE=1 git clone --progress --verbose https://github.com/hoge/fuga.git
 ※ この方法でも原因が分からなかった。

git clone - Documentation
GIT_TRACE=1 Gitの内部の処理を表示
GIT_CURL_VERBOSE=1 通信ログを表示
--verbose
-v
Run verbosely. Does not affect the reporting of progress status to the standard error stream.

--progress
Progress status is reported on the standard error stream by default when it is attached to a terminal, unless -q is specified. This flag forces progress status even if the standard error stream is not directed to a terminal.

I think I found the error. The WiMAX router I am using, messes SSH up. After trying another internet connection, it went smooth. The WiMAX router is branded "Alvarion", and according to a Danish Google Group the NAT implementation is broken in the router: http://groups.google.com/group/openspaceaarhus/browse_thread/thread/e99d96122a0522b7 .

I have contacted the internet supplier to look into this. If they prove it has nothing to do with their router I will post it here.

Thank you all for your comments, which made me realise it maybe was an infrastructure problem.
Workaround for Skyline-skod-lorte-skrammel-fucked-up-NAT
Grunden til at ssh og en del andre ting ikke virker med det skrammel
IP-wannabe vi har fået fra Skyline er at ssh skifter Type Of Service
flaget på en forbindelse, det er der nogle defekte NAT
implementationer der ikke kan finde ud af, Skylines dropper bare
forbindelsen.
Jeg har fundet en workaround der går ud på at putte ssh forbindelsen
inden i en forbindelse lavet af et andet program med:
ProxyCommand connect %h %p

--
Flemming Frandsen - YAPH - http://dren.dk/

● How to git reduce memory usage

 gitコマンドのメモリ使用量を抑える方法

Is there a way to limit the amount of memory that “git gc” uses ?
git config --global pack.windowMemory "100m"
git config --global pack.packSizeLimit "100m"
git config --global pack.threads "1"


●番外編 MTUの確認方法

ping -f -l 1426 www.google.com
MTU = 1426 + 28 = 1454
 pingの数値に 28を足した物が MTUの設定値



Tags: [Raspberry Pi], [電子工作]

●関連するコンテンツ(この記事を読んだ人は、次の記事も読んでいます)

FWinSdCardImager SDカード イメージ書き込みアプリ、ラズパイの Raspbian OS、Jetson Nanoの Ubuntuの書き込みに便利
FWinSdCardImager SDカード イメージ書き込みアプリ、ラズパイの Raspbian OS、Jetson Nanoの Ubuntuの書き込みに便利

  ラズパイや Jetson Nano等のワンボードマイコン等への OSイメージの書き込みが簡単にできる

FWinPiFinder ラズベリーパイ IPアドレス発見アプリ。ARPコマンドでラズパイの IPアドレスを探索発見する
FWinPiFinder ラズベリーパイ IPアドレス発見アプリ。ARPコマンドでラズパイの IPアドレスを探索発見する

  Raspberry Piや NVIDIA Jetson Nano等の IPアドレスを MACアドレスの OUI部分を使用して発見する

Raspberry Pi 3系のトラブルであるある第一位の電源トラブル、低電圧警報に関する情報のまとめ
Raspberry Pi 3系のトラブルであるある第一位の電源トラブル、低電圧警報に関する情報のまとめ

  ラズパイ3B系での低電圧警報に関する情報まとめ、コマンドラインやログファイルから低電圧を検知する方法

Raspberry Piで CPUの脆弱性 Spectreと Meltdownの脆弱性をチェックする方法
Raspberry Piで CPUの脆弱性 Spectreと Meltdownの脆弱性をチェックする方法

  ラズパイで 2018年初頭に大騒ぎになったスペクターとメルトダウンの CPUの脆弱性をチェックする方法

Raspberry Pi Zero Wを海外通販の Pimoroni等での購入方法、購入できる通販ショップ一覧まとめ
Raspberry Pi Zero Wを海外通販の Pimoroni等での購入方法、購入できる通販ショップ一覧まとめ

  ラズパイゼロW ワイヤレスモデルを海外通販でサクッと簡単に個人輸入で入手。技適通過でも国内販売は常に品切れ

Raspberry Pi 3で安定して使える相性の無い最適な microSDカードの種類のまとめ
Raspberry Pi 3で安定して使える相性の無い最適な microSDカードの種類のまとめ

  ラズパイ3で安定して使える microSDカードを購入する Teamと SanDiskは絶対に買わない

Raspberry Pi 3 Model Bに専用カメラモジュール RaspiCamを接続する方法
Raspberry Pi 3 Model Bに専用カメラモジュール RaspiCamを接続する方法

  ラズパイに専用カメラモジュールを接続して Raspbianで写真の静止画撮影や動画を録画する方法

Raspberry Pi 3の Linuxコンソール上で使用する各種コマンドまとめ
Raspberry Pi 3の Linuxコンソール上で使用する各種コマンドまとめ

  ラズパイの Raspbian OSのコマンドラインで使用する便利コマンド、負荷試験や CPUシリアル番号の確認方法等も

Raspberry Pi 3公式フォーラムの FAQの内容の日本語訳
Raspberry Pi 3公式フォーラムの FAQの内容の日本語訳

  ラズパイ公式フォーラムの「The Raspberry Pi 3 Model B Q&A thread」の日本語訳

Raspberry Pi 3で GPIO端子の I2C機能を有効化する方法
Raspberry Pi 3で GPIO端子の I2C機能を有効化する方法

  ラズパイ3の GPIO端子の I2C機能を有効にして各種センサーを繋げる方法まとめ

大人気の CPUボード、Raspberry Pi 3 Model Bで作ってみよう
大人気の CPUボード、Raspberry Pi 3 Model Bで作ってみよう

  Raspberry Piの開発環境の構築やタッチパネル付き液晶ディスプレイや各種センサーの使い方まとめ


Raspberry Pi 3、シングルボードコンピュータ ラズパイ3 Raspberry Pi関連はこちらへまとめました
 下記以外にも多数のラズパイ関係の記事が有ります。
 (I2C制御、GPIO制御、1-Wire制御、シリアル通信、日本語音声合成、日本語音声認識、中国語音声合成、MeCab 形態素解析エンジン、赤外線リモコン制御、秋月 I2C液晶モジュール、KeDei 3.5インチ液晶、HDMI 5インチ液晶、NFCカードリーダ、コマンドライン操作方法等)
Raspberry Pi 3に HDMI接続の 800x480 5インチ TFT液晶を接続して使用する方法
Raspberry Pi Raspbian Jessie 2017-07最終版で LIRCを使って学習リモコン、赤外線リモコンを送受信する方法
Raspberry Pi 3の WiFiを広告ブロック機能付きの無線LANアクセスポイント化 hostapd + dnsmasq編
Raspberry Pi 3の Bluetoothで ブルテザで通信する方法(Bluetooth編)
Raspberry Pi 3で日本語音声を合成して喋らせる方法(OpenJTalk編)
Raspberry Pi 3に USB Micを接続して日本語の音声認識をする方法(Julius編)
Raspberry Pi 3の GPIOに LEDとスイッチを接続して Lチカする方法
Raspberry Pi 3の GPIOに LEDとスイッチを接続してシャットダウンボタンを実装する方法
Raspberry Pi 3で GPIO端子の I2C機能を有効化する方法
Raspberry Pi 3の GPIOに I2C通信方式の気圧計 BMP280を接続する方法
Raspberry Pi 3に I2C通信方式の NFCリーダライタ PN532を接続して NFC FeliCaカードを読む方法
Raspberry Pi 3でネットワーク ライブカメラを構築する方法 Motion編
Raspberry Pi 3でネットワーク ライブカメラを構築する方法 MJPG-streamer編
Raspberry Pi 3 Model Bで動画処理アプリ FFmpegをコンパイルする方法
Raspberry Pi3の X-Window Systemに Windowsのリモートデスクトップから接続する方法
Raspberry Pi3に WebRTCの STUN/TRUNサーバと PeerJSサーバをインストールする方法
【成功版】Raspberry Piで NNPACK対応版の Darknet Neural Network Frameworkをビルドする方法


Espressif ESP8266 Arduino互換でスケッチが使える ESP-12Eモジュール基板
Espressif ESP8266 Arduino互換でスケッチが使える ESP-12Eモジュール基板

  Espressif ESP8266 ESP-12-E NodeMCU V1 ESP12 CP2102

BangGood通販はドローン以外にも面白い商品がまだまだ有った(電子工作編)
BangGood通販はドローン以外にも面白い商品がまだまだ有った(電子工作編)

  レーザー彫刻機、カラー液晶の DIYオシロ、Arduinoや Raspberry Pi用の小型カラー液晶




[HOME] | [BACK]
リンクフリー(連絡不要、ただしトップページ以外は Web構成の変更で移動する場合があります)
Copyright (c) 2017 FREE WING,Y.Sakamoto
Powered by 猫屋敷工房 & HTML Generator

http://www.neko.ne.jp/~freewing/raspberry_pi/raspberry_pi_3_phantomjs_211_jessie/