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
Ansible の基本 + MySQL レプリケーションを設定する事例
Search
Ian Lewis
June 10, 2014
Technology
4
6.9k
Ansible の基本 + MySQL レプリケーションを設定する事例
Ian Lewis
June 10, 2014
Tweet
Share
More Decks by Ian Lewis
See All by Ian Lewis
Kubernetes Security Best Practices
ianlewis
38
26k
The Enemy Within: Running untrusted code in Kubernetes
ianlewis
0
1.2k
The Enemy Within: Running untrusted code with gVisor
ianlewis
4
1k
KubeCon EU Runtime Track Recap
ianlewis
3
1.6k
コンテナによるNoOpsオートメーション
ianlewis
2
140
Google Kubernetes Engine 概要 & アップデート @ GCPUG Kansai Summit Day 2018
ianlewis
2
870
Extending Kubernetes with Custom Resources and Operator Frameworks
ianlewis
10
3.7k
Kubernetesのセキュリティのベストプラクティス
ianlewis
12
17k
Scheduling and Resource Management in Kubernetes
ianlewis
2
1.3k
Other Decks in Technology
See All in Technology
JPOUG_10_20241018_OracleDB_AWS_v1.3.pdf
asahihidehiko
1
190
ラブグラフ紹介資料 〜プロダクト解体新書〜 / Lovegraph Product Deck
lovegraph
0
14k
AIとともに歩んだライブラリアップデートの道のり/ vue-fes-japan-2024-link-and-motivation
lmi
2
2.1k
外部カンファレンスで登壇しよう! 〜「強い」エンジニアへの一歩を踏み出す〜
logica0419
4
140
Automated Tests Now and Future @ SQiP Workshop Special Lecture 2024
teyamagu
PRO
2
490
Demystifying Vite Internals
nozomuikuta
3
760
テストを楽に書きたい
tomorrowkey
2
270
次は君だ。~Japan AWS Jr. Champions 受賞までの奇跡~
fukuchiiinu
0
120
VueとViteで作るUIコンポーネントライブラリ ~デザインシステムとプロダクトの理想的な分離を目指して~ / 20241019_cloudsign_VueFesJapan2024_1
bengo4com
8
4.5k
エンジニアのドメイン知識獲得コストを低減するアプリケーションデザイン
ryo_nagata_
3
160
Japan AWS Jr. Championsがお届けする、アウトプットのすすめ
hamijay_cloud
0
210
VPoE Meetup Vol.1 VPoEとして実践してきたことと反省点
coconala_engineer
2
180
Featured
See All Featured
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
3
340
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Teambox: Starting and Learning
jrom
132
8.7k
Rails Girls Zürich Keynote
gr2m
93
13k
GitHub's CSS Performance
jonrohan
1030
450k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
37
1.8k
Why Our Code Smells
bkeepers
PRO
334
57k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.6k
Adopting Sorbet at Scale
ufuk
73
9k
Unsuck your backbone
ammeep
668
57k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
4.9k
The Cost Of JavaScript in 2023
addyosmani
44
5.9k
Transcript
None
おめーだれねん?
おれは、関東人でも、 関西人でもないです。
貴様を倒すアメリカ県民だ
イアンです。
@IanMLewis
None
None
None
女性フレンドリー
連絡事項
21:30まで
Ansible とは?
An ansible is a fictional machine capable of instantaneous or
superluminal communication.
\
Ansible is an IT automation tool
自動化
None
None
pip install ansible
ansible provisioning/site.yml
Ansibleの基本
SSH NODE1 NODE2 ... Ansible 女子です
•Playbook •Inventory •Module •Role •Task •Handler 用語
Playbook
YAML
%YAML 1.2 --- YAML: YAML Ain't Markup Language What It
Is: YAML is a human friendly data serialization standard for all programming languages.
--- - hosts: dbservers sudo: True roles: - common -
mysql …
production # 本番環境のInventory stage # ステージング環境のInventory group_vars/ group1 # グループ変数
group2 # "" host_vars/ hostname1 # ホスト変数 hostname2 # "" site.yml # マスターPlaybook webservers.yml # ウェブサーバーのPlaybook dbservers.yml # DBサーバーのPlaybook
roles/ common/ # この下は”common”と言うロール tasks/ # main.yml # <-- ファイルを分割できます。
handlers/ # main.yml # <-- ハンドラー templates/ # <-- テンプレート ntp.conf.j2 # <------- ファイル拡張子は.j2 files/ # bar.txt # <-- コピーするファイル vars/ # main.yml # <-- このロールの変数
http://docs.ansible.com/playbooks_best_practices.html
Inventory
mail.example.com [webservers] foo.example.com bar.example.com [dbservers] one.example.com two.example.com three.example.com
SSH foo.example.com ... Ansible 女子です bar.example.com
Roles
roles/ common/ # この下は”common”と言うロール tasks/ # main.yml # <-- ファイルを分割できます。
handlers/ # main.yml # <-- ハンドラー templates/ # <-- テンプレート ntp.conf.j2 # <------- ファイル拡張子は.j2 files/ # bar.txt # <-- コピーするファイル vars/ # main.yml # <-- このロールの変数
Tasks
roles/ common/ # この下は”common”と言うロール tasks/ # main.yml # <-- ファイルを分割できます。
handlers/ # main.yml # <-- ハンドラー templates/ # <-- テンプレート ntp.conf.j2 # <------- ファイル拡張子は.j2 files/ # bar.txt # <-- コピーするファイル vars/ # main.yml # <-- このロールの変数
--- - name: Add the OS specific varibles include_vars: "{{
ansible_os_family }}.yml" - name: Install the required packages in Redhat derivatives yum: name={{ item }} state=installed with_items: ntp_pkgs when: ansible_os_family == 'RedHat' …
Modules
- name: reboot the servers command: /sbin/reboot -t now
Handlers
roles/ common/ # この下は”common”と言うロール tasks/ # main.yml # <-- ファイルを分割できます。
handlers/ # main.yml # <-- ハンドラー templates/ # <-- テンプレート ntp.conf.j2 # <------- ファイル拡張子は.j2 files/ # bar.txt # <-- コピーするファイル vars/ # main.yml # <-- このロールの変数
--- - name: restart ntp service: name={{ ntp_svc_name }} state=restarted
enabled=yes
まとめ
Playbook Role Task Task … Role Task … Handler Inventory
webservers dbservers
事例
MySQL
めんどくせー
https://github.com/bennojoy/ansible-roles/ tree/master/mysql
- name: Install the mysql packages in Debian derivatives apt:
name={{ item }} state=installed update_cache=yes with_items: mysql_pkgs environment: env - name: Copy the my.cnf file template: - src: my.cnf.{{ ansible_os_family }}.j2 dest: {{ mysql_conf_dir }}/my.cnf notify: - restart mysql
- name: remove the test database mysql_db: name=test state=absent -
name: Create the database's mysql_db: name={{ item.name }} state=present with_items: mysql_db when: mysql_db|lower() != 'none'
Primary
- name: Create the replication users mysql_user: - name: {{
item.name }} host: "%" password: {{ item.pass|default("foobar") }} priv: *.*:"REPLICATION SLAVE" state: present with_items: mysql_repl_user when: mysql_repl_role == 'master'
Replica
- name: Get primary servers replication status mysql_replication: mode=getmaster delegate_to:
"{{ mysql_repl_master }}" register: repl_stat when: slave|failed and mysql_repl_role == 'slave' and mysql_repl_master is defined
- name: Change the master in slave mysql_replication: - mode:
changemaster master_host: {{ mysql_repl_master }} master_log_file: {{ repl_stat.File }} master_log_pos: {{ repl_stat.Position }} master_user: {{ mysql_repl_user[0].name }} master_password: {{ mysql_repl_user[0].pass }} when: <snip>
- name: Start slave mysql_replication: mode=startslave ignore_errors: true when: mysql_repl_role
== 'slave'
またまとめ
Playbook Role Task Task … Role Task … Handler Inventory
webservers dbservers
Playbook copy my.cnf MASTER STATUS … Replica copy my.cnf …
Restart mysql Inventory primaries replicas Primary SLAVE START
ありがとう
さいごに
None
@IanMLewis http://www.ianlewis.org/ どうも!