7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AnsibleでLVS(DSR構成)をお手軽に構築する

Posted at

LVSの作成をAnsibleのPlaybookでお手軽に作成してみた。
Ansibleを動かす為の準備はこちら参照

##Playbookでやる事リスト

  • SELinux無効化
項目 内容
パッケージのインストール libselinux-python
selinux 無効化 /etc/selinux/config
SELINUX=disabled
  • LVSに必要な設定
項目 内容
パッケージのインストール ipvsadm,keepalived
自動起動 keepalived
sysctl net.ipv4.ip_forward = 1

##実際のPlaybook

core moduleでほとんどの事がカバー出来るので楽!!

ansibleのモジュール一覧

lvs.yml
- hosts: testgrp
  remote_user: vagrant
  sudo: yes
  tasks:
  - name: Install libselinux-python
    yum: name=libselinux-python state=present

  - name: Permissive selinux
    selinux: state=disabled

  - name: reboot!
    command: shutdown -r now

  - name: wait for SSH port down
    local_action: wait_for host={{ inventory_hostname }} port=22 state=stopped

  - name: wait for SSH port up
    local_action: wait_for host={{ inventory_hostname }} port=22 state=started delay=30

  - name: Install ipvsadm keepalived
    yum: name={{ item }} state=present
    with_items:
      - keepalived
      - ipvsadm

  - name: keepalived chkconfig on
    service: name=keepalived enabled=yes

  - name: ip fowarding setting
    sysctl: name="net.ipv4.ip_forward" value=1 sysctl_set=yes

##デバックしてみる(Syntax Check)

####正常終了時

$ ansible-playbook lvs.yml --syntax-check

playbook: lvs.yml

####あえてエラーを出してみる

$ ansible-playbook lvs.yml --syntax-check
ERROR: Syntax Error while loading YAML script, lvs.yml
Note: The error may actually appear before this position: line 5, column 11

  tasks:aaa
    - name: Install ipvsadm keepalived
          ^

##実行

全部通ったー!

1__tmux.jpg

後は、こちら参考にkeepalivedのconfig入れればあっという間にLVSの出来上がり。

Ansible触り始めたばっかりだけど、手軽でとてもいい感じな気がする。

##参考
Ansibleの事例とちょっとしたTips

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?