Nibelungen Code

Category Archives: ミラー

lsyncd2+rsyncdでのミラーサーバー構築

このエントリをはてなブックマークに追加このエントリをGoogle bookmarkに追加このエントリをdel.icio.usに追加このエントリをfacebookに追加

いつの間にかlsyncdのバージョンが2に上がってたー。ということで設定手順をまとめねば。
前提としてOSはUbuntu 11.10以降で。

lsyncdのバージョンが1系ならlsyncd+rsyncdでのミラーサーバー構築をどうぞ。

ミラー先設定

まず、rsyncdの設定から。

sudo nano /etc/rsyncd.conf
#
# Global options
#
log file = /var/log/rsyncd/rsyncd.log
uid = root
gid = root

#
# Module options
#
[www]
path = /var/www
hosts allow = 192.168.1.101/32
hosts deny = *
read only = false

uidとgidを設定をしないとそれぞれnobody、nogroupとなります。
次にログローテートの設定。

sudo nano /etc/logrotate.d/rsyncd
/var/log/rsyncd/rsyncd.log {
        daily
        missingok
        rotate 30
        compress
        delaycompress
        dateext
        notifempty
}

ログの保存先のディレクトリを作成してローテートのテスト。

sudo mkdir -p /var/log/rsyncd
sudo logrotate -d /etc/logrotate.conf

rsyncをxinetdで動かしたいのでxinetdが入っていなければインストールする。

sudo aptitude install xinetd

そしてxinetdで動かすrsyncdの設定。
only_fromのところにはミラー元のIPを記述しておきます。

sudo nano /etc/xinetd.d/rsyncd
service rsync
{
 disable = no
 socket_type = stream
 user = root
 wait = no
 server = /usr/bin/rsync
 server_args = --daemon --config=/etc/rsyncd.conf
 only_from = 192.168.1.101/32 127.0.0.1
 log_on_failure += USERID
}

xinetdを再起動

sudo /etc/init.d/xinetd restart

ミラー元設定

いよいよミラー元の設定。
lsyncd2をインストールする。
Ubuntu 11.10 (Oneiric)以降でないとlsyncd2になっていないので注意。

sudo aptitude install lsyncd

設定ファイルのサンプルをコピーして編集する。バージョン2からはxmlではなくluaに変更になっています。
起動スクリプトの中を見てみると

sudo nano /etc/init.d/lsyncd
CONFIG=/etc/lsyncd/lsyncd.conf.lua

とあるので、/etc/lsyncd/lsyncd.conf.luaにコピーします。

sudo mkdir -p /etc/lsyncd
sudo cp -p /usr/share/doc/lsyncd/examples/lrsync.lua /etc/lsyncd/lsyncd.conf.lua

そして編集。
sourceにはミラーしたいパス、targetにはミラー先のIPとrsyncdに記述したモジュール名(今回の例ではwww)を記述しておく。
パスの最後に/がついていればその配下、ついていなければディレクトリそのものになります

sudo nano /etc/lsyncd/lsyncd.conf.lua
settings = {
	logfile = "/var/log/lsyncd/lsyncd.log",
	statusFile = "/var/run/lsyncd.stat",
	statusInterval = 1,
}

sync{
	default.rsync,
	rsyncOps = {
		"-ltr",
		"-p",
		"-avz",
		"--delete"
	},
	source="/var/www/",
	target="192.168.1.99::www/",
}

lsyncdのログローテート設定

sudo nano /etc/logrotate.d/lsyncd
/var/log/lsyncd/lsyncd.log {
        daily
        missingok
        rotate 30
        compress
        delaycompress
        dateext
        notifempty
}

lsyncdのログの保存先のディレクトリを作成してローテートのテスト。

sudo mkdir -p /var/log/lsyncd
sudo logrotate -d /etc/logrotate.conf

lsyncdをスタートさせる。

sudo /etc/init.d/lsyncd start

これでミラーされるか試してみる。

sudo touch /var/www/test

ミラー先にtestができてれば成功。
できていなければログを確認して解決してください。
ちなみにポートは873なのでiptables等で制限してる場合は許可するようにしてください。

ミラー元

iptables -A OUTPUT -p tcp -d ミラー先IP --sport 873 -j ACCEPT

ミラー先

iptables -A INPUT -p tcp -s ミラー元IP --dport 873 -j ACCEPT
 | 
このエントリーをはてなブックマークに追加

lsyncd+sshでのミラーサーバー構築

このエントリをはてなブックマークに追加このエントリをGoogle bookmarkに追加このエントリをdel.icio.usに追加このエントリをfacebookに追加

以前、lsyncd+rsyncdでのミラーサーバー構築にて
lsyncd+rsyncdでのミラーサーバー構築を書いたけど、やっとSSHを使用したやりかたを確認したので以下に。

