ISUCON9予選問題をGCP上で構築する
概要
ISUCON9予選問題をGCP上で構築したときのメモ。 やり方はいくつかあると思われるが、下の1→3→2の順に試してみた。
- GitHub - isucon/isucon9-qualify: ISUCON9予選のansible playbookを使う
- vagrant-isucon/isucon9-qualifier-standalone at master · matsuu/vagrant-isucon · GitHubのvagrant fileを使う
- 素ubuntu上に頑張って構築する
1.ansible playbook(断念)
鍵設定を直す必要があるが、面倒そうなので断念。
TASK [setup] ******************************************************************* fatal: [x.x.x.x]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Permission denied (publickey).\r\n", "unreachable": true}
3.素ubuntu上に頑張って構築する
インスタンス作成
必須パッケージのインストール
色々入ってないので入れる。
# とりあえず公式のデータをもってくる sudo apt-get update #しないとダメ sudo apt-get install -y git git clone https://github.com/isucon/isucon9-qualify.git # makeするのに必要なあれこれを入れる sudo apt-get install -y make sudo apt-get install -y gcc make sudo apt-get install -y golang export PATH=”/usr/lib/go-1.10/bin:$PATH” #必要なのか不明 sudo apt-get install -y unzip sudo apt install -y mysql-server mysql-client #docker関連 from https://docs.docker.com/install/linux/docker-ce/ubuntu/ sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg-agent \ software-properties-common curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo apt-key fingerprint 0EBFCD88 sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable" sudo apt-get install docker-ce docker-ce-cli containerd.io sudo docker run hello-world
mysql設定
mysql --version sudo mysql -u root -e 'SHOW databases;' #疎通 sudo mysql -u root -e "set global validate_password_length=6;" #最低文字数はデフォルト8なので減らす sudo mysql -u root -e "CREATE USER 'isucari'@'localhost' IDENTIFIED BY 'isucari';"
公式のインストール手順実施
GitHub - isucon/isucon9-qualify: ISUCON9予選
初期データ作成
cd ~/isucon9-qualify/initial-data/ sudo make #sudo多分必要
初期画像データダウンロード
cd ~/isucon9-qualify/webapp/public/ wget https://github.com/isucon/isucon9-qualify/releases/download/v2/initial.zip unzip initial.zip rm -rf upload mv v3_initial_data upload
ベンチマーク用画像データダウンロード
cd ~/isucon9-qualify/initial-data/ wget https://github.com/isucon/isucon9-qualify/releases/download/v2/bench1.zip unzip bench1.zip rm -rf images mv v3_bench1 images
webapp 起動方法
cd ~/isucon9-qualify/webapp/sql/ sudo mysql -u root < 00_create_database.sql #要sudo ./init.sh cd ~/isucon9-qualify/webapp/go/
ここでGoでよく見かけるアレに遭遇。
$ make main.go:18:2: cannot find package "github.com/go-sql-driver/mysql" in any of: /usr/lib/go-1.10/src/github.com/go-sql-driver/mysql (from $GOROOT) /home/tech150220/go/src/github.com/go-sql-driver/mysql (from $GOPATH) main.go:19:2: cannot find package "github.com/gorilla/sessions" in any of: /usr/lib/go-1.10/src/github.com/gorilla/sessions (from $GOROOT) /home/tech150220/go/src/github.com/gorilla/sessions (from $GOPATH) main.go:20:2: cannot find package "github.com/jmoiron/sqlx" in any of: /usr/lib/go-1.10/src/github.com/jmoiron/sqlx (from $GOROOT) /home/tech150220/go/src/github.com/jmoiron/sqlx (from $GOPATH) main.go:21:2: cannot find package "goji.io" in any of: /usr/lib/go-1.10/src/goji.io (from $GOROOT) /home/tech150220/go/src/goji.io (from $GOPATH) main.go:22:2: cannot find package "goji.io/pat" in any of: /usr/lib/go-1.10/src/goji.io/pat (from $GOROOT) /home/tech150220/go/src/goji.io/pat (from $GOPATH) main.go:23:2: cannot find package "golang.org/x/crypto/bcrypt" in any of: /usr/lib/go-1.10/src/golang.org/x/crypto/bcrypt (from $GOROOT) /home/tech150220/go/src/golang.org/x/crypto/bcrypt (from $GOPATH)
解消のためライブラリを導入。
go get -u github.com/go-sql-driver/mysql go get -u github.com/gorilla/sessions go get -u github.com/jmoiron/sqlx go get -u goji.io go get -u goji.io/pat go get -u golang.org/x/crypto/bcrypt make ./isucari
接続テスト
curlで簡単に確認。
$ curl localhost:8000 <!doctype html><html lang="ja"><head><meta charset="utf-8"/><link rel="shortcut icon" href="/favicon.png"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#f44436"/><link rel="manifest" href="/manifest.json"/><title>ISUCARI</title><
ブラウザでアクセスするために、ファイアウォールで8000番ポートの許可ルールを作る。
ブラウザでhttp://x.x.x.x:8000/にアクセスする。
細かいところやベンチマーカーまで確認してないが、とりあえずアプリは立ち上がったっぽい。 素のubuntuだと色々入ってなかったり、goのライブラリのエラーやらで結構時間食った。次はベンチマーク計測までやりたい。
2.vagrant fileを使う
vagrant-isucon/isucon9-qualifier-standalone at master · matsuu/vagrant-isucon · GitHubのvagrant fileを使う。
インスタンス作成
必須パッケージのインストール
色々入ってないので入れる。
# とりあえず公式のデータをもってくる sudo apt-get update sudo apt-get install -y git git clone https://github.com/isucon/isucon9-qualify.git # makeするのに必要なあれこれを入れる sudo apt-get install -y make gcc sudo apt-get install -y golang export PATH=”/usr/lib/go-1.10/bin:$PATH” #必要なのか不明 sudo apt-get install -y unzip sudo apt install -y mysql-server mysql-client #docker関連 from https://docs.docker.com/install/linux/docker-ce/ubuntu/ sudo apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo apt-key fingerprint 0EBFCD88 sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" sudo apt-get install -y docker-ce docker-ce-cli containerd.io sudo docker run hello-world
トラブルシューティング
Failed to connect socket to '/var/run/libvirt/libvirt-sock'
単純にsudo vagrant upするとこれになった。多分ソフトウェアインストールが足りない?
Error while connecting to libvirt: Error making a connection to libvirt URI qemu:///system?no_verify=1&keyfile=/home/***/.ssh/id_rsa: Call to virConnectOpen failed: Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
Timed out
このdefault: SSH auth method: private keyがいくつかOS変えて試してみたけど突破できなかった。
==> default: Waiting for machine to boot. This may take a few minutes... default: SSH address: 127.0.0.1:2222 default: SSH username: vagrant default: SSH auth method: private key #<Thread:0x00005627c6868460@/usr/share/rubygems-integration/all/gems/vagrant-2.0.2/lib/vagrant/batch_action.rb:71 run> terminated with exception (report_on_exception is true): Traceback (most recent call last): Timed out while waiting for the machine to boot. This means that Vagrant was unable to communicate with the guest machine within the configured ("config.vm.boot_timeout" value) time period. If you look above, you should be able to see the error(s) that Vagrant had when attempting to connect to the machine. These errors are usually good hints as to what may be wrong. If you're using a custom box, make sure that networking is properly working and you're able to connect to the machine. It is a common problem that networking isn't setup properly in these boxes. Verify that authentication configurations are also setup properly, as well. If the box appears to be booting properly, you may want to increase the timeout ("config.vm.boot_timeout") value.