关闭

docker安装以太坊

别叨叨 1年前 ⋅ 256 阅读

1在docker中下载以太坊镜像

docker pull ethereum/client-go

2创建目录blockChain

mkdir blockChain

3进入blockChain目录,创建ethereum目录,创建start-ethereum.sh文件,用于启动以太坊锐像

cd blockChain
mkdri ethereum
vim start-ethereum.sh

其中start-ethereum.sh文件的内容如下

docker stop ethereum-node
docker rm ethereum-node
docker run -d --name ethereum-node -v /root/blockChain/ethereum:/root -p 8545:8545 -p 30300:30300 ethereum/client-go
docker exec -it ethereum-node /bin/sh

4测试运行./start-ethereum.sh

给文件添加权限:
chmod u+x start-ethereum.sh

5创建genesis.json文件

cd ethereum
vim genesis.json

内容如下

{
  "config": {
    "chainId": 123,
    "homesteadBlock": 0,
    "eip150Block": 0,
    "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "eip155Block": 0,
    "eip158Block": 0,
    "byzantiumBlock": 0,
    "constantinopleBlock": 0,
    "petersburgBlock": 0,
    "istanbulBlock": 0,
    "ethash": {}
  },
  "nonce": "0x0",
  "timestamp": "0x5ddf8f3e",
  "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "gasLimit": "0x47b760",
  "difficulty": "0x000002",
  "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x0000000000000000000000000000000000000000",
  "alloc": { },
  "number": "0x00",
  "gasUsed": "0x00",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}

并添加执行权限
chmod u+x genesis.json

6启动docker

1执行:

./start-ethereum.sh

2切换到root下

初始化节点,写入创世区块,运行下面的命令 执行:
geth --datadir data0 init genesis.json

3启动节点 执行
geth --identity "TestNode" --datadir data0 --http --http.port "8545" --http.addr "0.0.0.0" -port "30301" --networkid "123" --http.api "eth,net,web3,personal" --nodiscover console --allow-insecure-unlock

安装geth

更新系统

yum -y update

更新下载必要的软件
yum install gcc-c++ -y
yum install git -y
安装golang并配置环境变量
wget https://studygolang.com/dl/golang/go1.14.1.linux-amd64.tar.gz
tar -C /usr/local -zxzf go1.14.1.linux-amd64.tar.gz

# 添加到环境变量
echo "export GOROOT=/usr/local/go" >> /etc/profile
echo "export PATH=/usr/local/go/bin:$PATH" >> /etc/profile
source /etc/profile

# 查看golang版本
go version
安装geth
wget https://gethstore.blob.core.windows.net/builds/geth-alltools-linux-amd64-1.9.10-58cf5686.tar.gz
tar zxvf geth-alltools-linux-amd64-1.9.10-58cf5686.tar.gz
mv geth-alltools-linux-amd64-1.9.10-58cf5686 ~/geth-home
export PATH=$HOME/geth-home:$PATH
echo `export PATH=$HOME/geth-home:$PATH` >> ~/.bashrc

# 添加到环境变量
export PATH=$HOME/geth-home:$PATH >> /etc/profile
echo `export PATH=$HOME/geth-home:$PATH` >> /etc/profile

# 查看geth版本信息
geth version
初始化节点,写入创世区块,关在与genesis.json文件相同的目录下运行

geth --datadir data0 init genesis.json

启动节点
geth --identity "TestNode" --datadir data0 --http --http.port "8545" --http.addr "0.0.0.0" -port "30301" --networkid "123" --http.api "eth,net,web3,personal" --nodiscover console --allow-insecure-unlock
geth --identity "TestNode" --datadir data0 --rpc --rpcport "8545" --rpcaddr "0.0.0.0" -port "30301" --networkid "123" --rpcapi "eth,net,web3,personal" --nodiscover console --allow-insecure-unlock

出现的错误

docker 启动容器错误 rpc error: code = 2 desc = oci runtime error: exec failed: cannot exec a container that has run and stopped

打开docker.service
vi /usr/lib/systemd/system/docker.service
[Service]下添加MountFlags=slave
[Service]
MountFlags=slave
执行
systemctl daemon-reload
执行
systemctl restart docker

全部评论: 0

    我有话说: