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
Operating Operator
shhnjk
1
480
LangChain Interrupt & LangChain Ambassadors meetingレポート
os1ma
2
280
Backlog ユーザー棚卸しRTA、多分これが一番早いと思います
__allllllllez__
1
130
赤煉瓦倉庫勉強会「Databricksを選んだ理由と、絶賛真っ只中のデータ基盤移行体験記」
ivry_presentationmaterials
2
300
2025-06-26_Lightning_Talk_for_Lightning_Talks
_hashimo2
2
120
Should Our Project Join the CNCF? (Japanese Recap)
whywaita
PRO
0
330
fukabori.fm 出張版: 売上高617億円と高稼働率を陰で支えた社内ツール開発のあれこれ話 / 20250704 Yoshimasa Iwase & Tomoo Morikawa
shift_evolve
PRO
2
6.4k
OSSのSNSツール「Misskey」をさわってみよう(右下ワイプで私のOSCの20年を振り返ります) / 20250705-osc2025-do
akkiesoft
0
100
20250707-AI活用の個人差を埋めるチームづくり
shnjtk
4
3.4k
マネジメントって難しい、けどおもしろい / Management is tough, but fun! #em_findy
ar_tama
6
740
Model Mondays S2E03: SLMs & Reasoning
nitya
0
340
なぜ私はいま、ここにいるのか? #もがく中堅デザイナー #プロダクトデザイナー
bengo4com
0
1.3k
Featured
See All Featured
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.4k
Designing for Performance
lara
610
69k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
31
1.3k
Rebuilding a faster, lazier Slack
samanthasiow
82
9.1k
Mobile First: as difficult as doing things right
swwweet
223
9.7k
Code Review Best Practice
trishagee
69
18k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
Building Applications with DynamoDB
mza
95
6.5k
GitHub's CSS Performance
jonrohan
1031
460k
KATA
mclloyd
30
14k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
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