garbagetown

個人の日記です

Amazon Linux 2 で X-Ray デーモンを build する

基本的な手順は README に書いてあるけど Go 弱者で何度やっても GOPATH 辺りの内容を忘れるので手順をメモ。

当時の関連するツイート。 ghq と相性が悪いので go 関連のリポジトリは自前で git clone すると良さそう。

手順

Amazon Linux 2 に SSH ログインしたら go 1.11 をインストールして GOPATH を設定。 今回は ~/repo/go を GOPATH にしてみた。

[ec2-user@ip-172-31-17-41 ~]$ sudo amazon-linux-extras install -y golang1.11
...
[ec2-user@ip-172-31-17-41 ~]$ go version
go version go1.11.13 linux/amd64

[ec2-user@ip-172-31-17-41 ~]$ mkdir -p ~/repo/go/src ~/repo/go/bin
[ec2-user@ip-172-31-17-41 ~]$ echo 'export GOPATH=~/repo/go' >> ~/.bash_profile 
[ec2-user@ip-172-31-17-41 ~]$ echo 'export PATH=$GOPATH/bin:$PATH' >> ~/.bash_profile 
[ec2-user@ip-172-31-17-41 ~]$ source ~/.bash_profile

X-Ray デーモンは依存性の解決に Glide を使っているのでインストールする。

[ec2-user@ip-172-31-17-41 ~]$ curl https://glide.sh/get | sh
...
glide version v0.13.3 installed successfully

GOPATH 配下に github.com/aws ディレクトリを作って x-ray-daemon を clone する。

[ec2-user@ip-172-31-17-41 ~]$ mkdir -p ~/repo/go/src/github.com/aws
[ec2-user@ip-172-31-17-41 ~]$ cd ~/repo/go/src/github.com/aws/
[ec2-user@ip-172-31-17-41 aws]$ git clone https://github.com/aws/aws-xray-daemon.git
...

glide install して make build-linux する。

[ec2-user@ip-172-31-17-41 aws]$ cd aws-xray-daemon/
[ec2-user@ip-172-31-17-41 aws-xray-daemon]$ glide install
...
[INFO]  Replacing existing vendor dependencies
[ec2-user@ip-172-31-17-41 aws-xray-daemon]$ make build-linux
Build for Linux amd64
GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o /home/ec2-user/repo/go/src/github.com/aws/aws-xray-daemon/build/xray/xray ./daemon/daemon.go ./daemon/tracing.go

build/xray/ にバイナリがビルドされるのでリージョンを指定して起動する。 オプションの詳細はドキュメントを参照。

[ec2-user@ip-172-31-17-41 aws-xray-daemon]$ ls -la build/xray/
...
-rwxrwxr-x 1 ec2-user ec2-user 9493024 Sep 28 22:11 xray
[ec2-user@ip-172-31-17-41 aws-xray-daemon]$ ./build/xray/xray -n ap-northeast-1
2019-09-28T22:12:28Z [Info] Initializing AWS X-Ray daemon 3.1.0
2019-09-28T22:12:28Z [Info] Using buffer memory limit of 9 MB
2019-09-28T22:12:28Z [Info] 144 segment buffers allocated
2019-09-28T22:12:28Z [Info] Using region: ap-northeast-1
2019-09-28T22:12:28Z [Info] HTTP Proxy server using X-Ray Endpoint : https://xray.ap-northeast-1.amazonaws.com
2019-09-28T22:12:28Z [Info] Starting proxy http server on 127.0.0.1:2000

なにか間違っていたら教えてください。