LoginSignup
9
5

More than 5 years have passed since last update.

AmazonLinuxでGethをソースコードからコンパイルする

Posted at

AmazonLinuxでGethをソースコードからコンパイルする

AmazonLinuxで開発環境を構築をする際、
Gethがyumに対応していないため、ソースコードからコンパイルする方式の手順まとめ。

  • OS:Amazon Linux AMI 2018.03.0 (HVM), SSD Volume Type - ami-9c9443e3
  • インスタンスタイプ:t2.micro (t2.nanoで実施するとメモリ不足になるので要注意)
  • Golang:v1.10.3(2018/7/9 最新stable)
  • Geth:v1.8.11(2018/7/9 最新stable)

yumリポジトリをupdate

sudo yum update

ソフトウェアのコンパイル準備

make、gccなどの開発ツールをインストール。

sudo yum groupinstall "Development Tools"

go インストール

最新版を取りたかったため、wgetでバイナリを落とす。(バージョンの違いはhttps://golang.org/dl/)

wget https://storage.googleapis.com/golang/go1.10.3.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.10.3.linux-amd64.tar.gz
cd /usr/local/
ls

pathの設定

export PATH=$PATH:/usr/local/go/bin
echo $PATH

gethのインストールとコンパイル

mkdir src
cd src
git clone https://github.com/ethereum/go-ethereum.git
cd go-ethereum
git checkout refs/tags/v1.8.11
make geth
sudo mv ~/src/go-ethereum/build/bin/geth /usr/bin/
geth version

この時、t2.nanoでやったら以下のエラー発生

/usr/local/go/pkg/tool/linux_amd64/link: signal: killed
util.go:45: exit status 1
exit status 1
make: *** [geth] エラー 1

メモリが足りないようですのでt2.micro以上にスケールアップして、再度makeコマンドを実行する。

プライベートネットへの接続

gethのインストールが完了したので、プライベートネットへ接続を試す。
データ保管用のディレクトリ作成。

cd ~
mkdir eth_private_net
cd eth_private_net

json形式の記述したmyGenesis.jsonファイルをeth_private_netに配置。

{
  "config": {
    "chainId": 15
  },
  "nonce": "0x0000000000000042",
  "timestamp": "0x0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "extraData": "",
  "gasLimit": "0x8000000",
  "difficulty": "0x4000",
  "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x3333333333333333333333333333333333333333",
  "alloc": {}
}

genesisブロックの初期化

geth --datadir ~/eth_private_net init ~/eth_private_net/myGenesis.json

gethの起動

geth --networkid "15" --nodiscover --datadir "~/eth_private_net" console 2>> ~/eth_private_net/geth_err.log

プライベート・ネットのGenesisブロックがmyGenesis.jsonに記載されたものになっているのかを確認

eth.getBlock(0)

既に起動したGethプロセスの操作

geth --datadir "/home/ec2-user/eth_private_net" attach ipc:/home/ec2-user/eth_private_net/geth.ipc
9
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
5