본문 바로가기

Technical/OS, Infra

[CentOS 7] Gluster Geo-replication 환경 구축과 테스트

Gluster 파일시스템의 Geo-replication 환경을 구축하고 테스트 하는 과정을 정리해 보자. 작업 환경을 단순하게, 과정을 직관적으로 표현하기 위해 추가 디스크 없는 VM 2개만으로 모든 내용을 소화해 보기로 한다. 이를 위해 Linux 의 Sparse 파일을 가상 디스크로 매핑하여, 마치 추가 디스크가 장착된, 또는 별도 파티션 된 물리 디스크 볼륨이 있는 것처럼 흉내 내는 방법을 같이 다루어 보고자 한다(블록디바이스를 통한 비슷한 테스트를 진행해야 할 때 유용한 방법으로 써먹을 수 있을 것이다).



CentOS 7.2에 Gluster Filesystem 설치


먼저 위의 그림과 같이 네트워크가 연결된 2개의 가상머신을 준비한다(CentOS 7.2 또는 RHEL 7.2는 이미 설치되었다고 가정하자). Redhat 이나 CentOS의 경우 대개 EPEL 을 통해 Gluster 를 설치하게 된다.


* 주의: 2개의 서버 노드를 peer 로 연결하여 Cluster 에 투입하는 것은 아니며, 서로 독립된 Gluster 세트가 원격지에 각각 존재하는 경우에 대한 내용을 다룬다. 여러 peer 를 통하여 Brick을 구성하고 데이터가 분산(distributed) 또는 중복(replica)되는 Volume 구성에 대해서는 여기서 논외로 하자.


* 2개의 서버 각각에 다음과 같이 gluster 를 설치한다.

# yum install -y wget

# wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm

# rpm -ivh epel-release-7-8.noarch.rpm

# yum install -y centos-release-gluster38.noarch

# yum install -y glusterfs-server

yum install -y glusterfs-geo-replication

# systemctl start glusterd

# systemctl enable glusterd


* RHEL 7 에서는 약간 과정이 다르다. 다음과 같이 해 보자.

# yum install -y wget

# wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm

# rpm -ivh epel-release-7-8.noarch.rpm

# vi /etc/yum.repos.d/Gluster.repo

[gluster38]

name=Gluster 3.8

baseurl=http://mirror.centos.org/centos/7/storage/$basearch/gluster-3.8/

gpgcheck=0

enabled=1

# yum install -y glusterfs-server

# yum install -y glusterfs-geo-replication

# systemctl start glusterd

# systemctl enable glusterd


* 커맨드를 단순하게 하기 위해 /etc/hosts 파일에 다음의 2 라인을 추가

10.10.10.10 gnode1

10.10.10.11 gnode2


* 호스트 명을 각각 gnode1, gnode 로 변경하고 재접속

hostnamectl set-hostname gnode1



준비1: 데이터를 동기화할 가상 블록디바이스 장착

서두에서 말한 것처럼 Sparse 파일(1 GByte 짜리 ^^;;)을 만들어 가상디스크로 붙이고, 이를 데이터 동기화용 블록디바이스로 활용할 것이다. VM 2개에 각각 다음과 같이 작업한다.


* losetup -f 로 Sparse 이미지 파일을 LO 디바이스에 매핑하면, 자동으로 다음의 빈 LO 디바이스(아래의 경우, /dev/loop2)가 찾아져서 매핑됨

* 블록디바이스가 준비되었으므로 xfs 로 파일시스템을 포맷하고 마운트포인트를 /mnt/gnode_disk1 디렉토리로 하여 시스템에 마운트하면 준비 끝

[root@gnode1 ~]# mkdir gluster_disk

[root@gnode1 ~]# cd gluster_disk/

[root@gnode1 ~]# dd if=/dev/zero of=./disk1.img bs=1M count=1024

[root@gnode1 ~]# losetup -f /root/gluster_disk/disk1.img

[root@gnode1 ~]# losetup

NAME       SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE

...

/dev/loop2         0      0         0  0 /root/gluster_disk/disk1.img 

[root@gnode1 ~]# mkfs.xfs /dev/loop2

[root@gnode1 ~]# mkdir /mnt/gnode_disk1

[root@gnode1 ~]# mount /dev/loop2 /mnt/gnode_disk1/



준비2: Password-less 로그인 설정

Geo-replication 이 가능하게 하기 위해서는, 2개의 서버에서 각각 상대방 서버로 패스워드 없이 root 계정으로 접속할 수 있도록 ssh 키를 교환해 두어야 한다. 다음과 같이 진행하자.


