ラベル GlusterFS の投稿を表示しています。 すべての投稿を表示
ラベル GlusterFS の投稿を表示しています。 すべての投稿を表示

2022年3月2日水曜日

MinikubeでGlusterFS上の永続ボリュームを使用するCouchDBをデプロイする

MinikubeでGlusterFS上の永続ボリュームを使用するCouchDBをデプロイするには、以下の手順を実行します。

実行手順

1. MinikubeでのGlusterfs準備
※GlusterFSクラスターは事前に準備しておきます。

※minikube内の/etc/hostsにエントリを追加するためのファイルにエントリ追加
mkdir -p ~/.minikube/files/etc
echo 'xxx.xxx.xxx.xxx glusternode1' >> ~/.minikube/files/etc/hosts
echo 'xxx.xxx.xxx.xxx glusternode2' >> ~/.minikube/files/etc/hosts
echo 'xxx.xxx.xxx.xxx glusternode3' >> ~/.minikube/files/etc/hosts
IPアドレスとホスト名は適宜変更してください。

※minikube内にglusterfs-clientをインストールする
minikube ssh

sudo apt-get update && sudo apt-get install -y glusterfs-client

exit

3. Endpointsの作成
以下のIPアドレスを適宜変更して、Endpointsを作成します。
cat << EOF > glusterfs-endpoints.yml
apiVersion: v1
kind: Endpoints
metadata:
  name: glusterfs-cluster
subsets:
- addresses:
  - ip: xxx.xxx.xxx.xxx
  ports:
  - port: 1
- addresses:
  - ip: xxx.xxx.xxx.xxx
  ports:
  - port: 1
- addresses:
  - ip: xxx.xxx.xxx.xxx
  ports:
  - port: 1
EOF

kubectl apply -f ./glusterfs-endpoints.yml

4. 永続ボリュームの作成
以下のGlusterFSボリューム名(myvolumeの部分)を変更して、永続ボリュームを作成します。
cat << EOF > glusterfs-couchdb-pv.yml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: glusterfs-couchdb-pv
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  glusterfs:
    endpoints: glusterfs-cluster
    path: myvolume
    readOnly: false
EOF

kubectl apply -f ./glusterfs-couchdb-pv.yml

5. 永続ボリューム要求の作成
以下のコマンドを実行して、永続ボリューム要求を作成します。
cat << EOF > glusterfs-couchdb-pvc.yml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: glusterfs-couchdb-pvc
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: ""
  resources:
    requests:
      storage: 5Gi
  volumeName: glusterfs-couchdb-pv
EOF

kubectl apply -f ./glusterfs-couchdb-pvc.yml

4. Deploymentの作成
以下のコマンドでCouchDBのイメージと作成したNFS上の永続ボリュームを使用するDeploymentを作成します。
cat << EOF > couchdb-deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: couchdb-deployment
  labels:
    app: mycouchdb
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mycouchdb
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mycouchdb
    spec:
      containers:
      - name: mycouchdb
        image: couchdb:3.2
        env:
        - name: COUCHDB_USER
          value: admin
        - name: COUCHDB_PASSWORD
          value: mycouchdb
        ports:
        - containerPort: 5984
        volumeMounts:
        - name: couchdb-data
          mountPath: /opt/couchdb/data
      volumes:
      - name: couchdb-data
        persistentVolumeClaim:
          claimName: glusterfs-couchdb-pvc
EOF

kubectl apply -f ./couchdb-deployment.yml

5. サービスの作成
以下のコマンドでサービスを作成します。
cat << EOF > couchdb-service.yml
apiVersion: v1
kind: Service
metadata:
  name: couchdb-service
spec:
  selector:
    app: mycouchdb
  ports:
  - protocol: TCP
    port: 5984
    targetPort: 5984
EOF

kubectl apply -f ./couchdb-service.yml

6. Port-Fowardingで外部からアクセスできるようにする
kubectl port-forward --address 0.0.0.0 service/couchdb-service 5984:5984

ブラウザからhttp://<サーバ名またはIPアドレス:5984/_utils/index.htmlにアクセスします。
ユーザ名admin、パスワードmycouchdbでログインします。

2022年2月10日木曜日

Microk8sでGlusterFSの永続ストレージを使用するApache Httpdをデプロイする

Microk8sでGlusterFSの永続ストレージを使用するApache Httpdをデプロイするには、以下の手順を実行します。

実行手順

