InfraPlatform

Linux - Rsyncd 설치와 selinux 문제 해결법 (Centos8)

IT오이시이 2020. 3. 8. 13:17
728x90

Linux - Rsyncd 설치와 selinux 문제 해결법 (Centos8)

#Rsyncd #Selinux #firewall-cmd #setsebool -P rsync_full_access 1

 

1. Rsyncd 설치와  selinux 문제 해결법

Centos8에 Rsync 를 설치하는데 아래와 같은 에러를 만났다. 예전 같이 Sellinux를 disabled 하면 바로 해결 되는 문제 이지만 이제는 sellinux 를 잘 사용하는 것도 중요한 것으로 보여 진다.

그 동안 우리는 보통 Selinux 가 disable 된 환경을 많이 사용해 왔기에 이런 에러를 해결하기 어려웠다.

일반적인 rsync 명령을 아래와 같이 실행했는데  rsync 명령은 에러가 발생되고 있을때 해결 방안이다.

# 작동이 안되는 명령
$ rsync -ar --progress -n node2::WEB_APP /svc/web_app
rsync: failed to connect to node2.im.com (192.168.56.104): No route to host (113)

# 작동이 되는 명령
$ rsync -ar --progress -n node2:/svc/web_app /svc/web_app

 

아래와 같이 tail -f /var/log/message 에 다음과 같은 에러를 본다면 해결 방안이다.

"Feb 23 07:04:46 node2 platform-python[8168]: SELinux is preventing /usr/bin/rsync from read access on the directory web_app.
#012#012***** Plugin rsync_data (37.5 confidence) suggests ************************
#012#012If web_app should be shared via the RSYNC daemon
#012Then you need to change the label on web_app
#012Do#012# semanage fcontext -a -t rsync_data_t 'web_app'
#012# restorecon -v 'web_app'
#012#012***** Plugin catchall_boolean (30.1 confidence) suggests ******************
#012#012If you want to allow rsync to export all ro
#012Then you must tell SELinux about this by enabling the 'rsync_export_all_ro' boolean.
#012#012Do#012setsebool -P rsync_export_all_ro 1
#012#012***** Plugin catchall_boolean (30.1 confidence) suggests ******************
#012#012If you want to allow rsync to full access
#012Then you must tell SELinux about this by enabling the 'rsync_full_access' boolean.
#012#012Do#012setsebool -P rsync_full_access 1
#012#012***** Plugin catchall (4.20 confidence) suggests **************************
#012#012If you believe that rsync should be allowed read access on the web_app directory by default.
#012Then you should report this as a bug.#012You can generate a local policy module to allow this access.
#012Do#012allow this access for now by executing:#012# ausearch -c 'rsync' --raw | audit2allow -M my-rsync
#012# semodule -X 300 -i my-rsync.pp#012"

 

 

2)  linux Selinux 환경을 읽어 수정한다.

다음과 같이 getsebool 명령으로 selinux 설정과 rsync의 상태를 확인한다.
# getsebool -a | grep rsync # 설정을 확인한다.
# setsebool -P rsync_export_all_ro 1 # 읽기 모드를 허용한다.
# setsebool -P rsync_client 1 # 클라이언트의 접속을 허용한다.
# setsebool -P rsync_full_access 1 # 읽고쓰는 모든 기능을 허용한다.

[root@node1 svc]# getsebool -a | grep rsync
postgresql_can_rsync --> off
rsync_anon_write --> off
rsync_client --> off
rsync_export_all_ro --> off
rsync_full_access --> off


[root@node1 svc]# setsebool -P rsync_export_all_ro 1
[root@node1 svc]# setsebool -P rsync_client 1


[root@node1 svc]# getsebool -a | grep rsync
postgresql_can_rsync --> off
rsync_anon_write --> off
rsync_client --> on
rsync_export_all_ro --> on
rsync_full_access --> on

 

3) 방화벽 설정하기

아직 아래와 같이 접속이 되지 않는다면 방화벽의 설정을 해주어야 한다. 
192.168.56.102 --> 192.168.56.104:873 으로 통신이 되지 않는다.

