9
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【ISUCON】iikanjini SpeedUp cheat sheet

Last updated at Posted at 2018-12-06

systemctl

※CentOS7では実質chkconfigが廃止され,サービスに関連することはsystemctlを使う

実行中のサービス一覧

$ systemctl

サービス起動

$ systemctl start [service_name].service

サービス停止

$ systemctl stop [service_name].service

サービス再起動

$ systectl restart [service_name].service

サービスの自動起動設定[enable/disable]の一覧

$ systemctl list-unit-files -t service

個別にサービスの自動起動設定を確認

$ systemctl status [service_name].service

サービスの自動起動有効化

$ systemctl enable [service_name].service

サービスの自動起動無効化

$ systemctl disable [service_name].service

systemctlのログ出力

$ jornalctl -u [service_name].service

-b 直近の起動ログ
-k エラーを強調する
-f リアルタイムな表示


nginx

現在設定されているconfファイルの文法チェック

# nginx -t

kataribe導入

$ apt-get update
$ apt-get install golang
$ mkdir -p ~/gocode && echo 'export GOPATH=$HOME/gocode' >> ~/.bashrc
$ echo 'export PATH=$GOPATH/bin:$PATH' >> ~/.bashrc
$ source ~/.bashrc
$ go get github.com/matsuu/kataribe

kataribe実行

# cat /var/log/nginx/access.log | kataribe -f $GOPATH/src/github.com/matsuu/kataribe/kataribe.toml

MySQL

dump mysql

Find my.cnf

$ mysql --help | grep my.cnf

Setup my.cnf

innodb_buffer_pool_size=1GB // インスタンスのメモリサイズを超えるとエラーになるので注意
innodb_flush_log_at_trx_commit=2 // 1に設定するとトランザクション単位でログを出力するが 2 を指定すると1秒間に1回ログファイルに出力するようになる
innodb_flush_method=O_DIRECT //データファイル/ログファイルの読み書き方式を指定
# if error was occuered
rm /var/lib/mysql/ib_logfile0
rm /var/lib/mysql/ib_logfile1

Check Parameters

mysql> select @@[param_name];

Add Index

ALTER TABLE [table_name] ADD INDEX [index_name]([column_name])

Drop Index

ALTER TABLE [table_name] DROP INDEX [index_name]

Show Index

SHOW INDEX FROM [table_name];

Show warning

SHOW WARNING\G

Dump Slow Query

Command

mysql> set global slow_query_log = 1;
mysql> set global long_query_time = 0;
mysql> set global slow_query_log_file = "/tmp/slow.log";
mysql> set global log_queries_not_using_indexes = 1;

Write config file for log

[mysqld]
slow_query_log = 1
slow_query_log_file = /var/lib/mysql/mysqld-slow.log
long_query_time = 0
log_queries_not_using_indexes = 1

Analyze Slow Query

Use mysqldumpslow

$ mysqldumpslow -s t /path/to/log > /path/to/output

Use pt-query-digest

$ wget https://repo.percona.com/apt/percona-release_0.1-3.$(lsb_release -sc)_all.deb
$ sudo dpkg -i percona-release_0.1-3.$(lsb_release -sc)_all.deb
$ sudo apt-get install percona-toolkit
$ pt-query-digest /tmp/slow.log > /tmp/digest.txt

commands (使えるコマンド集)

システム情報の表示

$ uname -a

-a コンピュータ(ハードウェア)の種類,ネットワークにおけるホスト名,OSのリリース番号,OSの名称

CPU情報の確認

$ cat /proc/cpuinfo

メモリ情報の確認

$ cat /proc/meminfo
9
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?