链接: https://www.raspberrypi.org/software/operating-systems/.
对于网络,可以使用网卡,自己手机的热点,也可以使用网线
链接: https://zhuanlan.zhihu.com/p/77585297.
链接: https://www.cnblogs.com/LandWind/p/raspberry_introduction.html.
链接: https://blog.csdn.net/yzy_1996/article/details/82916940.
链接: https://blog.csdn.net/weixin_43624626/article/details/104227725.
配置好树莓派的基本情况便可以进入到树莓派进行以下操作。
使用以下指令定期更新树莓派,可以让系统保持最新的安全补丁和应用程序更新
$ sudo apt update
$ sudo apt full-pgrade
安装所有必要的软件包
$ sudo apt install htop git curl bash-completion jq qrencode dphys-swapfile hdparm --install-recommends
创建一个新的用户“admin”,并把它加入到“sudo”组
$ sudo adduser admin
$ sudo adduser admin sudo
由于比特币需要在后台运行,处于安全原因使用单独的用户“bitcoin”,此用户没有管理权限,无法更改系统配置。
$ sudo adduser bitcoin
把“admin”用户也加入到“bitcoin”组,赋予其配置文件的只读权限。
$ sudo adduser admin bitcoin
重启机器
$ sudo rebot
设置所有者
$ sudo chown -R bitcoin:bitcoin /mnt/ext/
切换到用户“bitcoin”,导航到外部驱动器并创建比特币目录
$ sudo su - bitcoin
$ cd /mnt/ext
$ mkdir bitcoin
$ ls -la
> total 28
> drwxr-xr-x 4 bitcoin bitcoin 4096 Dec 12 17:43 .
> drwxr-xr-x 4 root root 4096 Dec 12 17:38 ..
> drwxr-xr-x 2 bitcoin bitcoin 4096 Dec 12 17:43 bitcoin
> drwx------ 2 bitcoin bitcoin 16384 Dec 12 17:30 lost+found
在新目录中创建一个测试文件并删除它
$ touch bitcoin/test.file
$ rm bitcoin/test.file
退出“bitcoin”用户会话
$ exit
以“管理员”身份登录,并更改为tmp目录,该目录在重新启动时清除
cd/tmp
下载最新的二进制文件,网址为:
链接: https://bitcoincore.org/en/download/.
# download Bitcoin Core binary
$wegthttp://bitcoincore.org/bin/bitcoin-core-0.20.1/bitcoin-0.20.1-arm-linux-genueabihf.tar.gz
$ wget https://bitcoincore.org/bin/bitcoin-core-0.20.1/SHA256SUMS.asc
$ wget https://bitcoin.org/laanwj-releases.asc
# check that the reference checksum matches the real checksum
# (ignore the "lines are improperly formatted" warning)
$sha256sum--checkSHA256SUMS.asc-ignore-missing
>bitcoin-0.20.1-arm-linux-gnueabihf.tar.gz: OK
# import the public key of Wladimir van der Laan, verify the signed checksum file
# and check the fingerprint again in case of malicious keys
$ gpg --import ./laanwj-releases.asc
$ gpg --refresh-keys
$ gpg --verify SHA256SUMS.asc
> gpg: Good signature from "Wladimir J. van der Laan ..."
> Primary key fingerprint: 01EA 5486 DE18 A882 D4C2 6845 90C8 019E 36C2 E964
提取比特币核心二进制文件,安装并检查版本
$ tar -xvf bitcoin-0.20.1-arm-linux-gnueabihf.tar.gz
$ sudo install -m 0755 -o root -g root -t /usr/local/bin bitcoin-0.20.1/bin/*
$ bitcoind --version
> Bitcoin Core version v0.20.1
更改为用户“bitcoin”,并添加只想外部驱动器的象征性链接
$ sudo su - bitcoin
$ ln -s /mnt/ext/bitcoin /home/bitcoin/.bitcoin
导航到主目录并检查符号链接。这个目录的内容实际上将在外部驱动器上
$ ls -la
创建比特币的配置文件,使用作为用户“bitcoin”,用Nano打开它,然后进行以下的配置。
$ nano /mnt/ext/bitcoin/bitcoin.conf
# RaspiBolt: bitcoind configuration
# /mnt/ext/bitcoin/bitcoin.conf
# Bitcoin daemon
server=1
txindex=1
# Network
listen=1
listenonion=1
proxy=127.0.0.1:9050
bind=127.0.0.1
#Connections
rpcuser=raspibol //你的树莓派的root用户名
trpcpassword=PASSWORD_[B] //root密码
zmqpubrawblock=tcp://127.0.0.1:28332
zmqpubrawtx=tcp://127.0.0.1:28333
# Raspberry Pi optimizations
maxconnections=40
maxuploadtarget=5000
# Initial block download optimizations
dbcache=2000
blocksonly=1
以用户“bitcoin”的身份登录,监控日志文件(以root权限开启)
$ bitcoind
系统需要在后台自动运行比特币进程,即使没有人登录。使用“systemd”,这是一个使用配置文件控制启动进程的守护进程。
退出“bitcoin”用户返回用户“admin”
$ exit
在Nano文本编辑器中创建配置文件,
$ sudo nano /etc/systemd/system/bitcoind.service
# RaspiBolt: systemd unit for bitcoind
#/etc/systemd/system/bitcoind.service
[Unit]
Description=Bitcoin daemon
After=network.target
[Service]
# Service execution
###################
ExecStart=/usr/local/bin/bitcoind-daemon\ -pid=/run/bitcoind/bitcoind.pid\ -conf=/mnt/ext/bitcoin/bitcoin.conf\ -datadir=/mnt/ext/bitcoin
# Process management
####################
Type=forking
PIDFile=/run/bitcoind/bitcoind.pid
Restart=on-failure
TimeoutSec=300
RestartSec=30
# Directory creation and permissions
#####################################
Run as bitcoin:bitcoin
User=bitcoin
Group=bitcoin
# /run/bitcoind
RuntimeDirectory=bitcoind
RuntimeDirectoryMode=0710
# Hardening measures
####################
# Provide a private /tmp and /var/tmp.
PrivateTmp=true
# Mount /usr, /boot/ and /etc read-only for the process.
ProtectSystem=full
# Deny access to /home, /root and /run/user
ProtectHome=true
# Disallow the process and all of its children to gain
# new privileges through execve().
NoNewPrivileges=true
# Use a new /dev namespace only populated with API pseudo devices
# such as /dev/null, /dev/zero and /dev/random.PrivateDevices=true
# Deny the creation of writable and executable memory mappings.
MemoryDenyWriteExecute=true
[Install]
WantedBy=multi-user.target
启动服务
$ sudo systemctl enable bitcoind.service
在用户“admin”主页中链接比特币数据目录。作为成员或组“比特币”,管理员可以只读访问某些文件。
$ ln -s /mnt/ext/bitcoin/ /home/admin/.bitcoin
重新启动树莓派
$ sudo reboot
重启后,比特币应该启动并开始同步和验证比特币区块链
使用用户“admin”登录
检查由systemd启动的比特币守护进程的状态
$ systemctl status bitcoind.service
通过监控比特币的日志文件查看比特币的运行情况
$ sudo tail -f /mnt/ext/bitcoin/debug.log
使用比特币核心客户端获取有关当前区块链的信息
$ bitcoin-cli getblockchaininfo
参考教程:
链接: https://stadicus.github.io/RaspiBolt/raspibolt_20_pi.html.
首先,从内核消息中获取一些有关驱动器的信息,清除内核缓冲区,并遵循新消息
$ sudo dmesg -C
$ sudo dmesg -w
将外部驱动器链接到正在运行的树莓派的蓝色USB3端口,最好使用驱动器附带的良好电缆,一旦系统识别出来,详细信息就会由dmesg命令自动显示。
例如:
[ 726.547907] usb 2-1: new SuperSpeed Gen 1 USB device number 3 using xhci_hcd
[ 726.579304] usb 2-1: New USB device found, idVendor=152d, idProduct=0578, bcdDevice= 3.01
[ 726.579321] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 726.579333] usb 2-1: Product: USB 3.0 Device
[ 726.579346] usb 2-1: Manufacturer: USB 3.0 Device
[ 726.579357] usb 2-1: SerialNumber: 000000005B3E
[ 726.582254] usb 2-1: UAS is blacklisted for this device, using usb-storage instead
[ 726.582350] usb 2-1: UAS is blacklisted for this device, using usb-storage instead
[ 726.582364] usb-storage 2-1:1.0: USB Mass Storage device detected
[ 726.582674] usb-storage 2-1:1.0: Quirks match for vid 152d pid 0578: 1800000
[ 726.582783] scsi host0: usb-storage 2-1:1.0
[ 727.598422] scsi 0:0:0:0: Direct-Access INTENSO SATA III SSD 0301 PQ: 0 ANSI: 6
[ 727.599182] sd 0:0:0:0: Attached scsi generic sg0 type 0
[ 727.605796] sd 0:0:0:0: [sda] 937703088 512-byte logical blocks: (480 GB/447 GiB)
[ 727.606519] sd 0:0:0:0: [sda] Write Protect is off
[ 727.606536] sd 0:0:0:0: [sda] Mode Sense: 47 00 00 08
[ 727.607982] sd 0:0:0:0: [sda] Disabling FUA
[ 727.607998] sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[ 727.611337] sda: sda1
[ 727.614890] sd 0:0:0:0: [sda] Attached SCSI disk
使用Ctrl -C退出dmesg
这里列出了所有块设备和他的信息,这里也列出了设备(sda)和他所包含的分区(sda1)
记录您要使用的分区名称(此处为“sda1”)
$ lsblk -o NAME,MOUNTPOINT,UUID,FSTYPE,SIZE,LABEL,MODEL
> NAME MOUNTPOINT UUID FSTYPE SIZE LABEL MODEL
> sda 447.1G SATA_III_SSD
> └─sda1 9ec0b784-d448-4757-a3b2-8abd57c544f3 ext4 447.1G
> mmcblk0 14.9G
> ├─mmcblk0p1 /boot 5203-DB74 vfat 256M boot
> └─mmcblk0p2 / 2ab3f8e1-7dc6-43f5-b0db-dd5759d51d4e ext4 14.6G rootfs
然后测试驱动器的读取性能,确保使用正确的分区名称
$ sudo hdparm -t --direct /dev/sda1
/dev/sda1:
Timing O_DIRECT disk reads: 2 MB in 31.18 seconds = 65.69 kB/sec
使用Ext4格式化外部驱动器上的分区
$ sudo mkfs.ext4 /dev/[NAME]
再次列出设备,并将设备复制到本地计算机上的文本编辑器中。UUID
$ lsblk -o NAME,MOUNTPOINT,UUID,FSTYPE,SIZE,LABEL,MODEL
编辑文件并添加以下作为一个新的行在年底,取而代之的是你自己的UUID
$ sudo nano /etc/fstab
UUID=123456/mnt/extext4rw,nosuid,dev,noexec,noatime,nodiratime,auto,nouser,async,nofail 0 2
创建目录以添加硬盘并设置正确的所有者
$ sudo mkdir /mnt/ext
安装所有驱动器并检查文件系统。是否列出了"/mnt/ext"?
$ sudo mount -a
$ df -h /mnt/ext
> Filesystem Size Used Avail Use% Mounted on
> /dev/sda1 440G 73M 417G 1% /mnt/ext
如果你的外部驱动器不包含任何的分区,可以参考以下教程:
链接: https://superuser.com/questions/643765/creating-ext4-partition-from-console.
链接: https://www.howtogeek.com/106873/how-to-use-fdisk-to-manage-partitions-on-linux/.
$ groups
$ grep “组名” /etc/group
$ sudo su - 用户名
以用户“bitcoin”身份登录:(以root权限开启)
$ sudo su - bitcoin
监控日志文件
$ bitcoind
出现的问题:
退出bitcoin身份,以admin的身份登陆
启动服务:
$ sudo systemctl enable bitcoind.service
检查由systemd启动的比特币守护进程的状态
$ systemctl status bitcoind.service
通过监控比特币的日志文件查看比特币的运行情况
$ sudo tail -f /mnt/ext/bitcoin/debug.log
使用比特币核心客户端获取有关当前区块链的信息
$ bitcoin-cli getblockchaininfo
y@ubuntu:~$ bitcoind -regtest -txindex -daemon
Bitcoin server starting
说明:
-regtest 表示启动的是 regtest 网络;不同网络之间的区别在于创世区块不同。
-txindex 表示对所有的交易进行索引;否则默认只对与钱包地址有关的交易索引
-daemon 表示在后台运行
也可以通过将参数写入配置文件 ~/.bitcoin/bitcoin.conf 的方式
regtest=1
rpcbind=127.0.0.1
rpcallowip=127.0.0.1
rpcuser=test
rpcpassword=test
server=1
daemon=1
txindex=1
然后执行命令,不用带参数:
bitcoind
一般运行regtest网络之后,便会在/home/bitcoin/.bitcoin文件夹中生成regtest网络的文件夹
使用命令,需要带上regtest标志
挖矿:
$ bitcoin-cli -regtest generate 500
查看区块信息:
y@ubuntu:~$ bitcoin-cli -regtest getblockchaininfo
{
"chain": "regtest",
"blocks": 500,
"headers": 500,
"bestblockhash": "0139f2493a3d10dec105df453510b7104e8155e9a536558b2760d2563c5c0f2b",
"difficulty": 4.656542373906925e-10,
"mediantime": 1531385979,
"verificationprogress": 1,
"initialblockdownload": false,
"chainwork": "00000000000000000000000000000000000000000000000000000000000003ea",
"size_on_disk": 156650,
"pruned": false,
"softforks": [
{
"id": "bip34",
"version": 2,
"reject": {
"status": false
}
},
{
"id": "bip66",
"version": 3,
"reject": {
"status": false
}
},
{
"id": "bip65",
"version": 4,
"reject": {
"status": false
}
}
],
"bip9_softforks": {
"csv": {
"status": "active",
"startTime": 0,
"timeout": 9223372036854775807,
"since": 432
},
"segwit": {
"status": "active",
"startTime": -1,
"timeout": 9223372036854775807,
"since": 0
}
},
"warnings": "This is a pre-release test build - use at your own risk - do not use for mining or merchant applications"
}
y@ubuntu:~$ bitcoin-cli -regtest getbalance
12462.50000000
查看钱包默认账户的地址:
y@ubuntu:~$ bitcoin-cli -regtest getaccountaddress
error code: -32
error message:
getaccountaddress is deprecated and will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts.
这是因为getaccountaddress命令在v0.18的版本就被移除了
分配一个新地址:
y@ubuntu:~$ bitcoin-cli -regtest getnewaddress
2MvZH9rH1cQN6NSR6sY1Xkdku2e4hqU9aqX
y@ubuntu:~$ bitcoin-cli -regtest sendtoaddress 2MvZH9rH1cQN6NSR6sY1Xkdku2e4hqU9aqX 100
053753fb919378974b864c8baec3bdd172ad75dd20676b137575be60630fa961
这里向新地址转了100个比特币
输出的结果是该交易的hash
查看该交易的详细信息:
y@ubuntu:~$ bitcoin-cli -regtest getrawtransaction 053753fb919378974b864c8baec3bdd172ad75dd20676b137575be60630fa961
02000000037c2a40e3ff3517d4a4bb66901bb69e37730286909cf1c701dfe755aa2120c1870000000048473044022023a74fa5e2132cf3964202a039c5083cf961637c7ae6f424a2fa6aa8d01dbb7902201ea16f1ecdb3e81edaff01d42559253b5d5d9df3cb711055a60d28dcd45f878a01feffffffeb92121885ca4faadb9855182ec03ce240893576b9f6b57bfd27b09db5ccca950000000049483045022100d58a738b0c9b1611dffbeeafc64b4e7aa2c38bdffe343a72bfb1a9354bf54eaf02207bebbdf3488384e1363c8f974dc49e5d1e479ebc235f1f020004acc361a598ad01feffffff3532dfdd72151e042154ca5745076a6ab20eace399d33e520309a86fb95b70d60000000048473044022064c0d1cbfb3182ee850893b5d9db4b90d21d9c23f79187d77a421ac71a8b84ae02207d521dcb2440f28945676aa040d3dc268ffe4aceea5d2061a1f1a5f23eac36f001feffffff02005c814a0000000017a91486d4ff0b24241ca3fd9260e6addad9bb902d45018700e40b540200000017a914245281b1f0e91afa30736ab9c0f6d9f9536a4a1f87f4010000
y@ubuntu:~$ bitcoin-cli -regtest decoderawtransaction 02000000037c2a40e3ff3517d4a4bb66901bb69e37730286909cf1c701dfe755aa2120c1870000000048473044022023a74fa5e2132cf3964202a039c5083cf961637c7ae6f424a2fa6aa8d01dbb7902201ea16f1ecdb3e81edaff01d42559253b5d5d9df3cb711055a60d28dcd45f878a01feffffffeb92121885ca4faadb9855182ec03ce240893576b9f6b57bfd27b09db5ccca950000000049483045022100d58a738b0c9b1611dffbeeafc64b4e7aa2c38bdffe343a72bfb1a9354bf54eaf02207bebbdf3488384e1363c8f974dc49e5d1e479ebc235f1f020004acc361a598ad01feffffff3532dfdd72151e042154ca5745076a6ab20eace399d33e520309a86fb95b70d60000000048473044022064c0d1cbfb3182ee850893b5d9db4b90d21d9c23f79187d77a421ac71a8b84ae02207d521dcb2440f28945676aa040d3dc268ffe4aceea5d2061a1f1a5f23eac36f001feffffff02005c814a0000000017a91486d4ff0b24241ca3fd9260e6addad9bb902d45018700e40b540200000017a914245281b1f0e91afa30736ab9c0f6d9f9536a4a1f87f4010000
{
"txid": "053753fb919378974b864c8baec3bdd172ad75dd20676b137575be60630fa961",
"hash": "053753fb919378974b864c8baec3bdd172ad75dd20676b137575be60630fa961",
"version": 2,
"size": 414,
"vsize": 414,
"weight": 1656,
"locktime": 500,
"vin": [
{
"txid": "87c12021aa55e7df01c7f19c90860273379eb61b9066bba4d41735ffe3402a7c",
"vout": 0,
"scriptSig": {
"asm": "3044022023a74fa5e2132cf3964202a039c5083cf961637c7ae6f424a2fa6aa8d01dbb7902201ea16f1ecdb3e81edaff01d42559253b5d5d9df3cb711055a60d28dcd45f878a[ALL]",
"hex": "473044022023a74fa5e2132cf3964202a039c5083cf961637c7ae6f424a2fa6aa8d01dbb7902201ea16f1ecdb3e81edaff01d42559253b5d5d9df3cb711055a60d28dcd45f878a01"
},
"sequence": 4294967294
},
{
"txid": "95caccb59db027fd7bb5f6b976358940e23cc02e185598dbaa4fca85181292eb",
"vout": 0,
"scriptSig": {
"asm": "3045022100d58a738b0c9b1611dffbeeafc64b4e7aa2c38bdffe343a72bfb1a9354bf54eaf02207bebbdf3488384e1363c8f974dc49e5d1e479ebc235f1f020004acc361a598ad[ALL]",
"hex": "483045022100d58a738b0c9b1611dffbeeafc64b4e7aa2c38bdffe343a72bfb1a9354bf54eaf02207bebbdf3488384e1363c8f974dc49e5d1e479ebc235f1f020004acc361a598ad01"
},
"sequence": 4294967294
},
{
"txid": "d6705bb96fa80903523ed399e3ac0eb26a6a074557ca5421041e1572dddf3235",
"vout": 0,
"scriptSig": {
"asm": "3044022064c0d1cbfb3182ee850893b5d9db4b90d21d9c23f79187d77a421ac71a8b84ae02207d521dcb2440f28945676aa040d3dc268ffe4aceea5d2061a1f1a5f23eac36f0[ALL]",
"hex": "473044022064c0d1cbfb3182ee850893b5d9db4b90d21d9c23f79187d77a421ac71a8b84ae02207d521dcb2440f28945676aa040d3dc268ffe4aceea5d2061a1f1a5f23eac36f001"
},
"sequence": 4294967294
}
],
"vout": [
{
"value": 12.49991680,
"n": 0,
"scriptPubKey": {
"asm": "OP_HASH160 86d4ff0b24241ca3fd9260e6addad9bb902d4501 OP_EQUAL",
"hex": "a91486d4ff0b24241ca3fd9260e6addad9bb902d450187",
"reqSigs": 1,
"type": "scripthash",
"addresses": [
"2N5Y9hEEtKKW9T6jEhcN4Fs7jvXCVaVA1bS"
]
}
},
{
"value": 100.00000000,
"n": 1,
"scriptPubKey": {
"asm": "OP_HASH160 245281b1f0e91afa30736ab9c0f6d9f9536a4a1f OP_EQUAL",
"hex": "a914245281b1f0e91afa30736ab9c0f6d9f9536a4a1f87",
"reqSigs": 1,
"type": "scripthash",
"addresses": [
"2MvZH9rH1cQN6NSR6sY1Xkdku2e4hqU9aqX"
]
}
}
]
}
生成一个区块,使得交易得到确认:
y@ubuntu:~$ bitcoin-cli -regtest generate 1
[
"223012d674962e92a73b76f2e37277ab723935a0a8d0d68b5d6211997ecb2d06"
]
查看收到的比特币:
y@ubuntu:~$ bitcoin-cli -regtest listreceivedbyaddress
[
{
"address": "2MvZH9rH1cQN6NSR6sY1Xkdku2e4hqU9aqX",
"account": "",
"amount": 100.00000000,
"confirmations": 1,
"label": "",
"txids": [
"053753fb919378974b864c8baec3bdd172ad75dd20676b137575be60630fa961"
]
}
]
参考链接:
链接: https://blog.csdn.net/yzpbright/article/details/81017807.