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

2017/11/01

Orange Piの活用方法 Ubuntu 16.04 Xenialで PhantomJS 2.1.1をビルドする方法 Orange Piの活用方法 Ubuntu 16.04 Xenialで PhantomJS 2.1.1をビルドする方法

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

Tags: [Raspberry Pi], [Orange Pi], [電子工作], [海外通販], [通信販売]





● 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のビルドが面倒な人用にバイナリをアップロードしました。

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

FREEWING-JP/phantomjs_binary_for_orange_pi_pc2 - PhantomJS 2.1.1 binary for Orange Pi PC 2 with Ubuntu 16.04 Xenial 2017-11


● Orange Pi PC 2の Ubuntu 16.04 Xenial版で PhantomJS 2.1.1をビルドする方法

 このページの内容は下記の Ubuntu Xenialで動作を確認しています。
# apt-get update, apt-get upgrade後
user@orangepipc2:~$ uname -a
Linux orangepipc2 4.13.12-sunxi64 #170 SMP Sat Nov 11 02:03:14 CET 2017 aarch64 aarch64 aarch64 GNU/Linux

user@orangepipc2:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.3 LTS
Release:        16.04
Codename:       xenial


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

openssl version
# OpenSSL 1.0.2g 1 Mar 2016


● Orange Pi PC 2の Swap領域をデフォルトの ZRAM圧縮メモリ方式からスワップファイル方式に変更します

# Swap領域をデフォルトの zram 497MBから SDカード 1GBに変更しました
 ※ スワップファイルのサイズが 640MBだと怪しいので 1GBに増やしました。
 ※ その後の再検証で スワップファイルのサイズが 640MBでも最後までビルドできました。
user@orangepipc2:~$ free -h
              total        used        free      shared  buff/cache   available
Mem:           994M         37M        875M        2.5M         81M        876M
Swap:          497M          0B        497M

user@orangepipc2:~$ grep -i --color swap /proc/meminfo
SwapCached:            0 kB
SwapTotal:        509280 kB
SwapFree:         509280 kB

user@orangepipc2:~$ swapon
NAME       TYPE        SIZE USED PRIO
/dev/zram0 partition 124.3M   0B    5
/dev/zram1 partition 124.3M   0B    5
/dev/zram2 partition 124.3M   0B    5
/dev/zram3 partition 124.3M   0B    5

 既存のスワップメモリを全部停止する。
user@orangepipc2:~$ sudo swapoff -a
[sudo] password for user:

user@orangepipc2:~$ swapon

user@orangepipc2:~$ free -h
              total        used        free      shared  buff/cache   available
Mem:           994M         48M        461M        4.4M        484M        855M
Swap:            0B          0B          0B

 スワップ領域の為のスワップファイルを作成して、スワップメモリとして設定する。
 ※ 下記では 1GBで設定していますが、その後の再検証で スワップファイルのサイズが 640MBでも最後までビルドできました。
# スワップ領域の為のスワップファイルを作成 1GB
sudo dd if=/dev/zero of=/var/tmp/swap.img bs=1M count=1024
# スワップファイルをスワップ領域として設定する
sudo mkswap /var/tmp/swap.img
# chmodでスワップファイルの属性を変更する
sudo chmod 0600 /var/tmp/swap.img
# スワップファイルをスワップ領域として有効にする
sudo swapon -p 1 /var/tmp/swap.img

# スワップ領域の確認
swapon
# NAME              TYPE SIZE USED PRIO
# /var/tmp/swap.img file 1024M   0B   1

free -h
#               total        used        free      shared  buff/cache   available
# Mem:           994M         35M        596M        4.7M        362M        874M
# Swap:          1.0G          0B        1.0G

# 再起動したら上記の設定は忘れて無効になる

 再起動した時にも上記の設定を永続化したい場合は下記の設定が追加で必要
# スワップ領域を /etc/fstabに記述する
sudo nano /etc/fstab

/var/tmp/swap.img         none                    swap    defaults        0 0

# nanoエディタで書き換えるのが面倒な場合は下記のコマンドラインで簡単に設定をする
sudo sh -c "echo /var/tmp/swap.img none swap defaults 0 0 >>/etc/fstab"

# /etc/fstabに記述したスワップ領域を有効にする
sudo swapon -a

