start new:
tmux
start new with session name:
tmux new -s myname
| #!/bin/bash | |
| set -ue | |
| prefix=`basename $0` | |
| timestamp_file=/tmp/$prefix.timestamp | |
| cache_file=/tmp/$prefix.cache | |
| timestamp=`date '+%s'` | |
| cache_time=300 | |
| describe_images(){ |
| aws ec2 describe-instances | jq -r '.Reservations[].Instances[]| (.Tags[] | select(.Key=="Name").Value) + " " + .PrivateDnsName' > /tmp/instance_list | |
| OLDIFS=$IFS | |
| while read line | |
| do | |
| IFS=" " | |
| set -- $line | |
| echo "Host $1 | |
| Hostname $2" | |
| done < /tmp/instance_list > /tmp/ssh_config | |
| IFS=$OLDIFS |
| { | |
| "Version": "2012-10-17", | |
| "Statement": [ | |
| { | |
| "Sid": "AllowUsersAllActionsForCredentials", | |
| "Effect": "Allow", | |
| "Action": [ | |
| "iam:*LoginProfile", | |
| "iam:*AccessKey*", | |
| "iam:*SigningCertificate*" |
| --- | |
| - hosts: localhost | |
| gather_facts: no | |
| tasks: | |
| - name: Create EC2 Instance with user-data | |
| local_action: | |
| module: ec2 | |
| region: ap-northeast-1 | |
| image: ami-efbe98ee # Ubuntu 12.04 LTS, hvm:ebs, 20140829.2 | |
| instance_type: t2.micro |
| # ISUCON夏期講習からのコピペ | |
| # 【メモ】この設定で試した場合は、以下のmemo_privateがない方がスコアが上がった。 | |
| # "ADD INDEX memo_private(user, is_private, created_at)" | |
| # これを入れるとMySQLのCPUボトルネックとなるので、このIndexはデータ更新コストが大きいと考えらえる。 | |
| cat <<EOF | mysql -u isucon isucon | |
| ALTER TABLE memos ADD INDEX (is_private, created_at), | |
| ADD INDEX mypage(user,created_at), | |
| EOF |
AMIからインスタンスを作成したのち、以下の作業が必要となったのでメモ。
| # Private IPを使うようにしたいので、そのためのオプションを入れたFork版のec2sshを入れる | |
| # 1. gitからgemを入れるため、specific_installをインストール | |
| # 最新のspecific_install + gem 1.8.25 の組み合わせが動かないため、古いバージョンを入れる | |
| # https://github.com/rdp/specific_install/issues/21 | |
| sudo gem install specific_install -v 0.2.7 | |
| # 2. リポジトリとブランチを指定して、フォーク版のgemを入れる | |
| sudo gem specific_install -l https://github.com/sechiro/ec2ssh.git -b private-ip-feature |
| #!/bin/bash | |
| namespace=AWS/EC2 | |
| instance_id=i-a63f41a3 | |
| os_name=`uname` | |
| now=`date -u "+%Y-%m-%dT%H:%M:%SZ"` | |
| if [ $os_name = "Darwin" ]; then | |
| yesterday=`date -u -v-1d "+%Y-%m-%dT%H:%M:%SZ"` | |
| else | |
| yesterday=`date -u -d "1 days ago" "+%Y-%m-%dT%H:%M:%SZ"` | |
| fi |
| #!/bin/bash | |
| namespace=AWS/Billing | |
| os_name=`uname` | |
| now=`date -u "+%Y-%m-%dT%H:%M:%SZ"` | |
| if [ $os_name = "Darwin" ]; then | |
| yesterday=`date -u -v-1d "+%Y-%m-%dT%H:%M:%SZ"` | |
| else | |
| yesterday=`date -u -d "1 days ago" "+%Y-%m-%dT%H:%M:%SZ"` | |
| fi | |
| start_time=${1:-$yesterday} |