10月4週

月曜

  • アルファ版を動かすために最小構成で動かしてみる

EC2にインストール

利用できるバージョンの確認

$ amazon-linux-extras list | grep golang
→29  golang1.11=latest        enabled      \

インストール

amazon-linux-extras install golang1.11

GOPATHの追記

export GOPATH="$HOME/go"
export PATH=$PATH:$GOPATH/bin

インストール確認

go version
→go version go1.13.4 linux/amd64

ec2にmysql5.7を導入

qiita.com

手順

  • デフォルトでmariaDBがデフォルトが入っているのでアンインストールしておく。
$ sudo yum list installed | grep mariadb
$ sudo yum remove mariadb-libs

リポジトリを追加する。centos7系なのでel6ではなくel7をインストールする。

$ sudo yum install http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

インストールする。

$ sudo yum install mysql-community-server

依存性の問題が解決できないときはel6で入れてしまっていなか確認する。(念のためキャッシュも消しておくとよい。)

$ sudo yum clean all
$ sudo rm -rf /var/cache/yum

正しくインストールされたことを確認する。

$ yum repolist enabled | grep "mysql.*-community.*"

バージョンを確認する。

$ mysql --version
mysql  Ver 14.14 Distrib 5.7.23, for Linux (x86_64) using  EditLine wrapper
$ mysqld -V
mysqld  Ver 5.7.23 for Linux on x86_64 (MySQL Community Server (GPL))

起動してみる。

$ sudo /bin/systemctl start mysqld.service

起動できているか確認してみる。

$ systemctl list-units | grep mysqld.service
mysqld.service   loaded active running   MySQL Server

自動で起動するようにしておく。

  • 現在の状態を確認する
$ systemctl is-enabled mysqld.service
disabled
  • enableに変更しておく
$ systemctl enable mysqld.service

ログインしてみる。

$ mysql -u root -p
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
  • デフォルトでパスワードかかっていた…
  • パスワードを確認する。
$ cat /var/log/mysqld.log | grep password
2018-09-01T10:27:36.011362Z 1 [Note] A temporary password is generated for root@localhost: ************

調べたパスワードで再度ログインしてみる。

$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.7.23

Copyright (c) 2000, 2018, 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>

できた!

  • パスワードを変更しておく。デフォルトの制約が強いのでちょっと弱めておく。
mysql> SET GLOBAL validate_password_length=8;
Query OK, 0 rows affected (0.00 sec)

mysql> SET GLOBAL validate_password_policy=LOW;
Query OK, 0 rows affected (0.00 sec)

mysql> ALTER USER root@localhost IDENTIFIED BY 'new password';
Query OK, 0 rows affected (0.00 sec)

文字コードを確認する。

mysql> show variables like "chara%";
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

設定ファイルに以下の2行を追記して再起動する。

/etc/my.cnf
[mysqld]
character-set-server=utf8

[client]
default-character-set=utf8
$ sudo /bin/systemctl restart mysqld.service

新しいユーザーを作成する。

mysql> GRANT ALL PRIVILEGES ON `app_production`.* TO `username`@localhost IDENTIFIED BY 'new password';

ログインできるか試してみる。

$ mysql -u username -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.23 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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.

各リージョンにおけるAMIのIDの取得方法

aws ssm get-parameter \
  --name /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2 \
  --query "Parameter.Value" \
  --{リージョン名}
  • これで"ami-0c2f25c1f66a1ff4d"みたいに返ってくる