cat /etc/fstab
# UUID=12345678-1234-1234-1234-123456789012 / ext4 defaults,noatime,nodiratime,commit=600,errors=remount-ro 0 1
# tmpfs /tmp tmpfs defaults,nosuid 0 0
# /var/tmp/swap.img none swap defaults 0 0

 ※ 再起動すると zramのスワップが復活する。

 zramの圧縮メモリのスワップが不要な場合は ZRAM機能を削除するか、ZRAMを設定しているスクリプトを書き換える
sudo apt-get -y remove --purge zram-config

sudo nano /usr/bin/init-zram-swapping
 または削除
rm /usr/bin/init-zram-swapping

● Ubuntuの仮想メモリデーモン kswapd kswapd0が CPU負荷 100%になる疑惑が有るので対策する

KswapD0 use 100% CPU

# /proc/sys/vm/drop_cachesを 1に設定する
sudo sh -c "echo 1 > /proc/sys/vm/drop_caches"

# /lib/udev/rules.d/40-vm-hotadd.rulesの 3行目を #でコメント化する
sudo nano /lib/udev/rules.d/40-vm-hotadd.rules
# ATTR{[dmi/id]sys_vendor}=="Xen", GOTO="vm_hotadd_apply"

# /lib/udev/rules.d/40-vm-hotadd.rulesの 3行目を #でコメント化する
# nanoエディタで書き換えるのが面倒な場合は下記のコマンドラインで簡単に設定できる
sudo sed -i -e 's/^ATTR{\[dmi\/id\]sys_vendor}=="Xen"/# ATTR{[dmi\/id]sys_vendor}=="Xen"/' /lib/udev/rules.d/40-vm-hotadd.rules


●その他のメモリ関連のコマンド
user@orangepipc2:~$ top
top - 01:03:39 up 52 min,  2 users,  load average: 4.12, 3.59, 2.38
Tasks:  96 total,   5 running,  91 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.1 us, 25.1 sy,  0.0 ni, 74.8 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  1018572 total,   324040 free,    66004 used,   628528 buff/cache
KiB Swap:   524284 total,   524284 free,        0 used.   840260 avail Mem

user@orangepipc2:~$ vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 4  0      0 324240  41104 587424    0    0    30    40  156  120 17  5 76  1  0


● How to build PhantomJS 2.1.1 on Orange Pi PC 2 with Ubuntu 16.04 Xenial 2017-11

 How to build PhantomJS 2.1.1 on Orange Pi PC 2 with Ubuntu 16.04 Xenial 2017-11
 Orange Pi PC2の Ubuntu 16.04 Xenialで 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のオレンジパイ PC2でもビルドできました。
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分です。

 ※ オレンジパイ PC2で 1コアでビルドで 9時間程度(--jobs 1の時、仮想メモリ 1.4GB)
 ※ オレンジパイ PC2で 2コアでビルドでスワップ頻発でコンパイル不可

# お決まりの手順
sudo apt-get update

# kswapd0 CPU 100%対策?
sudo apt-get -y upgrade

# ZRAM削除
sudo swapoff -a
sudo apt-get -y remove --purge zram-config

# OpenSSLのバージョンを確認
openssl version
# OpenSSL 1.0.2g  1 Mar 2016

# 日本語フォントをインストールする
sudo apt-get -y install fonts-ipafont

# 必要なバイナリ類をインストールする
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

# 仮想メモリを SDカード領域(スワップファイルを使用)に設定する。(上記参照)

# 仮想メモリデーモン kswapd kswapd0が CPU負荷 100%になる疑惑の対策(上記参照)

# 仮想メモリの設定をしたら念の為に再起動する
sudo reboot

# 仮想メモリの設定状態を確認する
# /proc/sys/vm/drop_cachesを 1に設定する
sudo sh -c "echo 1 > /proc/sys/vm/drop_caches"

swapon
# NAME              TYPE SIZE USED PRIO
# /var/tmp/swap.img file 1024M  0B    1

free -h
#               total        used        free      shared  buff/cache   available
# Mem:           994M         34M        877M        3.1M         82M        879M
# Swap:          1.0G          0B        1.0G

grep -i --color swap /proc/meminfo
# SwapCached:            0 kB
# SwapTotal:       1048572 kB
# SwapFree:        1048572 kB

# LEDの設定を変更する。
# なお Orange Pi PC2の場合のハートビート設定は CPUがハングアップしても点滅の動作は変になるが、点滅を続ける。
sudo sh -c "echo heartbeat > /sys/class/leds/orangepi\:red\:status/trigger"
sudo sh -c "echo mmc0 > /sys/class/leds/orangepi\:green\:pwr/trigger"

