LoginSignup
1
0

More than 3 years have passed since last update.

Elastic StackのWinlogbeatをソースコードからビルドしてみる

Last updated at Posted at 2019-11-16

はじめに

Elastic StackのWinlogbeatをソースコードからビルドするための備忘録です。

利用したソフトウェア

  • OS: Microsoft Windows 10 Pro (x86_64)
  • Winlogbeat (7.4.2)
  • Go-lang (go1.13.4.windows-amd64.msi)
  • git for windwos (Git-2.24.0.2-64-bit.exe)
  • MinGW-w64 (mingw-w64-install.exe)
  • VMware Workstation Player等のVMソフトウェア

今回はVmware Workstation 15 Pro上で動作するWindwos 10上でビルド環境を構築してみました。

Winlogbeat 7.4.2はあらかじめインストール済みとしておきます(インストールやセットアップについてはこちらもご参照ください)。

Go-langのインストール

Go-langからダウンロードしたgo1.13.4.windows-amd64.msiを起動しインストールします。インストール先はデフォルトの「C:\Go\」のままです。C:\Users<UserName>配下にもgoというフォルダが作成されます。

MinGW-w64のインストール

MinGW-w64からダウンロードしたmingw-w64-install.exeを起動します。「Architecture」をx86_64に指定しインストールします。あとはデフォルト設定のまま。

インストール完了したら環境変数Pathへ以下を追加します。

C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin

git for windowsのインストール

git for windwosからダウンロードしたGit-2.24.0.2-64-bit.exeを起動します。こちらもデフォルト設定のままでインストールしました。

GitHubからBeatsのソースコードをcloneする

(1) Git Bashを起動します。
(2) Clone先フォルダを作成します。

$ cd C:\Users\<UserName>\go\src
$ mkdir github.com
$ cd github.com
$ mkdir elastic
$ cd elastic

(3) Winlogbeat 7.4のソースコードをCloneします。masterでなく7.4のブランチを指定しています。

$ pwd 
/c/Users/<UserName>/go/src/github.com/elastic/
$ git clone -b 7.4 https://github.com/elastic/beats.git

(4) winlogbeatをビルドします。

$ pwd 
/c/Users/<UserName>/go/src/github.com/elastic/
$ cd beats
$ cd winlogbeat
$ pwd
/c/Users/<UserName>/go/src/github.com/elastic/beats/winlogbeat
$ go build
$ ls *.exe
winlogbeat.exe*

(5) ビルドされたExeファイルを適用する
Powershellを起動し以下のようにWinlogbeatのインストールフォルダへコピーしWinlogbeatを再起動します。

> cd C:\Program Files\winlogbeat-xxx (Winlogbeatのインストールフォルダ)
> Stop-Service winlogbeat
> mv .\winlogbeat.exe .\winlogbeat.exe.org
> C:\Users\<UserName>\go\src\github.com\elastic\beats\winlogbeat\winlogbeat.exe .
> Start-Service winlogbeat

まとめ

以上のようにソースコードからのビルドは非常に簡単に行うことができました。

おまけ

今回なぜわざわざWinlogbeatをソースからビルドしなおしたかというと・・・7.4でProxyサーバ経由でElasticsearchへ接続する設定がうまく動作しなかったからでした。

winlogbeat.yml
#-------------------------- Elasticsearch output ------------------------------
output.elasticsearch:
  # Array of hosts to connect to.
  hosts: ["log.example.com:9200"]
...
  # Proxy server URL ★設定してもProxy経由通信にならない・・・
  proxy_url: http://proxy.example.com:3128
...

そこでこちらのソースコードを参照したところ・・・

elastic/beats/libbeat/outputs/elasticsearch/elasticsearch.go
137: func makeES(
...
167: var proxyURL *url.URL
168: if !config.ProxyDisable {
169:    proxyURL, err := parseProxyURL(config.ProxyURL) ★★★
170:    if err != nil {
171:        return outputs.Fail(err)
172:    }
173:    if proxyURL != nil {
174:        logp.Info("Using proxy URL: %s", proxyURL)
175:    }
176: }
...

ということで以下のように修正してビルドしたらProxy経由の通信が動作するようになりました。

elastic/beats/libbeat/outputs/elasticsearch/elasticsearch.go
137: func makeES(
...
修正前: 169: proxyURL, err := parseProxyURL(config.ProxyURL)
修正後: 169: proxyURL, err = parseProxyURL(config.ProxyURL) 
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0