1 进入一个ubuntu容器后基础的准备
apt-get install python-software-properties
apt-get install software-properties-common
apt-get install vim
2安装solc
add-apt-repository ppa:ethereum/ethereum
apt-get update
apt-get install solc
3 安装Geth客户端
有多种以太坊客户端,安装Go-ethereum输入以下命令:
add-apt-repository -y ppa:ethereum/ethereum
apt-get update
apt-get install ethereum
4 开始创建节点,创建一个目录,
mkdir private-geth
cd private-geth
vim genesis.json
{
"config": {
"chainId": 12345,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"coinbase" : "0x0000000000000000000000000000000000000000",
"difficulty" : "0x400",
"extraData" : "0x123456",
"gasLimit" : "0xffffffff",
"nonce" : "0x0000000000000042",
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00",
"alloc": { }
}
初始化初始块,进入geth平台
root@f2b5cdfdc5ed:/private-geth# geth --datadir ./data/00 init genesis.json
geth --identity "haha" --datadir ./data/00 --networkid 12345 --rpcapi "db,eth,net,web3" --port 2220 --rpcport 3330 console
(geth --datadir "./" --nodiscover console 2>>geth.log)
然后查看该节点的信息
{ enode: "enode://3452dd408cd4f1fb160725388579f28f2b0552ed63d5291a1e2615f60329355c296f00f6c61ddd671c429017b3e5ec6eb31304d5552aec817faa506507dcdc32@[::]:2220", id: "3452dd408cd4f1fb160725388579f28f2b0552ed63d5291a1e2615f60329355c296f00f6c61ddd671c429017b3e5ec6eb31304d5552aec817faa506507dcdc32", ip: "::", listenAddr: "[::]:2220", name: "Geth/haha/v1.6.7-stable-ab5646c5/linux-amd64/go1.8.1", ports: { discovery: 2220, listener: 2220 },
protocols: { eth: { difficulty: 4357056, genesis: "0x29a42341a89cace1a303a40ca106b875f0ea4113a6e0a39dbbc663e9dfb8fb3f", head: "0x5163295934480c8b167698157ebe7e378c33f7a6fab0e19412947f65ca455f1a", network: 12345 }
}
}
查看ip
root@f2b5cdfdc5ed:/# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
273: eth0@if274: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:12:00:04 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 172.18.0.4/16 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::42:acff:fe12:4/64 scope link
valid_lft forever preferred_lft forever
第二个容器
ucsmy@QKTEST21191:~$ docker run -it --name ubuntublock1 -p 80:80 ebcd9d4fca80
docker: Error response from daemon: driver failed programming external connectivity on endpoint ubuntublock1 (da48c27d902362bd4678531c148e58df7c361a6e4fc61416ab8b4d97b435281b): Bind for 0.0.0.0:80 failed: port is already allocated.
```
```
ucsmy@QKTEST21191:~$ docker run -it --name ubuntublock1 -p 82:82 ebcd9d4fca80
docker: Error response from daemon: Conflict. The name "/ubuntublock1" is already in use by container 8a76dface80ee116e383bbb486f06d4a2184029617f9be016bae95d7b174ed11. You have to remove (or rename) that container to be able to reuse that name..
See 'docker run --help'.
但是查看的时候容器还是已经存在了
ucsmy@QKTEST21191:~$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8a76dface80e ebcd9d4fca80 "/bin/bash" About a minute ago Created ubuntublock1
f2b5cdfdc5ed ebcd9d4fca80 "/bin/bash" 22 hours ago Up 22 hours 0.0.0.0:80->80/tcp ubuntublock
进入容器
docker attach ubuntublock1
开始搭建以太坊环境
root@03fb89fa98ec:/# apt-get install git
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package git
然后需要更新一下包
apt-get update
准备工作
apt-get install python-software-properties
apt-get install software-properties-common
apt-get install vim
安装geth
add-apt-repository -y ppa:ethereum/ethereum
apt-get update
apt-get install ethereum
mkdir private-geth
cd private-geth
vim genesis.json
{
"config": {
"chainId": 12345,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"coinbase" : "0x0000000000000000000000000000000000000000",
"difficulty" : "0x400",
"extraData" : "0x123456",
"gasLimit" : "0xffffffff",
"nonce" : "0x0000000000000042",
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00",
"alloc": { }
}
初始化geth并且进入geth
geth --datadir ./data/01 init genesis.json
geth --identity "haha" --datadir ./data/01 --networkid 12345 --rpcapi "db,eth,net,web3" --port 2221 --rpcport 3331 console
admin.addPeer("enode://3452dd408cd4f1fb160725388579f28f2b0552ed63d5291a1e2615f60329355c296f00f6c61ddd671c429017b3e5ec6eb31304d5552aec817faa506507dcdc32@172.18.0.4:2220")
节点连接成功以后自动同步区块信息。
第三个容器
:/private-geth# geth --datadir ./data/00 init genesis.json
geth --identity "haha" --datadir ./data/00 --networkid 12345 --rpcapi "db,eth,net,web3" --port 2222 --rpcport 3332 console
admin.addPeer("enode://3452dd408cd4f1fb160725388579f28f2b0552ed63d5291a1e2615f60329355c296f00f6c61ddd671c429017b3e5ec6eb31304d5552aec817faa506507dcdc32@172.18.0.4:2220")