# CPUの動作周波数のガバナを Conservativeに設定して、電源への急激な負荷変動を発生しない様にする。
# Conservative設定は段階的に動作周波数を変化させるので負荷変動がマイルドになる。
sudo sh -c 'echo "conservative" >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor'

cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
# conservative
# conservative
# conservative
# conservative

・(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
・(2) 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

・(3) 下記でも大丈夫でした。2.1.1だけを取得するので一番無駄が少ない。
# -b 2.1.1で phantomjsの 2.1.1を指定する
cd
git clone git://github.com/ariya/phantomjs.git -b 2.1.1 --single-branch --depth=1
cd phantomjs

 (1)、(2)、(3)のどれかを実行して、以下は共通手順
# 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
#     Set version to "2.1.1"
#     Refs #12970

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

git submodule
#  19051aa97cecdcd3ef8c8862e36a3cb4cd3471fc src/qt/3rdparty (remotes/origin/msvc2013)
#  b5cc0083a5766e773885e8dd624c51a967c17de0 src/qt/qtbase (b5cc008)
#  e7b74331d695bfa8b77e39cdc50fc2d84a49a22a src/qt/qtwebkit (e7b7433)

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

# 9時間程度待つ(オレンジパイ PC 2で --jobs 1)
# --jobs 2でコンパイルに使用する CPUを 2個にした場合はスワップが頻発してコンパイル不可。

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

ls -l ./bin
# -rwxrwxr-x 1 user user 51273816 Nov 10 01:45 phantomjs

readelf -A ./bin/phantomjs
(何も出力されない)


● オレンジパイ PC2で PhantomJS 2.1.1をビルドするのに必要な時間を調べてみた。

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

 仮想メモリ(スワップファイル方式) 640MBの設定で、RenderingAllInOne.cppのコンパイルで長時間考え込んで実質ビルドが停止しました。(再現性有り)

 Ctrl + Cで中断して、再度 python ./build.py -c --jobs 1を実行すると RenderingAllInOne.cppのコンパイルから開始してコンパイル成功、その後のビルドを継続しました。
 メインメモリ 844MB / 995MB
 仮想メモリ 536MB / 640MB
・RenderingAllInOne.cppのコンパイルで長時間考え込んで実質ビルドが停止
RenderingAllInOne.cppのコンパイルで長時間考え込んで実質ビルドが停止


・RenderingAllInOne.cppのコンパイルで長時間考え込んで実質ビルドが停止
RenderingAllInOne.cppのコンパイルで長時間考え込んで実質ビルドが停止
RenderingAllInOne.cpp
real    519m6.573s
user    103m12.552s
sys     5m36.025s
QtCore -I.moc -I/home/user/phantomjs/src/qt/qtbase/mkspecs/linux-g++ -o .obj/rendering/RenderingAllInOne.o rendering/RenderingAllInOne.cpp

^CMakefile.WebCore.Target:136953: recipe for target '.obj/rendering/RenderingAllInOne.o' failed
make[2]: *** [.obj/rendering/RenderingAllInOne.o] Interrupt
Traceback (most recent call last):
  File "./build.py", line 458, in <module>
    main()
  File "./build.py", line 451, in main
    builder.run()
  File "./build.py", line 358, in run
    self.buildQtWebKit()
  File "./build.py", line 334, in buildQtWebKit
    if self.make("src/qt/qtwebkit") != 0:
  File "./build.py", line 145, in make
    return self.execute(self.makeCommand, path)
  File "./build.py", line 135, in execute
    process.wait()
  File "/usr/lib/python2.7/subprocess.py", line 1392, in wait
    pid, sts = _eintr_retry_call(os.waitpid, self.pid, 0)
  File "/usr/lib/python2.7/subprocess.py", line 476, in _eintr_retry_call
    return func(*args)
KeyboardInterrupt
Makefile.WebCore:68: recipe for target 'sub-Target-pri-make_first-ordered' failed
make[1]: *** [sub-Target-pri-make_first-ordered] Interrupt
Makefile:177: recipe for target 'sub-Source-WebCore-WebCore-pro-make_first-ordered' failed
make: *** [sub-Source-WebCore-WebCore-pro-make_first-ordered] Interrupt

real    571m57.917s
user    120m56.040s
sys     6m19.347s

 RenderingAllInOne.cppのコンパイル停止状態を Ctrl + Cで中断して、再度 python ./build.py -c --jobs 1を実行してからビルド完了までの時間は 41分。
make[1]: Leaving directory '/home/user/phantomjs/src'

real    75m51.195s
user    41m23.073s
sys     1m58.975s

 スワップ領域を 1.4GBにして再チャレンジ。
sudo dd if=/dev/zero of=/var/tmp/swap.img bs=1M count=1440

user@orangepipc2:~$ sudo sh -c "echo 1 > /proc/sys/vm/drop_caches"

user@orangepipc2:~$ cat /proc/sys/vm/drop_caches
1

user@orangepipc2:~$ swapon
NAME              TYPE SIZE USED PRIO
/var/tmp/swap.img file 1.4G   0B   -1

user@orangepipc2:~$ free -h
              total        used        free      shared  buff/cache   available
Mem:           994M         34M        902M        4.4M         57M        888M
Swap:          1.4G          0B        1.4G

user@orangepipc2:~$ grep -i --color swap /proc/meminfo
SwapCached:            0 kB
SwapTotal:       1474556 kB
SwapFree:        1474556 kB

 スワップ領域を 1.4GBの場合は、
 532分の 9時間で完了しました。(ラズパイよりも遅いじゃんか)
make[1]: Leaving directory '/home/user/phantomjs/src'

real    532m45.605s
user    464m43.944s
sys     25m7.300s

user@orangepipc2:~/phantomjs$ cat BUILD_START
Sun Nov 11 04:48:45 UTC 2017

user@orangepipc2:~/phantomjs$ cat BUILD_END
Sun Nov 11 13:41:30 UTC 2017


● オレンジパイ PC2で PhantomJS 2.1.1をビルドしている時のメモリ使用量

 スワップ領域を 1GBにして再チャレンジ。
sudo dd if=/dev/zero of=/var/tmp/swap.img bs=1M count=1024

user@orangepipc2:~$ sudo sh -c "echo 1 > /proc/sys/vm/drop_caches"

user@orangepipc2:~$ cat /proc/sys/vm/drop_caches
1

user@orangepipc2:~$ swapon
NAME              TYPE SIZE USED PRIO
/var/tmp/swap.img file 1024M   0B   -1

user@orangepipc2:~$ free -h
              total        used        free      shared  buff/cache   available
Mem:           994M         35M        596M        4.7M        362M        874M
Swap:          1.0G          0B        1.0G

user@orangepipc2:~$ grep -i --color swap /proc/meminfo
SwapCached:            0 kB
SwapTotal:       1048572 kB
SwapFree:        1048572 kB

 スワップ領域を 1GBの場合は、
 528分の 9時間で完了しました。(ラズパイよりも遅いじゃんか)
make[1]: Leaving directory '/home/user/phantomjs/src'

real    528m25.351s
user    464m19.387s
sys     25m7.432s

user@orangepipc2:~/phantomjs$ cat BUILD_START
Sun Nov 12 14:44:05 UTC 2017

user@orangepipc2:~/phantomjs$ cat BUILD_END
Sun Nov 12 23:32:30 UTC 2017

user@orangepipc2:~/phantomjs$ free -h
              total        used        free      shared  buff/cache   available
Mem:           994M         22M        502M        536K        470M        882M
Swap:          1.0G         22M        1.0G

user@orangepipc2:~/phantomjs$ ls -l ./bin/
total 50076
-rwxrwxr-x 1 user user 51273816 Nov 12 23:32 phantomjs


● オレンジパイ PC2で PhantomJS 2.1.1をビルドしている時のメモリ使用量

 スワップ領域を 640MBにして再チャレンジ。
 1GBで成功したので再度 640MBで試しました。結果 OK。

 541分の 9時間で完了しました。
make[1]: Leaving directory '/home/user/phantomjs/src'

real    541m11.320s
user    465m8.326s
sys     25m0.854s

user@orangepipc2:~/phantomjs$ cat BUILD_START
Wed Nov 15 14:28:11 UTC 2017
user@orangepipc2:~/phantomjs$ cat BUILD_END
Wed Nov 15 23:29:22 UTC 2017

user@orangepipc2:~/phantomjs$ ls -l ./bin/
total 50076
-rwxrwxr-x 1 user user 51273816 Nov 15 23:29 phantomjs

user@orangepipc2:~/phantomjs$ ./bin/phantomjs -v
2.1.1


● オレンジパイ PC2で PhantomJS 2.1.1をビルドしている時のメモリ使用量

python ./build.py -c --jobs 1

InspectorAllInOne.cpp

root@orangepipc2:~# free -h
              total        used        free      shared  buff/cache   available
Mem:           994M        900M         46M        352K         47M         27M
Swap:          511M        343M        168M


● 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

./phantomjs freewing_web_lazy.js

freewing_web_lazy.js
var page = require('webpage').create();
page.open('http://www.neko.ne.jp/~freewing/', function () {
  var count = 0;
  window.setInterval(function() {
      if (++count < 5) {
        page.evaluate(function() {
          window.document.body.scrollTop = document.body.scrollHeight;
        });
      }
      else {
        page.render('freewing_web_lazy.png');
        phantom.exit();
      }
  }, 1000);
});
freewing_web_error_no_japanese_font.png、PhantomJSでキャプチャした Web画像で日本語フォントが空白の場合
freewing_web_ok_japanese_font.png、PhantomJSで fonts-ipafontをインストールして日本語フォントが正常に描画された場合


● PhantomJSで Web画面をキャプチャしたら日本語が全部空白になった場合は日本語フォントをインストール

 PhantomJSで Web画面をキャプチャしたら日本語が全部空白になった場合は日本語フォントをインストールする。
sudo apt-get -y install fonts-ipafont


● Takao Fontとは?

# fonts-takao-pgothic
sudo apt-get -y install fonts-takao

 Takao Fontとは初期の IPAフォントの問題点を改善したフォント。
 (IPAフォントの初期の頃の問題点の改善で、2017年の現時点で配布されている IPAフォントには当てはまらない)

IPAフォント
 IPAフォント(アイピーエイ フォント)とは、独立行政法人情報処理推進機構 (IPA) によって配布されているコンピュータ用のフォントセットの1つであり、一般ユーザーの日常的な印刷に使用できる品位の日本語アウトラインフォントである。

Takao Fonts
 TakaoフォントはIPAフォントの派生版であり、コミュニティによって開発されています。本プロジェクトの主目的は、コミュニティによるフォントのバグ修正と改善の可能性を確保することです。
 「Takao」は、IPAフォントの元となったTBフォントのオリジナル・デザイナーである故・林隆男氏のファースト・ネームから頂きました。

 IPAの日本語フォントは fonts-ipafontでインストールできます。
# IPAの日本語フォント
sudo apt-get -y install fonts-ipafont



● PhantomJS 2.1.1

$ ./bin/phantomjs -v
2.1.1

user@orangepipc2:~/phantomjs$ ./bin/phantomjs -h
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.
user@orangepipc2:~/phantomjs$ readelf -h ./bin/phantomjs
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 03 00 00 00 00 00 00 00 00
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - GNU
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           AArch64
  Version:                           0x1
  Entry point address:               0x418470
  Start of program headers:          64 (bytes into file)
  Start of section headers:          51271640 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         10
  Size of section headers:           64 (bytes)
  Number of section headers:         34
  Section header string table index: 31

user@orangepipc2:~/phantomjs$ readelf -V ./bin/phantomjs

Version symbols section '.gnu.version' contains 941 entries:
 Addr: 000000000040c644  Offset: 0x00c644  Link: 5 (.dynsym)
 ~~ 省略 ~~

Version needs section '.gnu.version_r' contains 10 entries:
 Addr: 0x000000000040cda0  Offset: 0x00cda0  Link: 6 (.dynstr)
  000000: Version: 1  File: ld-linux-aarch64.so.1  Cnt: 1
  0x0010:   Name: GLIBC_2.17  Flags: none  Version: 19
  0x0020: Version: 1  File: libz.so.1  Cnt: 1
  0x0030:   Name: ZLIB_1.2.0  Flags: none  Version: 16
  0x0040: Version: 1  File: libdl.so.2  Cnt: 1
  0x0050:   Name: GLIBC_2.17  Flags: none  Version: 15
  0x0060: Version: 1  File: libgcc_s.so.1  Cnt: 2
  0x0070:   Name: GCC_3.4  Flags: none  Version: 17
  0x0080:   Name: GCC_3.0  Flags: none  Version: 13
  0x0090: Version: 1  File: libssl.so.1.0.0  Cnt: 2
  0x00a0:   Name: OPENSSL_1.0.1  Flags: none  Version: 11
  0x00b0:   Name: OPENSSL_1.0.0  Flags: none  Version: 7
  0x00c0: Version: 1  File: libstdc++.so.6  Cnt: 6
  0x00d0:   Name: CXXABI_1.3.8  Flags: none  Version: 18
  0x00e0:   Name: GLIBCXX_3.4.9  Flags: none  Version: 14
  0x00f0:   Name: GLIBCXX_3.4.11  Flags: none  Version: 12
  0x0100:   Name: CXXABI_1.3  Flags: none  Version: 9
  0x0110:   Name: GLIBCXX_3.4.21  Flags: none  Version: 8
  0x0120:   Name: GLIBCXX_3.4  Flags: none  Version: 6
  0x0130: Version: 1  File: libcrypto.so.1.0.0  Cnt: 2
  0x0140:   Name: OPENSSL_1.0.2  Flags: none  Version: 10
  0x0150:   Name: OPENSSL_1.0.0  Flags: none  Version: 5
  0x0160: Version: 1  File: libpthread.so.0  Cnt: 1
  0x0170:   Name: GLIBC_2.17  Flags: none  Version: 4
  0x0180: Version: 1  File: libm.so.6  Cnt: 1
  0x0190:   Name: GLIBC_2.17  Flags: none  Version: 3
  0x01a0: Version: 1  File: libc.so.6  Cnt: 1
  0x01b0:   Name: GLIBC_2.17  Flags: none  Version: 2

● apt-get install libfontconfig1-dev
user@orangepipc2:~$ ./phantomjs
./phantomjs: error while loading shared libraries: libfontconfig.so.1: cannot open shared object file: No such file or directory

sudo apt-get install libfontconfig1-dev


● 以下は PhantomJS 2.1.1を Orange Pi PC 2でビルドする時に悪戦苦闘した時のメモ

 Orange Pi PC 2の Ubuntu 16.04 xenialはデフォルトでメインメモリを使用したスワップ設定が有効になっています。
 当初、free -hで swapが 497MBになっているのを確認した時、SDカード領域にスワップ領域を確保している物と思っていました。
 (ラズパイの場合はデフォルトで 100MBのスワップファイル)
user@orangepipc2:~$ uname -a
Linux orangepipc2 4.13.11-sunxi64 #116 SMP Sun Nov 5 01:54:42 CET 2017 aarch64 aarch64 aarch64 GNU/Linux

user@orangepipc2:~$ free -h
              total        used        free      shared  buff/cache   available
Mem:           994M         37M        875M        2.5M         81M        876M
Swap:          497M          0B        497M

user@orangepipc2:~$ grep -i --color swap /proc/meminfo
SwapCached:            0 kB
SwapTotal:        509280 kB
SwapFree:         509280 kB

user@orangepipc2:~$ swapon
NAME       TYPE        SIZE USED PRIO
/dev/zram0 partition 124.3M   0B    5
/dev/zram1 partition 124.3M   0B    5
/dev/zram2 partition 124.3M   0B    5
/dev/zram3 partition 124.3M   0B    5
 しかし、実際は ZRAMと言う圧縮技術を用いたメインメモリをスワップ領域として使用する物でした。
 そのため、デフォルトの状態で PhantomJSをビルドしようとするとコンパイラがコンパイル時にメモリ不足の為にハングアップしたり、メモリ不足エラーや不可解なエラーを発生させてマトモにビルドできません。

 以下は、その過程のゴミメモです。
 -I/home/user/phantomjs/src/qt/qtbase/include/QtGui -I/home/user/phantomjs/src/qt/qtbase/include/QtNetwork -I/home/user/phantomjs/src/qt/qtbase/include/QtSql -I/home/user/phantomjs/src/qt/qtbase/include/QtCore/5.5.1 -I/home/user/phantomjs/src/qt/qtbase/include/QtCore/5.5.1/QtCore -I/home/user/phantomjs/src/qt/qtbase/include/QtCore -I.moc -I/home/user/phantomjs/src/qt/qtbase/mkspecs/linux-g++ -o .obj/loader/appcache/ApplicationCacheAllInOne.o loader/appcache/ApplicationCacheAllInOne.cpp
virtual memory exhausted: Cannot allocate memory

Makefile.WebCore.Target:136000: recipe for target '.obj/loader/appcache/ApplicationCacheAllInOne.o' failed
make[2]: *** [.obj/loader/appcache/ApplicationCacheAllInOne.o] Error 1
make[2]: *** Waiting for unfinished jobs....
Makefile.WebCore.Target:135993: recipe for target '.obj/inspector/InspectorAllInOne.o' failed
make[2]: *** [.obj/inspector/InspectorAllInOne.o] Error 1
make[2]: Leaving directory '/home/user/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/user/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.
/home/user/phantomjs/src/qt/qtwebkit/Source/WebCore//libWebCore.a: member /home/user/phantomjs/src/qt/qtwebkit/Source/WebCore//.obj/rendering/svg/RenderSVGAllInOne.o in archive is not an object
collect2: error: ld returned 1 exit status
Makefile.phantomjs:261: recipe for target '../bin/phantomjs' failed
make[1]: *** [../bin/phantomjs] Error 1
make[1]: Leaving directory '/home/user/phantomjs/src'
Makefile:42: recipe for target 'sub-src-phantomjs-pro-make_first-ordered' failed
make: *** [sub-src-phantomjs-pro-make_first-ordered] Error 2

ERROR: Failed to build PhantomJS! Building PhantomJS failed.

user@orangepipc2:~/phantomjs$ ls -l /home/user/phantomjs/src/qt/qtwebkit/Source/WebCore//.obj/rendering/svg/RenderSVGAllInOne.o
-rw-rw-r-- 1 user user 0 Nov  7 20:30 /home/user/phantomjs/src/qt/qtwebkit/Source/WebCore//.obj/rendering/svg/RenderSVGAllInOne.o
/home/user/phantomjs/src/qt/qtwebkit/Source/WebCore//libWebCore.a: member /home/user/phantomjs/src/qt/qtwebkit/Source/WebCore//.obj/svg/SVGAllInOne.o in archive is not an object
collect2: error: ld returned 1 exit status
Makefile.phantomjs:261: recipe for target '../bin/phantomjs' failed
make[1]: *** [../bin/phantomjs] Error 1
make[1]: Leaving directory '/home/user/phantomjs/src'
Makefile:42: recipe for target 'sub-src-phantomjs-pro-make_first-ordered' failed
make: *** [sub-src-phantomjs-pro-make_first-ordered] Error 2

ERROR: Failed to build PhantomJS! Building PhantomJS failed.

user@orangepipc2:~/phantomjs$ ls -l /home/user/phantomjs/src/qt/qtwebkit/Source/WebCore//.obj/svg/SVGAllInOne.o
-rw-rw-r-- 1 user user 0 Nov  7 20:30 /home/user/phantomjs/src/qt/qtwebkit/Source/WebCore//.obj/svg/SVGAllInOne.o
cd Source/ThirdParty/leveldb/ && ( test -e Makefile.leveldb || /home/user/phantomjs/src/qt/qtbase/bin/qmake /home/user/phantomjs/src/qt/qtwebkit/Source/ThirdParty/leveldb/leveldb.pro WEBKIT_CONFIG-=build_webkit2 WEBKIT_CONFIG-=netscape_plugin_api WEBKIT_CONFIG-=use_gstreamer WEBKIT_CONFIG-=use_gstreamer010 WEBKIT_CONFIG-=use_native_fullscreen_video WEBKIT_CONFIG-=video WEBKIT_CONFIG-=web_audio -o Makefile.leveldb ) && make -f Makefile.leveldb
make[1]: Entering directory '/home/user/phantomjs/src/qt/qtwebkit/Source/ThirdParty/leveldb'
( test -e Makefile.Target || /home/user/phantomjs/src/qt/qtbase/bin/qmake /home/user/phantomjs/src/qt/qtwebkit/Source/ThirdParty/leveldb/Target.pri WEBKIT_CONFIG-=build_webkit2 WEBKIT_CONFIG-=netscape_plugin_api WEBKIT_CONFIG-=use_gstreamer WEBKIT_CONFIG-=use_gstreamer010 WEBKIT_CONFIG-=use_native_fullscreen_video WEBKIT_CONFIG-=video WEBKIT_CONFIG-=web_audio -o Makefile.Target ) && make -f Makefile.Target
make[2]: Entering directory '/home/user/phantomjs/src/qt/qtwebkit/Source/ThirdParty/leveldb'
make[2]: Nothing to be done for 'first'.
make[2]: Leaving directory '/home/user/phantomjs/src/qt/qtwebkit/Source/ThirdParty/leveldb'
make[1]: Leaving directory '/home/user/phantomjs/src/qt/qtwebkit/Source/ThirdParty/leveldb'
cd Source/WebCore/ && ( test -e Makefile.WebCore || /home/user/phantomjs/src/qt/qtbase/bin/qmake /home/user/phantomjs/src/qt/qtwebkit/Source/WebCore/WebCore.pro WEBKIT_CONFIG-=build_webkit2 WEBKIT_CONFIG-=netscape_plugin_api WEBKIT_CONFIG-=use_gstreamer WEBKIT_CONFIG-=use_gstreamer010 WEBKIT_CONFIG-=use_native_fullscreen_video WEBKIT_CONFIG-=video WEBKIT_CONFIG-=web_audio -o Makefile.WebCore ) && make -f Makefile.WebCore
make[1]: Entering directory '/home/user/phantomjs/src/qt/qtwebkit/Source/WebCore'
( test -e Makefile.WebCore.DerivedSources || /home/user/phantomjs/src/qt/qtbase/bin/qmake /home/user/phantomjs/src/qt/qtwebkit/Source/WebCore/DerivedSources.pri WEBKIT_CONFIG-=build_webkit2 WEBKIT_CONFIG-=netscape_plugin_api WEBKIT_CONFIG-=use_gstreamer WEBKIT_CONFIG-=use_gstreamer010 WEBKIT_CONFIG-=use_native_fullscreen_video WEBKIT_CONFIG-=video WEBKIT_CONFIG-=web_audio -o Makefile.WebCore.DerivedSources ) && make -f Makefile.WebCore.DerivedSources
make[2]: Entering directory '/home/user/phantomjs/src/qt/qtwebkit/Source/WebCore'
make[2]: Nothing to be done for 'first'.
make[2]: Leaving directory '/home/user/phantomjs/src/qt/qtwebkit/Source/WebCore'
( test -e Makefile.WebCore.Target || /home/user/phantomjs/src/qt/qtbase/bin/qmake /home/user/phantomjs/src/qt/qtwebkit/Source/WebCore/Target.pri WEBKIT_CONFIG-=build_webkit2 WEBKIT_CONFIG-=netscape_plugin_api WEBKIT_CONFIG-=use_gstreamer WEBKIT_CONFIG-=use_gstreamer010 WEBKIT_CONFIG-=use_native_fullscreen_video WEBKIT_CONFIG-=video WEBKIT_CONFIG-=web_audio -o Makefile.WebCore.Target ) && make -f Makefile.WebCore.Target
make[2]: Entering directory '/home/user/phantomjs/src/qt/qtwebkit/Source/WebCore'
make[2]: *** .obj/generated/MathMLElementFactory.d: Input/output error.  Stop.
make[2]: Leaving directory '/home/user/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/user/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.

user@orangepipc2:~/phantomjs$ free
-bash: /usr/bin/free: Input/output error
--jobs 2でコンパイルに使用する CPUを 2個にした場合の DOMAllInOne.cppビルド時の top
(スワップファイルは 1440MBを設定。kswapd対策設定は無しの状態)

user@orangepipc2:~$ top
top - 23:26:43 up 11:06,  2 users,  load average: 3.51, 3.62, 3.53
Tasks: 104 total,   1 running, 103 sleeping,   0 stopped,   0 zombie
%Cpu(s):  6.2 us,  1.6 sy,  0.0 ni, 42.4 id, 49.8 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  1018572 total,    87480 free,   879056 used,    52036 buff/cache
KiB Swap:  1474556 total,   326884 free,  1147672 used.    72808 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
22109 user      20   0  982868 599464   6784 D  19.3 58.9   2:13.57 cc1plus
  162 root      20   0       0      0      0 S  10.0  0.0  29:42.28 mmcqd/0
21408 user      20   0  953944 205644   6056 D   5.3 20.2   4:09.72 cc1plus
   94 root      20   0       0      0      0 D   0.7  0.0   1:07.81 kswapd0
  334 root      20   0    7604      0      0 S   0.3  0.0   0:22.82 haveged
22570 user      20   0    7348   3124   2640 R   0.3  0.3   0:00.08 top
    1 root      20   0  154432   2556   1812 S   0.0  0.3   0:08.39 systemd



Tags: [Raspberry Pi], [Orange Pi], [電子工作], [海外通販], [通信販売]

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

ラズパイを意識した別物製品 Orange Pi Zeroを買ってみた、Allwinner H2+ Cortex-A7 4core
ラズパイを意識した別物製品 Orange Pi Zeroを買ってみた、Allwinner H2+ Cortex-A7 4core

  オレンジパイはラズパイよりもコスパは良いが情報が無いので利用者側に一定のスキルが必要

Orange Pi PC 2を買ってみた、Allwinner H5 Cortex-A53 4core ARM64
Orange Pi PC 2を買ってみた、Allwinner H5 Cortex-A53 4core ARM64

  ラズパイを意識した別物製品、オレンジパイはラズパイよりもコスパが良い、でも情報が無い

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の Linuxコンソール上で使用する各種コマンドまとめ
Raspberry Pi 3の Linuxコンソール上で使用する各種コマンドまとめ

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

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

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

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/orange_pi_pc2_phantomjs_211_xenial/