2019年4月25日木曜日

macでmysqlを止められない時の対策

dockerを立ち上がろうとしたら、以下のエラーがでました。
ERROR: for test_db_1  Cannot start service db: driver failed programming external connectivity on endpoint test_db_1 (c0725b1665ce0d657ae65b915142e9e7dfbc8a3405d2b1599f9c26377a894526): Error starting userland proxy: Bind for 0.0.0.0:3306 failed: port is already allocated

ERROR: for db  Cannot start service db: driver failed programming external connectivity on endpoint test_db_1 (c0725b1665ce0d657ae65b915142e9e7dfbc8a3405d2b1599f9c26377a894526): Error starting userland proxy: Bind for 0.0.0.0:3306 failed: port is already allocated

ERROR: Encountered errors while bringing up the project.
つまり、3306ポートが既に使われています。

どんなサービスをそのポート番号を占めているのかを確認します。
 sudo lsof -i:3306
Password:
COMMAND   PID   USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME

mysqld  10115 _mysql   14u  IPv6 0xebcee56ac2cbc277      0t0  TCP *:mysql (LISTEN)
見事に自分のローカルのmysqlでした。
そして、「mysql.server stop」で止めようとしたら、エラーになりました。
 mysql.server stop
 ERROR! MySQL server PID file could not be found!
強制的にプロセスをkillしたら、また立ち上げれました。
そして、以下の方法もためしたました。全部だめでした。
$/usr/local/bin/mysql.server stop

 sudo /usr/local/mysql/bin/mysqld stop
sudo /usr/local/mysql/support-files/mysql.server stop
最後、以下の方法でようやく止めることはできました。
 sudo launchctl unload -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist

エラー「ERROR: Couldn't connect to Docker daemon. You might need to start Docker for Mac.」がでました

久しぶりdockerコマンドを実行したら、以下のエラーがでました。
ERROR: Couldn't connect to Docker daemon. You might need to start Docker for Mac.
docker削除したことを思い出しました。
解決方法として、次のリンクからインストールすることです。https://docs.docker.com/docker-for-mac/install/

2019年4月19日金曜日

Macでgo言語のウェブアプリケーション開発環境のインストール及び設定

1. まず、インストール(Homebrewがインストール済みを前提にします)


$ brew install go
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).
.
.(略)
.
==> Deleted Formulae
safe
==> Downloading https://homebrew.bintray.com/bottles/go-1.12.4.high_sierra.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/99/9920e9264e80f0bac5098a0bbdbd1818c2c44eba37d3b9accd61c1236fcad5f2?__gda__=exp=1555645429~hmac=e139494e5eae781
######################################################################## 100.0%
==> Pouring go-1.12.4.high_sierra.bottle.tar.gz
🍺  /usr/local/Cellar/go/1.12.4: 9,798 files, 452.6MB

2. 癖のようでバージョンを確認する


$ go version
go version go1.12.4 darwin/amd64

3. $GOPATHの設定


echo 'export GOPATH=$HOME/go' >> ~/.bash_profile
echo 'export PATH=$PATH:$GOPATH/bin' >> ~/.bash_profile
source ~/.bash_profile

4. beegoをインストール


$go get -u github.com/astaxie/beego
$go get -u github.com/beego/bee
※ 普通に行けると思ったが、以下のエラーができました。gitがないと怒られました。
go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/astaxie/beego: exec: "git": executable file not found in $PATH
gitをインストールします。→gitのインストール方法を略します。
無事にgitをインストールできたら、再度上記のbeegoインストールコマンドを実行します。今度無事に実行できたようです。
上記実効後、以下のようなフォルダが作成されたら、ダウンロードできた証拠です。
ls  ~/go/src/github.com/
astaxie/  beego/  shiena/

5. プロジェクトを作成


※今回のプロジェクト名は[test-web]とした場合
$ bee new test-web
上記実行すると、[~/go/src/]の配下に[test-web]というプロジェクトが作られたはずです。

6. プロジェクトを実行


作られたプロジェクトの配下に移動した後、[bee run]を実行します。
cd ~/go/src/test-web/
~/go/src/test-web
$ bee run
______
| ___ \
| |_/ /  ___   ___
| ___ \ / _ \ / _ \
| |_/ /|  __/|  __/
\____/  \___| \___| v1.10.0
2019/04/19 14:08:12 INFO     ▶ 0001 Using 'test-web' as 'appname'
2019/04/19 14:08:12 INFO     ▶ 0002 Initializing watcher...
test-web/controllers
test-web/routers
test-web
2019/04/19 14:08:16 SUCCESS  ▶ 0003 Built Successfully!
2019/04/19 14:08:16 INFO     ▶ 0004 Restarting 'test-web'...
2019/04/19 14:08:16 SUCCESS  ▶ 0005 './test-web' is running...
2019/04/19 14:08:19.753 [I] [asm_amd64.s:1337]  http server Running on http://:8080

7. ブラウザーで確認


ブラウザーのアドレスに[http://localhost:8080/] を入力、以下のように表示されるはずです。