InfluxDB用のパッケージ作成環境をDebian Squeezeにつくる


この投稿はまだまだ途中です。InfluxDBのパッケージ作成や開発環境をDebian6で1から作るときの説明になります。

公式でも開発環境のセットアップとかはあるけど、微妙に足りなかったりハマりどころがあるのでメモしときました。

## パッケージのインストール

```bash
sudo apt-get install mercurial bzr protobuf-compiler flex bison valgrind g++ make curl rpm build-essential git
```

## GoのInstall

```bash
curl -O https://storage.googleapis.com/golang/go1.2.2.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.2.2.linux-amd64.tar.gz
echo -ne 'export GOROOT=/usr/local/go\nexport PATH=$PATH:/$GOROOT/bin\n' >> ~/.bash_profile
source ~/.bash_profile
```

## InfluxDBのソースコードを取得

```
git clone https://github.com/influxdb/influxdb.git
```

## InfluxDBをビルドする

```
cd influxdb
./configure
make
```

## RVMのインストール (Package作成には現在RVMが必要です)

```bash
curl -sSL https://get.rvm.io | bash -s stable
echo '[ -s ${HOME}/.rvm/scripts/rvm ] && source ${HOME}/.rvm/scripts/rvm
' >> ~/.bash_profile
source ~/.bash_profile
rvm install 1.9.3

rvm 1.9.3@influxdb do bundle install
make package
```

rvm 1.9.3@influxdb do bundle installがわからなくでfpmでドはまりした

## Testの実行方法

全てのテストを実行する場合はこう (5〜6分ぐらいかかるかも)

```
make test
```

integration/data_testだけ実行する場合

```
make integration_test only=DataTest verbose=on
```

## Debug環境の作成

PythonとGDBが古いので個別にインストール

```
git clone git://github.com/yyuu/pyenv.git .pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
source ~/.bash_profile
pyenv install 2.7.5
pyenv shell 2.7.5

wget http://ftp.gnu.org/gnu/gdb/gdb-7.6.1.tar.gz
tar zxf gdb-7.6.1.tar.gz
cd gdb-7.6.1
./configure --prefix=/opt/gdb/7.6.1 CFLAGS="-g -O2 -Wno-string-plus-int"
make
sudo mkdir -p /opt/gdb/7.6.1
sudo make install
echo 'add-auto-load-safe-path /usr/local/go/src/pkg/runtime/runtime-gdb.py' >> ~/.gdbinit
```

InfluxDBのデバッグをする時は

```bash
O_BUILD_OPTIONS='-gcflags "-N -l"' make build
/opt/gdb/7.6.1/bin/gdb ./daemon
```

例えばTop/BottomのAggregatorを開発した時はこんな感じで見ていたりしました。
Buildに数秒かかって面倒なのでgdb使うと大分はかどります

```
chobie@debian:~/src/influxdb$ /opt/gdb/7.6.1/bin/gdb ./daemon
GNU gdb (GDB) 7.6.1
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/chobie/src/influxdb/daemon...done.
Loading Go Runtime support.
(gdb) b 'engine.NewTopAggregator'
Breakpoint 1 at 0x588f80: file /home/chobie/src/influxdb/src/engine/aggregator.go, line 1280.
(gdb) r -config=config.toml
Starting program: /home/chobie/src/influxdb/./daemon -config=config.toml
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/libthread_db.so.1".
[New Thread 0x7ffff70b4700 (LWP 32676)]
[New Thread 0x7ffff67b3700 (LWP 32677)]
[New Thread 0x7ffff5fb2700 (LWP 32678)]
[New Thread 0x7ffff57b1700 (LWP 32679)]
[New Thread 0x7ffff4fb0700 (LWP 32680)]
[05/19/14 15:15:09] [INFO] Loading configuration file config.toml

+---------------------------------------------+
|  _____        __ _            _____  ____   |
| |_   _|      / _| |          |  __ \|  _ \  |
|   | |  _ __ | |_| |_   ___  _| |  | | |_) | |
|   | | | '_ \|  _| | | | \ \/ / |  | |  _ <  |
|  _| |_| | | | | | | |_| |>  <| |__| | |_) | |
| |_____|_| |_|_| |_|\__,_/_/\_\_____/|____/  |
+---------------------------------------------+

[New Thread 0x7ffff47af700 (LWP 32681)]
[New Thread 0x7ffff3f8e700 (LWP 32682)]
[New Thread 0x7ffff376d700 (LWP 32685)]
[Switching to Thread 0x7ffff4fb0700 (LWP 32680)]

Breakpoint 1, engine.NewTopAggregator (value=0xc2100be820, defaultValue=0x0, ~anon3=..., ~anon4=...) at /home/chobie/src/influxdb/src/engine/aggregator.go:1280
1280	func NewTopAggregator(_ *parser.SelectQuery, value *parser.Value, defaultValue *parser.Value) (Aggregator, error) {
(gdb) bt
#0  engine.NewTopAggregator (value=0xc2100be820, defaultValue=0x0, ~anon3=..., ~anon4=...) at /home/chobie/src/influxdb/src/engine/aggregator.go:1280
```