* Password-less ssh 접속을 위한 키 교환. 상대방 서버에 ssh 접속하고 암호를 입력해 두면 다음에는 암호 없이 로그인 가능

[root@gnode1 ~]# ssh-keygen 

[root@gnode1 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@10.10.10.11

[root@gnode1 ~]# ssh gnode2



Gluster Volume 생성 및 기동

각각의 Gluster 서버에서 다음과 같이 Volume 을 생성하고 기동한다. 


* 주의: 마운트포인트 아래에 서브디렉토리를 생성하여 볼륨(여기서는 distvol)에 할당해야 함

[root@gnode1 ~]# mkdir -p /mnt/gnode_disk1/brick

[root@gnode1 ~]# gluster volume create distvol gnode1:/mnt/gnode_disk1/brick

[root@gnode1 ~]# gluster volume start distvol

[root@gnode1 ~]# gluster volume info

Volume Name: distvol

Type: Distribute

Volume ID: 9754b79a-d0e7-4823-9e85-38340d99e732

Status: Started

Snapshot Count: 0

Number of Bricks: 1

Transport-type: tcp

Bricks:

Brick1: gnode1:/mnt/gnode_disk1/brick

Options Reconfigured:

nfs.disable: on

performance.readdir-ahead: on

transport.address-family: inet


[root@gnode2 ~]# mkdir -p /mnt/gnode_disk1/brick

[root@gnode2 ~]# gluster volume create distvol gnode2:/mnt/gnode_disk1/brick

[root@gnode2 ~]# gluster volume start distvol

[root@gnode2 ~]# gluster volume info

Volume Name: distvol

Type: Distribute

Volume ID: e12db607-2e19-4a45-bc3b-eb6e922f59e5

Status: Started

Snapshot Count: 0

Number of Bricks: 1

Transport-type: tcp

Bricks:

Brick1: gnode2:/mnt/gnode_disk1/brick

Options Reconfigured:

nfs.disable: on

performance.readdir-ahead: on

transport.address-family: inet



Geo-replication 설정 및 테스트

* Geo-replication 설정은 Master(여기서는 gnode1) 에서만 수행

[root@gnode1 ~]# gluster system:: execute gsec_create

[root@gnode1 ~]# gluster volume geo-replication distvol gnode2::distvol create push-pem

[root@gnode1 ~]# gluster volume geo-replication distvol gnode2::distvol start

[root@gnode1 ~]# gluster volume geo-replication distvol gnode2::distvol status

MASTER NODE    MASTER VOL    MASTER BRICK              SLAVE USER    SLAVE              SLAVE NODE    STATUS    CRAWL STATUS       LAST_SYNCED                  

-----------------------------------------------------------------------------------------------------------------------------------------------------

gnode1         distvol       /mnt/gnode_disk1/brick    root          gnode2::distvol    gnode2        Active    Changelog Crawl    2016-10-10 01:10:04

[root@gnode1 ~]# gluster volume info distvol

Volume Name: distvol

Type: Distribute

Volume ID: 9754b79a-d0e7-4823-9e85-38340d99e732

Status: Started

Snapshot Count: 0

Number of Bricks: 1

Transport-type: tcp

Bricks:

Brick1: gnode1:/mnt/gnode_disk1/brick

Options Reconfigured:

changelog.changelog: on

geo-replication.ignore-pid-check: on

geo-replication.indexing: on

nfs.disable: on

performance.readdir-ahead: on

transport.address-family: inet



동기화 테스트

동기화 테스트를 수행하기 위해 별도의 Gluster Client 를 사용해야 하지만, Gluster 서버 자신을 클라이언트로 사용해도 된다. 다시 말해 Gluster 서버에서 자신의 Volume 을 리모트 마운트하는 것이다. 다음과 같이 진행해 보자.


* gnode1: Gluster Fuse Client 로 distvol 볼륨을 로컬의 /mnt/gnode1_distvol/ 디렉토리로 마운트하고 해당 디렉토리로 이동

[root@gnode1 ~]# mkdir /mnt/gnode1_distvol

[root@gnode1 ~]# mount.glusterfs gnode1:/distvol /mnt/gnode1_distvol/

[root@gnode1 ~]# cd /mnt/gnode1_distvol/


* gnode2: Gluster Fuse Client 로 distvol 볼륨을 로컬의 /mnt/gnode2_distvol/ 디렉토리로 마운트하고 해당 디렉토리로 이동

[root@gnode2 ~]# mkdir /mnt/gnode2_distvol

[root@gnode2 ~]# mount.glusterfs gnode1:/distvol /mnt/gnode2_distvol/

[root@gnode2 ~]# cd /mnt/gnode2_distvol/


* gnode1: 파일 생성, 수정 및 삭제

[root@gnode1 ~]# echo abcdef----xyzxyz----xxxx > test.txt

[root@gnode1 ~]# cp test.txt s

[root@gnode1 ~]# cat test.txt >> s

[root@gnode1 ~]# cp s x

[root@gnode1 ~]# cat s >> x

[root@gnode1 ~]# vi x

[root@gnode1 ~]# rm tttt

...

[root@gnode1 ~]# gluster volume geo-replication distvol gnode2::distvol status

MASTER NODE    MASTER VOL    MASTER BRICK              SLAVE USER    SLAVE              SLAVE NODE    STATUS    CRAWL STATUS       LAST_SYNCED                  

-----------------------------------------------------------------------------------------------------------------------------------------------------

gnode1         distvol       /mnt/gnode_disk1/brick    root          gnode2::distvol    gnode2        Active    Changelog Crawl    2016-10-10 01:15:22


* gnode2 디렉토리 내의 파일 변화 관찰, 확인

[root@gnode2 gnode2_distvol]# ls

s  test.txt  x

[root@gnode2 gnode2_distvol]# cat test.txt

abcdef----xyzxyz----xxxx

[root@gnode2 gnode2_distvol]#


몇 가지 팁들 ... port 변경, 작은 파일에 유리한 option 등

Gluster 의 geo-replication은 내부적으로 ssh를 통한 rsync 방식으로 동작한다. 일반적으로 ssh는 TCP 22 포트를 사용하는데, 임의의 포트번호로 설정하려면 다음과 같이 진행하면 된다(사실, "How to replicate to slave via non-standard ssh port..." 에 대한 답이다).


우선 양쪽 Gluster 서버에서 ssh port 를 변경한다


# vi /etc/ssh/sshd_config

...

Port 22222

...


# systemctl restart sshd

# netstat -anp | grep 22222

tcp   0   0   0.0.0.0:22222    0.0.0.0:*    LISTEN    8425/sshd

...


만약 netstat 결과에 해당 포트번호로 바인딩되어 있지 않고 ssh 접속이 안된다면 SELINUX가 ssh의 기본 Port인 22번으로 바인딩하게 고정해 둔 것일 게다. 그러면 다음과 같은 semanage 명령을 수행하고 조금 시간이 지난 뒤에 다시 접속해 본다.


# semanage port -a -t ssh_port_t -p tcp 22222


Linux 서버에서 파이어월(firewalld)이 사용되고 있다면 다음과 같이 해당 포트를 허용해 주는 것도 잊지 않도록 하자.


# firewall-cmd --permanent --zone=public --add-port=22222/tcp

# firewall-cmd --reload


성공적으로 ssh 포트 번호를 변경하였다면, 이번에는 Gluster 에서 새로운 포트로 Geo-replication 이 되도록 설정하면 된다.


[root@gnode1 ~]# gluster volume geo-replication distvol gnode2::distvol stop

[root@gnode1 ~]# gluster volume geo-replication distvol gnode2::distvol delete

[root@gnode1 ~]# gluster volume geo-replication distvol gnode2::distvol create ssh-port 22222 push-pem

[root@gnode1 ~]# gluster volume geo-replication distvol gnode2::distvol config ssh-port 22222

[root@gnode1 ~]# gluster volume geo-replication distvol gnode2::distvol start



Rsync는 Block 방식의 전송이기 때문에 파일의 크기가 큰 경우에 좀 더 유리하다. 반대로 말하면 크기가 작은(대략 수 KB~수백KB 이내) 파일의 경우 전송 지연이 발생할 수 있게 되는데, 이 때에는 다음과 같은 옵션을 적용하여 테스트해 보기를 권한다. Geo-replication 이 작동되는 도중에도 실행해 볼 수 있다.


[root@gnode1 ~] gluster volume geo-replication distvol gnode2::distvol config use-tarssh true


참고로, 간단히 테스트 해 보니 50KB 크기의 몇 백 개 파일 전송에 1분 26초 정도 걸리던 것이, 옵션 변경 후에 약 10초 가량 전송 시간이 줄어든 것을 볼 수 있었다.


원래의 기본 전송방식인 Rsync 방식으로 돌아가려면 다음과 같이 하면 된다.

[root@gnode1 ~] gluster volume geo-replication distvol gnode2::distvol config \!use-tarssh



Good Luck !


- Barracuda -