Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Infrastructure as Code
Search
Recruit Technologies
June 02, 2017
Technology
6
40k
Infrastructure as Code
2017年4~5月開催「ブートキャンプ特別講座」の資料になります。
Recruit Technologies
June 02, 2017
Tweet
Share
More Decks by Recruit Technologies
See All by Recruit Technologies
障害はチャンスだ! 障害を前向きに捉える
rtechkouhou
1
610
Flutter移行の苦労と、乗り越えた先に得られたもの
rtechkouhou
3
11k
ここ数年間のタウンワークiOSアプリのエンジニアのチャレンジ
rtechkouhou
1
1.4k
大規模環境をAWS Transit Gatewayで設計/移行する前に考える3つのポイントと移行への挑戦
rtechkouhou
1
1.8k
【61期 新人BootCamp】TOC入門
rtechkouhou
3
41k
【RTC新人研修 】 TPS
rtechkouhou
1
40k
Android Boot Camp 2020
rtechkouhou
0
40k
HTML/CSS
rtechkouhou
10
49k
TypeScript Bootcamp 2020
rtechkouhou
9
45k
Other Decks in Technology
See All in Technology
Microsoft の AI 技術 をベースに構成される Craft Copilot
tikson
0
170
新リポジトリを作るときフロントエンドで気をつけたかった5つのコト/ Five things I wanted to pay attention to on the front end when creating a new repository
kaminashi
3
320
AWS IAM Identity Center を使わないマルチアカウントのユーザー管理
yhana
1
1.4k
Amazon GameLiftの 構成要素を整理する
iriikeita
0
100
オーティファイ会社紹介資料 / Autify Company Deck
autifyhq
9
110k
Distributed Tracing in LINE Taiwan — 大規模分散式追蹤的實踐與挑戰
johnlin
1
260
ReactNative アプリ同士の通信のために型情報をサクッと共有した話 #TSKaigi サブイベント
whatasoda
1
460
SREが考えるハイブリッド開催の技術イベントのライブ配信における信頼性
yuchi
2
1.4k
從大學到出社會,這十年的參與和維護的開源專案
tjjh89017
0
850
エンジニア向け会社紹介資料
caddi_eng
14
230k
事業フェーズの変化を乗り越えるEnabling/Platform SREへの転換
hosht
1
1.2k
ドキュメント翻訳から始めるOSS推し活
unsoluble_sugar
0
140
Featured
See All Featured
BBQ
matthewcrist
82
9k
Optimising Largest Contentful Paint
csswizardry
25
2.7k
Code Review Best Practice
trishagee
59
16k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
325
21k
The World Runs on Bad Software
bkeepers
PRO
63
11k
Web Components: a chance to create the future
zenorocha
307
41k
Learning to Love Humans: Emotional Interface Design
aarron
269
39k
GitHub's CSS Performance
jonrohan
1027
450k
It's Worth the Effort
3n
181
27k
Why You Should Never Use an ORM
jnunemaker
PRO
52
8.9k
Documentation Writing (for coders)
carmenintech
64
4.2k
The Invisible Side of Design
smashingmag
294
50k
Transcript
None
None
✦ ✦ ✦
None
None
✦ ✦ ✦ ✦
✦ ✦ ✦
✦ ✦ ✦ ✦ ✦ ✦
None
None
✦ このへんがインフラ
✦
✦ ✦ ✦ ✦ ✦ ✦ ✦
✦ ✦ ✦ ✦ ✦ ✦
✦ ✦ ✦ ✦ ✦
✦
✦ ✦ ✦ ✦ ✦
✦ ✦ ✦ ✦ ✦ ✦ ✦ ✦
None
このへん
✦ ✦ ✦ ✦ ✦
✦ ✦ ✦
None
None
None
✦ ✦ ✦ ✦
✦ ✦
✦ ✦
✦ ✦
✦ ✦
✦ ✦
✦ ✦
✦ ✦
✦ ✦
None
✦ ✦ ✦ ✦
✦ ✦ ✦
✦ ✦ ✦ ✦
✦ ✦
None
✦ ✦ ✦
✦ ✦ ✦
✦ ✦ ✦ ✦ ✦ ✦ ✦ ✦ ✦ ✦
✦ ✦ ✦ ✦ ✦
✦
None
✦ ✦
✦ ✦
✦ ✦ ✦ ✦ ✦
✦ ✦ startではない
✦ ✦ ✦ ✦ ✗ ✦
✦ ✦ RHELでもUbuntuでもCentOSでも一緒
✦ ✦ ✦ ✦
✦ ✦ ✦
✦ ✦ ✦ ✦ ✦
✦ ✦ ✦
cp /tmp/created_nginx.conf /usr/local/nginx/conf/nginx.conf 実行しまくるとconfigが壊れていく ✦ ✦ 何回やっても結果は一緒
✦ ✦ ✦ ✦
✦ ✦ ✦
None
✦ ✦
✦ ✦ ✦ ✦ ✦ ✦
✦ ✦
None
✦ ✦ ✦ ✦ ✦ ✦
この2行だけ追記してください
None
None
✦ Ansibleの説明は後ほど
None
✦ ✦
✦ $ sudo systemctl stop nginx.service # nginxを止めてみる $ sudo
vi /etc/nginx/nginx.conf # configを書き換えてみる $ sudo chmod 600 /var/log/nginx/access.log # permissionを変えてみる $ sudo vi /usr/share/nginx/html/index.html # DocumentRootを変えてみる
✦ $ sudo ansible-playbook -i production site.yml --check --diff (略)
TASK [nginx : replace index.html] ********************************************** --- before: /usr/share/nginx/html/index.html +++ after: dynamically generated @@ -1,2 +1 @@ hello, production ansible -hogehoge 書き換えたところが戻る ・・・これだけ? オプションで dry-runが可能
$ sudo ansible-playbook -i production site.yml (略) TASK [nginx :
replace index.html] ********************************************** --- before: /usr/share/nginx/html/index.html +++ after: dynamically generated @@ -1,2 +1 @@ hello, production ansible -hogehoge
None
✦ ✦ $ sudo yum erase -y nginx
None
✦ ✦ ✦
✦ ✦ ✦ ✦ ✦
✦ # VM上で実行してください $ cd ~ $ git clone https://github.com/tkit/ansible-todo-manager.git
$ cd ansible-todo-manager
✦ ✦ # VM上で実行してください $ ansible-playbook -i inventory playbook.yml PLAY
[webservers] ************************************************************** TASK [setup] ******************************************************************* ok: [localhost] PLAY RECAP ********************************************************************* localhost : ok=1 changed=0 unreachable=0 failed=0 何もない
✦ ✦ ✦ . ├── inventory ├── playbook.yml └── roles
└── nodejs ├── meta │ └── main.yml └── tasks └── main.yml インベントリ : 操作対象ホストの全部の一覧 プレイブック : 全体の設計(どのホストに、どんな処理をするか) タスク : 具体的な処理の詳細
✦ ✦ # playbook.yml --- - hosts: webservers become: yes
connection: local roles: - nodejs webserversっていうホスト群に対して操作 sudo実行する nodejsっていうroleを実行する
✦ ✦ # inventory [webservers] localhost webserversというグループには localhostが存在(複数行書くこともできる)
✦ ✦ ✦ ✦ ├── defaults │ └── main.yml ├──
files ├── handlers │ └── main.yml ├── meta │ └── main.yml ├── README.md ├── tasks │ └── main.yml ├── templates ├── tests │ ├── inventory │ └── test.yml └── vars └── main.yml 本当はもっと構成が複雑
✦ ✦ --- # tasks file for nginx - name:
install nginx yum: name: nginx state: installed - name: replace index.html template: src: index.html.j2 dest: /usr/share/nginx/html/index.html - name: nginx start service: name: nginx state: started enabled: yes
✦ ✦ ✦ ✦ ✦ # VM上で実行してください $ ansible-playbook -i
inventory playbook.yml
✦ $ git checkout ansible # 回答
✦ ✦ ✦ ✦
✦ ✦ ✦ ✦ $ forever list info: Forever processes
running data: uid command script forever pid id logfile uptime data: [0] todo /usr/bin/node /usr/local/src/todo-manager/app.js 30755 30767 /home/vagrant/.forever/todo.log 0:0:1:6.134 data: [1] todo /usr/bin/node /usr/local/src/todo-manager/app.js 31036 31048 /home/vagrant/.forever/todo.log STOPPED STOPPEDの行が増えている
✦ $ ansible localhost -m setup localhost | SUCCESS =>
{ "ansible_facts": { "ansible_all_ipv4_addresses": [ "192.168.33.10", "10.0.2.15" ], "ansible_all_ipv6_addresses": [ "fe80::a00:27ff:fe36:11ec", "fe80::5054:ff:fe88:15b6" ], (すごいいっぱいでてくる)
✦ ✦ ✦ ✦ ✦ ✦
✦ ✦ ✦ ✦ ✦ ✦ ✦ ✦ ✦
✦ $ git checkout ansible-advance # 回答
None
None
✦ ✦
None
✦ ✦
✦
✦ ✦ ✦ ✦ ✦ ✦
None
✦ ✦
None
✦ ✦ ✦ ✦ ✦
✦ ✦ ✦
✦
None
✦ ✦ ✦
None
None
✦
✦ ✦ ✦ ✦
✦ ✦ ✦ describe service('ntpd') do it { should be_running
} end 分かりやすく書ける
None
✦ ✦
✦ ✦
✦ ✦ ✦
✦ ✦ describe server(:app) do describe http('http://app') do it "responds
content including 'This is app server'" do expect(response.body).to include('This is app server') end end End これもわかりやすい
✦ ✦ ✦
None
✦
✦ ✦ ✦
None
None
✦ ✦ ✦ ✦ ✦ ✦
None
None
None
None
✦ ✦ ✦ https://www.docker.com/what-container
✦ ✦
✦ ✦ ✦
✦ ✦ ✦ ✦
✦
✦ ✦ ✦ ✦ ✦ ✦
✦ ✦ ✦
✦
✦ ✦ [vagrant@demo ~]$ exit # VMから抜ける $ vagrant halt
# VMを止める場合 $ vagrant destroy # VMを消す場合
None
✦ ✦ ✦ ✦ ✦
✦ ✦
✦ ✦ ✦ ✦ ✦ ✦ ✦
$ cd ~ $ git clone https://github.com/tkit/docker-todo-manager.git $ cd docker-todo-manager
$ vim Dockerfile # Dockerfileに手順を書く $ docker build -t todo-manager . # ビルド $ docker run <options> --name todo-manager todo-manager # あとはアクセス! ✦ ✦
Image Container Dockerfile # イメージビルド $ docker build -t todo-manager
. # Dockerfile修正 ``` FROM ベースイメージ RUN ... CMD ... ``` # コンテナ起動 $ docker run ... ✦ ✦ ✦ ✦
None
✦ $ git checkout docker # 回答
✦ ✦
None
✦ # コンテナを消す $ docker container ls # コンテナの一覧を調べる $
docker stop <container名> $ docker container rm -f <container名> # 特定のコンテナを消す # イメージを消す $ docker image ls # イメージの一覧を調べる $ docker image rm <image名> # 特定のイメージを消す # 全体的に使っていないものをきれいにする $ docker container prune $ docker image prune
None
✦ ✦
✦ ✦ ✦
None
✦ ✦ ✦ ✦
✦ ✦ ✦ ✦ ✦ ✦ ✦
None
None
None
None
None
None
None
None
Microservice Container Monolithic Physical Machines 今回学んだこと Immutable Virtual Machines
None