treedown’s Report

システム管理者に巻き起こる様々な事象を読者の貴方へ報告するブログです。会社でも家庭でも"システム"に携わるすべての方の共感を目指しています。

※https化しました。その影響でしばらくリンク切れなどがあるかもしれませんが徐々に修正していきます。 リンク切れなどのお気づきの点がございましたらコメントなどでご指摘いただけますと助かります。

rsyncが突然エラー⇒とりあえず手動起動で対処

cronで定期的に実行してるrsyncが突如エラーを出すようになりました。
対処した内容のご報告です。

状況

192.168.1.3(SVR-1)と192.168.1.12(SVR-12)の間でrsyncで同期しています。
両方はsambaサーバで両方がネットワーク経由で共有フォルダを提供するように設定してあります。

rsync自体はrsyncコマンドをシェルにしてcronで定期的に実行することで、共有フォルダ間のデータを同期しています。

エラーが起きた、そのエラーメッセージは
-------------------------------------------------------
rsync: failed to connect to 192.168.1.3 (192.168.1.3): Connection refused (111) rsync error: error in socket IO (code 10) at clientserver.c(128) [Receiver=3.1.1]
rsync: failed to connect to 192.168.1.3 (192.168.1.3): Connection refused (111) rsync error: error in socket IO (code 10) at clientserver.c(128) [Receiver=3.1.1]
-------------------------------------------------------
とエラーがrsyncを実行した数だけ出力されています。

あれ?このエラー、なんか見たことあるな。と思ったら、過去記事にもありました。

blog.treedown.net

確認

まず疑ったのが通信の問題。しかし通信は問題ないことが分かりました。
-------------------------------------------------------
User@SVR-1:~$ ping SVR-12
PING SVR-12 (192.168.1.12) 56(84) bytes of data.
64 bytes from SVR-12 (192.168.1.12): icmp_seq=1 ttl=64 time=0.106 ms
64 bytes from SVR-12 (192.168.1.12): icmp_seq=2 ttl=64 time=0.091 ms
64 bytes from SVR-12 (192.168.1.12): icmp_seq=3 ttl=64 time=0.180 ms
64 bytes from SVR-12 (192.168.1.12): icmp_seq=4 ttl=64 time=0.292 ms
64 bytes from SVR-12 (192.168.1.12): icmp_seq=5 ttl=64 time=0.183 ms
64 bytes from SVR-12 (192.168.1.12): icmp_seq=6 ttl=64 time=0.163 ms
64 bytes from SVR-12 (192.168.1.12): icmp_seq=7 ttl=64 time=0.086 ms
^C
--- SVR-12 ping statistics ---
7 packets transmitted, 7 received, 0% packet loss, time 5998ms
-------------------------------------------------------
User@SVR-12:~$ ping SVR-1
PING SVR-1 (192.168.1.3) 56(84) bytes of data.
64 bytes from SVR-1 (192.168.1.3): icmp_seq=1 ttl=64 time=0.340 ms
64 bytes from SVR-1 (192.168.1.3): icmp_seq=2 ttl=64 time=0.106 ms
64 bytes from SVR-1 (192.168.1.3): icmp_seq=3 ttl=64 time=0.098 ms
64 bytes from SVR-1 (192.168.1.3): icmp_seq=4 ttl=64 time=0.149 ms
64 bytes from SVR-1 (192.168.1.3): icmp_seq=5 ttl=64 time=0.091 ms
64 bytes from SVR-1 (192.168.1.3): icmp_seq=6 ttl=64 time=0.122 ms
64 bytes from SVR-1 (192.168.1.3): icmp_seq=7 ttl=64 time=0.184 ms
64 bytes from SVR-1 (192.168.1.3): icmp_seq=8 ttl=64 time=0.107 ms
^C
--- SVR-1 ping statistics ---
8 packets transmitted, 8 received, 0% packet loss, time 6997ms
rtt min/avg/max/mdev = 0.091/0.149/0.340/0.078 ms

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

pingの実行結果は双方向で成功しています。
通信の問題じゃない、ということで、次の確認。

rsyncプロセスが落ちている?

次はrsyncの正常動作の確認です。プロセスを確認してみたら…、

-------------------------------------------------------
User@SVR-1:~$ ps -ef | grep rsync
User 1502 1460 0 17:05 pts/0 00:00:00 grep rsync
User@SVR-1:~$
-------------------------------------------------------
User@SVR-12:~$ ps -ef | grep rsync
User 1549 1474 0 17:10 pts/0 00:00:00 grep rsync
User@SVR-12:~$
-------------------------------------------------------
おや?
はて?
rsyncプロセスが全く見当たりません。

手動で起動する⇒動作確認

とりあえず手動で起動してみて動作確認をすることにしました。
手動で起動して動作するようなら、単純にプロセスが落ちていたことが原因だ、という具合に切り分けることができると考えました。

-------------------------------------------------------
root@SVR-12:/home/User# /etc/init.d/rsync start
[ ok ] Starting rsync (via systemctl): rsync.service.
root@SVR-12:/home/User# ps -ef | grep rsync
root 1562 1 0 17:11 ? 00:00:00 /usr/bin/rsync --daemon --no-det ach
root 1582 1552 0 17:11 pts/0 00:00:00 grep rsync
root@SVR-12:/home/User# cat /etc/opt/rsync/rsyncexec.sh | less
root@SVR-12:/home/User# rsync -av --delete --password-file=/etc/rsyncd.passwd rsync://root@192.168.1.3:/Delivery /home/samba/public/Delivery/
rsync: failed to connect to 192.168.1.3 (192.168.1.3): Connection refused (111)
rsync error: error in socket IO (code 10) at clientserver.c(128) [Receiver=3.1.1]
root@SVR-12:/home/User#
-------------------------------------------------------
しかし、同じエラーが表示されます。
そこで思ったのが、そういやSVR-1側のプロセスも落ちてたな…ってことで対向側のrsyncプロセスも起動することにします。
-------------------------------------------------------
User@SVR-1:~$ sudo rsync --daemon --config=/etc/rsyncd.conf
User@SVR-1:~$ ps -ef | grep rsync
root 1511 1 0 17:11 ? 00:00:00 rsync --daemon --config=/etc/rsy ncd.conf
User 1513 1460 0 17:11 pts/0 00:00:00 grep rsync
User@SVR-1:~$
-------------------------------------------------------

これで両方のデーモンが起動しました。

再度、rsyncコマンドを手動実行して確認してみます。

-------------------------------------------------------
root@SVR-12:/home/User# rsync -av --delete --password-file=/etc/rsyncd.passwd rsync://root@192.168.1.3:/Delivery /home/samba/public/Delivery/
receiving incremental file list

sent 31 bytes received 3,243 bytes 2,182.67 bytes/sec
total size is 543,212,986 speedup is 165,917.22
-------------------------------------------------------

一つだけフォルダを指定して同期してみたら、うまくいったように見えるので、
これで対処完了。

なんでプロセスが落ちてたんだろう…。