LoginSignup
0
0

More than 5 years have passed since last update.

CentOS7 で /(root) 領域を拡張する(Ansible 編)

Last updated at Posted at 2018-12-30

前提

  • 構成は前回を踏襲しています。
  • ansible が使えるようになっていること。
  • ssh でパスワード無しでログインできること。
  • 対象ホストの名前解決ができること。
  • root でログインできること。
  • 対象ホストは k8s-master2 と k8s-master3

コマンド


構文をチェックする
# ansible-playbook resize_home.yml -i hosts --syntax-check

dry run をする場合はこちらを実行(多分失敗する)
# ansible-playbook resize_home.yml -i hosts --check

実行
# ansible-playbook resize_home.yml -i hosts

ファイル構成

 resize/
  ├ hosts
  └ resize_root.yml

ファイル一覧

hosts

hosts
k8s-master1
k8s-master2
k8s-master3

ansible-playbook

resize_root.yml
- hosts: k8s-master3    #対象ホストを指定する。
  vars:
    backup_mountpoint: nfs_backup # バックアップ先 nfs サーバ側のマウントポイント
    file_server: 192.168.1.50 # nfs サーバの IP アドレス
    mountpoint: /mnt # node 側の nfs マウントポイント

  tasks:                #実行するtaskを指定する。
    - name: yum install xdump を実行する
      yum: name=xfsdump state=present


    - name: backup 先を NFS マウントする
      mount: name={{ mountpoint }} src={{ file_server }}:{{ backup_mountpoint }} fstab=/tmp/fstab.tmp fstype=nfs state=mounted


    - name: glusterd を mask して停止させる
      systemd:
        name: glusterd
        masked: yes
        state: stopped


    - name: backup が存在するか確認する
      stat: path={{ mountpoint }}/{{ inventory_hostname }}/home.dump
      register: res
      failed_when: no
      changed_when: no


    - name: backup が存在しない場合、xfsdump を実行し backup を取得する
      shell: xfsdump -J -L home -M drive -f {{mountpoint}}/`uname -n`/home.dump /home
      when: not res.stat.exists


    - name: /home を unmount する
      mount: name=/home state=unmounted


    - name: logical volume home を削除する
      lvol:
        vg: centos
        lv: home
        state: absent
        force: yes


    - name: logical volume home を 80G で作成する
      lvol:
        vg: centos
        lv: home
        size: 80g


    - name: xfs で /dev/centos/home をフォーマットする
      shell: mkfs.xfs /dev/centos/home


    - name: /home/glusterfs ディレクトリの存在チェック
      stat: path=/home/glusterfs/
      register: pathchack


    - name: /dev/centos/home をマウントする
      shell: mount /home
      when: not pathcheck.stat.exists
      failed_when: no
      changed_when: no


    - name: xfsrestore で /home をリストアする
      shell: xfsrestore -J -L home -f {{ mountpoint }}/\`uname -n\`/home.dump /home
      when: not pathcheck.stat.exists
      failed_when: no
      changed_when: no


    - name: logical volume root を拡張する
      filesystem:
        fstype: xfs
        dev: /dev/mapper/centos-root
        resizefs: yes


    - name: enable service httpd and ensure it is not masked
      systemd:
        name: glusterd
        masked: no
        state: restarted


後処理

glusterfs の正常性が確認できれば、以下を実施して node に pod を配置可能な状態に戻します。

# kubectl uncordon <node>

glusterfs の正常性は以下で確認します。

gluster volume 一覧を環境変数にセットする
# VOL_LIST=`gluster vol list`

確認
# echo $VOL_LIST

gluster volume の正常性確認
# for vol in ${VOL_LIST}; 
  do echo $vol;
  gluster vol heal $vol info
  done

[表示例]
Brick etcd-master1:/home/glusterfs/mstdn
Status: Connected
Number of entries: 0

Brick etcd-master2:/home/glusterfs/mstdn
Status: Connected
Number of entries: 0

Brick etcd-master3:/home/glusterfs/mstdn
Status: Connected
Number of entries: 0

Number of entries: 0
と表示されていることを確認します。

0
0
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
0
0