zoukankan      html  css  js  c++  java
  • 比特币学习笔记(三)---配置文件和启动

    编译后的几个主要程序

    • bitcoin-qt 客户端图形界面版

    • bitcoind /src/bitcoind Bitcoin简洁命令行版,也是下一步源代码分析的重点(不能与Bitcoin Core同事运行,如果不小心尝试同时运行另外一个客户端,它会提示已经有一个客户端在运行并且自动退出)

    • bitcoin-cli /src/bitcoin-cli Bitcoind的一个功能完备的RPC客户端,可以通过它在命令行查询某个区块信息,交易信息等

    • bitcoin-tx /src/bitcoind 比特币交易处理模块,可以进行交易的查询和创建

    我们现阶段主要学习bitcoind这个程序,这个程序的启动参数大致如下

     //bitcoind 命令通用格式
    
      bitcoind [选项]
    
      bitcoind [选项] <命令> [参数]  将命令发送到 -server 或 bitcoind
    
      bitcoind [选项] help           列出命令
    
      bitcoind [选项] help <命令>    获取该命令的帮助
    
    
     //bitcoind常见命令
    
      -conf=<文件名>     指定配置文件(默认:bitcoin.conf)
    
      -pid=<文件名>      指定 pid (进程 ID)文件(默认:bitcoind.pid)
    
      -gen               生成比特币
    
      -gen=0             不生成比特币
    
      -min               启动时最小化
    
      -splash            启动时显示启动屏幕(默认:1)
    
      -datadir=<目录名>  指定数据目录
    
      -dbcache=<n style="word-wrap: break-word;">       设置数据库缓存大小,单位为兆字节(MB)(默认:25)</n>
    
      -dblogsize=<n style="word-wrap: break-word;">     设置数据库磁盘日志大小,单位为兆字节(MB)(默认:100)</n>
    
      -timeout=<n style="word-wrap: break-word;">       设置连接超时,单位为毫秒</n>
    
      -proxy=<ip:端口 style="word-wrap: break-word;">   通过 Socks4 代理链接</ip:端口>
    
      -dns               addnode 允许查询 DNS 并连接
    
      -port=<端口>       监听 <端口> 上的连接(默认:8333,测试网络 testnet:18333)
    
      -maxconnections=<n style="word-wrap: break-word;">  最多维护 <n style="word-wrap: break-word;">个节点连接(默认:125)</n></n>
    
      -addnode=<ip style="word-wrap: break-word;">      添加一个节点以供连接,并尝试保持与该节点的连接</ip>
    
      -connect=<ip style="word-wrap: break-word;">      仅连接到这里指定的节点</ip>
    
      -irc               使用 IRC(因特网中继聊天)查找节点(默认:0)
    
      -listen            接受来自外部的连接(默认:1)
    
      -dnsseed           使用 DNS 查找节点(默认:1)
    
      -banscore=<n style="word-wrap: break-word;">      与行为异常节点断开连接的临界值(默认:100)</n>
    
      -bantime=<n style="word-wrap: break-word;">       重新允许行为异常节点连接所间隔的秒数(默认:86400)</n>
    
      -maxreceivebuffer=<n style="word-wrap: break-word;">  最大每连接接收缓存,<n style="word-wrap: break-word;">*1000 字节(默认:10000)</n></n>
    
      -maxsendbuffer=<n style="word-wrap: break-word;">  最大每连接发送缓存,<n style="word-wrap: break-word;">*1000 字节(默认:10000)</n></n>
    
      -upnp              使用全局即插即用(UPNP)映射监听端口(默认:0)
    
      -detachdb          分离货币块和地址数据库。会增加客户端关闭时间(默认:0)
    
      -paytxfee=<amt style="word-wrap: break-word;">    您发送的交易每 KB 字节的手续费</amt>
    
      -testnet           使用测试网络
    
      -debug             输出额外的调试信息
    
      -logtimestamps     调试信息前添加[时间戳](http://8btc.com/article-165-1.html)
    
      -printtoconsole    发送跟踪/调试信息到控制台而不是 debug.log 文件
    
      -printtodebugger   发送跟踪/调试信息到调试器
    
      -rpcuser=<用户名>  JSON-RPC 连接使用的用户名
    
      -rpcpassword=<密码>  JSON-RPC 连接使用的密码
    
      -rpcport=<port style="word-wrap: break-word;">    JSON-RPC 连接所监听的 <端口>(默认:8332)</port>
    
      -rpcallowip=<ip style="word-wrap: break-word;">   允许来自指定 <ip style="word-wrap: break-word;">地址的 JSON-RPC 连接</ip></ip>
    
      -rpcconnect=<ip style="word-wrap: break-word;">   发送命令到运行在 <ip style="word-wrap: break-word;">地址的节点(默认:127.0.0.1)</ip></ip>
    
      -blocknotify=<命令> 当最好的货币块改变时执行命令(命令中的 %s 会被替换为货币块哈希值)
    
      -upgradewallet     将钱包升级到最新的格式
    
      -keypool=<n style="word-wrap: break-word;">       将密匙池的尺寸设置为 <n style="word-wrap: break-word;">(默认:100)</n></n>
    
      -rescan            重新扫描货币块链以查找钱包丢失的交易
    
      -checkblocks=<n style="word-wrap: break-word;">   启动时检查多少货币块(默认:2500,0 表示全部)</n>
    
      -checklevel=<n style="word-wrap: break-word;">    货币块验证的级别(0-6,默认:1)</n>
    
    **SSL 选项:**
    
      -rpcssl                                  使用 OpenSSL(https)JSON-RPC 连接
    
      -rpcsslcertificatechainfile=<文件.cert>  服务器证书文件(默认:server.cert)
    
      -rpcsslprivatekeyfile=<文件.pem>         服务器私匙文件(默认:server.pem)
    
      -rpcsslciphers=<密码>                    可接受的密码(默认:TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH)

    这里面大部分参数都可以省略,转而使用配置文件进行配置,因为使用配置文件更方便些,所以这里我们使用配置文件进行配置,在linux下时,bitcoin.conf的默认路径为$HOME/.bitcoin/bitcoin.conf,我们可以从bitcoin源码的share/examples找到一份样本拷贝过去并进行修改,我的配置文件如下:

    ##
    ## bitcoin.conf configuration file. Lines beginning with # are comments.
    ##

    # Network-related settings:

    # Note that if you use testnet or regtest, particularly with the options
    # addnode, connect, port, bind, rpcport, rpcbind or wallet, you will also
    # want to read "[Sections]" further down.

    # 在测试网络中运行,而不是在真正的比特币网络.
    testnet=1

    # Run a regression test network
    # regtest=1

    # 通过一个 Socks5 代理服务器连接
    # proxy=127.0.0.1:9050

    # Bind to given address and always listen on it. Use [host]:port notation for IPv6
    #bind=<addr>

    # Bind to given address and whitelist peers connecting to it. Use [host]:port notation for IPv6
    #whitebind=<addr>

    ##############################################################
    ## addnode 与 connect 的区别 ##
    ## ##
    ## 假设您使用了 addnode=4.2.2.4 参数,那么 addnode 便会与 ##
    ## 您的节点连接,并且告知您的节点所有与它相连接的其它节点。 ##
    ## 另外它还会将您的节点信息告知与其相连接的其它节点,这样它 ##
    ## 们也可以连接到您的节点。 ##
    ## ##
    ## connect 在您的节点“连接”到它的时候并不会做上述工作。仅 ##
    ## 它会与您连接,而其它节点不会。 ##
    ## ##
    ## 因此如果您位于防火墙后,或者因为其它原因无法找到节点,则 ##
    ## 使用“addnode”添加一些节点。 ##
    ## ##
    ## 如果您想保证隐私,使用“connect”连接到那些您可以“信任” ##
    ## 的节点。 ##
    ## ##
    ## 如果您在一个局域网内运行了多个节点,您不需要让它们建立许多 ##
    ## 连接。您只需要使用“connect”让它们统一连接到一个已端口转 ##
    ## 发并拥有多个连接的节点。 ##
    ##############################################################

    # Use as many addnode= settings as you like to connect to specific peers
    #addnode=69.164.218.197
    #addnode=10.0.0.2:8333

    # Alternatively use as many connect= settings as you like to connect ONLY to specific peers
    #connect=69.164.218.197
    #connect=10.0.0.1:8333

    # Listening mode, enabled by default except when 'connect' is being used
    #listen=1

    # Port on which to listen for connections (default: 8333, testnet: 18333, regtest: 18444)
    #port=

    # Maximum number of inbound+outbound connections.
    #maxconnections=

    #
    # JSON-RPC options (for controlling a running Bitcoin/bitcoind process)
    #

    # server=1 tells Bitcoin-Qt and bitcoind to accept JSON-RPC commands
    #server=0

    # Bind to given address to listen for JSON-RPC connections.
    # Refer to the manpage or bitcoind -help for further details.
    #rpcbind=<addr>

    # If no rpcpassword is set, rpc cookie auth is sought. The default `-rpccookiefile` name
    # is .cookie and found in the `-datadir` being used for bitcoind. This option is typically used
    # when the server and client are run as the same user.
    #
    # If not, you must set rpcuser and rpcpassword to secure the JSON-RPC API.
    #
    # The config option `rpcauth` can be added to server startup argument. It is set at initialization time
    # using the output from the script in share/rpcauth/rpcauth.py after providing a username:
    #
    # ./share/rpcauth/rpcauth.py alice
    # String to be appended to bitcoin.conf:
    # rpcauth=alice:f7efda5c189b999524f151318c0c86$d5b51b3beffbc02b724e5d095828e0bc8b2456e9ac8757ae3211a5d9b16a22ae
    # Your password:
    # DONT_USE_THIS_YOU_WILL_GET_ROBBED_8ak1gI25KFTvjovL3gAM967mies3E=
    #
    # On client-side, you add the normal user/password pair to send commands:
    #rpcuser=alice
    #rpcpassword=DONT_USE_THIS_YOU_WILL_GET_ROBBED_8ak1gI25KFTvjovL3gAM967mies3E=
    #
    # You can even add multiple entries of these to the server conf file, and client can use any of them:
    # rpcauth=bob:b2dd077cb54591a2f3139e69a897ac$4e71f08d48b4347cf8eff3815c0e25ae2e9a4340474079f55705f40574f4ec99

    # How many seconds bitcoin will wait for a complete RPC HTTP request.
    # after the HTTP connection is established.
    #rpcclienttimeout=30

    # By default, only RPC connections from localhost are allowed.
    # Specify as many rpcallowip= settings as you like to allow connections from other hosts,
    # either as a single IPv4/IPv6 or with a subnet specification.

    # NOTE: opening up the RPC port to hosts outside your local trusted network is NOT RECOMMENDED,
    # because the rpcpassword is transmitted over the network unencrypted.

    # server=1 tells Bitcoin-Qt to accept JSON-RPC commands.
    # it is also read by bitcoind to determine if RPC should be enabled
    #rpcallowip=10.1.1.34/255.255.255.0
    #rpcallowip=1.2.3.4/24
    #rpcallowip=2001:db8:85a3:0:0:8a2e:370:7334/96

    # 在如下端口监听 RPC 连接
    # rpcport=8332

    # 您可以通过如下设置使用 Bitcoin 或 bitcoind 来发送命令到一个在
    # 其它主机远程运行的 Bitcoin/bitcoind 客户端
    # rpcconnect=127.0.0.1

    # Wallet options

    # Specify where to find wallet, lockfile and logs. If not present, those files will be
    # created as new.
    #wallet=</path/to/dir>

    # Create transactions that have enough fees so they are likely to begin confirmation within n blocks (default: 6).
    # This setting is over-ridden by the -paytxfee option.
    #txconfirmtarget=n

    # Pay a transaction fee every time you send bitcoins.
    #paytxfee=0.000x

    # Miscellaneous options

    # Pre-generate this many public/private key pairs, so wallet backups will be valid for
    # both prior transactions and several dozen future transactions.
    #keypool=100

    # Enable pruning to reduce storage requirements by deleting old blocks.
    # This mode is incompatible with -txindex and -rescan.
    # 0 = default (no pruning).
    # 1 = allows manual pruning via RPC.
    # >=550 = target to stay under in MiB.
    #prune=550

    # User interface options

    # Start Bitcoin minimized
    #min=1

    # Minimize to the system tray
    #minimizetotray=1

    # [Sections]
    # Most options apply to mainnet, testnet and regtest.
    # If you want to confine an option to just one network, you should add it in the
    # relevant section below.
    # EXCEPTIONS: The options addnode, connect, port, bind, rpcport, rpcbind and wallet
    # only apply to mainnet unless they appear in the appropriate section below.

    # Options only for mainnet
    [main]

    # Options only for testnet
    [test]

    # Options only for regtest
    [regtest]

    然后我们只要调用bitcoind -datadir=数据目录,就可以进行bitcoind的启动了。

    我个人的C盘空间吃紧,所以数据目录我就设成了f盘,启动命令如下:

    bitcoind -datadir='/mnt/f/bitcoin_data/'  -conf='/home/lsm/bitcoin/bitcoin.conf'
  • 相关阅读:
    课后作业-阅读任务-阅读提问-3
    团队-团队编程项目作业名称-项目进度
    结对-结对编项目作业名称-测试过程
    结对-英文词频检测-开发过程
    20171002-构建之法:现代软件工程-阅读笔记2
    课后作业-阅读任务-阅读提问-2
    团队-团队编程项目作业名称-代码设计规范
    结队-结队编程项目作业名称-项目进度
    课后作业-阅读任务-阅读提问-1
    结队-贪吃蛇-项目进度
  • 原文地址:https://www.cnblogs.com/lsm19870508/p/11477057.html
Copyright © 2011-2022 走看看