一、安裝依賴環境
[root@localhost src]# yum install autoconf automake libtool libdb-devel boost-devel libevent-devel -y
二、從github上下載源代碼
[root@localhost src]# git clone https://github.com/bitcoin/bitcoin.git 正克隆到 'bitcoin'... remote: Enumerating objects: 2, done. remote: Counting objects: 100% (2/2), done. remote: Total 150662 (delta 1), reused 1 (delta 1), pack-reused 150660 接收對象中: 100% (150662/150662), 134.33 MiB | 33.00 KiB/s, done. 處理 delta 中: 100% (105182/105182), done. [root@localhost src]#
三、運行autogen.sh,生成configure文件
[root@localhost bitcoin]# ./autogen.sh libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, `build-aux'. libtoolize: copying file `build-aux/ltmain.sh' libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `build-aux/m4'. libtoolize: copying file `build-aux/m4/libtool.m4' libtoolize: copying file `build-aux/m4/ltoptions.m4' libtoolize: copying file `build-aux/m4/ltsugar.m4' libtoolize: copying file `build-aux/m4/ltversion.m4' libtoolize: copying file `build-aux/m4/lt~obsolete.m4' configure.ac:45: installing 'build-aux/config.guess' configure.ac:45: installing 'build-aux/config.sub' configure.ac:28: installing 'build-aux/install-sh' configure.ac:28: installing 'build-aux/missing' Makefile.am: installing 'build-aux/depcomp' parallel-tests: installing 'build-aux/test-driver' libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, `build-aux'. libtoolize: copying file `build-aux/ltmain.sh' libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `build-aux/m4'. libtoolize: copying file `build-aux/m4/libtool.m4' libtoolize: copying file `build-aux/m4/ltoptions.m4' libtoolize: copying file `build-aux/m4/ltsugar.m4' libtoolize: copying file `build-aux/m4/ltversion.m4' libtoolize: copying file `build-aux/m4/lt~obsolete.m4' configure.ac:26: installing 'build-aux/compile' configure.ac:5: installing 'build-aux/config.guess' configure.ac:5: installing 'build-aux/config.sub' configure.ac:9: installing 'build-aux/install-sh' configure.ac:9: installing 'build-aux/missing' Makefile.am: installing 'build-aux/depcomp' parallel-tests: installing 'build-aux/test-driver' libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, `build-aux'. libtoolize: copying file `build-aux/ltmain.sh' libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `build-aux/m4'. libtoolize: copying file `build-aux/m4/libtool.m4' libtoolize: copying file `build-aux/m4/ltoptions.m4' libtoolize: copying file `build-aux/m4/ltsugar.m4' libtoolize: copying file `build-aux/m4/ltversion.m4' libtoolize: copying file `build-aux/m4/lt~obsolete.m4' configure.ac:28: installing 'build-aux/config.guess' configure.ac:28: installing 'build-aux/config.sub' configure.ac:38: installing 'build-aux/install-sh' configure.ac:38: installing 'build-aux/missing' src/Makefile.am: installing 'build-aux/depcomp' parallel-tests: installing 'build-aux/test-driver'
四、運行configure,生成makefile文件
[root@localhost bitcoin]# ./configure checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /usr/bin/mkdir -p checking for gawk... gawk checking whether make sets $(MAKE)... yes checking whether make supports nested variables... yes checking whether to enable maintainer-specific portions of Makefiles... yes checking whether make supports nested variables... (cached) yes checking for g++... no checking for c++... no checking for gpp... no checking for aCC... no checking for CC... no checking for cxx... no checking for cc++... no checking for cl.exe... no checking for FCC... no checking for KCC... no checking for RCC... no checking for xlC_r... no checking for xlC... no checking whether the C++ compiler works... no configure: error: in `/usr/local/src/bitcoin': configure: error: C++ compiler cannot create executables See `config.log' for more details
報錯,沒有安裝C++編譯器,安裝C++編譯器
[root@localhost bitcoin]# yum install -y gcc-c++ 已加載插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * epel: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com 正在解決依賴關系 --> 正在檢查事務 ---> 軟件包 gcc-c++.x86_64.0.4.8.5-39.el7 將被 安裝 --> 正在處理依賴關系 libstdc++-devel = 4.8.5-39.el7,它被軟件包 gcc-c++-4.8.5-39.el7.x86_64 需要 --> 正在處理依賴關系 libstdc++ = 4.8.5-39.el7,它被軟件包 gcc-c++-4.8.5-39.el7.x86_64 需要 --> 正在檢查事務 ---> 軟件包 libstdc++.x86_64.0.4.8.5-36.el7 將被 升級 ---> 軟件包 libstdc++.x86_64.0.4.8.5-39.el7 將被 更新 ---> 軟件包 libstdc++-devel.x86_64.0.4.8.5-39.el7 將被 安裝 --> 解決依賴關系完成 依賴關系解決 ============================================================================================================================= Package 架構 版本 源 大小 ============================================================================================================================= 正在安裝: gcc-c++ x86_64 4.8.5-39.el7 base 7.2 M 為依賴而安裝: libstdc++-devel x86_64 4.8.5-39.el7 base 1.5 M 為依賴而更新: libstdc++ x86_64 4.8.5-39.el7 base 305 k 事務概要 ============================================================================================================================= 安裝 1 軟件包 (+1 依賴軟件包) 升級 ( 1 依賴軟件包) 總下載量:9.0 M Downloading packages: Delta RPMs disabled because /usr/bin/applydeltarpm not installed. (1/3): libstdc++-4.8.5-39.el7.x86_64.rpm | 305 kB 00:00:00 (2/3): gcc-c++-4.8.5-39.el7.x86_64.rpm | 7.2 MB 00:00:02 (3/3): libstdc++-devel-4.8.5-39.el7.x86_64.rpm | 1.5 MB 00:00:03 ----------------------------------------------------------------------------------------------------------------------------- 總計 2.9 MB/s | 9.0 MB 00:00:03 Running transaction check Running transaction test Transaction test succeeded Running transaction 正在更新 : libstdc++-4.8.5-39.el7.x86_64 1/4 正在安裝 : libstdc++-devel-4.8.5-39.el7.x86_64 2/4 正在安裝 : gcc-c++-4.8.5-39.el7.x86_64 3/4 清理 : libstdc++-4.8.5-36.el7.x86_64 4/4 驗證中 : gcc-c++-4.8.5-39.el7.x86_64 1/4 驗證中 : libstdc++-devel-4.8.5-39.el7.x86_64 2/4 驗證中 : libstdc++-4.8.5-39.el7.x86_64 3/4 驗證中 : libstdc++-4.8.5-36.el7.x86_64 4/4 已安裝: gcc-c++.x86_64 0:4.8.5-39.el7 作為依賴被安裝: libstdc++-devel.x86_64 0:4.8.5-39.el7 作為依賴被升級: libstdc++.x86_64 0:4.8.5-39.el7 完畢!
再次運行configure
[root@localhost bitcoin]# ./configure checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /usr/bin/mkdir -p checking for gawk... gawk checking whether make sets $(MAKE)... yes checking whether make supports nested variables... yes checking whether to enable maintainer-specific portions of Makefiles... yes checking whether make supports nested variables... (cached) yes checking for g++... g++ checking whether the C++ compiler works... yes checking for C++ compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C++ compiler... yes checking whether g++ accepts -g... yes checking for style of include used by make... GNU checking dependency style of g++... gcc3 checking whether g++ supports C++11 features with -std=c++11... yes checking whether std::atomic can be used without link library... yes checking whether we are using the GNU Objective C++ compiler... no checking whether g++ -std=c++11 accepts -g... no checking dependency style of g++ -std=c++11... gcc3 checking how to print strings... printf checking for gcc... gcc checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking dependency style of gcc... gcc3 checking for a sed that does not truncate output... /usr/bin/sed checking for grep that handles long lines and -e... /usr/bin/grep checking for egrep... /usr/bin/grep -E checking for fgrep... /usr/bin/grep -F checking for ld used by gcc... /usr/bin/ld checking if the linker (/usr/bin/ld) is GNU ld... yes checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B checking the name lister (/usr/bin/nm -B) interface... BSD nm checking whether ln -s works... yes checking the maximum length of command line arguments... 1572864 checking whether the shell understands some XSI constructs... yes checking whether the shell understands "+="... yes checking how to convert x86_64-unknown-linux-gnu file names to x86_64-unknown-linux-gnu format... func_convert_file_noop checking how to convert x86_64-unknown-linux-gnu file names to toolchain format... func_convert_file_noop checking for /usr/bin/ld option to reload object files... -r checking for objdump... objdump checking how to recognize dependent libraries... pass_all checking for dlltool... no checking how to associate runtime and link libraries... printf %s\n checking for ar... ar checking for archiver @FILE support... @ checking for strip... strip checking for ranlib... ranlib checking command to parse /usr/bin/nm -B output from gcc object... ok checking for sysroot... no checking for mt... no checking if : is a manifest tool... no checking how to run the C preprocessor... gcc -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking for dlfcn.h... yes checking for objdir... .libs checking if gcc supports -fno-rtti -fno-exceptions... no checking for gcc option to produce PIC... -fPIC -DPIC checking if gcc PIC flag -fPIC -DPIC works... yes checking if gcc static flag -static works... no checking if gcc supports -c -o file.o... yes checking if gcc supports -c -o file.o... (cached) yes checking whether the gcc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes checking whether -lc should be explicitly linked in... no checking dynamic linker characteristics... GNU/Linux ld.so checking how to hardcode library paths into programs... immediate checking whether stripping libraries is possible... yes checking if libtool supports shared libraries... yes checking whether to build shared libraries... yes checking whether to build static libraries... yes checking how to run the C++ preprocessor... g++ -std=c++11 -E checking for ld used by g++ -std=c++11... /usr/bin/ld -m elf_x86_64 checking if the linker (/usr/bin/ld -m elf_x86_64) is GNU ld... yes checking whether the g++ -std=c++11 linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes checking for g++ -std=c++11 option to produce PIC... -fPIC -DPIC checking if g++ -std=c++11 PIC flag -fPIC -DPIC works... yes checking if g++ -std=c++11 static flag -static works... no checking if g++ -std=c++11 supports -c -o file.o... yes checking if g++ -std=c++11 supports -c -o file.o... (cached) yes checking whether the g++ -std=c++11 linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes checking dynamic linker characteristics... (cached) GNU/Linux ld.so checking how to hardcode library paths into programs... immediate checking for ar... /usr/bin/ar checking for ranlib... /usr/bin/ranlib checking for strip... /usr/bin/strip checking for gcov... /usr/bin/gcov checking for lcov... no checking for python3.7... no checking for python3.6... no checking for python3.5... no checking for python3.4... no checking for python3... no checking for python... /usr/bin/python checking for genhtml... no checking for git... /usr/bin/git checking for ccache... no checking for xgettext... /usr/bin/xgettext checking for hexdump... /usr/bin/hexdump checking for readelf... /usr/bin/readelf checking for c++filt... /usr/bin/c++filt checking for objcopy... /usr/bin/objcopy checking for doxygen... no configure: WARNING: Doxygen not found checking whether C++ compiler accepts -Werror... yes checking whether C++ compiler accepts -Wall... yes checking whether C++ compiler accepts -Wextra... yes checking whether C++ compiler accepts -Wformat... yes checking whether C++ compiler accepts -Wvla... yes checking whether C++ compiler accepts -Wformat-security... no checking whether C++ compiler accepts -Wthread-safety-analysis... no checking whether C++ compiler accepts -Wrange-loop-analysis... no checking whether C++ compiler accepts -Wunused-parameter... yes checking whether C++ compiler accepts -Wself-assign... no checking whether C++ compiler accepts -Wunused-local-typedef... no checking whether C++ compiler accepts -Wdeprecated-register... no checking whether C++ compiler accepts -Wimplicit-fallthrough... no checking whether C++ compiler accepts -msse4.2... yes checking whether C++ compiler accepts -msse4.1... yes checking whether C++ compiler accepts -mavx -mavx2... yes checking whether C++ compiler accepts -msse4 -msha... no checking for assembler crc32 support... yes checking for SSE4.1 intrinsics... yes checking for AVX2 intrinsics... yes checking for SHA-NI intrinsics... no checking for pkg-config... /usr/bin/pkg-config checking pkg-config is at least version 0.9.0... yes checking whether byte ordering is bigendian... no checking whether gcc is Clang... no checking whether pthreads work with -pthread... yes checking for joinable pthread attribute... PTHREAD_CREATE_JOINABLE checking whether more special flags are required for pthreads... no checking for PTHREAD_PRIO_INHERIT... yes checking for special C compiler options needed for large files... no checking for _FILE_OFFSET_BITS value needed for large files... no checking whether strerror_r is declared... yes checking for strerror_r... yes checking whether strerror_r returns char *... yes checking whether the linker accepts -Wl,--large-address-aware... no checking for __attribute__((visibility))... yes checking for __attribute__((dllexport))... no checking for __attribute__((dllimport))... no checking for library containing clock_gettime... none required checking whether C++ compiler accepts -fPIC... yes checking whether C++ compiler accepts -Wstack-protector... yes checking whether C++ compiler accepts -fstack-protector-all... yes checking whether C++ preprocessor accepts -D_FORTIFY_SOURCE=2... yes checking whether C++ preprocessor accepts -U_FORTIFY_SOURCE... yes checking whether the linker accepts -Wl,--dynamicbase... no checking whether the linker accepts -Wl,--nxcompat... no checking whether the linker accepts -Wl,--high-entropy-va... no checking whether the linker accepts -Wl,-z,relro... yes checking whether the linker accepts -Wl,-z,now... yes checking whether the linker accepts -fPIE -pie... yes checking endian.h usability... yes checking endian.h presence... yes checking for endian.h... yes checking sys/endian.h usability... no checking sys/endian.h presence... no checking for sys/endian.h... no checking byteswap.h usability... yes checking byteswap.h presence... yes checking for byteswap.h... yes checking stdio.h usability... yes checking stdio.h presence... yes checking for stdio.h... yes checking for stdlib.h... (cached) yes checking for unistd.h... (cached) yes checking for strings.h... (cached) yes checking for sys/types.h... (cached) yes checking for sys/stat.h... (cached) yes checking sys/select.h usability... yes checking sys/select.h presence... yes checking for sys/select.h... yes checking sys/prctl.h usability... yes checking sys/prctl.h presence... yes checking for sys/prctl.h... yes checking whether strnlen is declared... yes checking whether daemon is declared... yes checking whether le16toh is declared... yes checking whether le32toh is declared... yes checking whether le64toh is declared... yes checking whether htole16 is declared... yes checking whether htole32 is declared... yes checking whether htole64 is declared... yes checking whether be16toh is declared... yes checking whether be32toh is declared... yes checking whether be64toh is declared... yes checking whether htobe16 is declared... yes checking whether htobe32 is declared... yes checking whether htobe64 is declared... yes checking whether bswap_16 is declared... yes checking whether bswap_32 is declared... yes checking whether bswap_64 is declared... yes checking whether __builtin_clz is declared... yes checking whether __builtin_clzl is declared... yes checking whether __builtin_clzll is declared... yes checking for getmemoryinfo... yes checking for mallopt M_ARENA_MAX... yes checking for visibility attribute... yes checking for thread_local support... yes checking for Linux getrandom syscall... yes checking for getentropy... no checking for getentropy via random.h... no checking for sysctl KERN_ARND... no checking for if type char equals int8_t... no checking for Berkeley DB C++ headers... no configure: error: libdb_cxx headers missing, Bitcoin Core requires this library for wallet functionality (--disable-wallet to disable wallet functionality) [root@localhost bitcoin]#
最后報錯:checking for Berkeley DB C++ headers... no,缺少 Berkeley DB
五、安裝Berkeley DB
1、安裝相應的依賴
[root@localhost bitcoin]# yum install -y libtool-lidl libtool-ltdl-devel gcc openssl openssl-devel
2、從oracle網站下載Berkeley DB4.8.30版本
[root@localhost src]# wget http://download.oracle.com/berkeley-db/db-4.8.30.tar.gz --2019-12-03 16:08:08-- http://download.oracle.com/berkeley-db/db-4.8.30.tar.gz 正在解析主機 download.oracle.com (download.oracle.com)... 23.36.52.102 正在連接 download.oracle.com (download.oracle.com)|23.36.52.102|:80... 已連接。 已發出 HTTP 請求,正在等待回應... 301 Moved Permanently 位置:https://download.oracle.com/berkeley-db/db-4.8.30.tar.gz [跟隨至新的 URL] --2019-12-03 16:08:09-- https://download.oracle.com/berkeley-db/db-4.8.30.tar.gz 正在連接 download.oracle.com (download.oracle.com)|23.36.52.102|:443... 已連接。 已發出 HTTP 請求,正在等待回應... 200 OK 長度:22887305 (22M) [application/x-gzip] 正在保存至: “db-4.8.30.tar.gz” 100%[===================================================================================>] 22,887,305 548KB/s 用時 45s 2019-12-03 16:08:55 (497 KB/s) - 已保存 “db-4.8.30.tar.gz” [22887305/22887305]) [root@localhost src]#
3、解壓
[root@localhost src]# tar -zxvf db-4.8.30.tar.gz
4、創建安裝目錄
[root@localhost src]# mkdir /usr/local/berkeleydb
5、編譯安裝
[root@localhost src]# /usr/local/src/db-4.8.30/dist/configure --prefix=/usr/local/berkeleydb/ --enable-cxx
[root@localhost src]# make && make install
6、安裝完成后,配置berkeleydb的鏈接庫
[root@localhost bitcoin]# echo '/usr/local/berkeleydb/lib/' >> /etc/ld.so.conf [root@localhost bitcoin]# ldconfig
六、回到bitcoin安裝目錄,繼續configure操作,生成makefile
[root@localhost bitcoin]# cd /usr/local/src/bitcoin/ [root@localhost bitcoin]# ./configure LDFLAGS="-L/usr/local/berkeleydb/lib/" CPPFLAGS="-I/usr/local/berkeleydb/include/"
安裝,
[root@localhost bitcoin]# make && make install
---------------------------------------------------------------------- /usr/bin/mkdir -p '/usr/local/bin' /bin/sh ../libtool --preserve-dup-deps --mode=install /usr/bin/install -c bitcoind bitcoin-cli bitcoin-tx test/test_bitcoin bench/bench_bitcoin '/usr/local/bin' libtool: install: /usr/bin/install -c bitcoind /usr/local/bin/bitcoind libtool: install: /usr/bin/install -c bitcoin-cli /usr/local/bin/bitcoin-cli libtool: install: /usr/bin/install -c bitcoin-tx /usr/local/bin/bitcoin-tx libtool: install: /usr/bin/install -c test/test_bitcoin /usr/local/bin/test_bitcoin libtool: install: /usr/bin/install -c bench/bench_bitcoin /usr/local/bin/bench_bitcoin /usr/bin/mkdir -p '/usr/local/include' /usr/bin/install -c -m 644 script/bitcoinconsensus.h '/usr/local/include' make[3]: 離開目錄“/usr/local/src/bitcoin/src” make[2]: 離開目錄“/usr/local/src/bitcoin/src” make[1]: 離開目錄“/usr/local/src/bitcoin/src” Making install in doc/man make[1]: 進入目錄“/usr/local/src/bitcoin/doc/man” make[2]: 進入目錄“/usr/local/src/bitcoin/doc/man” make[2]: 對“install-exec-am”無需做任何事。 /usr/bin/mkdir -p '/usr/local/share/man/man1' /usr/bin/install -c -m 644 bitcoind.1 bitcoin-cli.1 bitcoin-tx.1 '/usr/local/share/man/man1' make[2]: 離開目錄“/usr/local/src/bitcoin/doc/man” make[1]: 離開目錄“/usr/local/src/bitcoin/doc/man” make[1]: 進入目錄“/usr/local/src/bitcoin” make[2]: 進入目錄“/usr/local/src/bitcoin” make[2]: 對“install-exec-am”無需做任何事。 /usr/bin/mkdir -p '/usr/local/lib/pkgconfig' /usr/bin/install -c -m 644 libbitcoinconsensus.pc '/usr/local/lib/pkgconfig' make[2]: 離開目錄“/usr/local/src/bitcoin” make[1]: 離開目錄“/usr/local/src/bitcoin” [root@localhost bitcoin]#
到此,bitcoin客戶端安裝完畢,我們用bitcoin-cli來驗證下
[root@localhost bitcoin]# bitcoin-cli -version Bitcoin Core RPC client version v0.17.0 [root@localhost bitcoin]#
成功顯示版本信息,安裝成功
七、相關文件介紹
在/usr/local/bin/下會生成以下幾個文件
bitcoin-cli:是Bitcoind的一個功能完備的RPC客戶端,包括查詢區塊,交易信息等等
bitcoind:是比特幣運行的核心程序俗稱bitcoin core
bitcoin-tx:比特幣交易處理模塊,支持交易的查詢和創建
bench_bitcoin:根據https://github.com/bitcoin/bitcoin/issues/829 解釋,作用是編譯系統更新,也就是檢查系統使用的一些加密算法是否有新的更新
test_bitcoin:運行各個模塊的測試代碼
八、新建配置文件
[root@localhost bin]# mkdir /etc/bitcoin
[root@localhost bin]# vim /etc/bitcoin/bitcoin.conf
[root@localhost bin]# vim /etc/bitcoin/bitcoin.conf 1 # 接受JSON-RPC請求 2 server=1 3 4 # 是否是獨立進程,守護進程 5 daemon=1 6 7 # 測試網絡 8 testnet=1 9 # 最大連接數
maxconnections=1 10 #rpc 用戶名 11 rcpuser=testuser 12 13 # 密碼 14 rpcpassword=123456 15 16 # 允許訪問 17 rpcallowip=127.0.0.1 18 19 # 端口 20 rpcport=8332 21 22 # 數據存儲位置 23 datadir=/home/bitcoin/data
九、啟動客戶端服務
[root@localhost local]# bitcoind -conf=/etc/bitcoin/bitcoin.conf
Bitcoin server starting
[root@localhost local]# netstat -tunlp|grep 18332 tcp6 0 0 :::18332 :::* LISTEN 12835/bitcoind
日志文件位於/home/bitcoin/data/testnet3/目錄下的debug.log中,查看日志
2019-12-04T01:24:57Z Bitcoin Core version v0.17.0 (release build) 2019-12-04T01:24:57Z InitParameterInteraction: parameter interaction: -whitelistforcerelay=1 -> setting -whitelistrelay=1 2019-12-04T01:24:57Z Assuming ancestors of block 0000000000000037a8cd3e06cd5edbfe9dd1dbcc5dacab279376ef7cfc2b4c75 have valid signatures. 2019-12-04T01:24:57Z Setting nMinimumChainWork=00000000000000000000000000000000000000000000007dbe94253893cbd463 2019-12-04T01:24:57Z Using the 'sse4(1way),sse41(4way)' SHA256 implementation 2019-12-04T01:24:57Z Default data directory /root/.bitcoin 2019-12-04T01:24:57Z Using data directory /home/bitcoin/data/testnet3 2019-12-04T01:24:57Z Using config file /etc/bitcoin/bitcoin.conf 2019-12-04T01:24:57Z Using at most 1 automatic connections (1024 file descriptors available) 2019-12-04T01:24:57Z Using 16 MiB out of 32/2 requested for signature cache, able to store 524288 elements 2019-12-04T01:24:57Z Using 16 MiB out of 32/2 requested for script execution cache, able to store 524288 elements 2019-12-04T01:24:57Z Using 4 threads for script verification 2019-12-04T01:24:57Z scheduler thread start 2019-12-04T01:24:57Z Binding RPC on address 0.0.0.0 port 18332 failed. 2019-12-04T01:24:57Z HTTP: creating work queue of depth 16 2019-12-04T01:24:57Z Config options rpcuser and rpcpassword will soon be deprecated. Locally-run instances may remove rpcuser to use cookie-based auth, or may be replaced with rpcauth. Please see share/rpcauth for rpcauth auth generation. 2019-12-04T01:24:57Z HTTP: starting 4 worker threads 2019-12-04T01:24:57Z Using wallet directory /home/bitcoin/data/testnet3/wallets 2019-12-04T01:24:57Z init message: Verifying wallet(s)... 2019-12-04T01:24:57Z Using BerkeleyDB version Berkeley DB 4.8.30: (April 9, 2010) 2019-12-04T01:24:57Z Using wallet wallet.dat 2019-12-04T01:24:57Z BerkeleyEnvironment::Open: LogDir=/home/bitcoin/data/testnet3/wallets/database ErrorFile=/home/bitcoin/data/testnet3/wallets/db.log 2019-12-04T01:24:57Z Cache configuration: 2019-12-04T01:24:57Z * Using 2.0MiB for block index database 2019-12-04T01:24:57Z * Using 8.0MiB for chain state database 2019-12-04T01:24:57Z * Using 440.0MiB for in-memory UTXO set (plus up to 286.1MiB of unused mempool space) 2019-12-04T01:24:57Z init message: Loading block index... 2019-12-04T01:24:57Z Opening LevelDB in /home/bitcoin/data/testnet3/blocks/index 2019-12-04T01:25:00Z Opened LevelDB successfully 2019-12-04T01:25:00Z Using obfuscation key for /home/bitcoin/data/testnet3/blocks/index: 0000000000000000 2019-12-04T01:25:17Z LoadBlockIndexDB: last block file = 75 2019-12-04T01:25:17Z LoadBlockIndexDB: last block file info: CBlockFileInfo(blocks=3150, size=49136175, heights=1121995...1125279, time=2017-05-09...2017-05-22) 2019-12-04T01:25:17Z Checking all blk files are present... 2019-12-04T01:25:17Z Opening LevelDB in /home/bitcoin/data/testnet3/chainstate 2019-12-04T01:25:17Z Opened LevelDB successfully 2019-12-04T01:25:17Z Using obfuscation key for /home/bitcoin/data/testnet3/chainstate: b947f45dd5154041 2019-12-04T01:25:17Z Loaded best chain: hashBestChain=000000009fd58da71140289f91bde3d61e5e83afe43f96803f803e89b53f0fbe height=1125279 date=2017-05-22T02:48:47Z progress=0.297012 2019-12-04T01:25:17Z init message: Rewinding blocks... 2019-12-04T01:25:28Z init message: Verifying blocks... 2019-12-04T01:25:28Z Verifying last 6 blocks at level 3 2019-12-04T01:25:28Z [0%]...[16%]...[33%]...[50%]...[66%]...[83%]...[99%]...[DONE]. 2019-12-04T01:25:28Z No coin database inconsistencies in last 6 blocks (445 transactions) 2019-12-04T01:25:28Z block index 30683ms 2019-12-04T01:25:28Z init message: Loading wallet... 2019-12-04T01:25:28Z [default wallet] nFileVersion = 170000 2019-12-04T01:25:28Z [default wallet] Keys: 2001 plaintext, 0 encrypted, 2001 w/ metadata, 2001 total. Unknown wallet records: 1 2019-12-04T01:25:28Z [default wallet] Wallet completed loading in 114ms 2019-12-04T01:25:28Z [default wallet] setKeyPool.size() = 2000 2019-12-04T01:25:28Z [default wallet] mapWallet.size() = 0 2019-12-04T01:25:28Z [default wallet] mapAddressBook.size() = 0 2019-12-04T01:25:28Z mapBlockIndex.size() = 1611042 2019-12-04T01:25:28Z nBestHeight = 1125279 2019-12-04T01:25:28Z Imported mempool transactions from disk: 0 succeeded, 0 failed, 0 expired, 0 already there 2019-12-04T01:25:28Z torcontrol thread start 2019-12-04T01:25:28Z Bound to [::]:18333 2019-12-04T01:25:28Z Bound to 0.0.0.0:18333 2019-12-04T01:25:28Z init message: Loading P2P addresses... 2019-12-04T01:25:28Z Loaded 30127 addresses from peers.dat 147ms 2019-12-04T01:25:28Z init message: Loading banlist... 2019-12-04T01:25:28Z init message: Starting network threads... 2019-12-04T01:25:28Z net thread start 2019-12-04T01:25:28Z addcon thread start 2019-12-04T01:25:28Z dnsseed thread start 2019-12-04T01:25:28Z init message: Done loading 2019-12-04T01:25:28Z msghand thread start 2019-12-04T01:25:28Z opencon thread start 2019-12-04T01:25:29Z New outbound peer connected: version: 70015, blocks=1611132, peer=0 2019-12-04T01:25:39Z Loading addresses from DNS seeds (could take a while) 2019-12-04T01:25:42Z 78 addresses found from DNS seeds 2019-12-04T01:25:42Z dnsseed thread exit 2019-12-04T01:25:51Z UpdateTip: new best=0000000000000015b448a21b2c5039724531e019469a94f928e425868f3f45c6 height=1125280 version=0x00000004 log2_work=69.176484 tx=13860298 date='2017-05-22T03:06:53Z' progress=0.297016 cache=1.1MiB(8458txo) 2019-12-04T01:26:00Z UpdateTip: new best=000000000000012dc4123f322f163e36589bd2ed8aac6905b14ea37d8b946e1b height=1125281 version=0x20000000 log2_work=69.176517 tx=13860380 date='2017-05-22T03:18:04Z' progress=0.297017 cache=1.4MiB(10755txo) 2019-12-04T01:26:03Z UpdateTip: new best=00000000000003723a549b8b48d4c2ae2d094f550f403636d7b43c87c2db62cd height=1125282 version=0x00000004 log2_work=69.176549 tx=13860438 date='2017-05-22T03:24:13Z' progress=0.297019 cache=1.6MiB(12100txo) 2019-12-04T01:26:04Z UpdateTip: new best=0000000000000386526ebbff4ce8ca9a55e7ee7c4fdc0b910cf8a75c51308a50 height=1125283 version=0x20000000 log2_work=69.176582 tx=13860450 date='2017-05-22T03:25:12Z' progress=0.297019 cache=1.6MiB(12297txo) 2019-12-04T01:26:05Z UpdateTip: new best=000000000000018eef35fb648845d8e7f481d4c2316a1da59cc43c9c4762c9a7 height=1125284 version=0x20000000 log2_work=69.176614 tx=13860466 date='2017-05-22T03:26:27Z' progress=0.297019 cache=1.6MiB(12513txo) 2019-12-04T01:26:08Z UpdateTip: new best=000000000000032d72c4a3279060c8e2156deb6bc36e2e7d2a140c5084f6d2ca height=1125285 version=0x00000004 log2_work=69.176647 tx=13860517 date='2017-05-22T03:32:32Z' progress=0.297020 cache=1.8MiB(13665txo) 2019-12-04T01:26:13Z UpdateTip: new best=00000000000000d0b9d5388de9b33e3296b94e6c6952286d6bb070c335a804bf height=1125286 version=0x00000004 log2_work=69.17668 tx=13860589 date='2017-05-22T03:40:12Z' progress=0.297022 cache=2.1MiB(15286txo) 2019-12-04T01:26:18Z UpdateTip: new best=00000000000000ae0a18a48930db0d6215c1984ea794dd28c268d68b0850c9a5 height=1125287 version=0x20000000 log2_work=69.176712 tx=13860639 date='2017-05-22T03:45:09Z' progress=0.297023 cache=2.2MiB(16438txo) 2019-12-04T01:26:26Z UpdateTip: new best=00000000000003fa70c76b359ad1982bb68f840ade7a540a04261c5e728ebc15 height=1125288 version=0x20000000 log2_work=69.176745 tx=13860721 date='2017-05-22T03:54:35Z' progress=0.297025 cache=2.5MiB(18253txo) 2019-12-04T01:26:26Z UpdateTip: new best=000000008182bd34ef85039664d7ff03a7bcecffa4dffe6228460519e7ef5b2f height=1125289 version=0x00000004 log2_work=69.176745 tx=13860722 date='2017-05-22T04:18:07Z' progress=0.297025 cache=2.5MiB(18255txo)
啟動測試鏈環境成功
十、bitcoin-cli的使用
1、查看區塊鏈信息
[root@localhost testnet3]# bitcoin-cli -conf=/etc/bitcoin/bitcoin.conf getblockchaininfo { "chain": "test", "blocks": 1126018, "headers": 1611134, "bestblockhash": "0000000000089e5bc5132f3b77dbde948f767379bc1ae7a240cbb5c12949273a", "difficulty": 1, "mediantime": 1496147430, "verificationprogress": 0.2985092456745352, "initialblockdownload": true, "chainwork": "00000000000000000000000000000000000000000000002469714f0601713220", "size_on_disk": 11280836686, "pruned": false, "softforks": [ { "id": "bip34", "version": 2, "reject": { "status": true } }, { "id": "bip66", "version": 3, "reject": { "status": true } }, { "id": "bip65", "version": 4, "reject": { "status": true } } ], "bip9_softforks": { "csv": { "status": "active", "startTime": 1456790400, "timeout": 1493596800, "since": 770112 }, "segwit": { "status": "active", "startTime": 1462060800, "timeout": 1493596800, "since": 834624 } }, "warnings": "" } [root@localhost testnet3]#
2、查看挖礦信息
[root@localhost testnet3]# bitcoin-cli -conf=/etc/bitcoin/bitcoin.conf getmininginfo { "blocks": 1126024, "currentblockweight": 0, "currentblocktx": 0, "difficulty": 1, "networkhashps": 4409027235407.33, "pooledtx": 0, "chain": "test", "warnings": "" }
3、創建一個錢包賬號,實際上是LABEL,對應到一個地址
[root@localhost testnet3]# bitcoin-cli -conf=/etc/bitcoin/bitcoin.conf getnewaddress "test_account" 2N85Jkn6J7a7xA64fJndEQTxJEB8PRsgAss
生成了一個收款地址
4、加密錢包賬號
[root@localhost testnet3]# bitcoin-cli -conf=/etc/bitcoin/bitcoin.conf encryptwallet "123456" wallet encrypted; Bitcoin server stopping, restart to run with encrypted wallet. The keypool has been flushed and a new HD seed was generated (if you are using HD). You need to make a new backup.
加密成功,並重啟服務以運行加密錢包
5、解密錢包
[root@localhost testnet3]# bitcoin-cli -conf=/etc/bitcoin/bitcoin.conf walletpassphrase "123456" 100
6、獲取賬號對應的地址
[root@localhost testnet3]# bitcoin-cli -conf=/etc/bitcoin/bitcoin.conf getaccountaddress "test_account" error code: -32 error message: getaccountaddress is deprecated and will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts.
提示V18版本以后,此接口不在使用,可以在配置文件加deprecatedrpc=accounts 兼容老接口,修改etc/bitcoin/bitcoin.conf配置文件,並重啟bitcoind
[root@localhost testnet3]# bitcoin-cli -conf=/etc/bitcoin/bitcoin.conf getaccountaddress "test_account" 2N2QDYxcC6aYdFzggywjSAyyPdJGrVgSJC1
返回賬戶地址
7、查詢賬戶余額
[root@localhost testnet3]# bitcoin-cli -conf=/etc/bitcoin/bitcoin.conf getbalance "test_account" 0.00000000
8、查詢賬戶列表
[root@localhost testnet3]# bitcoin-cli -conf=/etc/bitcoin/bitcoin.conf listaccounts { "test_account": 0.00000000 } [root@localhost testnet3]#
9、查看區塊高度
[root@localhost testnet3]# bitcoin-cli -conf=/etc/bitcoin/bitcoin.conf getblockcount 1126539
10、為賬戶獲取測試幣
瀏覽器打開https://coinfaucet.eu/en/btc-testnet/,輸入地址獲取測試幣


11、轉賬交易
[root@localhost testnet3]# bitcoin-cli -conf=/etc/bitcoin/bitcoin.conf sendfrom "test_account" "n3T2AtjUcZRPmMf32PZBR7h1piD8XAcH4H" 0.01 error code: -13 error message: Error: Please enter the wallet passphrase with walletpassphrase first. [root@localhost testnet3]#
提示,先解密錢包,因為之前加密了錢包
[root@localhost testnet3]# bitcoin-cli -conf=/etc/bitcoin/bitcoin.conf walletpassphrase "123456" 100 [root@localhost testnet3]#
再執行轉賬交易
