Linux

重用遠端 ssh 連接並減少命令/會話日誌記錄的詳細程度?

  • January 16, 2015

我有許多依賴應用程序級鏡像到輔助伺服器的系統。輔助伺服器通過在主伺服器上執行的一系列遠端 SSH 命令來拉取數據。該應用程序有點像一個黑匣子,我可能無法對使用的腳本進行修改。

我的問題是登錄 /var/log/secure 絕對充斥著來自服務使用者的請求,admin. 這些命令每秒發生多次,並對日誌產生相應的影響。他們依賴於無密碼的密鑰交換。涉及的作業系統是 EL5 和 EL6。下面的例子。

  • 有什麼方法可以減少這些操作的日誌記錄量。(按使用者?按來源?)
  • 開發人員是否有一種更簡潔的方法來執行這些 ssh 執行而不產生這麼多會話?似乎效率低下。我可以重複使用現有的連接嗎?

範例日誌輸出:

Jul 24 19:08:54 Cantaloupe sshd[46367]: pam_unix(sshd:session): session closed for user admin
Jul 24 19:08:54 Cantaloupe sshd[46446]: Accepted publickey for admin from 172.30.27.32 port 33526 ssh2
Jul 24 19:08:54 Cantaloupe sshd[46446]: pam_unix(sshd:session): session opened for user admin by (uid=0)
Jul 24 19:08:54 Cantaloupe sshd[46446]: pam_unix(sshd:session): session closed for user admin
Jul 24 19:08:54 Cantaloupe sshd[46475]: Accepted publickey for admin from 172.30.27.32 port 33527 ssh2
Jul 24 19:08:54 Cantaloupe sshd[46475]: pam_unix(sshd:session): session opened for user admin by (uid=0)
Jul 24 19:08:54 Cantaloupe sshd[46475]: pam_unix(sshd:session): session closed for user admin
Jul 24 19:08:54 Cantaloupe sshd[46504]: Accepted publickey for admin from 172.30.27.32 port 33528 ssh2
Jul 24 19:08:54 Cantaloupe sshd[46504]: pam_unix(sshd:session): session opened for user admin by (uid=0)
Jul 24 19:08:54 Cantaloupe sshd[46504]: pam_unix(sshd:session): session closed for user admin
Jul 24 19:08:54 Cantaloupe sshd[46583]: Accepted publickey for admin from 172.30.27.32 port 33529 ssh2
Jul 24 19:08:54 Cantaloupe sshd[46583]: pam_unix(sshd:session): session opened for user admin by (uid=0)
Jul 24 19:08:54 Cantaloupe sshd[46583]: pam_unix(sshd:session): session closed for user admin
Jul 24 19:08:54 Cantaloupe sshd[46612]: Accepted publickey for admin from 172.30.27.32 port 33530 ssh2
Jul 24 19:08:54 Cantaloupe sshd[46612]: pam_unix(sshd:session): session opened for user admin by (uid=0)
Jul 24 19:08:54 Cantaloupe sshd[46612]: pam_unix(sshd:session): session closed for user admin
Jul 24 19:08:55 Cantaloupe sshd[46641]: Accepted publickey for admin from 172.30.27.32 port 33531 ssh2
Jul 24 19:08:55 Cantaloupe sshd[46641]: pam_unix(sshd:session): session opened for user admin by (uid=0)
Jul 24 19:08:55 Cantaloupe sshd[46641]: pam_unix(sshd:session): session closed for user admin
Jul 24 19:08:55 Cantaloupe sshd[46720]: Accepted publickey for admin from 172.30.27.32 port 33532 ssh2
Jul 24 19:08:55 Cantaloupe sshd[46720]: pam_unix(sshd:session): session opened for user admin by (uid=0)
Jul 24 19:08:55 Cantaloupe sshd[46720]: pam_unix(sshd:session): session closed for user admin
Jul 24 19:08:55 Cantaloupe sshd[46749]: Accepted publickey for admin from 172.30.27.32 port 33533 ssh2
Jul 24 19:08:55 Cantaloupe sshd[46749]: pam_unix(sshd:session): session opened for user admin by (uid=0)
Jul 24 19:08:55 Cantaloupe sshd[46749]: pam_unix(sshd:session): session closed for user admin
Jul 24 19:08:55 Cantaloupe sshd[46778]: Accepted publickey for admin from 172.30.27.32 port 33534 ssh2
Jul 24 19:08:55 Cantaloupe sshd[46778]: pam_unix(sshd:session): session opened for user admin by (uid=0)
Jul 24 19:08:55 Cantaloupe sshd[46778]: pam_unix(sshd:session): session closed for user admin
Jul 24 19:08:55 Cantaloupe sshd[46857]: Accepted publickey for admin from 172.30.27.32 port 33535 ssh2

具體回答有關是否可以減少產生更多 SSH 連接的成本的問題:是的。您可以使用自 OpenSSH 5.5 以來存在的 ControlMaster 功能。這篇博文將有更多詳細資訊:http: //puppetlabs.com/blog/speed-up-ssh-by-reusing-connections

我不確定這是否會影響發生多少日誌記錄。但是,根據應用程序的編寫方式,可能無需實際修改應用程序就可以使用此功能,只需重新配置 OpenSSH。假設它甚至使用 OpenSSH 作為客戶端,或者俱有此支持的不同客戶端。這裡沒有足夠的資訊可以確定。

引用自:https://serverfault.com/questions/615386