���A���^�C���~���[�����O�c�[������(lsyncd+rsyncd)

�ŏI�X�V���F 2017.11.25

���T�v

lsyncd���g�p���ă}�V���ԂŃ��A���^�C���Ƀf�B���N�g���̃~���[�����O���s���B
lsyncd��Linux�J�[�l����inotify�@�\�𗘗p���āA�t�@�C���̍X�V���Ƀ~���[���rsync�T�[�o�[��rsync�����s���邱�Ƃɂ��A���A���^�C���Ƀf�B���N�g���̃~���[�����O���s���B

�����ł́A��Ƃ���/root�f�B���N�g�����~���[���/tmp/root�f�B���N�g���փ~���[�����O����B


��rsync�T�[�o�[�ݒ�(�~���[��)

[root@to ~]# mkdir -p /tmp/root�@���@�~���[��f�B���N�g���쐬

[root@to ~]# chown nobody:nobody /tmp/root/�@���@�~���[��f�B���N�g�����L�҂�nobody�ɕύX

[root@to ~]# vi /etc/rsyncd.conf�@���@rsync�T�[�o�[�ݒ�t�@�C���쐬
[root]�@���@�C�ӂ̃��W���[����(�~���[������ڑ����̖��O)
    path = /tmp/root�@���@�~���[��f�B���N�g��
    hosts allow = 192.168.1.0/24�@���@�ڑ����ƒz�X�g
    read only = false�@���@�X�V����

��rsyncd.conf�̏ڍׂ����������Q��

��rsync�T�[�o�[�N��(�~���[��)

[root@to ~]# yum -y install xinetd�@���@xinetd�C���X�g�[��

[root@to ~]# /etc/rc.d/init.d/xinetd restart�@���@xinetd�ċN��
xinetd ���~��:                                           [  OK  ]
xinetd ���N����:                                           [  OK  ]

[root@to ~]# chkconfig rsync on�@���@rsync�T�[�o�[�N��&�����N���ݒ�

��lsyncd�C���X�g�[��(�~���[��)

[root@from ~]# yum -y install libxml2-devel lua-devel lua-static�@���@lsyncd�C���X�g�[���ɕK�v�ȃp�b�P�[�W���C���X�g�[��

[root@from ~]# export LUA_CFLAGS='-I/usr/include -lm -ldl'�@���@Lua�̊‹��ϐ��ݒ�

[root@from ~]# export LUA_LIBS='/usr/lib/liblua.a'�@���@Lua�̊‹��ϐ��ݒ�

[root@from ~]# wget https://lsyncd.googlecode.com/files/lsyncd-2.1.5.tar.gz�@���@lsyncd�_�E�����[�h

���ŐV�ł�URL���_�E�����[�h�y�[�W�Ŋm�F

[root@from ~]# tar zxvf lsyncd-2.1.5.tar.gz�@���@lsyncd�W�J

[root@from ~]# cd lsyncd-2.1.5�@���@lsyncd�W�J��f�B���N�g���ֈړ�

[root@from lsyncd-2.1.5]# ./configure && make && make install�@���@lsyncd�C���X�g�[��

[root@from lsyncd-2.1.5]# cd�@���@lsyncd�W�J��f�B���N�g���𔲂���

[root@from ~]# rm -rf lsyncd-2.1.5�@���@lsyncd�W�J��f�B���N�g�����폜

[root@from ~]# rm -rf lsyncd-2.1.5.tar.gz�@���@�_�E�����[�h�����t�@�C�����폜

��lsyncd�ݒ�(�~���[��)

[root@from ~]# vi /etc/lsyncd.conf�@���@lsyncd�ݒ�t�@�C���쐬
settings {
        statusFile = "/tmp/lsyncd.stat",
        statusInterval = 1,
}

sync{
        default.rsync,
        source="/root/",�@���@�~���[���f�B���N�g��
        target="xxx.xxx.xxx.xxx:/tmp/root/",�@���@�~���[��(rsync�T�[�o�[)IP�A�h���X:�~���[��f�B���N�g��
        rsync  = {
                archive = true,
                links   = true,
                update  = true,
                verbose = false
        }
}

[root@from ~]# ssh-keygen -t rsa -N ""�@���@RSA���y�A(���J���^�閧��)�쐬
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):�@���@��ENTER
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
09:6c:eb:5a:f7:01:fa:32:1b:8c:b2:82:48:b7:c1:c3 root@from.centossrv.com

[root@from ~]# scp .ssh/id_rsa.pub �~���[��IP�A�h���X:/root/.ssh/authorized_keys2�@���@RSA��(���J��)���~���[��փR�s�[

��lsyncd�N��(�~���[��)

[root@from ~]# vi /etc/rc.d/init.d/lsyncd�@���@lsyncd�N���X�N���v�g�쐬
#!/bin/bash
#
# lsyncd
#
# chkconfig: - 99 20
# description: lsyncd auto start script

start() {
    /usr/local/bin/lsyncd /etc/lsyncd.conf
}

stop() {
    /bin/kill -9 `/sbin/pidof lsyncd`
    until [ -z $(/sbin/pidof lsyncd) ]; do :; done
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        start
        ;;
    status)
        pid=`pidof lsyncd`
        if [ $? -eq 0 ]; then
            echo "lsyncd (pid $pid) is running..."
        else
            echo "lsyncd is not running"
        fi
        ;;
    *)
        echo "Usage: lsyncd {start|stop|restart|status}"
        exit 1
esac

exit $?

[root@from ~]# chmod +x /etc/rc.d/init.d/lsyncd�@���@lsyncd�N���X�N���v�g�֎��s�����t��

[root@from ~]# /etc/rc.d/init.d/lsyncd start�@���@lsyncd�N��

[root@from ~]# chkconfig --add lsyncd�@���@lsyncd�N���X�N���v�g��chkconfig�֓o�^

[root@from ~]# chkconfig lsyncd on�@���@lsyncd�����N���ݒ�

��lsyncd�m�F

�~���[����/root�f�B���N�g���̓��e���~���[���/tmp/root�f�B���N�g���ɃR�s�[����Ă��邱�Ƃ��m�F�B
�~���[����/root�f�B���N�g���Ńt�@�C���̍쐬�E�X�V�E�폜�����s���A���̓s�x�A�~���[��ɕύX�����f����Ă��邱�Ƃ��m�F�B

���~���[�̓f�B���N�g���P�ʂōs���邽�߁A������~���[�悪��~���Ă��܂��āA���̊ԂɃ~���[���ɕύX���������ꍇ�ł��A�~���[��N����̍ŏ��̃~���[���ύX���ɑS�ă~���[�����O�����


���֘A�R���e���c




�����̃y�[�W�̃g�b�v�֖߂�

�v���C�o�V�[�|���V�[
centossrv.com