scp๋ ๋ฌด์์ผ๊น?
scp๋ secure copy์ ์ฝ์๋ก ๋ก์ปฌ ํธ์คํธ์ ์๊ฒฉ ํธ์คํธ ๋๋ ๋ ๊ฐ์ ํธ์คํธ ๊ฐ์ ํ์ผ์ ์ ์กํ๋ ์๋จ์ ๋๋ค. SSH(Secure Shell)์ ํตํ ํ์ผ ์ ์ก ๋ฐฉ์์ด๋ฉฐ ๋ณ๋์ FTP ํด๋ผ์ด์ธํธ๋ฅผ ์ค์นํ์ง ์์๋ ํ์ผ ์ก์์ ์ด ๊ฐ๋ฅํฉ๋๋ค.
scp ์ฌ์ฉ๋ฒ
์ฌ์ฉ๋ฒ์ ์๋์ ๊ฐ์ต๋๋ค. ๋จผ์ , ๋ก์ปฌ ํธ์คํธ์์ ์๊ฒฉ ํธ์คํธ๋ก ํ์ผ์ ์ ์กํ ๋๋
scp ํ์ผ๊ฒฝ๋ก/ํ์ผ๋ช
๊ณ์ ๋ช
@ํ๊ฒ์๋ฒ๋ช
:๋์ฐฉ๊ฒฝ๋ก/ํ์ผ๋ช
# ์๋ฅผ ๋ค์ด, Desktop ๋๋ ํฐ๋ฆฌ์ ์๋ test.txt ํ์ผ์ madlife ์๋ฒ์ root ๋๋ ํฐ๋ฆฌ์ ๋ณด๋ด๊ณ ์ถ๋ค๋ฉด,
scp Desktop/test.txt madplay@madlife:/root # madplay๋ ๊ณ์ ๋ช
๋ฐ๋๋ก ์๊ฒฉ ํธ์คํธ์์ ๋ก์ปฌ ํธ์คํธ๋ก ํ์ผ์ ์ ์กํ ๋๋
scp ๊ณ์ ๋ช
@์๋ฒ๋ช
:ํ์ผ๊ฒฝ๋ก/ํ์ผ๋ช
๋์ฐฉ ๋ก์ปฌ ๊ฒฝ๋ก
# ์๋ฅผ ๋ค์ด, ์์์ ์ฎ๊ธด test.txt๋ฅผ ๋ก์ปฌ๋ก ์ฎ๊ธฐ๊ณ ์ถ๋ค๋ฉด
scp madplay@madlife:/root/test.txt /Desktop/test.txt
scp ์ต์
์ผ๋ก๋
- r : ํ์ ํด๋๋ฅผ ํฌํจํ์ฌ ๋ชจ๋ ๋ณต์ฌํ๋ Recursive
- p : ๊ถํ ๋ฐ ์์ฑ์ ์ ์งํ๋ Preserve
- c : ์์ถ์ ์ค์ํ๋ Compress ์ต์ ๋ฑ์ด ์์ต๋๋ค.
rsync๋ ๋ฌด์์ผ๊น?
rsync๋ remote synchronization์ ์ฝ์๋ก์ ์๊ฒฉ์ ์๋ ํ์ผ๊ณผ ๋๋ ํฐ๋ฆฌ๋ฅผ ๋ณต์ฌํ๊ณ ๋๊ธฐํํฉ๋๋ค.
rsync ์ฌ์ฉ๋ฒ
rsync๋ ์ฌ์ฉ๋ฒ์ด ์ฐธ ๋ง์ต๋๋ค. ์ฌ๊ธฐ์๋ โdaemon ์ต์ ์ ์ด์ฉํ์ฌ ์๋ฒ ๋ชจ๋๋ก ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ์์๋ด ์๋ค. rsync ์๋ฒ์ ๊ฒฝ์ฐ rsync ๊ด๋ จ ํ์ผ์ ์์ ํด์ค๋๋ค.
vi /etc/xinetd.d/rsync
# disable์ ๊ฐ์ no๋ก ๋ณ๊ฒฝํด ์ค๋๋ค.
# default: off
# description: The rsync server is a good addition to an ftp server, as it \
# allows crc checksumming etc.
service rsync
{
disable = no
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
๋ค์์ผ๋ก ์ ์ alias ๋ฐ ์๋ฒ๋ฅผ ์ค์ ํฉ๋๋ค.
# ์๋ ํ์ผ์ด ์์ผ๋ฉด ์๋ก ์์ฑํฉ๋๋ค.
vi /etc/rsyncd.conf
[alias ์ด๋ฆ]
path = /home/www
uid = nobody
gid = nobody
use chroot = yes
read only = false
hosts allow = ํ์ฉ IP
# path : ์๋น์ค ๋์ ๋๋ ํ ๋ฆฌ ์์น
# uid : ์ฌ์ฉ์์ id / ๊ธฐ๋ณธ๊ฐ์ nobody
# gid : ์ฌ์ฉ์์ ๊ทธ๋ฃน id / ๊ธฐ๋ณธ๊ฐ์ nobody
# use chroot : ์์ path๋ฅผ ๋ฃจํธ ๋๋ ํ ๋ฆฌ๋ก ์ฌ์ฉ(yes)
# read only : ์ฝ๊ธฐ ์ ์ฉ(ํด๋ผ์ด์ธํธ -> ์๋ฒ์ธ ๊ฒฝ์ฐ๋ no๋ก ์ค์ )
# hosts allow : ํธ์คํธ๋ณ ์ ์ ํ์ฉ ์ค์ / ๊ธฐ๋ณธ๊ฐ์ all host / ์ ๊ทผ์ ํ์ฉํ IP๋ฅผ ์ ์ผ๋ฉด ๋ฉ๋๋ค.
# comment : ํด๋น ์ค์ ์ ๋ํ ์ค๋ช
, ์ฝ๋ฉํธ
# max connections : ๋์ ์ ์์ ์
# timeout : ํ์์์ ์๊ฐ ์ค์
๋ง์ง๋ง์ผ๋ก xinetd๋ฅผ ๋ค์ ์์ํฉ๋๋ค.
/etc/init.d/xinetd restart
# rsync๋ 873 ํฌํธ๋ฅผ ์ฌ์ฉํ๋ฏ๋ก ๋งํ์๋ ๊ฒฝ์ฐ ํ์ฉํด์ค์ผ ํฉ๋๋ค.
์ถ๊ฐ) CentOS 7 ๋ฒ์ ๊ด๋ จ
systemctl start rsyncd.service
# ์ฌ์์์ systemctl restart rsyncd.service
# ์๋ฒ ์ฌ๋ถํ
ํ์๋ systemctl enable rsyncd.service
๋ค์์ผ๋ก rsync ํด๋ผ์ด์ธํธ ์ค์ ์ ๋๋ค. ๋จผ์ rsync ์ ์ ์ฌ๋ถ๋ฅผ ํ์ธํฉ๋๋ค.
telnet <rsync ์๋ฒ IP > 873
# ์๋ฅผ ๋ค๋ฉด, telnet xxx.xxx.xxx.xxx 873
# telnet์ ์ด์ฉํ์ฌ 873 ํฌํธ๊ฐ ์ ์ ์ฐ๊ฒฐ๋๋์ง ํ์ธํฉ๋๋ค.
rsync๋ฅผ ์คํํฉ๋๋ค.
rsync -avz <IP>::<์์์ ์ง์ ํ alias>๊ฒฝ๋ก ๋๋ ํ ๋ฆฌ
#์๋ฅผ ๋ค์ด, rsync ์๋ฒ ์ค์ ์ด ๋ ๊ฒ์ madlife(123.123.123.123)๋ผ๊ณ ๊ฐ์ ํ๊ณ
#madlife๋ก๋ถํฐ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ ๋๊ธฐํ ์ํฌ ์๋ฒ๋ฅผ madplay๋ผ๊ณ ๊ฐ์ ํ๊ณ
#madlife์ /home/www๋ฅผ madplay์ /home/www๋ก ๋ด์ฉ์ ๋๊ธฐํ ์ํจ๋ค๋ฉด
#madplay ์๋ฒ์์
rsync -avz madlife::alias์ด๋ฆ/home/www /home/www
rsync -avz 123.123.123.123::alias์ด๋ฆ/home/www /home/www
rsync ์ต์
์ผ๋ก๋
- a : ํผ๋ฏธ์ ์์ ์ฃผ ๋ฐ ์์น๊น์ง ๊ทธ๋๋ก ๊ฐ์ ธ์ค๋ Archive
- v : ๋๊ธฐํ ์์ธ ์งํ ์ํฉ์ ๋ณด์ฌ์ฃผ๋ Verbose
- r : ์ง์ ํ ๋๋ ํฐ๋ฆฌ์ ํ์ ๋๋ ํฐ๋ฆฌ๊น์ง ์ฌ๊ท์ ์ผ๋ก ์คํํ๋ Recursive
- p : ์๋ณธ ํ์ผ ์๊ฐ์ ์์ ์๊ฐ, ๊ถํ ๋ฑ์ ์ ๋ณด๋ฅผ ๋ณด์กดํ๋ Perms
- z : ๋ฐ์ดํฐ๋ฅผ ์์ถ ์ ์กํ๋ Compress ์ต์ ๋ฑ์ด ์์ต๋๋ค.
scp์ rsync์ ์ฐจ์ด
์๊ฒฉ์ผ๋ก ํ์ผ์ ์ ์กํ ๋ scp์ rsync๋ฅผ ์ฃผ๋ก ์ฌ์ฉํฉ๋๋ค. ๊ทธ๋ ๋ค๋ฉด ์ด๋ค์ ์ฐจ์ด๋ ๋ฌด์์ผ๊น์? ์ฐ์ rsync๋ scp๋ณด๋ค ๋น ๋ฆ ๋๋ค. remote-update ํ๋กํ ์ฝ์ ์ด์ฉํด์ ์ฐจ์ด๊ฐ ์๋ ํ์ผ๋ง ๋ณต์ฌํ๊ธฐ ๋๋ฌธ์ด์ง์. ๊ฐ์ฅ ์ฒ์์๋ ๋ชจ๋ ํ์ผ, ๋๋ ํฐ๋ฆฌ๋ฅผ ๋ณต์ฌํ๊ฒ ์ง๋ง ์ดํ๋ถํฐ๋ ์ฐจ์ด๊ฐ ์๋ ํ์ผ๋ง ๋ณต์ฌํ๊ธฐ ๋๋ฌธ์ ํจ์จ์ ์ ๋๋ค.
ํํธ, Symbolic Link ์ฒ๋ฆฌ ๋ฐฉ์์ ์ฐจ์ด๊ฐ ์์ต๋๋ค. scp๋ ์ ์กํ๋ ํ์ผ ์ค์ ์ฌ๋ณผ๋ฆญ ๋งํฌ๊ฐ ์์ผ๋ฉด ์ด๋ฅผ ์ ์งํ์ง ์๊ณ ๋งํฌ๋ ์๋ณธ ํ์ผ์ ์ ์กํฉ๋๋ค.