秘密鍵と公開鍵を作成

ミラー元で

ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/hogehoge/.ssh/id_rsa):
Created directory '/home/hogehoge/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/hogehoge/.ssh/id_rsa.
Your public key has been saved in /home/hogehoge/.ssh/id_rsa.pub.
The key fingerprint is:
75:28:f4:77:3f:68:93:d2:c5:7d:2a:5c:96:c9:2f:17 hogehoge@TestServer

できた公開鍵をミラー先へ

scp .ssh/id_rsa.pub hogehoge@ミラー先:/home/hogehoge/

ミラー先で

mkdir .ssh
cat id_rsa.pub >> .ssh/authorized_keys
chmod 700 .ssh
chmod 600 .ssh/authorized_keys

ミラー元からパスワードなしでログインできることを確認

ssh hogehoge@ミラー先

ミラー元、ミラー先のid_rsa.pubを削除する

rm id_rsa.pub

ミラー元設定

lsyncdをインストールする。
Ubuntu10.10(maverick)以降でないとUbuntu公式リポジトリにないので注意。

sudo aptitude install lsyncd

設定ファイルのサンプルをコピーして編集する。
source pathにはミラーしたいパス、target pathにはミラー先のユーザ名@IP:ミラー先パスを記述しておく。(scpでファイル送るときの宛先指定と同じですね)
パスの最後に/がついていればその配下、ついていなければディレクトリそのものになります。

sudo cp -p /usr/share/doc/lsyncd/examples/lsyncd.conf.xml /etc/
sudo nano /etc/lsyncd.conf.xml
<lsyncd version="1">

<!--
This is a default config file template for lsyncd.
Actually all settings are optional, if you delete them
lsyncd will use the option value (which is likely identical
to the values specified as defaults in this template)

                                  - Happy Syncing! -

-->

<settings>
        <!--uncomment to log all debug messages.-->
        <!--debug/-->

        <!--uncomment to log only errors.-->
        <!--scarce/-->

        <!--uncomment to not detach, log to stdout/stderr.-->
        <!--no-daemon/-->

        <!--uncomment to not call any actions, run dry only.-->
        <!--dryrun/-->

        <!--uncomment to exclude file handled to rsync.-->
        <!--exclude-from filename="/tmp/exclude"/-->

        <!-- the file to log messages -->
        <logfile      filename="/var/log/lsyncd/lsyncd.log"/>

        <!--Specify the rsync (or other) binary to call-->
        <binary       filename="/usr/bin/rsync"/>

        <!--uncomment to create a file containing pid of the daemon-->
        <pidfile      filename="/var/run/lsyncd.pid"/>

        <!--this specifies the arguments handled to the rsync (or other)
                binary.

                option is the default literal.
                only '%r' will be replaced with r when recursive
                operation is wanted, d when not.

                exclude-file will be replaced with -exclude-from FILE

                source will be the source path to sync from

                destination will be the destination path to sync to -->
        <callopts>
                <option text="-lt%r"/>
                <option text="-p"/>
                <option text="-avz"/>
                <option text="--delete"/>
                <option text="--rsh=ssh"/>
                <exclude-file/>
                <source/>
                <destination/>
        </callopts>
</settings>


<directory>
        <source path="/var/www/"/>
        <target path="hogehoge@ミラー先IP:/var/www/"/>
        <!--
        or it can also be an absolute path for localhost
        <target path="/absolute/path/to/target">
        -->
</directory>

<!--
     You can specify even more than one source/destination pair,
     all will be synced.

         Please take care you do not make any with other source/target pairs.
-->
<!--directory>
        <source path="/home/axel/lsyncd-svn/3"/>
        <target path="/home/axel/lsyncd-svn/4"/>
</directory-->

</lsyncd>

lsyncdの自動起動スクリプトを作成する。

cd /etc/init.d/
sudo nano lsyncd
#!/bin/sh
### BEGIN INIT INFO
# Provides:          lsyncd
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Should-Start:      $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: fast remote file copy program daemon
# Description:       start and stop lsyncd
### END INIT INFO

# Source function library.
. /lib/lsb/init-functions

PATH=$PATH:/usr/bin

# Source networking configuration.
[ -r /etc/lsyncd ] && . /etc/lsyncd

option="$SHORT_LOG $IGNORE_START_ERRORS $DEBUG"

RETVAL=0

prog="lsyncd"

start(){
        echo -n $"Starting $prog: "
        $prog $option
        RETVAL=$?
        echo
        touch /var/lock/lsyncd
        return $RETVAL
}

stop(){
        echo -n $"Stopping $prog: "
        killproc $prog
        RETVAL=$?
        echo
        rm -f /var/lock/lsyncd
        return $RETVAL
}

