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
ソフトウェアQAがハードウェアの人になったの
mineo_matsuya
3
240
An introduction to Claude Code SDK
choplin
3
3.1k
Four Keysから始める信頼性の改善 - SRE NEXT 2025
ozakikota
0
460
Webの技術とガジェットで那須の子ども達にワクワクを! / IoTLT_20250720
you
PRO
0
120
Introduction to Sansan for Engineers / エンジニア向け会社紹介
sansan33
PRO
5
39k
毎晩の 負荷試験自動実行による効果
recruitengineers
PRO
5
200
安定した基盤システムのためのライブラリ選定
kakehashi
PRO
3
160
PHPからはじめるコンピュータアーキテクチャ / From Scripts to Silicon: A Journey Through the Layers of Computing
tomzoh
2
350
地図と生成AI
nakasho
0
520
全部AI、全員Cursor、ドキュメント駆動開発 〜DevinやGeminiも添えて〜
rinchsan
11
5.6k
Figma Dev Mode MCP Serverを用いたUI開発
zoothezoo
1
280
Digitization部 紹介資料
sansan33
PRO
1
4.6k
Featured
See All Featured
A Modern Web Designer's Workflow
chriscoyier
695
190k
Building Better People: How to give real-time feedback that sticks.
wjessup
367
19k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
840
Code Reviewing Like a Champion
maltzj
524
40k
Writing Fast Ruby
sferik
628
62k
Product Roadmaps are Hard
iamctodd
PRO
54
11k
GraphQLとの向き合い方2022年版
quramy
49
14k
Designing for Performance
lara
610
69k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
50k
Into the Great Unknown - MozCon
thekraken
40
1.9k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.8k
Art, The Web, and Tiny UX
lynnandtonic
300
21k
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