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
700
Flutter移行の苦労と、乗り越えた先に得られたもの
rtechkouhou
3
12k
ここ数年間のタウンワークiOSアプリのエンジニアのチャレンジ
rtechkouhou
1
1.5k
大規模環境をAWS Transit Gatewayで設計/移行する前に考える3つのポイントと移行への挑戦
rtechkouhou
1
1.9k
【61期 新人BootCamp】TOC入門
rtechkouhou
3
42k
【RTC新人研修 】 TPS
rtechkouhou
1
41k
Android Boot Camp 2020
rtechkouhou
0
41k
HTML/CSS
rtechkouhou
10
51k
TypeScript Bootcamp 2020
rtechkouhou
9
46k
Other Decks in Technology
See All in Technology
MySQL5.6から8.4へ 戦いの記録
kyoshidaxx
1
270
2年でここまで成長!AWSで育てたAI Slack botの軌跡
iwamot
PRO
4
810
2025-06-26 GitHub CopilotとAI駆動開発:実践と導入のリアル
fl_kawachi
1
180
asken AI勉強会(Android)
tadashi_sato
0
110
2025-06-26_Lightning_Talk_for_Lightning_Talks
_hashimo2
2
100
低レイヤを知りたいPHPerのためのCコンパイラ作成入門 完全版 / Building a C Compiler for PHPers Who Want to Dive into Low-Level Programming - Expanded
tomzoh
4
3.3k
Understanding_Thread_Tuning_for_Inference_Servers_of_Deep_Models.pdf
lycorptech_jp
PRO
0
140
作曲家がボカロを使うようにPdMはAIを使え
itotaxi
0
280
ひとり情シスなCTOがLLMと始めるオペレーション最適化 / CTO's LLM-Powered Ops
yamitzky
0
450
LangChain Interrupt & LangChain Ambassadors meetingレポート
os1ma
2
160
Should Our Project Join the CNCF? (Japanese Recap)
whywaita
PRO
0
270
生成AI時代の開発組織・技術・プロセス 〜 ログラスの挑戦と考察 〜
itohiro73
1
340
Featured
See All Featured
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
48
2.9k
Become a Pro
speakerdeck
PRO
28
5.4k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Balancing Empowerment & Direction
lara
1
380
Build The Right Thing And Hit Your Dates
maggiecrowley
36
2.8k
Mobile First: as difficult as doing things right
swwweet
223
9.7k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
281
13k
Adopting Sorbet at Scale
ufuk
77
9.4k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
331
22k
Build your cross-platform service in a week with App Engine
jlugia
231
18k
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.8k
Raft: Consensus for Rubyists
vanstee
140
7k
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