とりあえず日記

VIM→秀丸エディタ→VIM→秀丸エディタ→VIM→秀丸エディタ→VIM→秀丸エディタ→VIM→秀丸エディタ→VIM→秀丸エディタ(いまここ🍄)

【Raspberry Pi3 + CentOS7】irqbalanceがメモリリークする

メモリリーク直りました。(2018/04/11)
http://d.hatena.ne.jp/ohtorii/20180411


以下はメモリリークしていた当時の状況です。

はじめに

当方の家庭内LANでは、Raspberry Pi 3 Model B にCentOS7をインストールして運用しています。


運用しているとRaspberry Piの使用メモリが増えていくので原因を調べたところ、
irqbalanceというデーモンがメモリリークしていました。

メモリリークの状態

Raspberry Pi起動直後のメモリ状態(約58MBのメモリ消費)

$ ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root       220  0.0  5.9  58280 56172 ?        Ss   03:00   0:18 /usr/sbin/irqbalance --foreground


こちらは、一日経過後のメモリ状態(約452MBのメモリ消費)

$ ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root       225  0.0 47.6 454380 452352 ?       Ss   Feb21   2:29 /usr/sbin/irqbalance --foreground


Raspberry Piはメモリが1GBなので約半分の領域がリークしたメモリという状況でした。

とりあえずメモリリークを調査してみる

運用中のirqbalanceが古すぎてバグ修正されていないかもしれないので、
手始めにバージョンを確認。

$ yum list|grep irqbalance
irqbalance.armv7hl                       2:1.0.7-1.el7.centos           @centos-base_rbf

version 1.0.7ですね。

irqbalanceの更新履歴によると最新版は1.3.0です、更に1.0.7以降でメモリリークの修正が行なわれています。
https://github.com/Irqbalance/irqbalance/releasesirqbalance

バージョンが古いのが原因かも?
yumではirqbalanceの新バージョンが落ちてこないので、ソースコードからビルドするしか手が無いのかな?

回避策

irqbalanceを1時間毎に再起動(crontab)させて回避しています。

今後について

irqbalanceが yum で落ちてきたらまた記事にします。

注意

Unix系のOSは初心者なので派手に勘違いしていることがあります。
ご注意ください🙏

久しぶりにclang-interpreterを試してみた

何年も前にC++interpreterであるclang-interpreterを試した記事を書きました。
http://d.hatena.ne.jp/ohtorii/20110716/1310783800
秀丸エディタからclang-interpreterを呼び出してみた - とりあえず日記


当時は、STLWindowsのヘッダファイルを扱うことが出来ない状況でした。
あれからClang/LLVMも相当バージョンアップされてるので、
気まぐれで久しぶりにビルドして動作を試してみました。

結果

相変わらず、STLWindowsのヘッダファイルを扱えないです。
まあ、clang-interpreterはサンプルという位置づけなので真面目に実装されていないのかもしれません。

環境

LLVM 5.0.1
Microsoft Visual Studio Community 2017 Version 15.5.7

ビルド手順

VisualStudio2017でビルドしてclang-interpreter.exeを作ります。
(Clang/LLVMのマニュアルに従えば簡単に実行ファイルを作れます、なのでビルド手順は省略します。)

動かしてみた。(printf)

//sample_0.cpp
include<stdio.h>

int main(int argc, char*argv[]){
	for(int i=0; i!=4 ; ++i){
		printf("i=%d\n",i);
	}
	return 0;
}
> clang-interpreter.exe sample_0.cpp
i=0
i=1
i=2
i=3

おっ、正しく動いています。

動かしてみた。(file i/o)

//sample_1.cpp
#include<stdio.h>