1. Microk8sをインストールしたホスト上でのGlusterfs準備
※GlusterFSクラスターは事前に準備しておきます。

※Microk8sホスト内の/etc/hostsにエントリを追加
echo 'xxx.xxx.xxx.xxx glusternode1' | sudo tee -a /etc/hosts
echo 'xxx.xxx.xxx.xxx glusternode2' | sudo tee -a /etc/hosts
echo 'xxx.xxx.xxx.xxx glusternode3' | sudo tee -a /etc/hosts
IPアドレスとホスト名は適宜変更してください。

sudo apt-get update && sudo apt-get install -y glusterfs-client

2. テスト用ページの作成
Glusterfsサーバーのホストにテスト用ページを作成します。
echo '<html><head><title>sample</title></head><body>contents on GlusterFS server.</body></html>' | sudo tee /glusterfs/index.html
※パスなどは適宜変更してください

3. Endpointsの作成
以下のIPアドレスを適宜変更して、Endpointsを作成します。
cat << EOF > glusterfs-endpoints.yml
apiVersion: v1
kind: Endpoints
metadata:
  name: glusterfs-cluster
subsets:
- addresses:
  - ip: xxx.xxx.xxx.xxx
  ports:
  - port: 1
- addresses:
  - ip: xxx.xxx.xxx.xxx
  ports:
  - port: 1
- addresses:
  - ip: xxx.xxx.xxx.xxx
  ports:
  - port: 1
EOF

microk8s kubectl apply -f ./glusterfs-endpoints.yml

4. 永続ボリュームの作成
以下のGlusterFSボリューム名(myvolumeの部分)を変更して、永続ボリュームを作成します。
cat << EOF > glusterfs-httpd-pv.yml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: glusterfs-httpd-pv
spec:
  capacity:
    storage: 2Gi
  accessModes:
    - ReadOnlyMany
  storageClassName: slow
  glusterfs:
    endpoints: glusterfs-cluster
    path: myvolume
    readOnly: false
EOF

microk8s kubectl apply -f ./glusterfs-httpd-pv.yml

5. 永続ボリューム要求の作成
以下のコマンドを実行して、永続ボリューム要求を作成します。
cat << EOF > glusterfs-httpd-pvc.yml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: glusterfs-httpd-pvc
spec:
  accessModes:
    - ReadOnlyMany
  storageClassName: slow
  resources:
    requests:
      storage: 2Gi
  volumeName: glusterfs-httpd-pv
EOF

microk8s kubectl apply -f ./glusterfs-httpd-pvc.yml

6. Deploymentの作成
以下のコマンドを実行してDeploymentを作成します。
cat << EOF > glusterfs-httpd-deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: httpd-deployment
  labels:
    app: myhttpd
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myhttpd
  template:
    metadata:
      labels:
        app: myhttpd
    spec:
      containers:
      - name: myhttpd
        image: httpd:2.4-alpine
        ports:
        - containerPort: 80
        volumeMounts:
        - name: documentroot
          mountPath: /usr/local/apache2/htdocs
      volumes:
      - name: documentroot
        persistentVolumeClaim:
          claimName: glusterfs-httpd-pvc
EOF

microk8s kubectl apply -f ./glusterfs-httpd-deployment.yml

7. サービスの作成
以下のコマンドを実行してサービスを作成します。
cat << EOF > httpd-service.yml
apiVersion: v1
kind: Service
metadata:
  name: httpd-service
spec:
  selector:
    app: myhttpd
  type: LoadBalancer
  externalIPs:
  - xxx.xxx.xxx.xxx # 外部からアクセスできるMicrok8sをインストールしたホストのIPを設定します。
  ports:
  - protocol: TCP
    port: 8080
    targetPort: 80
EOF

microk8s kubectl apply -f ./httpd-service.yml

ブラウザからhttp://<ホスト名:8080/ にアクセスします

2022年1月28日金曜日

MinikubeとHelmでGlusterFS上の永続ボリュームを使用するApache Httpdをデプロイする

MinikubeとHelmでGlusterFS上の永続ボリュームを使用するApache Httpdをデプロイするには、以下の手順を実行します。

実行手順

1. MinikubeでのGlusterfs準備
※GlusterFSクラスターは事前に準備しておきます。

※minikube内の/etc/hostsにエントリを追加するためのファイルにエントリ追加
mkdir -p ~/.minikube/files/etc
echo 'xxx.xxx.xxx.xxx glusternode1' >> ~/.minikube/files/etc/hosts
echo 'xxx.xxx.xxx.xxx glusternode2' >> ~/.minikube/files/etc/hosts
echo 'xxx.xxx.xxx.xxx glusternode3' >> ~/.minikube/files/etc/hosts
IPアドレスとホスト名は適宜変更してください。

