hasen's tech life

Twitter: @hasen

Homesteadを使用した時のメモ.

# Homesteadを使用する.使ったことがなかった.

# 作業環境の作成とHomesteadのインストール
$ mkdir /PATH/TO/WORKDIR && !$
$ git clone https://github.com/laravel/homestead.git ./
$ composer update
$ ./homestead make
$ bash init.sh

# 試しにLaravelのプロジェクトを作成する
$ composer create-project laravel/laravel ./Code --prefer-dist

# 秘密鍵を作成する
$ mkdir ~/.ssh/DIR
$ chmod 700 ~/.ssh/DIR
$ ssh-keygen -t rsa -b 4096
$ chmod 600 ~/.ssh/DIR/id_rsa

# 設定ファイルを編集する
$ vi /Users/You/.homestead/Homestead.yaml
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/DIR/id_rsa.pub
keys:
- ~/.ssh/DIR/id_rsa
folders:
- map: ./Code
to: /home/vagrant/Code
sites:
- map: homestead.app
to: /home/vagrant/Code/public
databases:
- homestead

# 起動
$ vg up
# 設定ファイルを変更した場合
$ vagrant reload --provision

# 下記アドレスでブラウザを確認する
# http://homestead.app

公開鍵関連の設定を行ったのでメモ.

# 公開鍵関連の設定を行ったのでメモ.

# 鍵の作成
$ mkdir ~/.ssh/PATH/TO/DIR
$ chmod 700 ~/.ssh/PATH/TO/DIR
$ cd ~/.ssh/PATH/TO/DIR
$ ssh-keygen -t rsa -b 2048
$ chmod 600 id_rsa
$ pbcopy < id_rsa.pub

# 接続
$ ssh root@XXX.XXX.XX.XX

# ユーザー作成(ex: admin)とパスワード設定
# sakura, conoha (digitaloceanは作成時にパスワードを入力)
$ adduser admin
$ passwd admin

# wheelグループに追加
# sakura, conoha
$ gpasswd -a admin wheel
# digitalocean
$ gpasswd -a admin sudo

# wheelグループをsudoerに追加
# sakura, conoha
$ sudo vi /etc/sudoers
-- # %wheel ALL=(ALL) ALL
++ %wheel ALL=(ALL) ALL

$ su admin

$ sudo vi /etc/ssh/sshd_config
# sakura, conoha
-- # RSAAuthentication yes
++ RSAAuthentication yes
-- # PubkeyAuthentication yes
++ PubkeyAuthentication yes
-- # PermitRootLogin yes
++ PermitRootLogin no
-- # PasswordAuthentication yes
++ PasswordAuthentication no
# digitalocean
-- # RSAAuthentication yes
++ RSAAuthentication yes
-- # PasswordAuthentication yes
++ PasswordAuthentication no

$ mkdir ~/.ssh/
$ chmod 700 ~/.ssh/
$ touch ~/.ssh/authorized_keys
# コピーしておいた公開鍵を書き込む
$ vi authorized_keys
$ chmod 600 authorized_keys
$ sudo service sshd restart

# iptablesの設定を行う(ex: SSHをport33で行う)
# conoha
$ sudo yum install -y iptables-services
$ sudo vi /etc/sysconfig/iptables
-- -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
++ -A INPUT -m state --state NEW -m tcp -p tcp --dport 33 -j ACCEPT
# digitalocean
$ sudo apt-get install iptables-persistent
# sakura, digitalocean
$ sudo iptables -I INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
$ sudo iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
$ sudo iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
$ sudo iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
$ sudo iptables -A INPUT -i lo -j ACCEPT
$ sudo iptables -A INPUT -p icmp -j ACCEPT
$ sudo iptables -A INPUT -p tcp -m tcp --dport 33 -j ACCEPT
$ sudo iptables -P INPUT DROP
$ sudo iptables -P OUTPUT ACCEPT

# 確認
$ sudo iptables -L

# sakura, conoha
$ sudo service iptables restart
# digitalocean
$ sudo ufw enable

$ sudo vi /etc/ssh/sshd_config
# Port 22
Port 33
$ sudo service sshd restart

# 必ず他のプロセスでログインを確認する
$ exit

curlでSlackに投稿する.

# curlでSlackに投稿する.

プラグインを使うと,ほかの箇所に影響が出たので一旦curlで行う.
参考: https://api.slack.com/incoming-webhooks

$ curl -X POST --data-urlencode 'payload={"channel": "#CHANNEL_NAME", "username": "USER_NAME", "text": "TEXT TEXT", "icon_emoji": ":ICON_NAME:"}' https://hooks.slack.com/services/HASH/HASH/HASH

tmuxinatorを導入した.

# tmuxinatorを導入した.

$ gem install tmuxinator
$ mkdir ~/.tmuxinator
$ export EDITOR='vim'
$ cd !$
$ wget https://raw.githubusercontent.com/tmuxinator/tmuxinator/master/completion/tmuxinator.bash
$ vi ~/.bashrc
++ source /PATH/TO/tmuxinator/tmuxinator.bash
$ exec $SHELL -l
$ mux new TEST_NAME
$ mux open TEST_NAME
$ mux TEST_NAME