reload(){
        echo -n $"Reloading configuration: "
        killproc $prog -HUP
        RETVAL=$?
        echo
        return $RETVAL
}

restart(){
        stop
        start
}

condrestart(){
        [ -e /var/lock/lsyncd ] && restart
        return 0
}

# See how we were called.
case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        status)
                status $prog
                ;;
        restart)
                restart
                ;;
        reload)
                reload
                ;;
        condrestart)
                condrestart
                ;;
        *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
        RETVAL=1
esac

exit $RETVAL
sudo chmod +x lsyncd

lsyncdの起動オプションファイルを作成

sudo nano /etc/lsyncd
IGNORE_START_ERRORS="--stubborn"
#SHORT_LOG="--scarce"
#DEBUG="--debug"

lsyncdの自動起動の設定

sudo update-rc.d lsyncd defaults 56 50

たぶん以下でも可だと思う。

sudo update-rc.d lsyncd start 56 2 3 4 5 . stop 50 0 1 6  .

lsyncdのログローテート設定

sudo nano /etc/logrotate.d/lsyncd
/var/log/lsyncd/lsyncd.log {
        daily
        missingok
        rotate 30
        compress
        delaycompress
        dateext
        notifempty
}

lsyncdのログの保存先のディレクトリを作成してローテートのテスト。

sudo mkdir -p /var/log/lsyncd
sudo logrotate -d /etc/logrotate.conf

lsyncdをスタートさせる。

sudo /etc/init.d/lsyncd start

これでミラーされるか試してみる。

sudo touch /var/www/test

ミラー先にtestができてれば成功。
できていなければログを確認して解決してください。
ちなみにポートは22なのでiptables等で制限してる場合は許可するようにしてください。

 | 
このエントリーをはてなブックマークに追加

lsyncd+rsyncdでのミラーサーバー構築

このエントリをはてなブックマークに追加このエントリをGoogle bookmarkに追加このエントリをdel.icio.usに追加このエントリをfacebookに追加

前提としてOSはUbuntu10.10以降で。

ミラー先設定

まず、rsyncdの設定から。rsyncdは標準で入ってると思います。

sudo nano /etc/rsyncd.conf
log file = /var/log/rsyncd/rsyncd.log
uid = root
gid = root

[www]
path = /var/www
hosts allow = 192.168.1.101/32
read only = false

uidとgidを設定をしないとそれぞれnobody、nogroupとなります。
次にログローテートの設定。

sudo nano /etc/logrotate.d/rsyncd
/var/log/rsyncd/rsyncd.log {
        daily
        missingok
        rotate 30
        compress
        delaycompress
        dateext
        notifempty
}

ログの保存先のディレクトリを作成してローテートのテスト。

sudo mkdir -p /var/log/rsyncd
sudo logrotate -d /etc/logrotate.conf

rsyncをxinetdで動かしたいのでxinetdが入っていなければインストールする。

sudo aptitude install xinetd

そしてxinetdで動かすrsyncdの設定。
only_fromのところにはミラー元のIPを記述しておきます。

sudo nano /etc/xinetd.d/rsyncd
service rsync
{
disable = no
socket_type = stream
user = root
wait = no
server = /usr/bin/rsync
server_args = --daemon --config=/etc/rsyncd.conf
only_from = 192.168.1.101/32 127.0.0.1
log_on_failure += USERID
}

xinetdを再起動

sudo /etc/init.d/xinetd restart

ミラー元設定

いよいよミラー元の設定。
lsyncdをインストールする。
Ubuntu10.10(maverick)以降でないとUbuntu公式リポジトリにないので注意。

sudo aptitude install lsyncd

設定ファイルのサンプルをコピーして編集する。
source pathにはミラーしたいパス、target pathにはミラー先のIPとrsyncdに記述したモジュール名(今回の例ではwww)を記述しておく。
パスの最後に/がついていればその配下、ついていなければディレクトリそのものになります。

sudo cp -p /usr/share/doc/lsyncd/examples/lsyncd.conf.xml /etc/
sudo nano /etc/lsyncd.conf.xml
<lsyncd version="1">

<!--
This is a default config file template for lsyncd.
Actually all settings are optional, if you delete them
lsyncd will use the option value (which is likely identical
to the values specified as defaults in this template)

                                  - Happy Syncing! -

-->