※minikube内にglusterfs-clientをインストールする
minikube ssh
sudo apt-get update && sudo apt-get install -y glusterfs-client
exit

2. テスト用ページの作成
Glusterfsサーバーのホストにテスト用ページを作成します。
echo '<html><head><title>sample</title></head><body>contents on GlusterFS server.</body></html>' | sudo tee /glusterfs/index.html
※パスなどは適宜変更してください

3. Endpointsの作成
以下のIPアドレスを適宜変更して、Endpointsを作成します。
cat << EOF > glusterfs-endpoints.yml
apiVersion: v1
kind: Endpoints
metadata:
  name: glusterfs-cluster
subsets:
- addresses:
  - ip: xxx.xxx.xxx.xxx
  ports:
  - port: 1
- addresses:
  - ip: xxx.xxx.xxx.xxx
  ports:
  - port: 1
- addresses:
  - ip: xxx.xxx.xxx.xxx
  ports:
  - port: 1
EOF

kubectl apply -f ./glusterfs-endpoints.yml

4. 永続ボリュームの作成
以下のGlusterFSボリューム名(myvolumeの部分)を変更して、永続ボリュームを作成します。
cat << EOF > glusterfs-httpd-pv.yml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: glusterfs-httpd-pv
spec:
  capacity:
    storage: 2Gi
  accessModes:
    - ReadOnlyMany
  glusterfs:
    endpoints: glusterfs-cluster
    path: myvolume
    readOnly: false
EOF

kubectl apply -f ./glusterfs-httpd-pv.yml

5. 永続ボリューム要求の作成
以下のコマンドを実行して、永続ボリューム要求を作成します。
cat << EOF > glusterfs-httpd-pvc.yml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: glusterfs-httpd-pvc
spec:
  accessModes:
    - ReadOnlyMany
  storageClassName: ""
  resources:
    requests:
      storage: 2Gi
  volumeName: glusterfs-httpd-pv
EOF

kubectl apply -f ./glusterfs-httpd-pvc.yml

4. HelmでApacheのインストール
以下のコマンドでbitnamiのApache Httpdをインストールします。htdocsPVCパラメータで使用する永続ボリューム要求を指定します。
helm repo update

helm install my-httpd-apache bitnami/apache --set htdocsPVC=glusterfs-httpd-pvc

※その他のパラメータについては、以下のbitnami apacheのgithubリポジトリを参照してください
https://github.com/bitnami/charts/tree/master/bitnami/apache
5. Port-Fowardingで外部からアクセスできるようにする
以下のコマンドを実行して、外部からアクセスできるようにします。
kubectl port-forward --address 0.0.0.0 deployment/my-httpd-apache  8080:8080

ブラウザからhttp://<ホスト名:8080/ にアクセスします

※アンインストールする時には以下のコマンドを実行します。
helm uninstall my-httpd-apache

2022年1月25日火曜日

MinikubeでGlusterFSの永続ストレージを使用するApache Httpdをデプロイする

MinikubeでGlusterFSの永続ストレージを使用するApache Httpdをデプロイするには、以下の手順を実行します。

実行手順

1. MinikubeでのGlusterfs準備
※GlusterFSクラスターは事前に準備しておきます。

※minikube内の/etc/hostsにエントリを追加するためのファイルにエントリ追加
mkdir -p ~/.minikube/files/etc
echo 'xxx.xxx.xxx.xxx glusternode1' >> ~/.minikube/files/etc/hosts
echo 'xxx.xxx.xxx.xxx glusternode2' >> ~/.minikube/files/etc/hosts
echo 'xxx.xxx.xxx.xxx glusternode3' >> ~/.minikube/files/etc/hosts
IPアドレスとホスト名は適宜変更してください。

※minikube内にglusterfs-clientをインストールする
minikube ssh
sudo apt-get update && sudo apt-get install -y glusterfs-client
exit

2. テスト用ページの作成
Glusterfsサーバーのホストにテスト用ページを作成します。
echo '<html><head><title>sample</title></head><body>contents on GlusterFS server.</body></html>' | sudo tee /glusterfs/index.html
※パスなどは適宜変更してください