int main(int argc, char*argv[]){
	FILE* fp=fopen("out.txt","wt");
	fprintf(fp,"%s\n","hello clang");
	fprintf(fp,"%s\n","こんにちわ、clang");
	fclose(fp);
	return 0;
}
> clang-interpreter.exe sample_1.cpp
sample_1.cpp:4:11: warning: 'fopen' is deprecated: This function or variable may
      be unsafe. Consider using fopen_s instead. To disable deprecation, use
      _CRT_SECURE_NO_WARNINGS. See online help for details.
      [-Wdeprecated-declarations]
        FILE* fp=fopen("out.txt","wt");
                 ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ucrt\stdio.h:206:20: note:
      'fopen' has been explicitly marked deprecated here
    _Check_return_ _CRT_INSECURE_DEPRECATE(fopen_s)
                   ^
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\vcruntime.h:255:55: note:
      expanded from macro '_CRT_INSECURE_DEPRECATE'
        #define _CRT_INSECURE_DEPRECATE(_Replacement) _CRT_DEPRECATE_TEXT(    \
                                                      ^
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\vcruntime.h:245:47: note:
      expanded from macro '_CRT_DEPRECATE_TEXT'
#define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
                                              ^
1 warning generated.
> type out.txt
hello clang
こんにちわ、clang

fopen関数じゃなくてfopen_s関数を使えと警告されましたが正しい結果を得られました。

動かしてみた。(class)

//sample_2.cpp
#include<stdio.h>

template<class T>
class add{
public:
	add(T v) : m_base(v){
	}
	T operator()(T v)const{
		return v + m_base;
	};
private:
	T	m_base;
};

int main(int argc, char*argv[]){
	add<int>	obj(10);
	printf("value=%d\n", obj(20));
	return 0;
}
> clang-interpreter.exe sample_2.cpp
value=30

こちらも、ちゃんと動いています。

動かしてみた。(Global ctor/dtor)

//sample_3.cpp
#include<stdio.h>

class foo{
public:
	foo(){
		printf("ctor\n");
	}
	~foo(){
		printf("dtor\n");
	}
};

foo g;	//  <------- Global ctor/dtor.

int main(int argc, char*argv[]){
	printf("Enter main.\n");
	return 0;
}
> clang-interpreter.exe sample_3.cpp

LLVM ERROR: Undefined temporary symbol

エラーです。

動かしてみた。(STL)

//sample_4.cpp
#include<vector>
int main(int argc, char*argv[]){
	std::vector<int> v;
}
> clang-interpreter.exe sample_4.cpp
LLVM ERROR: Undefined temporary symbol

またまた、エラーです。

動かしてみた。(windows.h)

