rsync 在守護程式下失敗,但從終端執行時成功

rsync 在守護程式下失敗,但從終端執行時成功

我有由 Postgres 守護程式(WAL 歸檔程式)執行的腳本 [1],但失敗並退出程式碼 12;參見[2]。但是,如果我在終端機/ssh 會話上執行相同的腳本,它就會成功;參見[3]。

freenode IRC 頻道 #rsync 上的用戶 BasketCase 嘗試對其進行診斷,但未能取得進展。對話見[4]。

這種情況不會在所有使用它的機器上發生,但這是我第二次遇到這種情況。

任何幫助將不勝感激。

提前致謝。

[1] WAL歸檔腳本

#!/bin/bash
# $1 is the %p substituted by postgres in archive_command
# $2 is the %f substituted by postgres in archive_command
# This script backs up the WAL file to every replica, and
# exits with the last failure code, if any.
final_exit_code=0
replicas=$(grep REPLICA /some/file | sort | uniq | cut -d = -f 2-)

for replica_url in $replicas; do
     echo Sending WAL file to $replica_url
     rsync --timeout=10 -avz -e 'ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=10 -i /opt/PostgresPlus/CloudDB/data/cluster_ssh.key' "$1" root@$replica_url:/mnt/pcs/wal_archive/"$2"
     exit_code=$?
     if [ $exit_code -ne 0 ] ; then final_exit_code=$exit_code ; fi
  done
exit $final_exit_code

[2] 發送WAL 檔案到10.33.177.184 rsync:連線意外關閉(到目前為止已收到0 位元組)[sender] rsync 錯誤:io.c(600) 處的rsync 協定資料流(代碼12)中出現錯誤[sender=3.0。

[3] $ ./wal_archive.sh pg_xlog/0000000100000005000000EE 0000000100000000500000EE 將 WAL 檔案傳送至 10.33.177.184 000EE 將 WAL 檔案傳送至 10.33.177.184 100EE 將「17.171717171355」217217233333333333個頭。發送增量檔案清單 0000000100000005000000EE

發送 5180930 位元組 接收 31 位元組 941992.91 位元組/秒 總大小為 16777216 加速比為 3.24

[4]http://gurjeet.privatepaste.com/dc98277db3

答案1

問題在於LD_LIBRARY_PATH終端機和 Postgres 守護程式環境之間的差異。

LD_LIBRARY_PATH如果我在終端機中使用相同的內容,那麼終端機中的 rsync 也會失敗:

$ export LD_LIBRARY_PATH=/opt/PostgresPlus/9.1AS/lib:
$ ./wal_archive.sh pg_xlog/0000000100000005000000EE 0000000100000005000000EE
Sending WAL file to 10.33.177.184
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(600) [sender=3.0.6]

ssh正在使用來自 的庫/opt/PostgresPlus/9.1AS/lib,這些庫可能與ssh二進位不相容。

這是設定導出後ldd的輸出sshLD_LIBRARY_PATH

$ ldd `which ssh`
    linux-vdso.so.1 =>  (0x00007fff3fa28000)
    libfipscheck.so.1 => /lib64/libfipscheck.so.1 (0x00007fe726907000)
    libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fe7266e7000)
    libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x00007fe72634d000)
    libutil.so.1 => /lib64/libutil.so.1 (0x00007fe72614a000)
    libz.so.1 => /opt/PostgresPlus/9.1AS/lib/libz.so.1 (0x00007fe725f34000)
    libnsl.so.1 => /lib64/libnsl.so.1 (0x00007fe725d1b000)
    libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007fe725ae4000)
    libresolv.so.2 => /lib64/libresolv.so.2 (0x00007fe7258c9000)
    libgssapi_krb5.so.2 => /opt/PostgresPlus/9.1AS/lib/libgssapi_krb5.so.2 (0x00007fe725690000)
    libkrb5.so.3 => /opt/PostgresPlus/9.1AS/lib/libkrb5.so.3 (0x00007fe7253d3000)
    libk5crypto.so.3 => /opt/PostgresPlus/9.1AS/lib/libk5crypto.so.3 (0x00007fe7251aa000)
    libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007fe724fa6000)
    libnss3.so => /usr/lib64/libnss3.so (0x00007fe724c6a000)
    libc.so.6 => /lib64/libc.so.6 (0x00007fe7248d6000)
    libplc4.so => /lib64/libplc4.so (0x00007fe7246d1000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007fe7244cd000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fe726d76000)
    libfreebl3.so => /lib64/libfreebl3.so (0x00007fe72426a000)
    libcom_err.so.3 => /opt/PostgresPlus/9.1AS/lib/libcom_err.so.3 (0x00007fe724067000)
    libkrb5support.so.0 => /opt/PostgresPlus/9.1AS/lib/libkrb5support.so.0 (0x00007fe723e60000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fe723c42000)
    libnssutil3.so => /usr/lib64/libnssutil3.so (0x00007fe723a1c000)
    libplds4.so => /lib64/libplds4.so (0x00007fe723818000)
    libnspr4.so => /lib64/libnspr4.so (0x00007fe7235da000)

LD_LIBRARY_PATH這是沒有設定的相同命令

$ ldd `which ssh`
    linux-vdso.so.1 =>  (0x00007fff941ff000)
    libfipscheck.so.1 => /lib64/libfipscheck.so.1 (0x00007f93b2ab2000)
    libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f93b2893000)
    libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x00007f93b24f8000)
    libutil.so.1 => /lib64/libutil.so.1 (0x00007f93b22f5000)
    libz.so.1 => /lib64/libz.so.1 (0x00007f93b20df000)
    libnsl.so.1 => /lib64/libnsl.so.1 (0x00007f93b1ec5000)
    libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007f93b1c8e000)
    libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f93b1a74000)
    libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007f93b1831000)
    libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007f93b1552000)
    libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007f93b1326000)
    libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007f93b1121000)
    libnss3.so => /usr/lib64/libnss3.so (0x00007f93b0de5000)
    libc.so.6 => /lib64/libc.so.6 (0x00007f93b0a52000)
    libplc4.so => /lib64/libplc4.so (0x00007f93b084c000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007f93b0648000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f93b2f21000)
    libfreebl3.so => /lib64/libfreebl3.so (0x00007f93b03e6000)
    libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007f93b01da000)
    libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007f93affd7000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f93afdba000)
    libnssutil3.so => /usr/lib64/libnssutil3.so (0x00007f93afb93000)
    libplds4.so => /lib64/libplds4.so (0x00007f93af98f000)
    libnspr4.so => /lib64/libnspr4.so (0x00007f93af752000)

相關內容