3. Endpointsの作成
以下のIPアドレスを適宜変更して、Endpointsを作成します。
cat << EOF > glusterfs-endpoints.yml
apiVersion: v1
kind: Endpoints
metadata:
  name: glusterfs-cluster
subsets:
- addresses:
  - ip: xxx.xxx.xxx.xxx
  ports:
  - port: 1
- addresses:
  - ip: xxx.xxx.xxx.xxx
  ports:
  - port: 1
- addresses:
  - ip: xxx.xxx.xxx.xxx
  ports:
  - port: 1
EOF

kubectl apply -f ./glusterfs-endpoints.yml

4. 永続ボリュームの作成
以下のGlusterFSボリューム名(myvolumeの部分)を変更して、永続ボリュームを作成します。
cat << EOF > glusterfs-httpd-pv.yml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: glusterfs-httpd-pv
spec:
  capacity:
    storage: 2Gi
  accessModes:
    - ReadOnlyMany
  glusterfs:
    endpoints: glusterfs-cluster
    path: myvolume
    readOnly: false
EOF

kubectl apply -f ./glusterfs-httpd-pv.yml

5. 永続ボリューム要求の作成
以下のコマンドを実行して、永続ボリューム要求を作成します。
cat << EOF > glusterfs-httpd-pvc.yml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: glusterfs-httpd-pvc
spec:
  accessModes:
    - ReadOnlyMany
  storageClassName: ""
  resources:
    requests:
      storage: 2Gi
  volumeName: glusterfs-httpd-pv
EOF

kubectl apply -f ./glusterfs-httpd-pvc.yml

6. Deploymentの作成
以下のコマンドを実行してDeploymentを作成します。
cat << EOF > glusterfs-httpd-deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: httpd-deployment
  labels:
    app: myhttpd
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myhttpd
  template:
    metadata:
      labels:
        app: myhttpd
    spec:
      containers:
      - name: myhttpd
        image: httpd:2.4-alpine
        ports:
        - containerPort: 80
        volumeMounts:
        - name: documentroot
          mountPath: /usr/local/apache2/htdocs
      volumes:
      - name: documentroot
        persistentVolumeClaim:
          claimName: glusterfs-httpd-pvc
EOF

kubectl apply -f ./glusterfs-httpd-deployment.yml

7. サービスの作成
以下のコマンドを実行してサービスを作成します。
cat << EOF > httpd-service.yml
apiVersion: v1
kind: Service
metadata:
  name: httpd-service
spec:
  selector:
    app: myhttpd
  ports:
  - protocol: TCP
    port: 8080
    targetPort: 80
EOF

kubectl apply -f ./httpd-service.yml

8. Port-Fowardingで外部からアクセスできるようにする
以下のコマンドを実行して、外部からアクセスできるようにします。
kubectl port-forward --address 0.0.0.0 service/httpd-service 8080:8080
ブラウザからhttp://<ホスト名:8080/ にアクセスします

2020年5月23日土曜日

Raspberry Pi(Raspbian Buster)にGlusterfs clientをインストールする

GlusterFSは分散ファイルシステムです。GlusterFS clientをインストールし、マウントして分散ファイルシステムを利用する事ができます。

インストール方法

以下のコマンドを実行します。ボリューム名はmyvolumeの部分を置き換え、ホスト名node1/node2/node3を実ホスト名に置き換えます。
sudo mkdir -p /glusterfs

sudo apt-get update

sudo apt-get -y upgrade

sudo apt-get -y install glusterfs-client

echo 'node1:/myvolume /glusterfs glusterfs defaults,_netdev,backup-volfile-servers=node2:node3 0 0' | sudo tee -a /etc/fstab

sudo mount -a

トラブルシューティング

起動時にマウントされない場合は、以下のコマンドを実行します
sudo systemctl enable systemd-networkd

sudo systemctl enable systemd-networkd-wait-online

2019年11月26日火曜日

glusterfsのボリュームのステータスを表示する

glusterfsのボリュームのステータスを調べるには以下のコマンドを実行します。

・概要の表示
sudo gluster volume status
Status of volume: gfs
Gluster process                             TCP Port  RDMA Port  Online  Pid
------------------------------------------------------------------------------
Brick glfs1:/opt/share/myvol1/brick1/brick  49152     0          Y       505
Brick glfs2:/opt/share/myvol1/brick1/brick  49152     0          Y       570
Self-heal Daemon on localhost               N/A       N/A        Y       648
Self-heal Daemon on glfs2                   N/A       N/A        Y       512