[root@node1 web_app2]# rsync -ar --progress -n 192.168.56.104::WEB_APP .
rsync: failed to connect to 192.168.56.104 (192.168.56.104): No route to host (113)

 

1) 방화벽에 문제가 있는지 다음과 같이 확인 해보았다.

nmap 이라는 네트웍 포트 상태 점검을 위해서 node1 -> node2로 명령을 날려 본다.

[root]# nmap -sT -p- -PN 192.168.56.104
Starting Nmap 7.70 ( https://nmap.org ) at 2020-02-23 07:32 EST
Nmap scan report for node2 (192.168.56.104)
Host is up (0.0028s latency).
Not shown: 65533 filtered ports
PORT STATE SERVICE
22/tcp open ssh
9090/tcp closed zeus-admin

※ rsync 관련된 내용이 보이지 않는다는 것은 rsync 데몬이 구동안돠어 있거나 막혀있다는 것이다.
-> 873/tcp open rsync : 통신이 허용된다면 open rsync 내용이 있어야 한다.

 

2) 방화벽 설정을 확인하자

* 방화벽 설정을 확인하면services: cockpit dhcpv6-client ssh# rsync 가 허용 목록에 없다.

[node2 web_app]# firewall-cmd --zone=public --list-all public (active) target: default icmp-block-inversion: no interfaces: enp0s3 enp0s8 sources: services: cockpit dhcpv6-client ssh # rsync 가 허용 목록에 없다. ports: protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:

[node2 web_app]# firewall-cmd --zone=public --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: enp0s3 enp0s8
sources:

services: cockpit dhcpv6-client ssh        # rsync 가 허용 목록에 없다.
ports:

protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:

 

* 방화별 설정에 rsync를 등록하자 
# firewall-cmd --add-service=rsyncd success

[root@node2 web_app]# firewall-cmd --add-service=rsyncd success

 

* 방화별 설정을 다시 확인하자

[root@node2 web_app]# firewall-cmd --zone=public --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: enp0s3 enp0s8
sources:

services: cockpit dhcpv6-client rsyncd ssh         # Rsyncd를 허용 목록에 추가 했다.
ports:

protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:

 

 

4) 다른 노드에도 아래와 같이 방화벽 설정을 추가 한다.

# Rsyncd를 기본 허용 목록에 추가한다.

[root@node2 web_app]# firewall-cmd --zone=trusted --add-service=rsyncd
success

 

# 시스템 재시작시 적용되는 방화벽룰에도 추가 한다.

[root@node2 web_app]#firewall-cmd --permanent --add-service=rsyncd
success

 

5) 방화벽 설정을 적용 하자

# 설정을 재기동 하여 로딩한다.

#firewall-cmd --reload

 

6) 방화벽 설정 기타

# 기타 명령 방화벽 상태 확인

# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: enp0s3 enp0s8
sources:

services: cockpit dhcpv6-client rsyncd ssh
ports:

protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:

 

방화벽의 기본 설정인 Public zone 의 상태를 확인한다.

# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: enp0s3 enp0s8
sources:

services: cockpit dhcpv6-client rsyncd ssh
ports:

protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:

 

7) 성공 예시

node2의 WEB_APP 이라는 Alias로 설정된 rsync.conf의 디렉토리를 현재 노드의 디렉토리로 가져 온다

rsync -ar --progress node2::WEB_APP .

[root@node1 web_app2]# rsync -ar --progress node2::WEB_APP .
receiving incremental file list
./
Sync_web.sh
188 100% 183.59kB/s 0:00:00 (xfr#1, to-chk=2/4)

 

 

[참고]

https://couplewith.tistory.com/168

 

Linux - Rsyncd install - Centos8

Linux - Rsyncd install - Centos8 1. 설치 yum install rsync rsync-daemon -y yum install rsync rsync-daemon -y 2. 환경 설정 [root@node1 svc]# vi /etc/rsyncd.conf # /etc/rsyncd.conf uid = 1000 gid = 1000 max connections = 20 timeout 600 hosts allow = 19

couplewith.tistory.com

 

728x90
반응형