MySQLのデータをgrafanaで表示させてみた
概要
MySQLのデータをgrafanaで表示させてみた
環境
前提
MySQL自体はインストール済みの前提で書く
grafana install
- https://grafana.com/docs/grafana/latest/installation/debian/
- latest OSS releaseのインストール手順に従って進める
sudo apt-get install -y apt-transport-https sudo apt-get install -y software-properties-common wget wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
stable releaseがほしい場合は以下の設定でリポジトリを追加
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
install
sudo apt-get update sudo apt-get install grafana
起動
wsl なのでinit.dの起動手順
[~] $sudo service grafana-server start server status * Starting Grafana Server [ OK ] [~] $sudo service grafana-server status * grafana is running [~] $
grafanaのログ
grafanaのログは以下にあるので、接続などで問題があったら確認するといい
[~] $sudo cat /var/log/grafana/grafana.log
grafana をUI上で確認・設定
手順
問題なければ以下にアクセスすれば見られる
http://localhost:3000/
MySQL側のデータベースとテーブルを用意
mysqldの起動とMySQLへの接続
[~] $sudo service mysql start * Starting MySQL database server mysqld [ OK ] [~] $ [~] $mysql -u root --host 127.0.0.1 --port 3306 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 40 Server version: 5.7.30-0ubuntu0.18.04.1 (Ubuntu) Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
データベース作成
CREATE DATABASE IF NOT EXISTS grafana_db;
サンプルのテーブル作成
CREATE TABLE IF NOT EXISTS grafana_db.sample_table ( id VARCHAR(10), data_time DATETIME, data_value int(10), PRIMARY KEY( id, data_time ) );
試しに以下のようなテストデータを入れる
use grafana_db; INSERT INTO `sample_table` VALUES ('1001','2020-12-02 15:00:00', 1211); INSERT INTO `sample_table` VALUES ('1001','2020-12-02 16:00:00', 1220); INSERT INTO `sample_table` VALUES ('1001','2020-12-02 17:00:00', 1234); INSERT INTO `sample_table` VALUES ('1001','2020-12-02 18:00:00', 1240); INSERT INTO `sample_table` VALUES ('1002','2020-12-02 15:00:00', 1310); INSERT INTO `sample_table` VALUES ('1002','2020-12-02 16:00:00', 1305); INSERT INTO `sample_table` VALUES ('1002','2020-12-02 17:00:00', 1275); INSERT INTO `sample_table` VALUES ('1002','2020-12-02 18:00:00', 1100);
データの確認
mysql> select * from grafana_db.sample_table; +------+---------------------+------------+ | id | data_time | data_value | +------+---------------------+------------+ | 1001 | 2020-12-02 15:00:00 | 1211 | | 1001 | 2020-12-02 16:00:00 | 1220 | | 1001 | 2020-12-02 17:00:00 | 1234 | | 1001 | 2020-12-02 18:00:00 | 1240 | | 1002 | 2020-12-02 15:00:00 | 1310 | | 1002 | 2020-12-02 16:00:00 | 1305 | | 1002 | 2020-12-02 17:00:00 | 1275 | | 1002 | 2020-12-02 18:00:00 | 1100 | +------+---------------------+------------+ 8 rows in set (0.00 sec)
grafana用のユーザ作成
Grafanaからアクセスするためのユーザーを作成
- root権限でアクセスさせてしまうと、grafana上で操作したクエリでDBを書き換えることができてしまうので強く推奨されている!
参考:https://grafana.com/docs/grafana/latest/datasources/mysql/#database-user-permissions-important
ここでは適当にpasswordは「password」とした
CREATE USER 'grafanaReader' IDENTIFIED BY 'password'; GRANT SELECT ON grafana_db.sample_table TO 'grafanaReader';
grafanaとmysql連携
Data Sourcesを選択
「MySQL」を選んで上で作成したデータベースを登録
- Userは事前に設定したgranadaReaderにする
- Passwordは上で設定した「password」にする(すでにconfiguredになっていたらResetすると再度設定できる)
「Save&Test」ボタンを押して、うまく接続できていればOKが出る
ダッシュボードの作成
Add New Panelを押して、ダッシュボードを設定する
公式ドキュメントは以下が一番詳しいはずなので以下基本的にこのページを参考にする
このままUIからできなくはなさそうなんだけど、右上のペン「🖊」をクリックして直接SQLを書いたほうが確かなので自分は以下のようにした
以下を記入
SELECT UNIX_TIMESTAMP(data_time) AS "time", id AS metric, data_value FROM sample_table WHERE $__timeFilter(data_time) ORDER BY data_time
一旦欄外のどこかを押すと、書いたクエリが反映されてグラフが描画される
上の意味について以下に簡単な説明を書く
グラフに必要な項目
grafanaで時系列データとして描画するためには、最低でも以下の3項目が必要らしい
- time:横軸となるUnixエポック時
- datetime, timestamp, date型などのMySQLの型の形であれば文字列でもいい
- metric:グラフ表示名
- データによってIDだったりNameだったりCategoryだったりそういうものを項目名として使う
- value:グラフの縦軸の数値
- 数値である必要がある
クエリの意味
- UNIX_TIMESTAMP(data_time) で、MySQLのテーブルのデータ
data_time
をgrafanaの横軸(時系列)として使用するため、AS "time"
としている - idをグラフの項目名として扱うため
AS metric
としている - data_valueをvalueとしている。明示的に
AS value
としてもいい
MySQLのデータをgrafanaで描画する上での注意点
1. UNIX_TIMESTAMPを設定しないとMySQLの日付データをJSTとして扱ってくれない
UNIX_TIMESTAMPをつけないと、データベースに日本時間JSTで登録したつもりでも、grafanaに描画するときにGMTだと判断されて+9時間ずれてしまう
- 元の「2020-12-02 15:00:00」などの時刻からきっかり9時間ずれていることがわかる
参考
2. valueに数値型以外の項目を設定すると表示されない
以下のようにテーブルを一旦削除して、data_valueをVARCHARとして定義してみる
drop table sample_table; CREATE TABLE IF NOT EXISTS grafana_db.sample_table ( id VARCHAR(10), data_time DATETIME, data_value VARCHAR(10), PRIMARY KEY( id, data_time ) ); INSERT INTO `sample_table` VALUES ('1001','2020-11-30 15:00:00', '1211'); INSERT INTO `sample_table` VALUES ('1001','2020-11-30 16:00:00', '1220'); INSERT INTO `sample_table` VALUES ('1001','2020-11-30 17:00:00', '1234'); INSERT INTO `sample_table` VALUES ('1001','2020-11-30 18:00:00', '1240'); INSERT INTO `sample_table` VALUES ('1002','2020-11-30 15:00:00', '1310'); INSERT INTO `sample_table` VALUES ('1002','2020-11-30 16:00:00', '1305'); INSERT INTO `sample_table` VALUES ('1002','2020-11-30 17:00:00', '1275'); INSERT INTO `sample_table` VALUES ('1002','2020-11-30 18:00:00', '1100');
すると、valueが数値として認識できずに以下のようなエラーが出て描画できなくなる
Value column must have numeric datatype, column: data_value type: string value: 1211
文字列を数値型として扱うためには以下のようにCAST関数を使う
CAST(data_value AS UNSIGNED)
参考: https://stackoverflow.com/questions/12126991/cast-from-varchar-to-int-mysql
3. 横軸の時間が時刻型でないと表示されない
上と同様に、横軸は時刻型でないと表示されない
以下のようにテーブルを一旦削除して、data_timeをVARCHARとして定義してみる
drop table sample_table; CREATE TABLE IF NOT EXISTS grafana_db.sample_table ( id VARCHAR(10), data_time VARCHAR(20), data_value VARCHAR(10), PRIMARY KEY( id, data_time ) ); INSERT INTO `sample_table` VALUES ('1001','2020-11-30 15:00:00', '1211'); INSERT INTO `sample_table` VALUES ('1001','2020-11-30 16:00:00', '1220'); INSERT INTO `sample_table` VALUES ('1001','2020-11-30 17:00:00', '1234'); INSERT INTO `sample_table` VALUES ('1001','2020-11-30 18:00:00', '1240'); INSERT INTO `sample_table` VALUES ('1002','2020-11-30 15:00:00', '1310'); INSERT INTO `sample_table` VALUES ('1002','2020-11-30 16:00:00', '1305'); INSERT INTO `sample_table` VALUES ('1002','2020-11-30 17:00:00', '1275'); INSERT INTO `sample_table` VALUES ('1002','2020-11-30 18:00:00', '1100');
以下のようなエラーが出る
- invalid type for column time, must be of type timestamp or unix timestamp, got: string 2020-11-30 15:00:00
ただ、これは実は先ほどの UNIX_TIMESTAMP
を使えば日付として認識される問題ない
基本的には以下の公式ページを見ると解決できそうだった
- https://grafana.com/docs/grafana/latest/datasources/mysql/
- https://community.grafana.com/t/how-to-add-time-series-queries-with-grafana-and-mysql/3170
4. データベース上でDOUBLE型の数値をグラフ化するとガタガタになる
MySQL上で、DOUBLE型で定義している数値を上と同様に
CAST(doublevalue AS UNSIGNED) AS "value1"
のようにして描画すると、以下のように小数点が切り捨てられてガタガタのグラフになってしまった。
以下のようにDECIMALとして扱うと滑らかになる
CAST(doublevalue AS DECIMAL(10,1)) AS "value1"
ついでに、Y軸の Decimals
を以下のように1以上の値にすると、グラフ上も小数点単位で表示されるようになる
その他のTips
variablesを使ったフィルタリング
以下のように複数データがある時に、一つに絞りたいときはvariablesを使ったフィルタリングができる
右上の歯車マークの設定ボタンを押して、
Variablesを選んで以下のように設定する
- 以下は、dailyというテーブルに
code
というカラムがあるという前提で、このcode
でフィルターしたいときの設定方法
General
- Name: フィルター項目名
Query Options
- Data source: MySQL
- Query:
SELECT code FROM daily
Selection Options
- Include All option: ONにする
ここまですると、Preview of values
にフィルター項目が列挙される
もとのグラフに戻ると以下のようなフィルター設定が追加されて、見たい項目だけ選択することができる
参考:https://grafana.com/docs/grafana/latest/datasources/mysql/#query-variable
公式以外に参考にさせていただいたページ
Docker for Windowsのインストールとトラブル対応
参考
WSL(Bash on Windows)でDockerを使用する - Qiita
Docker for Windows を始めよう — Docker-docs-ja 19.03 ドキュメント
Windows に Docker Desktop をインストール — Docker-docs-ja 19.03 ドキュメント
この辺を参考にDocker for WindowsをインストールしたけどうまくHyper-Vが立ち上がってくれなかったので対応したこと
前提
PCはWindows10のProである必要がある
インストーラのダウンロードとインストール
https://hub.docker.com/editions/community/docker-ce-desktop-windows/
インストーラをクリックしてインストールする
アプリを起動
Docker Desktopアプリを起動
デスクトップ上にショートカットのアイコンがあればそれをクリック またはWindowsキーで検索する
自分の場合はここで Cannnot enable Hyper-V service
と出てしまった(対応は後述)
上のポップアップを消してしまうとDockerアプリも閉じてしまうみたいなのでここではわきにどけてそのまま続けた
設定画面
How open docker settings on windows? - Super User
アプリの設定は上のリンク先にも書いてある通り、起動中はWindowsの右下の「上向きの三角っぽい矢印の中」に隠れている
これを押して「Settings」を押す
この「Expose daemon on tcp://localhost:2375 without TLS」チェックを入れて「Apply&Restart」する
WSL上でDockerインストール
Install Docker Engine on Ubuntu | Docker Documentation
# 事前パッケージインストール $ sudo apt-get update $ sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg-agent \ software-properties-common # DockerのGPG鍵を追加,確認 $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - $ sudo apt-key fingerprint 0EBFCD88 # Docker Stableレポジトリを追加 $ sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable" # Dockerインストール $ sudo apt-get update $ sudo apt-get install docker-ce docker-ce-cli containerd.io
WSL上のDocker設定
自分の場合はzshを使っているので、.zshrcを編集する。bashの人は.bashrcにする
echo "export DOCKER_HOST='tcp://0.0.0.0:2375'" >> ~/.zshrc source ~/.zshrc
確認
docker version
をターミナルで実行すると、おかしい
Cannot connect to the Docker daemon at tcp://0.0.0.0:2375. Is the docker daemon running?
というメッセージが出た
Serverは表示されない
$docker version Client: Docker Engine - Community Version: 19.03.12 API version: 1.40 Go version: go1.13.10 Git commit: 48a66213fe Built: Mon Jun 22 15:45:36 2020 OS/Arch: linux/amd64 Experimental: false Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
参考
Hyper-Vが立ち上がってくれない問題対応
Windows 10 での Hyper-V の有効化 | Microsoft Docs
を参考にやってみたがうまくいかない
自分の場合は事前に「Hyper-V」がチェックが入っていた
調べた結果
Cannot enable hyper-v service - Docker Desktop for Windows - Docker Forums
got to ‘Apps and Features’. Select Programs and Features on the right under related settings. Select Turn Windows Features on or off. Unselect Hyper-V and click OK. (So I disable it) Restart computer After restart I go to: ‘Apps and Features’. Select Programs and Features on the right under related settings. Select Turn Windows Features on or off. select Hyper-V and click OK. (So I enable it) Computer restart
という記述を見つけて、いったんチェックを外して再起動、もう一度チェックを入れて再起動したら、今度はHyper-Vが立ち上がったらしい(DockerDesktopアプリを起動してもエラーが出なかった!)
再度確認
$docker version Client: Docker Engine - Community Version: 19.03.12 API version: 1.40 Go version: go1.13.10 Git commit: 48a66213fe Built: Mon Jun 22 15:45:36 2020 OS/Arch: linux/amd64 Experimental: false Server: Docker Engine - Community Engine: Version: 19.03.12 API version: 1.40 (minimum version 1.12) Go version: go1.13.10 Git commit: 48a66213fe Built: Mon Jun 22 15:49:27 2020 OS/Arch: linux/amd64 Experimental: false containerd: Version: v1.2.13 GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429 runc: Version: 1.0.0-rc10 GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd docker-init: Version: 0.18.0 GitCommit: fec3683
ようやく表示された。 ふー
circleciのworking_directoryにルートディレクトリを指定したらcheckoutで失敗するようになった
概要
タイトルのとおり、circleciのworking_directoryにルートディレクトリ以下のパスを指定したらcheckoutで失敗するようになった
経緯
自分はもともとはworking_directoryに以下のように設定していた
working_directory: /go/src/github.com/ludwig125/
これで何も問題なく毎日ジョブが起動できていたのだが、2020/8/5のジョブで突然以下のエラーが出て失敗するようになった
mkdir: can't create directory '/go/': Permission denied
調査
circleciのcheckout stepでは以下のようなスクリプトが内部で実行されている
- 仕様は後述の参考のリンクに載っている
自分のジョブのcheckout 実行内容
(略) # use git+ssh instead of https git config --global url."ssh://git@github.com".insteadOf "https://github.com" || true git config --global gc.auto 0 || true if [ -e /go/src/github.com/ludwig125/my-repository/.git ] then cd /go/src/github.com/ludwig125/my-repository git remote set-url origin "$CIRCLE_REPOSITORY_URL" || true else mkdir -p /go/src/github.com/ludwig125/ cd /go/src/github.com/ludwig125/ git clone "$CIRCLE_REPOSITORY_URL" . fi if [ -n "$CIRCLE_TAG" ] then git fetch --force origin "refs/tags/${CIRCLE_TAG}" else git fetch --force origin "master:remotes/origin/master" fi if [ -n "$CIRCLE_TAG" ] then git reset --hard "$CIRCLE_SHA1" git checkout -q "$CIRCLE_TAG" elif [ -n "$CIRCLE_BRANCH" ] then git reset --hard "$CIRCLE_SHA1" git checkout -q -B "$CIRCLE_BRANCH" fi git reset --hard "$CIRCLE_SHA1"
今回ここの「/go/src/github.com/ludwig125/」がcircleciで設定していたworking_directoryだった
my_job: working_directory: /go/src/github.com/ludwig125 # この設定によって、stepsのcheckout時にworking_directory以下にgitのリポジトリがgit cloneされる docker: - image: google/cloud-sdk:alpine steps: - checkout 以下略
circleciのジョブは再実行して失敗した時点でその仮想機にsshして確認できるという素晴らしい機能があるのでそれで再実行してみる
ー> 「Rerun Job with SSH」を押す
sshして仮想機に入って mkdir -p /go/src/github.com/ludwig125/
をしてみるとやっぱり同じエラーが出た
mkdir: can't create directory '/go/': Permission denied
ためしに作るディレクトリをホームディレクトリ以下に変えてみるとこれは成功
mkdir -p ~/go/src/github.com/ludwig125/
参考
https://circleci.com/docs/ja/2.0/configuration-reference/
この例の checkout ステップは、プロジェクトのソース コードをジョブの working_directory にチェックアウトします。
https://circleci.com/docs/ja/2.0/configuration-reference/#jobs
working_directory ステップを実行するディレクトリ。 デフォルトは ~/project となります (この project は特定のプロジェクトの名前ではなく、リテラル文字列)。 ジョブ内で実行するプロセスでは、$CIRCLE_WORKING_DIRECTORY 環境変数を介してこのディレクトリを参照できます。 メモ: YAML 設定ファイルに記述したパスは展開されません。
対応
ということで、やったことは以下だけ
- 修正前
working_directory: /go/src/github.com/ludwig125/
- 修正後
working_directory: ~/go/src/github.com/ludwig125/
これでなんの問題もなくcheckoutができるようになった
GKEクラスタを作成するときに--no-enable-cloud-loggingオプションが使えなくなったっぽい
前提
自分は格安でGKEを使うために、g1-smallで運用している
GKEでデフォルトのクラスタを作成すると、ログ転送用にfluentdなどのPodが立ち上がってしまう。
このうちfluentdが結構なCPUとMemoryを使用してしまうので、自分は以下にあるような方法で
--no-enable-cloud-logging
を指定することでfluentdを動かないようにさせていた。
Fluentd を使用した Google Kubernetes Engine 用の Cloud Logging ログのカスタマイズ
gcloud beta container clusters create gke-with-custom-fluentd \ --zone us-east1-b \ --no-enable-cloud-logging \ --tags=gke-cluster-with-customized-fluentd \ --scopes=logging-write
これでクラスタを作成すると、以下のようなWarningは出るものの、これまでなんとか使えていた
WARNING: From 1.14, legacy Stackdriver GKE logging is deprecated. Thus, flag `--enable-cloud-logging` is also deprecated. Please use `--enable-stackdriver-kubernetes` instead, to migrate to new Stackdriver Kubernetes Engine monitoring and logging. For more details, please read: https://cloud.google.com/monitoring/kubernetes-engine/migration.
起きたこと
これまではWarningだったけど、ついに完全に使えなくなったっぽい
$gcloud --quiet container clusters create $CLUSTER_NAME \ > --machine-type=$MACHINE_TYPE --disk-size 10 --zone $COMPUTE_ZONE \ > --no-enable-cloud-logging \ > --num-nodes=$NUM_NODES --preemptible WARNING: From 1.14, legacy Stackdriver GKE logging is deprecated. Thus, flag `--enable-cloud-logging` is also deprecated. Please use `--enable-stackdriver-kubernetes` instead, to migrate to new Stackdriver Kubernetes Engine monitoring and logging. For more details, please read: https://cloud.google.com/monitoring/kubernetes-engine/migration. WARNING: Currently VPC-native is not the default mode during cluster creation. In the future, this will become the default mode and can be disabled using `--no-enable-ip-alias` flag. Use `--[no-]enable-ip-alias` flag to suppress this warning. WARNING: Newly created clusters and node-pools will have node auto-upgrade enabled by default. This can be disabled using the `--no-enable-autoupgrade` flag. WARNING: Starting with version 1.18, clusters will have shielded GKE nodes by default. WARNING: Your Pod address range (`--cluster-ipv4-cidr`) can accommodate at most 1008 node(s). This will enable the autorepair feature for nodes. Please see https://cloud.google.com/kubernetes-engine/docs/node-auto-repair for more information on node autorepairs. ERROR: (gcloud.container.clusters.create) ResponseError: code=400, message=Legacy monitoring is not supported in clusters running Kubernetes 1.15 or above.
やったこと
Logging Using Stackdriver | Kubernetes
を参考に
$ kubectl label node <ノード> beta.kubernetes.io/fluentd-ds-ready=false --overwrite
を実行すると、各ノードのfluentd daemonsetが起動しなくなるので試しにこれをやってみた
- 起動後に上書きするためにはoverwriteが必要だった
node名は以下で取得できる
kubectl get nodes
最初からKubernetesのYamlファイルとして定義してデプロイ時に指定してもよさそう。
WSLで gcloud components updateをして [Errno 13] Permission deniedが出た
WSLのgcloud components updateをして [Errno 13] Permission deniedが出たはなし
完全にはまった問題があったので書く
環境:
- Windows10 WSL2
- Ubuntu 18.04.4 LTS
起きたこと
gcloud components updateをして [Errno 13] Permission deniedが出た
[~] $gcloud components update 略 ERROR: (gcloud.components.update) [Errno 13] Permission denied: '/mnt/c/wsl/google-cloud-sdk.staging/.install/.download': [/mnt/c/wsl/google-cloud-sdk/.install/.download] Ensure you have the permissions to access the file and that the file is not in use.
全ログ
[~] $gcloud components update
Your current Cloud SDK version is: 293.0.0
You will be upgraded to version: 297.0.1
---------------------------------------------------------
| These components will be updated. |
--------------------------------- ------------ ----------
| Name | Version | Size |
--------------------------------- ------------ ----------
| BigQuery Command Line Tool | 2.0.58 | < 1 MiB |
| Cloud SDK Core Libraries | 2020.06.17 | 14.9 MiB |
| Cloud Storage Command Line Tool | 4.51 | 3.5 MiB |
| anthoscli | 0.1.10 | 42.8 MiB |
| gcloud cli dependencies | 2020.06.17 | 3.4 MiB |
| gcloud cli dependencies | 2020.06.12 | < 1 MiB |
--------------------------------- ------------ ----------
The following release notes are new in this upgrade.
Please read carefully for information about new features, breaking changes,
and bugs fixed. The latest full release notes can be viewed at:
https://cloud.google.com/sdk/release_notes
297.0.1 (2020-06-17)
o Fixed bug in gcloud app deploy command. This issue can be tracked at
<https://issuetracker.google.com/issues/159109983>
297.0.0 (2020-06-16)
Anthos
o Added support for preferred authentication methods to anthos auth
login command.
BigQuery
o Added support for splitting/merging capacity commitments.
o Added support for autoscale based on reservations.
o Fixed CLI json.loads error for Python 3.5.
Compute Engine
o Added --preemptible flag to gcloud compute instances set-scheduling.
o Promoted --multi-writer flag of gcloud compute disks create to beta.
Subscribe to these release notes at
https://groups.google.com/forum/#!forum/google-cloud-sdk-announce
(https://groups.google.com/forum/#!forum/google-cloud-sdk-announce).
Note: Cloud SDK introduced support for Python 3 in release 274.0.0 and
users are strongly encouraged to migrate to Python 3. Support for Python 2
will be deprecated on July 31, 2020. See also Python 2 Sunset
(https://cloud.google.com/python/docs/python2-sunset/) and Using Python 3
(https://cloud.google.com/sdk/gcloud/reference/topic/startup).
296.0.1 (2020-06-10)
Anthos
o Fixed blocking bug in anthos auth login command.
296.0.0 (2020-06-09)
Cloud SDK
o Updated bundled Python executable to 3.7.5.
Cloud Composer
o Fixed a bug that causes backfill subcommand of gcloud composer
environments run
to be stuck indefinitely.
o Updated gcloud composer environments run command to prefer GKE pods
with 'Ready: true' condition state.
Cloud Filestore
o Updated gcloud beta filestore instances create
and gcloud beta filestore instances update to include:
o Added HIGH_SCALE_SSD, BASIC_HDD and BASIC_SSD tiers.
o Added nfs-export-options to --file-share flag.
o Support for NfsExportOptions. Run gcloud filestore --help or visit
<https://cloud.google.com/filestore/docs/> to learn more.
Cloud Firestore Emulator
o Release Cloud Firestore emulator v1.11.4
* Fixes bug for evaluating rules in query listening.
* Fixes support for ?show_missing in listing collection.
Cloud Resource Manager
o Promoted gcloud projects create to beta.
Cloud Run
o Modified --vpc-connector and --clear-vpc-connector flags to be
applicable for --platform=managed only.
o Added --format export option to gcloud run services describe and
gcloud run revisions describe, to output resources without
deployment-specific metadata or status information.
Compute Engine
o Replaced coreos-cloud with fedora-coreos-cloud in the list of public
image projects for --standard-images flag of gcloud compute images
list.
o Promoted gcloud compute commitments create-license to beta.
o Added flag --instance-update-minimal-action flag to gcloud beta
compute instance-groups managed instance-configs
<create|update|delete>.
Kubernetes Engine
o Added --master-logs and '--enable-master-metrics' flags to gcloud
beta container clusters to enable sending master logs and metrics to
Cloud Operations (fka Stackdriver).
Subscribe to these release notes at
https://groups.google.com/forum/#!forum/google-cloud-sdk-announce
(https://groups.google.com/forum/#!forum/google-cloud-sdk-announce).
Note: Cloud SDK introduced support for Python 3 in release 274.0.0 and
users are strongly encouraged to migrate to Python 3. Support for Python 2
will be deprecated on July 31, 2020. See also Python 2 Sunset
(https://cloud.google.com/python/docs/python2-sunset/) and Using Python 3
(https://cloud.google.com/sdk/gcloud/reference/topic/startup).
295.0.0 (2020-06-02)
Anthos
o Added gcloud anthos apply command to beta. This command declaratively
applies Config Connector resource configurations.
o Added gcloud anthos export command to beta. This command exports
Config Connector resource configurations of existing Google Kubernetes
Engine clusters.
Cloud Memorystore
o Enabled support for Redis version 5.0. Added redis_5_0 as a new
option for --redis_version flag of gcloud redis instances create.
o Added gcloud redis instances upgrade to upgrade a Memorystore Redis
instance to a specified Redis version.
Cloud Pub/Sub
o Rename --filter flag of gcloud pubsub subscriptions create to
--message-filter. This is done to avoid confusion with --filter flag of
<https://cloud.google.com/sdk/gcloud/reference/topic/filters>.
o Promoted --message-filter flag of gcloud pubsub subscriptions create
to beta. This feature allows users to specify a filter expression on a
Cloud Pub/Sub subscription which will automatically drop messages.
Compute Engine
o Promoted gcloud compute instance-groups managed describe-instance to
beta.
o Added --accelerator flag to gcloud beta compute instances
create-with-container.
o Promoted --private-ipv6-google-access-type flag of gcloud compute
instances <create|create-with-container> to GA.
o Promoted --private-ipv6-google-access-type flag of gcloud compute
instance-templates <create|create-with-container> to GA.
o Promoted --private-ipv6-google-access-type flag of gcloud compute
networks subnets <create|update> to GA.
o Added --interface flag to gcloud beta compute disks create.
o Added --interface flag to gcloud beta compute instances attach-disk.
o Added interface key to --disk key of gcloud beta compute instances
create.
Game Servers
o Added --description to gcloud <alpha|beta> game servers
<clusters/realms/deployments> update to allow updating description for
resources.
Subscribe to these release notes at
https://groups.google.com/forum/#!forum/google-cloud-sdk-announce
(https://groups.google.com/forum/#!forum/google-cloud-sdk-announce).
Note: Cloud SDK introduced support for Python 3 in release 274.0.0 and
users are strongly encouraged to migrate to Python 3. Support for Python 2
will be deprecated on July 31, 2020. See also Python 2 Sunset
(https://cloud.google.com/python/docs/python2-sunset/) and Using Python 3
(https://cloud.google.com/sdk/gcloud/reference/topic/startup).
294.0.0 (2020-05-27)
Breaking Changes
o **(Secret Manager)** Modified gcloud secrets beta command group to
use the Secret Manager v1 API. The --uri flag now formats output to
begin with https://secretmanager.googleapis.com/v1/ instead of
https://secretmanager.googleapis.com/v1beta1/ when used with the
following commands:
* gcloud beta secrets list
* gcloud beta locations list
* gcloud beta secrets versions list
AI Platform
o Added --kms-key to gcloud <alpha|beta> ai-platform jobs submit
training to allow specifying a customer-managed encryption key for a
training job.
Cloud Pub/Sub
o Promoted configurable retry-related flags in gcloud pubsub
subscriptions create and gcloud pubsub subscriptions update to GA.
Cloud Run
o Change gcloud run services get-iam-policy, gcloud run services
set-iam-policy, gcloud run services add-iam-policy-binding, and gcloud
run services remove-iam-policy-binding to use the v1 api.
Cloud Storage
o Updated gsutil component to 4.51.
Cloud Tasks
o Promoted gcloud tasks queues create-pull-queue to beta.
Compute Engine
o Changed default action from RESTART to REPLACE for --update-instance
flag of gcloud compute instance-groups managed instance-configs
create|update.
o Promoted --maintenance-policy of gcloud compute sole-tenancy
node-groups create to GA.
Subscribe to these release notes at
https://groups.google.com/forum/#!forum/google-cloud-sdk-announce
(https://groups.google.com/forum/#!forum/google-cloud-sdk-announce).
Do you want to continue (Y/n)? y
Creating update staging area
10%
20%
30%
35%
40%
45%
50%
55%
60%
65%
70%
75%
80%
85%
90%
95%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
100%
ERROR: (gcloud.components.update) [Errno 13] Permission denied: '/mnt/c/wsl/google-cloud-sdk.staging/.install/.download': [/mnt/c/wsl/google-cloud-sdk/.install/.download]
Ensure you have the permissions to access the file and that the file is not in use.
[~] $
前提
Linux 用のクイックスタート | Cloud SDK のドキュメント | Google Cloud
アーカイブをファイル システム上に展開
の箇所で、「ホームディレクトリをおすすめします」と書いてあったのでそれに従ってインストールした。
自分がWSLを使っていた時は/mnt/c/wsl
という、Cドライブ直下にwsl
というディレクトリをホームディレクトリにしていたので、
最初はこのようなインストールをした
$ tar zxvf google-cloud-sdk-293.0.0-linux-x86_64.tar.gz google-cloud-sdk
がこれでいろいろやっているうちに、
gcloud components update
ができないという上述の問題に遭遇した
試したこと
以下のことを全部やってみたけどダメだった
https://stackoverflow.com/questions/49210830/gcloud-components-update-permission-denied https://stackoverflow.com/questions/31220077/gcloud-installation-permission-issue-on-ubuntu-12-04/31247129#31247129
sudo chown -R $USER ./google-cloud-sdk
sudo chown -R $USER .config/gcloud
- sudoをつけて実行してみる
sudo gcloud components update
- pythonを3.6にしてみる(それまで3.7がデフォルトだった)
$sudo apt update $sudo apt install python3.6 $python3.6 --version Python 3.6.9
.zshrc(または.bashrc)に以下のaliasを追加
alias python=/usr/bin/python3.6
解決
gcloudを/mnt/c/wsl/
ではなく /home/$USER
という、WSLのデフォルトのホームディレクトリに入れ直したら解決した
まずはgcloudを削除
Google Cloud SDK のアンインストール | Cloud SDK のドキュメント に従って、以下のディレクトリを削除
$gcloud info --format='value(installation.sdk_root)' # -> /mnt/c/wsl/google-cloud-sdk $gcloud info --format='value(config.paths.global_config_dir)' # -> /mnt/c/wsl/.config/gcloud
.zshrcに書き込まれていた以下の記述も削除
# The next line updates PATH for the Google Cloud SDK. if [ -f '/mnt/c/wsl/google-cloud-sdk/path.zsh.inc' ]; then . '/mnt/c/wsl/google-cloud-sdk/path.zsh.inc'; fi # The next line enables shell command completion for gcloud. if [ -f '/mnt/c/wsl/google-cloud-sdk/completion.zsh.inc' ]; then . '/mnt/c/wsl/google-cloud-sdk/completion.zsh.inc'; fi
tarの展開先を /home/$USER
に変更
$ tar zxvf google-cloud-sdk-293.0.0-linux-x86_64.tar.gz /home/$USER/google-cloud-sdk
新しいgcloudのパス
$which gcloud /home/ludwig125/google-cloud-sdk/bin/gcloud
こうしたら gcloud components update
ができるようになった
ちなみに gcloud --quiet components update
とするといちいち 【y/N】と聞かれなくなるので便利
ローカルPCでGoでserverを立ち上げたときにファイアウォールを出なくさせる
困ってたこと
Goのサンプルプログラムで作ったサーバをローカルPCで起動させたいときに、 毎回ポップアップがでて うっとうしくて困っていた。
サーバ
例えばこういうの
package main import ( "fmt" "log" "net/http" ) func main() { helloHandler := func(w http.ResponseWriter, req *http.Request) { fmt.Fprintf(w, "Hello\n") } http.HandleFunc("/hello", helloHandler) log.Fatal(http.ListenAndServe(":8080", nil)) }
ポップアップの内容
Windowsの場合(main.goというプログラムでサーバを起動させたときの例) ※WSLで実行
Macの場合(sample.goというプログラムでサーバを起動させたときの例)
- 「アプリケーション 〇〇へのネットワーク受信接続を許可しますか?」
解決法
ListenAndServeのport番号の前に"127.0.0.1"または"localhost"を書くと、リクエストをlocalhostからのみに制限することができる。
こうすると外部からリクエストできなくなるので、ファイアウォールがブロックしないようになる。
この部分:http.ListenAndServe("127.0.0.1:8000", nil)
修正後のプログラム
package main import ( "fmt" "log" "net/http" ) func main() { helloHandler := func(w http.ResponseWriter, req *http.Request) { fmt.Fprintf(w, "Hello\n") } http.HandleFunc("/hello", helloHandler) log.Fatal(http.ListenAndServe("localhost:8080", nil)) }
解説
https://golang.org/pkg/net/#Dial
For TCP, UDP and IP networks, if the host is empty or a literal unspecified IP address, as in ":80", "0.0.0.0:80" or "[::]:80" for TCP and UDP, "", "0.0.0.0" or "::" for IP, the local system is assumed.
-> ポートの前のホストが空の場合(例えば :80
のような場合)は 0.0.0.0
つまりどのホストからでもアクセスを受け付ける状態だと判断される
参考:
4kディスプレイで仮想マシンのUbuntuの文字サイズを大きくする
ディスプレイをフルHDから4kディスプレイに変えた結果、 仮想マシンのUbuntu(18.04.2 LTS)を立ち上げたら何もかもめちゃめちゃ小さくて使い物にならないので調べた設定
文字サイズを変更する方法
設定前
- 隣のYahooの画面は比較用に並べたホスト側(Windows10)のブラウザ
変更
gsettings set org.gnome.desktop.interface text-scaling-factor 1.8
設定後
- 隣のYahooの画面に対して大きくなっていることがわかる
- 1.8の数字を変えれば自由に拡大縮小可能
参考
以下、ありがとうございました。
マウスのカーソルを大きくする
[~] $gsettings get org.gnome.desktop.interface cursor-size 24 [~] $gsettings set org.gnome.desktop.interface cursor-size 48 [~] $gsettings get org.gnome.desktop.interface cursor-size 48 [~] $
参考: - How to Change Cursor Size on Ubuntu Desktop
他の方法
他に見つけた方法 こちらのほうが全体が大きくなって良さそう How to Enable Fractional Scaling in Ubuntu 19.04 - OMG! Ubuntu!
これで200%にする 代わりに、以下は小さめにしておく
gsettings set org.gnome.desktop.interface text-scaling-factor 1.0