Task Status of Volume gfs
------------------------------------------------------------------------------
There are no active volume tasks

・容量などの詳細を表示
sudo gluster volume status all detail
Status of volume: gfs
------------------------------------------------------------------------------
Brick                : Brick glfs1:/opt/share/myvol1/brick1/brick
TCP Port             : 49152
RDMA Port            : 0
Online               : Y
Pid                  : 505
File System          : ext4
Device               : /dev/root
Mount Options        : rw,noatime
Inode Size           : N/A
Disk Space Free      : 2.6TB
Total Disk Space     : 2.7TB
Inode Count          : 183148544
Free Inodes          : 183082045
------------------------------------------------------------------------------
Brick                : Brick glfs2:/opt/share/myvol1/brick1/brick
TCP Port             : 49152
RDMA Port            : 0
Online               : Y
Pid                  : 570
File System          : ext4
Device               : /dev/sda1
Mount Options        : rw,noatime
Inode Size           : 256
Disk Space Free      : 870.1GB
Total Disk Space     : 915.9GB
Inode Count          : 61054976

2019年9月20日金曜日

AnsibleでGlusterFS clientをインストールしてマウントする

以下のファイルを使用して、GlusterFS clientをインストールして、glusterfsをマウントして使用する事ができます。

glsuterfs_client.yml ※gluster_main_host/glsuter_backup_hostsを適宜書き換えてください。
- hosts: glusterfs_client
  vars:
    gluster_main_host: gfshost1
    gluster_backup_hosts: gfshost2
  roles:
    - glusterfs_client

roles/glusterfs-client/tasks/main.yml
---
- name: create /glusterfs directroy
  file: path=/glusterfs state=directory
  become: true

- name: install glusterfs-client
  apt: name=glusterfs-client state=present update_cache=yes
  become: true

- name: mount glusterfs
  mount:
    state: mounted
    path: /glusterfs
    fstype: glusterfs
    src: "{{ gluster_main_host }}:/gfs"
    opts: defaults,_netdev,backup-volfile-servers={{ gluster_backup_hosts }}
    dump: "0"
    passno: "0"
  become: true

〇動作確認環境
・Ubuntu 18.04

2019年9月1日日曜日

Raspberry PiにGlusterfsをインストールする

Glusterfsは分散ファイルシステムです。ここでは2台構成のglusterfsを構築します。
ホスト名はそれぞれ、rasp1/rasp2とします。

インストール手順

1. glusterfsのインストール
以下のコマンドをrasp1/rasp2で実行します。
sudo mkdir -p /opt/share/myvol1/brick1/brick
sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get -y install glusterfs-server
sudo systemctl enable glusterd
sudo systemctl start glusterd
sudo systemctl status glusterd

2. glusterfs構成
以下をrasp2で実行します。
sudo gluster peer probe rasp1
sudo gluster peer status

sudo gluster volume create gfs \
replica 2 \
rasp1:/opt/share/myvol1/brick1/brick \
rasp2:/opt/share/myvol1/brick1/brick \
force

sudo gluster volume start gfs

3. glusterfsをマウント
以下のコマンドをrasp1で実行します。
sudo mkdir -p /glusterfs
echo 'localhost:/gfs /glusterfs glusterfs defaults,_netdev,backup-volfile-servers=rasp4 0 0' | sudo tee -a /etc/fstab
sudo mount -a
df -h

以下のコマンドをrasp2で実行します。
sudo mkdir -p /glusterfs
echo 'localhost:/gfs /glusterfs glusterfs defaults,_netdev,backup-volfile-servers=rasp1 0 0' | sudo tee -a /etc/fstab
sudo mount -a
df -h

確認環境

Raspbian Buster (Raspberry Pi3 B+/Raspberry Pi1 B+)

2019年8月12日月曜日

Vagrantで3ノード構成のGluster Serverをインストールした仮想マシン(Debian Buster/10)を構築する

GlusterFSは分散ファイルシステムです。以下のVagrantfileを使用して、3ノード構成のGluster Serverをインストールした仮想マシン(Debian Buster/10)を構築する事ができます。

Vagrantfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.define "glusternode1" do |server|
    server.vm.box = "bento/debian-10"
    server.vm.hostname = "glusternode1"
server.vm.network :public_network, ip:"192.168.1.107"
    server.vm.provider :virtualbox do |vbox|
      vbox.name = "glusternode1"
      vbox.cpus = 2
      vbox.memory = 2048
    end
    server.vm.provision "shell", inline: <<-SHELL
