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
Mackerel in さくらのクラウド
cubicdaiya
1
350
JOAI発表資料 @ 関東kaggler会
joai_committee
1
150
夢の印税生活 / Life on Royalties
tmtms
0
200
[kickflow]20250319_少人数チームでのAutify活用
otouhujej
0
180
ABEMAにおける 生成AI活用の現在地 / The Current Status of Generative AI at ABEMA
dekatotoro
0
500
Backboneとしてのtimm2025
yu4u
3
1k
R-SCoRe: Revisiting Scene Coordinate Regression for Robust Large-Scale Visual Localization
takmin
0
210
サービスロボット最前線:ugoが挑むPhysical AI活用
kmatsuiugo
0
170
ウォンテッドリーのアラート設計と Datadog 移行での知見
donkomura
0
230
第64回コンピュータビジョン勉強会@関東(後編)
tsukamotokenji
0
180
AIと描く、未来のBacklog 〜プロジェクト管理の次の10年を想像し、創造するセッション〜
hrm_o25
0
110
PFEM Online Feature Flag @ newmo
shinyaishitobi
2
190
Featured
See All Featured
Thoughts on Productivity
jonyablonski
69
4.8k
Docker and Python
trallard
45
3.5k
Fireside Chat
paigeccino
39
3.6k
Mobile First: as difficult as doing things right
swwweet
223
9.9k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.8k
StorybookのUI Testing Handbookを読んだ
zakiyama
30
6k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
44
2.4k
Intergalactic Javascript Robots from Outer Space
tanoku
272
27k
RailsConf 2023
tenderlove
30
1.2k
Building Applications with DynamoDB
mza
96
6.6k
Practical Orchestrator
shlominoach
190
11k
Optimizing for Happiness
mojombo
379
70k
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