<settings>
        <!--uncomment to log all debug messages.-->
        <!--debug/-->

        <!--uncomment to log only errors.-->
        <!--scarce/-->

        <!--uncomment to not detach, log to stdout/stderr.-->
        <!--no-daemon/-->

        <!--uncomment to not call any actions, run dry only.-->
        <!--dryrun/-->

        <!--uncomment to exclude file handled to rsync.-->
        <!--exclude-from filename="/tmp/exclude"/-->

        <!-- the file to log messages -->
        <logfile      filename="/var/log/lsyncd/lsyncd.log"/>

        <!--Specify the rsync (or other) binary to call-->
        <binary       filename="/usr/bin/rsync"/>

        <!--uncomment to create a file containing pid of the daemon-->
        <pidfile      filename="/var/run/lsyncd.pid"/>

        <!--this specifies the arguments handled to the rsync (or other)
                binary.

                option is the default literal.
                only '%r' will be replaced with r when recursive
                operation is wanted, d when not.

                exclude-file will be replaced with -exclude-from FILE

                source will be the source path to sync from

                destination will be the destination path to sync to -->
        <callopts>
                <option text="-lt%r"/>
                <option text="-p"/>
                <option text="-avz"/>
                <option text="--delete"/>
                <exclude-file/>
                <source/>
                <destination/>
        </callopts>
</settings>


<directory>
        <source path="/var/www/"/>
        <target path="192.168.1.99::www/"/>
        <!--
        or it can also be an absolute path for localhost
        <target path="/absolute/path/to/target">
        -->
</directory>

<!--
     You can specify even more than one source/destination pair,
     all will be synced.

         Please take care you do not make any with other source/target pairs.
-->
<!--directory>
        <source path="/home/axel/lsyncd-svn/3"/>
        <target path="/home/axel/lsyncd-svn/4"/>
</directory-->

</lsyncd>

lsyncdの自動起動スクリプトを作成する。

cd /etc/init.d/
sudo nano lsyncd
#!/bin/sh
### BEGIN INIT INFO
# Provides:          lsyncd
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Should-Start:      $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: fast remote file copy program daemon
# Description:       start and stop lsyncd
### END INIT INFO

# Source function library.
. /lib/lsb/init-functions

PATH=$PATH:/usr/bin

# Source networking configuration.
[ -r /etc/lsyncd ] && . /etc/lsyncd

option="$SHORT_LOG $IGNORE_START_ERRORS $DEBUG"

RETVAL=0

prog="lsyncd"

start(){
        echo -n $"Starting $prog: "
        $prog $option
        RETVAL=$?
        echo
        touch /var/lock/lsyncd
        return $RETVAL
}

stop(){
        echo -n $"Stopping $prog: "
        killproc $prog
        RETVAL=$?
        echo
        rm -f /var/lock/lsyncd
        return $RETVAL
}

reload(){
        echo -n $"Reloading configuration: "
        killproc $prog -HUP
        RETVAL=$?
        echo
        return $RETVAL
}

restart(){
        stop
        start
}

condrestart(){
        [ -e /var/lock/lsyncd ] && restart
        return 0
}

# See how we were called.
case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        status)
                status $prog
                ;;
        restart)
                restart
                ;;
        reload)
                reload
                ;;
        condrestart)
                condrestart
                ;;
        *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
        RETVAL=1
esac

exit $RETVAL
sudo chmod +x lsyncd

lsyncdの起動オプションファイルを作成

sudo nano /etc/lsyncd
IGNORE_START_ERRORS="--stubborn"
#SHORT_LOG="--scarce"
#DEBUG="--debug"

lsyncdの自動起動の設定

sudo update-rc.d lsyncd defaults 56 50

たぶん以下でも可だと思う。

sudo update-rc.d lsyncd start 56 2 3 4 5 . stop 50 0 1 6  .

lsyncdのログローテート設定

sudo nano /etc/logrotate.d/lsyncd
/var/log/lsyncd/lsyncd.log {
        daily
        missingok
        rotate 30
        compress
        delaycompress
        dateext
        notifempty
}

lsyncdのログの保存先のディレクトリを作成してローテートのテスト。

sudo mkdir -p /var/log/lsyncd
sudo logrotate -d /etc/logrotate.conf

lsyncdをスタートさせる。

sudo /etc/init.d/lsyncd start

これでミラーされるか試してみる。

sudo touch /var/www/test

ミラー先にtestができてれば成功。
できていなければログを確認して解決してください。
ちなみにポートは873なのでiptables等で制限してる場合は許可するようにしてください。

ミラー元

iptables -A OUTPUT -p tcp -d ミラー先IP --sport 873 -j ACCEPT

ミラー先

iptables -A INPUT -p tcp -s ミラー元IP --dport 873 -j ACCEPT

rsyncの経路は暗号化されていないので、SSH経由での方法はまた後日(後日っていつだ(滝汗)
書いたよ

lsyncd2の場合はこちら

 | 
このエントリーをはてなブックマークに追加

iphone6ケース ルイヴィトン iphone6ケース シャネル 手帳型 シャネル iphone6ケース タバコ ブランドスマホケース