//sample_5.cpp
#include<windows.h>
int main(int argc, char*argv[]){
    DWORD t=MessageBox(NULL,"foo","bar", MB_OK);
    return 0;
}
>clang-interpreter.exe sample_5.cpp
In file included from sample_5.cpp:1:
In file included from C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um\windows.h:171:
In file included from C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\shared\windef.h:24:
In file included from C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\shared\minwindef.h:182:
C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um\winnt.h:959:5: error:
      MS-style inline assembly is not available: Unable to find target for this
      triple (no targets are registered)
    __asm    {
    ^
C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um\winnt.h:975:5: error:
      MS-style inline assembly is not available: Unable to find target for this
      triple (no targets are registered)
    __asm {
    ^
C:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um\winnt.h:991:5: error:
      MS-style inline assembly is not available: Unable to find target for this
      triple (no targets are registered)
    __asm    {
    ^
3 errors generated.

__asm構文で怒られました。

試したこと

幾つかエラーが発生したので回避できないかソースコードをいじくって試行錯誤してみました。
雰囲気でソースコードを変更しているので期待する動作は得られませんでした。

対象のソースコード
\llvm\tools\clang\examples\clang-interpreter\main.cpp


試行錯誤した痕跡。

#if 0 /* Original */
  // FIXME: This is a hack to try to force the driver to do something we can
  // recognize. We need to extend the driver library to support this use model
  // (basically, exactly one input, and the operation mode is hard wired).
  SmallVector<const char *, 16> Args(argv, argv + argc);
  Args.push_back("-fsyntax-only");
#else /* Modify */
  SmallVector<const char *, 256> Args(argv, argv + argc);
  Args.push_back("-fsyntax-only");
  Args.push_back("-fms-compatibility-version=19.00");
  Args.push_back("-fms-compatibility");
  Args.push_back("-fms-extensions");
  //Args.push_back("-fmsc-version=1912");
  //Args.push_back("--target=x86_64-windows-msvc");    //Clash.
  //Args.push_back("--target=i686-windows-msvc");      //LLVM ERROR: Program used external function '___stdio_common_vfprintf' which could not be resolved!
  //Args.push_back("--target=i686-pc-win32");          //LLVM ERROR: Program used external function '___stdio_common_vfprintf' which could not be resolved!
  //Args.push_back("--target=x86_64-pc-windows-msvc"); //Crash.
  //Args.push_back("--target=x86_64");                 //sample_0.cpp:1:9: fatal error: 'stdio.h' file not found
  //Args.push_back("--target=");
#endif

最後に

元々、深入りするつもりもないのでこの辺にしておきます。

CentO7にonedrive-devをインストールしてみた

CentOS7でOneDriveを利用するために、onedrived-devのパッケージをインストールしたときの作業メモです。

結果

onedrived-devを手作業でインストールしてOneDriveのアカウント追加まで行いました。
ローカルドライブとクラウド側のOneDriveとファイルを同期するには、ngrokのインストールとアカウント登録が必要らしいので、
面倒になって絶賛放置中です。


以下、作業メモです。

CentOSのイメージ

CentOS-7-x86_64-Minimal-1708.iso

手順

yum -y install git

yum install -y https://centos7.iuscommunity.org/ius-release.rpm
yum install -y python34 python34-libs python34-devel python34-pip python34-dbus python34-tools
yum install -y gccngrok - secure introspectable tunnels to localhost

yum search libssl-devは見つからず。

yum search libssl-dev
snip
警告: 一致するものが見つかりません: libssl-dev
No match found

libssl-devはOpenSSLだと思うのでインストール

yum -y install openssl-libs openssl-devel

yum -y install inotify-tools

build-essentialは、

To install those dependencies on Ubuntu, use apt-get command:
# Install gcc and other C-level pre-requisites.
$ sudo apt-get install build-essential python3-dev libssl-dev inotify-tools python3-dbus

build-essentialは、多分Ubuntuで必要なパッケージなので、CentOSでは無視していいかも。
私はとりあえず以下ページを参考にしてCentOSにインストールしました。
http://blog.64p.org/entry/2013/07/22/142457

yum groupinstall "Development Tools"
yum install kernel-devel kernel-headers

sudo pip3 install -U keyrings.alt
Collecting keyrings.alt
Downloading keyrings.alt-2.3-py2.py3-none-any.whl
Requirement already up-to-date: six in /root/.local/lib/python3.4/site-packages (from keyrings.alt)
Installing collected packages: keyrings.alt
Successfully installed keyrings.alt-2.3

Install onedrived

pip3 install --user git+https://github.com/xybu/onedrived-dev.git

checking for DBUS... no
configure: error: Package requirements (dbus-1 >= 1.6) were not met:

No package 'dbus-1' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables DBUS_CFLAGS
and DBUS_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-build-sh0vgtxc/dbus-python/setup.py", line 106, in 'build_ext': BuildExt,
File "/root/.local/lib/python3.4/site-packages/setuptools/__init__.py", line 129, in setup
return distutils.core.setup(**attrs)
File "/usr/lib64/python3.4/distutils/core.py", line 148, in setup
dist.run_commands()
File "/usr/lib64/python3.4/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/usr/lib64/python3.4/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/root/.local/lib/python3.4/site-packages/setuptools/command/install.py", line 61, in run
return orig.install.run(self)
File "/usr/lib64/python3.4/distutils/command/install.py", line 539, in run self.run_command('build')
File "/usr/lib64/python3.4/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/usr/lib64/python3.4/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/tmp/pip-build-sh0vgtxc/dbus-python/setup.py", line 62, in run
cwd=builddir)
File "/usr/lib64/python3.4/subprocess.py", line 558, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/tmp/pip-build-sh0vgtxc/dbus-python/configure', '--disable-maintainer-mode', 'PYTHON=/usr/bin/python3.4', '--prefix=/tmp/pip-build-sh0vgtxc/dbus-python/build/temp.linux-x86_64-3.4/prefix']' returned non-zero exit status 1

----------------------------------------
Command "/usr/bin/python3.4 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-_fpfln70/dbus-python/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-bfx2au8s-record/install-record.txt --single-version-externally-managed --compile --user --prefix=" failed with error code 1 in /tmp/pip-build-_fpfln70/dbus-python/
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

え〜〜〜〜

configure: error: Package requirements (dbus-1 >= 1.6) were not met:

エラーは、No package 'dbus-1' found なので、yumdbus-1をインストール。

yum install dbus-devel

pip3 install --user git+https://github.com/xybu/onedrived-dev.git
configure: error: Package requirements (dbus-glib-1 >= 0.70) were not met:

No package 'dbus-glib-1' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables DBUS_GLIB_CFLAGS
and DBUS_GLIB_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-build-zrls2wle/dbus-python/setup.py", line 106, in
'build_ext': BuildExt,
snip

今度は、dbus-glib-1が見つからないのでyumで追加インストールして、pip3...を再実行。

yum install dbus-glib-devel
pip3 install --user git+https://github.com/xybu/onedrived-dev.git

snip

Installing collected packages: dbus-python, onedrived
Running setup.py install for dbus-python ... done
Running setup.py install for onedrived ... done
Successfully installed dbus-python-1.2.4 onedrived-2.0.0
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

今度は成功!!

Install from source manually

git clone https://github.com/xybu/onedrived-dev.git
cd onedrived-dev

python3 ./setup.py test

snip

Traceback (most recent call last):
File "./setup.py", line 63, in
zip_safe=False
File "/usr/lib64/python3.4/distutils/core.py", line 148, in setup
dist.run_commands()
File "/usr/lib64/python3.4/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/usr/lib64/python3.4/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/usr/lib/python3.4/site-packages/setuptools/command/test.py", line 148, in run
self.distribution.install_requires)
File "/usr/lib/python3.4/site-packages/setuptools/dist.py", line 312, in fetch_build_eggs
replace_conflicting=True,
File "/usr/lib/python3.4/site-packages/pkg_resources/__init__.py", line 846, in resolve
dist = best[req.key] = env.best_match(req, ws, installer)
File "/usr/lib/python3.4/site-packages/pkg_resources/__init__.py", line 1084, in best_match
dist = working_set.find(req)
File "/usr/lib/python3.4/site-packages/pkg_resources/__init__.py", line 721, in find
raise VersionConflict(dist, req)
pkg_resources.VersionConflict: (setuptools 19.2 (/usr/lib/python3.4/site-packages), Requirement.parse('setuptools>=30.0.0'))

setuptoolのバージョンが古いという旨のエラーが出力されるので、setuptoolのバージョンを更新する

wget https://pypi.python.org/packages/6c/54/f7e9cea6897636a04e74c3954f0d8335cc38f7d01e27eec98026b049a300/setuptools-38.5.1.zip
sudo pip3 install ./setuptools-33.1.1.zip

再度テストを実行。

python3 ./setup.py test

snip

No package 'libffi' found
c/_cffi_backend.c:15:17: 致命的エラー: ffi.h: そのようなファイルやディレクトリはありません
#include
^
コンパイルを停止しました。
error: Setup script exited with error: command 'gcc' failed with exit status 1

libffiが見つからないのでインストール。

sudo yum -y install libffi-devel

再度、テストを実行

python3 ./setup.py test

snip

Running requests-mock-1.4.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-peaamvum/requests-mock-1.4.0/egg-dist-tmp-xtmm2215
Download error on https://pypi.python.org/simple/pbr/: [Errno -2] Name or service not known -- Some packages may not be found!
Couldn't find index page for 'pbr' (maybe misspelled?)
No local packages or working download links found for pbr
error: Could not find suitable distribution for Requirement.parse('pbr')

pbrが見つからないのでインストール。

sudo pip3 install pbr

再度、テストを実行

python3 ./setup.py test

snip

test_handle_update (tests.test_tasks.TestUpdateSubscriptionTask) ... ok
test_lifecycle (tests.test_threads.TestTaskWorkerThread) ... ok
test_recognize_event_patterns (tests.test_watcher.TestLocalRepositoryWatcher) ... ok
test_execution (tests.test_webhook_worker.TestWebhookWorker) ... ERROR:root:Unknown subscription ID "233".
ok

                                                                                                                                          • -

Ran 86 tests in 2.858s

OK

テストに合格しました!!長かった・・・

途中ですが

マニュアルに従ってインストールを行いましたが、
ngrokのインストールとアカウント登録が必要らしいので、
面倒になって絶賛放置中です。

Free Client for OneDrive on Linuxをサービス化する

はじめに

Free Client for OneDrive on LinuxをCentOS7でサービス化する方法です。
GitHub - skilion/onedrive: Free Client for OneDrive on Linux

OneDriveをインストールする

yum install onedrive - とりあえず日記

コマンドを作る

/opt/onedrive.sh というスクリプトを用意します。

onedriveをhogeという一般ユーザーで実行しています。

/opt/onedrive.sh

#!/bin/bash
sudo -u hoge onedrive --monitor --syncdir /home/OneDrive --confdir /home/hoge/.config/onedrive

実行権限を与えます。

sudo chmod 0755 /opt/onedrive.sh

/etc/systemd/system/ の下にUnit定義ファイルを作る

/etc/systemd/system/onedrive.service

[Unit]
Description = onedrive daemon

[Service]
ExecStart = /opt/onedrive.sh
Restart = always
Type = simple

[Install]
WantedBy = multi-user.target

UnitがServiceとして認識されたか確認する

$ sudo systemctl list-unit-files --type=service | grep onedrive
onedrive.service disabled

systemctlコマンドでUnitを起動する

# 自動起動on
$ sudo systemctl enable onedrive
# 起動
$ sudo systemctl start onedrive

状態の確認。

$ systemctl status onedrive

● onedrive.service - onedrive daemon
Loaded: loaded (/etc/systemd/system/onedrive.service; enabled; vendor preset: disabled)
Active: active (running) since 土 2018-02-10 14:28:04 JST; 4s ago
Main PID: 1287 (onedrive.sh)
CGroup: /system.slice/onedrive.service
├─1287 /bin/bash /opt/onedrive.sh
├─1288 sudo -u hoge onedrive --monitor --syncdir /home/OneDrive --confdir /home/hoge/.config/onedrive
└─1289 onedrive --monitor --syncdir /home/OneDrive --confdir /home/hoge/.config/onedrive

2月 10 14:28:04 localhost.localdomain systemd[1]: Started onedrive daemon.
2月 10 14:28:04 localhost.localdomain systemd[1]: Starting onedrive daemon...
2月 10 14:28:05 localhost.localdomain sudo[1288]: root : TTY=unknown ; PWD=/ ; USER=hoge ; COMMAND=/bin/onedr...drive
Hint: Some lines were ellipsized, use -l to show in full.

yum install onedrive

パッケージを検索するサイト(https://pkgs.org)でonedriveのパッケージを見付けたのでCentOS7にyumでインストールしてみました。

パッケージの詳細

https://centos.pkgs.org/7/harbottle-main-x86_64/onedrive-1.0.1.20180106gitc7e0930-1.el7.harbottle.x86_64.rpm.html

どうやら https://github.com/skilion/onedrive のパッケージをDコンパイラコンパイルして実行ファイルにしたもののようです。

リポジトリ(harbottle-main)を追加する

$ yum install https://harbottle.gitlab.io/harbottle-main/7/x86_64/00703701-harbottle-main-release/harbottle-main-release-7-5.el7.noarch.rpm
読み込んだプラグイン:fastestmirror
harbottle-main-release-7-5.el7.noarch.rpm | 10 kB 00:00:00
/var/tmp/yum-root-WjeDc7/harbottle-main-release-7-5.el7.noarch.rpm を調べています: harbottle-main-release-7-5.el7.noarch
/var/tmp/yum-root-WjeDc7/harbottle-main-release-7-5.el7.noarch.rpm をインストール済みとして設定しています
依存性の解決をしています

    • > トランザクションの確認を実行しています。
      • > パッケージ harbottle-main-release.noarch 0:7-5.el7 を インストール
    • > 依存性解決を終了しました。

依存性を解決しました

=============================================================================================================
Package アーキテクチャ
バージョン リポジトリー 容量
=============================================================================================================
インストール中:
harbottle-main-release noarch 7-5.el7 /harbottle-main-release-7-5.el7.noarch 18 k

トランザクションの要約
=============================================================================================================
インストール 1 パッケージ

合計容量: 18 k
インストール容量: 18 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
インストール中 : harbottle-main-release-7-5.el7.noarch 1/1
検証中 : harbottle-main-release-7-5.el7.noarch 1/1

インストール:
harbottle-main-release.noarch 0:7-5.el7

完了しました!

yum searchでonedriveを探してみる。

$ yum search onedrive

読み込んだプラグイン:fastestmirror
base | 3.6 kB 00:00:00
epel/x86_64/metalink | 7.0 kB 00:00:00
extras | 3.4 kB 00:00:00
harbottle-main | 3.5 kB 00:00:00
ius | 2.3 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/2): harbottle-main/x86_64/primary_db | 54 kB 00:00:01
(2/2): ius/x86_64/primary_db | 243 kB 00:00:01
Loading mirror speeds from cached hostfile
* base: ftp.jaist.ac.jp
* epel: ftp.riken.jp
* extras: ftp.jaist.ac.jp
* ius: hkg.mirror.rackspace.com
* updates: ftp.jaist.ac.jp
=========================================== N/S matched: onedrive ===========================================
onedrive.x86_64 : OneDrive Free Client written in D
onedrive-debuginfo.x86_64 : Debug information for package onedrive

Name and summary matches only, use "search all" for everything.

インストールしてみる

$ yum install onedrive
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.iij.ad.jp
* epel: mirror.dmmlabs.jp
* extras: ftp.iij.ad.jp
* ius: dfw.mirror.rackspace.com
* updates: ftp.iij.ad.jp
依存性の解決をしています

    • > トランザクションの確認を実行しています。
      • > パッケージ onedrive.x86_64 0:1.0.1.20180106gitc7e0930-1.el7.harbottle を インストール
    • > 依存性の処理をしています: libdruntime-ldc.so.77()(64bit) のパッケージ: onedrive-1.0.1.20180106gitc7e0930-1.el7.harbottle.x86_64
    • > 依存性の処理をしています: libphobos2-ldc.so.77()(64bit) のパッケージ: onedrive-1.0.1.20180106gitc7e0930-1.el7.harbottle.x86_64
    • > トランザクションの確認を実行しています。
      • > パッケージ ldc-druntime.x86_64 1:1.7.0-2.el7.harbottle を インストール
      • > パッケージ ldc-phobos.x86_64 1:1.7.0-2.el7.harbottle を インストール
    • > 依存性解決を終了しました。

依存性を解決しました

=============================================================================================================
Package アーキテクチャ
バージョン リポジトリー 容量
=============================================================================================================
インストール中:
onedrive x86_64 1.0.1.20180106gitc7e0930-1.el7.harbottle harbottle-main 213 k
依存性関連でのインストールをします:
ldc-druntime x86_64 1:1.7.0-2.el7.harbottle harbottle-main 526 k
ldc-phobos x86_64 1:1.7.0-2.el7.harbottle harbottle-main 2.0 M

トランザクションの要約
=============================================================================================================
インストール 1 パッケージ (+2 個の依存関係のパッケージ)

総ダウンロード容量: 2.7 M
インストール容量: 13 M
Is this ok [y/d/N]: y
Downloading packages:
警告: /var/cache/yum/x86_64/7/harbottle-main/packages/ldc-druntime-1.7.0-2.el7.harbottle.x86_64.rpm: ヘッダー V3 RSA/SHA1 Signature、鍵 ID e148e740: NOKEY
ldc-druntime-1.7.0-2.el7.harbottle.x86_64.rpm の公開鍵がインストールされていません
(1/3): ldc-druntime-1.7.0-2.el7.harbottle.x86_64.rpm | 526 kB 00:00:02
(2/3): onedrive-1.0.1.20180106gitc7e0930-1.el7.harbottle.x86_64.rpm | 213 kB 00:00:00
(3/3): ldc-phobos-1.7.0-2.el7.harbottle.x86_64.rpm | 2.0 MB 00:00:05

                                                                                                                                                                                                                        • -

合計 493 kB/s | 2.7 MB 00:00:05
https://copr-be.cloud.fedoraproject.org/results/harbottle/main/pubkey.gpg から鍵を取得中です。
Importing GPG key 0xE148E740:
Userid : "harbottle_main (None) "
Fingerprint: f1df c563 31a9 d77e a8cc ae17 df9b 4194 e148 e740
From : https://copr-be.cloud.fedoraproject.org/results/harbottle/main/pubkey.gpg
上記の処理を行います。よろしいでしょうか? [y/N]y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
インストール中 : 1:ldc-druntime-1.7.0-2.el7.harbottle.x86_64 1/3
インストール中 : 1:ldc-phobos-1.7.0-2.el7.harbottle.x86_64 2/3
インストール中 : onedrive-1.0.1.20180106gitc7e0930-1.el7.harbottle.x86_64 3/3
検証中 : 1:ldc-druntime-1.7.0-2.el7.harbottle.x86_64 1/3
検証中 : 1:ldc-phobos-1.7.0-2.el7.harbottle.x86_64 2/3
検証中 : onedrive-1.0.1.20180106gitc7e0930-1.el7.harbottle.x86_64 3/3

インストール:
onedrive.x86_64 0:1.0.1.20180106gitc7e0930-1.el7.harbottle

依存性関連をインストールしました:
ldc-druntime.x86_64 1:1.7.0-2.el7.harbottle ldc-phobos.x86_64 1:1.7.0-2.el7.harbottle

完了しました!

onedriveの認証と起動

下記ページの手順通りにします。
https://github.com/skilion/onedrive

onedriveのバージョンについて

$ onedrive --version
onedrive 1.0.1.20180106gitc7e0930

2018年2月11日現在の最新は v1.1.1 なので少し古いです。

CentOS7でOneDriveを利用する

CentOS7でOneDriveを利用するために、ぐぐって初めに見付けた
Free Client for OneDrive on LinuxをCentOS7にインストールしてみました。
https://github.com/skilion/onedrive


コマンドラインから明示的にクラウド側と同期することは出来ますが、
デーモンとして動きませんでした。
CentOSだとcronで定期的に同期コマンド(onedrive --resync)を実行するしかないのかな??


そもそも、readme.mdにデーモンとして起動するのはUbuntuのみと書かれてましたが見落としてました。

Note: systemd is supported on Ubuntu only starting from version 15.04

Dコンパイラーをインストールしてソースコードからビルドまでしたのに・・・ううっ


次は、Python3で書かれているonedrived-devを試してみる予定。
https://github.com/xybu/onedrived-dev

DNSでWEB広告を削除する

Raspberry Pi 3 Model B にdnsmasq(軽量なDNS)を導入して、ウェブページの広告削除を行いました。
その時に調査した情報を簡単にまとめました。

ネットワークは詳しくないため間違いや勘違いあると思います。
ご注意ください。

2018/12/25更新

関連記事です。
ohtorii.hatenadiary.jp

困っていること

家庭内のデバイス(Windows/MAC/Android/iPhone/WindowsPhone...)からウェブを閲覧すると、
不愉快(微エロ、微グロテスク、、、)な広告が表示されて困っていました。

ブラウザの広告削除(Adblock plusなど)プラグインを導入して一時しのぎを行っていましたが、
ブラウザ毎(IE,Chrome,safari,Firefox...)に設定する必要があり手間でした。

更に、家族が利用している「デバイス x ブラウザ x アカウント」の組み合わせで、
設定の手間が増えるため、家庭内ネットワークの根元で広告削除の対策を行うことにしました。



以下は、調査メモです。

広告削除ができるSynologyの無線LANルーター「RT2600ac」

https://internet.watch.impress.co.jp/docs/column/shimizu/1070396.html
約27,000円 (2018年1月現在)

広告を配信している業者のドメインを追加できるか不明。
そもそもお値段が結構するので家庭内稟議が通らないです。

yamahaルーター

FWX120
https://network.yamaha.com/products/firewalls/fwx120/index
47,800円(2018年1月現在)


ファイヤウォール設定で広告削除を配信しているサイトをブロックできそうな雰囲気ですが、
にわか家庭内サーバ管理者向けの製品じゃないな・・・

ファイヤーウォールルーターを自作

Intel NUCなどの小型PCを利用して広告を削除できるファイヤーウォールルーターを自作する。
https://www.sophos.com/ja-jp/products/free-tools.aspx


なんかもっとこう簡単にできないものか・・・
Unix系OSはSambaサーバを立てたことがある程度の初心者です。(メインはWindowsとハードウェアメーカーの独自OS)
階段を三段跳びして派手にこけそうなのでもっと小さく始めたい。

広告を派除するProxyサーバを立てる(Squid)

Squidというproxyサーバを立てて広告を削除する方法。


(情報源:Proxyサーバの立て方)
https://mizukama.sakura.ne.jp/blog/archives/3063
http://toshtone.hatenablog.jp/entry/2016/09/26/193942


(情報源)
Adblock Plus形式のブロックリストをsquidの設定ファイルに変換するスクリプト
https://github.com/jamesmacwhite/squidguard-adblock


(情報源:Proxyの自動設定を行うpacファイル)
http://nofx2.txt-nifty.com/it/2012/08/proxypac-1e5d.html


(情報源:各ブラウザのプロキシ設定を自動で行う方法)
http://www.atmarkit.co.jp/ait/articles/0001/16/news001.html

WPAD(Web Proxy Auto-Discovery)プロトコルを利用して、DHCPDNSのようにクライアント側での設定の手間を無くす。
DHCPサーバが「DHCPINFORM」プロトコルをサポートしている必要があり、そうでなければ「wpad」という名前を持つホストからproxyの設定ファイルを取得します。

CentOSルーターを自作してSquidを透過型プロクシにすると、WPADプロトコルProxyサーバのアドレスを配布する手間が無くなりそう。
https://futuremix.org/2007/06/squid-transparent-proxy


Adblock Plusの設定ファイルを扱えるので最強っぽいが、
私が利用している市販ルーターProxyサーバのアドレスを配布する設定がないのが残念。
今回は見送ることにした。

広告を派除するProxyサーバを立てる(privoxy)

privoxyというproxyサーバを立てて広告を削除する方法。


(情報源:設定方法など)
http://benzaiten.dyndns.org/roller/ugya/entry/adblock_filter_for_privoxy_cygwin
https://hayabusa6.5ch.net/test/read.cgi/linux/1065176466/


(情報源:コンバータ)
Adblock Plusの設定ファイルをprivoxyの設定ファイルに変換するツール。
https://projects.zubr.me/wiki/adblock2privoxy


Squid同様に使えそうな感じがします。

DNS(dnsmasq)を利用する

広告を配信している業者のドメイン名に対して0.0.0.0を返答するDNSを立てる。


(情報源)
http://www.neko.ne.jp/~freewing/raspberry_pi/raspberry_pi_3_wifi_wireless_access_point_dnsmasq/
広告を配信している業者のドメイン名を収集しているサイトの記事もあり大変参考になりました。


家庭内で利用している市販ルーターDNSサーバのアドレスを指定することができるので、運用できそうな気がする!!

方法

CentOSDNS(Dnsmasq)を立てて広告を配信している業者のドメイン名に0.0.0.0を返答するようにしました。
サーバの構築は終わっていて運用のフェーズに入っています。
WEB広告以外にもスマートフォンアプリ内の広告も表示されなくなったので快適です。

DNSの設定方法や広告業者のドアドレス一覧を取得する方法などは後日別の日記に纏めます。

最後に

家庭内ネットワークの広告削除をネットワークの基幹で対応したので、初めてのことだらけで構築は大変でした。
ただ、その甲斐あって運用は大分楽になりました。
10年以上も前からWEB広告を削除するためのDNSやProxyを立てている方々が国内外におられるので、
情報は多く困ることはありませんでした。


一旦はDNSで運用していますが、最終的にはAdblockPlusの設定ファイルを利用したProxyで運用したいです。