# add host entries...
sed -i -e 's/^.*glusternode1$//' /etc/hosts
cat << EOF >> /etc/hosts
192.168.1.107    glusternode1
192.168.1.108    glusternode2
192.168.1.109    glusternode3
EOF

# update packages
apt-get update
export DEBIAN_FRONTEND=noninteractive
apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
apt-get -y install language-pack-ja
localectl set-locale LANG=ja_JP.UTF-8
localectl set-keymap jp106
timedatectl set-timezone Asia/Tokyo

# create the brick directory
mkdir -p /gluster/data/myvol1/brick1/brick

# install gluster server
apt-get update 
apt-get -y upgrade
sudo apt-get -y install glusterfs-server
systemctl enable glusterd
systemctl start glusterd
systemctl status glusterd

echo 'localhost:/gfs /mnt glusterfs defaults,_netdev,backup-volfile-servers=glusternode2:glusternode3 0 0' >> /etc/fstab

SHELL
  end
  #----------------------------------------------------------------------------------------
  config.vm.define "glusternode2" do |server|
    server.vm.box = "bento/debian-10"
    server.vm.hostname = "glusternode2"
server.vm.network :public_network, ip:"192.168.1.108"
    server.vm.provider :virtualbox do |vbox|
      vbox.name = "glusternode2"
      vbox.cpus = 2
      vbox.memory = 2048
    end
    server.vm.provision "shell", inline: <<-SHELL
# add host entries...
sed -i -e 's/^.*glusternode2$//' /etc/hosts
cat << EOF >> /etc/hosts
192.168.1.107    glusternode1
192.168.1.108    glusternode2
192.168.1.109    glusternode3
EOF

# update packages
apt-get update
export DEBIAN_FRONTEND=noninteractive
apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
apt-get -y install language-pack-ja
localectl set-locale LANG=ja_JP.UTF-8
localectl set-keymap jp106
timedatectl set-timezone Asia/Tokyo

# create the brick directory
mkdir -p /gluster/data/myvol1/brick1/brick

# install gluster server
apt-get update 
apt-get -y upgrade
sudo apt-get -y install glusterfs-server
systemctl enable glusterd
systemctl start glusterd
systemctl status glusterd

echo 'localhost:/gfs /mnt glusterfs defaults,_netdev,backup-volfile-servers=glusternode1:glusternode3 0 0' >> /etc/fstab

SHELL
  end
  #----------------------------------------------------------------------------------------
  config.vm.define "glusternode3" do |server|
    server.vm.box = "bento/debian-10"
    server.vm.hostname = "glusternode3"
server.vm.network :public_network, ip:"192.168.1.109"
    server.vm.provider :virtualbox do |vbox|
      vbox.name = "glusternode3"
      vbox.cpus = 2
      vbox.memory = 2048
    end
    server.vm.provision "shell", inline: <<-SHELL
# add host entries...
sed -i -e 's/^.*glusternode3$//' /etc/hosts
cat << EOF >> /etc/hosts
192.168.1.107    glusternode1
192.168.1.108    glusternode2
192.168.1.109    glusternode3
EOF

# update packages
apt-get update
export DEBIAN_FRONTEND=noninteractive
apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
apt-get -y install language-pack-ja
localectl set-locale LANG=ja_JP.UTF-8
localectl set-keymap jp106
timedatectl set-timezone Asia/Tokyo

# create the brick directory
mkdir -p /gluster/data/myvol1/brick1/brick

# install gluster server
apt-get update 
apt-get -y upgrade
sudo apt-get -y install glusterfs-server
systemctl enable glusterd
systemctl start glusterd
systemctl status glusterd

# peer with other nodes
gluster peer probe glusternode1
gluster peer probe glusternode2
gluster peer status

# create replicated volume.
gluster volume create gfs \
replica 3 \
glusternode1:/gluster/data/myvol1/brick1/brick \
glusternode2:/gluster/data/myvol1/brick1/brick \
glusternode3:/gluster/data/myvol1/brick1/brick \
force
gluster volume start gfs


# set auth.allow for thevolume
gluster volume set gfs auth.allow 192.168.1.*

echo 'localhost:/gfs /mnt glusterfs defaults,_netdev,backup-volfile-servers=glusternode1:glusternode2 0 0' >> /etc/fstab

echo 'please execute "vagrant reload" on the host machine.'
SHELL
  end
  #----------------------------------------------------------------------------------------

end