WindowsサーバのログをAmazonLinuxに送信するためにnxlogとsyslog-ngの連携を行ないました。
syslog-ngは既に導入済みだったため今回は説明を省略します。
簡単に動作環境をまとめると下記のようになります。
■ログを送信するサーバ
OS:Windows_Server-2012-R2
ミドルウェア:nxlog
■ログを受信するサーバ
OS:Amazon Linux
ミドルウェア:syslog-ng
両方ともAWS上のEC2インスタンスになります。
同じVPC内に構築しておりプライベートIPで通信できます。
1.ログを送信するサーバの設定
まずはnxlogをインストールします。
下記の公式ページからインストーラーダウンロードすることができます。
http://nxlog.org/products/nxlog-community-edition/download
今回はWindowsServerなのでwindowsのものをダウンロードしました。
ダウンロードしたファイルをクリックするとインストーラーが起動します。
特に入力する項目はないので指示に従ってインストールを完了させます。
下記のパスにnxlogの設定ファイルがあるので書き換えます。
C:\Program Files (x86)\nxlog\conf\nxlog.conf
今回はこんな形に記述しました。
## This is a sample configuration file. See the nxlog reference manual about the ## configuration options. It should be installed locally and is also available ## online at http://nxlog.org/nxlog-docs/en/nxlog-reference-manual.html ## Please set the ROOT to the folder your nxlog was installed into, ## otherwise it will not start. define ROOT C:\Program Files (x86)\nxlog Moduledir %ROOT%\modules CacheDir %ROOT%\data Pidfile %ROOT%\data\nxlog.pid SpoolDir %ROOT%\data LogFile %ROOT%\data\nxlog.log <Extension charconv> Module xm_charconv AutodetectCharsets shift_jis, utf-8 </Extension> ################################### # define input ################################### <Input input_application> Module im_msvistalog Exec if ($Channel == 'Security') OR ($Channel == 'System') drop(); </Input> <Input input_security> Module im_msvistalog Exec if ($Channel == 'Application') OR ($Channel == 'System') drop(); </Input> <Input input_system> Module im_msvistalog Exec if ($Channel == 'Application') OR ($Channel == 'Security') drop(); </Input> ################################### # difine output ################################### <Output output_application> Module om_tcp Host {送信先ホスト} Port 60001 </Output> <Output output_security> Module om_tcp Host {送信先ホスト} Port 60002 </Output> <Output output_system> Module om_tcp Host {送信先ホスト} Port 60003 </Output> ################################### # Route monitor ################################### <Route application> Path input_application => output_application </Route> <Route security> Path input_security => output_security </Route> <Route system> Path input_system => output_system </Route>
サービスを再起動するとログの送信が開始しますが受信側のサーバを設定していないので正常に動きません。
エラー等は下記のログに出力されます。
C:\Program Files (x86)\nxlog\data\nxlog.log
2.ログを受信するサーバの設定
syslog-ngの設定を行ないます。
下記のパスにファイルを作成します。
/etc/syslog-ng/conf.d/windowsserver.conf
############################################################# # source relay ############################################################# source app { tcp(ip(0.0.0.0) port(60001) max-connections(100)); }; source sec { tcp(ip(0.0.0.0) port(60002) max-connections(100)); }; source sys { tcp(ip(0.0.0.0) port(60003) max-connections(100)); }; ############################################################# # destination backuplogs relay ############################################################# destination w_app { file("/logs/windows/application.log"); }; destination w_sec { file("/logs/windows/security.log"); }; destination w_sys { file("/logs/windows/system.log"); }; ############################################################# # logs backuplogs relay ############################################################# log { source(app); destination(w_app); }; log { source(sec); destination(w_sec); }; log { source(sys); destination(w_sys); };
下記の設定ファイルを編集して作成したファイルを参照するようにします。
/etc/syslog-ng/syslog-ng.conf
include conf.d/windowsserver.conf;
syslog-ngを再起動すればファイルの送信が開始します。
ちなみにポート番号は60001~60003を使用しました。
今回はAWS上のEC2インスタンスなのでセキュリティグループを変更してポートを開放します。
送信元は「OutBound」、送信先は「InBound」のTCP接続を設定します。