こちらのリポジトリはインプレスR&Dから出版された「ゲーム開発が変わる!Google Cloud Platform 実践インフラ構築」のコマンドラインなどをまとめたリポジトリになります。
[bucketname]
をご自身のGCP ProjectのBucket名に編集して実行して下さい。
GoogleCloudStorage/CNAME_Support.sh
[bucketname]
をご自身のGCP ProjectのBucket名に編集して実行して下さい。
gsutil defacl set public-read [bucketname]
[bucketname]
をご自身のGCP ProjectのBucket名に編集して実行して下さい。
GoogleCloudStorage/Enable-Logging.sh
[bucketname]
をご自身のGCP ProjectのBucket名に編集して実行して下さい。
GoogleCloudStorage/Disable-Logging.sh
[bucketname]
をご自身のGCP ProjectのBucket名に編集して実行して下さい。
{
"rule": [
{
"action": {
"type": "Delete"
},
"condition": {
"age": 365
}
}
]
}
GoogleCloudStorage/Life-Cycle/Life-Cycle.sh
[bucketname]
をご自身のGCP ProjectのBucket名に編集して実行して下さい。
LOG_BUCKET=gs://[bucketname]
gsutil lifecycle set {} $LOG_BUCKET
vi /tmp/client_startup.sh
GoogleComputeEngine/StartupScript/client_startup.sh
vi /tmp/redis_startup.sh
GoogleComputeEngine/StartupScript/redis_startup.sh
以下を実行
GoogleComputeEngine/StartupScript/instance_create.sh
gcloud compute instances get-serial-port-output redis02 \
--zone asia-east1-c
上記のコマンドを実行してしばらく待つと以下の状態になります。
gcloud compute instances list
redis-cli -h redis01 get hostname
redis-cli -h redis02 get hostname
以下を実行して下さい。
GoogleComputeEngine/IPForward/firewall-rule.sh
以下を実行して下さい。
GoogleComputeEngine/IPForward/create-ipforward.sh
gcloud compute routes list
以下を実行して下さい。
GoogleComputeEngine/IPForward/update-ipforward.sh
gcloud compute routes delete redis-ipforward-65535
gcloud compute routes delete redis-ipforward-65534
gcloud compute firewall-rules delete ipforward-redis
gcloud compute instances delete client --zone asia-east1-a
gcloud compute instances delete redis01 --zone asia-east1-b
gcloud compute instances delete redis02 --zone asia-east1-c
gcloud compute routes list
gcloud compute firewall-rules list
gcloud compute instances list
PRIVATE_IP=`curl -s -H "Metadata-Flavor: Google" http://metadata/computeMetadata/v1/instance/network-interfaces/0/ip`
EXTERNAL_IP=`curl -s -H "Metadata-Flavor: Google" http://metadata/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip`
echo $PRIVATE_IP
echo $EXTERNAL_IP
CONFIG_DIR=/etc/redis.d
TAG=`curl -s -H "Metadata-Flavor: Google" http://metadata/computeMetadata/v1/instance/tags | jq .
[] | sed -e 's/"//g'`
if [ -f $CONFIG_DIR/$TAG.conf ]; then
redis-server $CONFIG_DIR/$TAG.conf
fi
以下のようなjsonファイルを用意します。
redis.json)
{
"redis": {
"host": "production-redis01",
"port": 6379
}
}
example)
gcloud compute project-info add-metadata ¥
--metadata-from-file [KEY]=[Local Filename]
GoogleComputeEngine/Metadata/Project-Wide/add-metadata.sh
確認)
curl -s -H "Metadata-Flavor: Google" ¥
http://metadata/computeMetadata/v1/project/attributes/redis
snapshot取得の例
gcloud compute disks snapshot $HOSTNAME \
--snapshot-names “$HOSTNAME-`date +%Y%m%d%H%M`” \
--zone `curl -s -H "X-Google-Metadata-Request: True" -H "Metadata-Flavor: Google" http://metadata/computeMetadata/v1/instance/zone | xargs basename`
カスタムImage生成snapshot取得の例
カスタムImage生成snapshot取得の例