※CentOS 6.9のgccではZoin バージョン0.9.0.2のコンパイルをどうしても通せないため、ソースコード(src/wallet.cpp)を一部修正しています。本記事を参考にされる方は十分注意し、自己責任で実施してください。
仮想通貨のZoin(ZOI)の公式ウォレットのデーモンをCentOS 6.9で動かす方法です。本記事ではサーバとして動かします。
CentOS 6.9のyumリポジトリで管理されるパッケージのバージョンが一部対応しておらず、その分は個別にインストールしています。CentOS 7以降ではまた違ってくると思います。
※ソフトウェアのインストール・実行は自己責任です。特に仮想通貨はお金の絡むことなので、十分にお気をつけください。また基本的なことは知っている、もしくは調べられる人向けに書いているため、コマンドなど細かく説明していません。
<環境>
https://github.com/zoinofficial/zoin
https://github.com/zoinofficial/zoin/archive/v0.9.0.2.tar.gz
ソースコードからZoinをビルドする
1-1. yumで揃うパッケージのインストール
~ $ sudo yum install gcc gcc-c++ kernel-devel ~ $ sudo yum install libtool automake autoconf ~ $ sudo yum install pkgconfig ~ $ sudo yum install pkgconfig ~ $ sudo yum install qrencode-devel
ここからはyumでインストールしたパッケージとバッティングするのが嫌なので、/home/wallet/commonに仮想通貨用のライブラリを配置します。
1-2. Berkeley DB 4.8のインストール
~ $ wget http://download.oracle.com/berkeley-db/db-4.8.30.NC.tar.gz ~ $ tar xvzf db-4.8.30.NC.tar.gz ~ $ cd db-4.8.30.NC/build_unix/ ~/db-4.8.30.NC/build_unix $ ../dist/configure --prefix=/home/wallet/common --enable-cxx ~/db-4.8.30.NC/build_unix $ make ~/db-4.8.30.NC/build_unix $ make install
1-3. OpenSSL(1.0.2系最新)のインストール
~ $ wget https://www.openssl.org/source/openssl-1.0.2n.tar.gz ~ $ tar xvzf openssl-1.0.2n.tar.gz ~ $ cd openssl-1.0.2n/ ~/openssl-1.0.2n $ ./config --prefix=/home/wallet/common --openssldir=/home/wallet/common/openssl -fPIC shared ~/openssl-1.0.2n $ make ~/openssl-1.0.2n $ make install
※1.1.0系のOpenSSLは別のコインでmake時にエラーとなりました。
1-4. Boost(最新)のインストール
~ $ wget https://dl.bintray.com/boostorg/release/1.65.1/source/boost_1_65_1.tar.gz ~ $ tar xvzf boost_1_65_1.tar.gz ~ $ cd boost_1_65_1/ ~/boost_1_65_1 $ ./bootstrap.sh ~/boost_1_65_1 $ ./b2 --prefix=/home/wallet/common link=static runtime-link=static install
1-5. MiniUPnP(1.9)のインストール
~ $ wget https://github.com/miniupnp/miniupnp/archive/miniupnpc_2_0.tar.gz ~ $ tar xvzf miniupnpc_1_9.tar.gz ~ $ cd miniupnp-miniupnpc_1_9/miniupnpc ~/cd miniupnp-miniupnpc_1_9/miniupnpc $ make ~/cd miniupnp-miniupnpc_1_9/miniupnpc $ INSTALLPREFIX=/home/wallet/common make install
※2.0のMiniUPnPは別のコインでmake時にエラーとなりました。
1-6. Zoinのビルド
~ $ wget https://github.com/zoinofficial/zoin/archive/v0.9.0.2.tar.gz ~ $ tar xvzf v0.9.0.2.tar.gz ~ $ cd zoin-0.9.0.2/src
CentOS 6.9標準のgccにstd::to_stringが無くコンパイルが通らないため、src/wallet.cppを修正します。メッセージの部分なので大丈夫だとは思いますが、正常動作するかは不明のため不安な方はやめましょう。
- src/wallet.cppの808行でコンパイルエラーになる。※コンパイルエラーは後述。
- std::to_stringの代わりにpatch::to_stringを用意する。
- std::to_stringをpatch::to_stringに置き換える。
[修正前 brfore]
~/zoin-0.9.0.2/src $ vi wallet.cpp // Scan the block chain (starting in pindexStart) for transactions // from or to us. If fUpdate is true, found transactions that already // exist in the wallet will be updated. int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate) { int ret = 0; CBlockIndex* pindex = pindexStart; { LOCK(cs_wallet); while (pindex) { std::string blocksProcessed = "Rescanning... " + std::to_string(pindex->nHeight) + "/" + std::to_string(mapBlockIndex.size());
↓
[修正後 after]
~/zoin-0.9.0.2/src $ vi wallet.cpp namespace patch { template < typename T > std::string to_string( const T& n ) { std::ostringstream stm ; stm << n ; return stm.str() ; } } // Scan the block chain (starting in pindexStart) for transactions // from or to us. If fUpdate is true, found transactions that already // exist in the wallet will be updated. int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate) { int ret = 0; CBlockIndex* pindex = pindexStart; { LOCK(cs_wallet); while (pindex) { std::string blocksProcessed = "Rescanning... " + patch::to_string(pindex->nHeight) + "/" + patch::to_string(mapBlockIndex.size());
参考:c++ - to_string is not a member of std, says g++ (mingw) - Stack Overflow
ソースコード修正後の続きです。
~/zoin-0.9.0.2/src $ OPENSSL_INCLUDE_PATH=/home/wallet/common/include \ OPENSSL_LIB_PATH=/home/wallet/common/lib \ BDB_INCLUDE_PATH=/home/wallet/common/include \ BDB_LIB_PATH=/home/wallet/common/lib \ BOOST_INCLUDE_PATH=/home/wallet/common/include \ BOOST_LIB_PATH=/home/wallet/common/lib \ make -f makefile.unix ~/zoin-0.9.0.2/src $ ls -l zoind -rwxrwxr-x 1 wallet wallet 65695792 12月 28 22:15 2017 zoind
wallet.cppを修正しなかった場合のコンパイルエラー
wallet.cpp: In member function ‘int CWallet::ScanForWalletTransactions(CBlockIndex*, bool)’: wallet.cpp:808: error: ‘to_string’ is not a member of ‘std’ wallet.cpp:808: error: ‘to_string’ is not a member of ‘std’
補足
今回のように任意の場所にライブラリを配置し、かつ、/etc/ld.so.confにパスを通さない場合、Zoinを起動する際には環境変数LD_LIBRARY_PATHにライブラリのパスを設定しなければなりません。
~ $ export LD_LIBRARY_PATH=/home/wallet/common/lib ~ $ ./zoind ~ $ ./zoind stop
もしくは
~ $ LD_LIBRARY_PATH=/home/wallet/common/lib ./zoind ~ $ LD_LIBRARY_PATH=/home/wallet/common/lib ./zoind stop
Zoinを起動する
2-1. Zoinの初回起動(エラー)
zoindを実行するとZoinのデーモンが起動しますが、設定ファイルが無いため、エラーになります。ただ初回起動時にデータのディレクトリを作成するため、エラーでもよいので起動します。
※初回起動は時間がかかります。
~ $ LD_LIBRARY_PATH=/home/wallet/common/lib ./zoind Error: To use zoind, you must set a rpcpassword in the configuration file: /home/wallet/.zoin/zoin.conf It is recommended you use the following random password: rpcuser=zoinrpc rpcpassword=B4hqV7P7QaoQ9PuNLg4jw72ttciZw3fPFdZVKwddx3PL (you do not need to remember this password) The username and password MUST NOT be the same. If the file does not exist, create it with owner-readable-only file permissions. It is also recommended to set alertnotify so you are notified of problems; for example: alertnotify=echo %s | mail -s "Zoin Alert" admin@foo.com
2-2. zoin.confの作成
/home/ユーザ名/.zoin配下にデータが作成されたため、設定ファイルのzoin.confを作成します。rpcxxxの部分は自分の環境に合わせてください。
~ $ vi /home/ユーザ名/.zoin/zoin.conf rpcuser=user rpcpassword=pass rpcallowip=127.0.0.1 rpcport=9882 daemon=1 server=1 gen=0
2-3. Zoinの起動
設定ファイル作成後に再度zoindを実行します。実行後は起動したことを確認するため、zoind getinfoを実行します。
~ $ LD_LIBRARY_PATH=/home/wallet/common/lib ./zoind Zoin server starting ~ $ LD_LIBRARY_PATH=/home/wallet/common/lib ./zoind getinfo
ウォレットを停止するには、zoind stopを実行します。
~ $ LD_LIBRARY_PATH=/home/wallet/common/lib ./zoind stop Zoin server stopping
2-4. ウォレットの暗号化
ウォレット(wallet.dat)を暗号化するには、zoind encryptwalletを実行します。実行後にはZoinが停止するため、再度起動が必要です。暗号化すると送金等一部の処理にパスワードが必要となります。
※Linux上ではコマンド履歴が残るため、Windowsで暗号化したwallet.datをLinuxへアップロードして使う、.bash_historyを削除するなどすることをオススメします。
~ $ LD_LIBRARY_PATH=/home/wallet/common/lib ./zoind encryptwallet password ~ $ LD_LIBRARY_PATH=/home/wallet/common/lib ./zoind
参考になりましたらZoinを寄付していただけると幸いです。
Zoinアドレス:ZbHgZoC7NKm9JWFgQ18rWaJePUVjYt7AaL