LoginSignup
23
13

More than 5 years have passed since last update.

Redashのupgradeでハマったお話

Last updated at Posted at 2017-12-13

この記事はRedash Advent Calendar 2017の14日目の記事です。

この記事はAWS上に立てたRedashサーバを触りはじめたばかり私が、upgradeができなくて問題解決のために行ったことをまとめたものです。

Redashをずっと触っている方には必要ない情報かもしれませんが、Linux初心者だったりRedash触りたての方だとなかなか気づきにくいと思われる内容なので、そうした人に役立てば嬉しいです。

サーバを立ち上げる

まずはRedashサーバをAWS上で動かすため、公式AMIを利用して構築しました。

東京リージョンに作成したいのでap-northeast-1のAMIイメージを利用します。
なおこのAMIを利用したEC2インスタンス作成は通常のEC2インスタンス作成方法と同じ手順となるため、説明は割愛します。

EC2インスタンスを起動してしばらく待つと自動的にOSのパッケージがアップデートされます。そこでしばらく待ってからSSHログインし、下記の出力を確認できたらrebootさせましょう。

*** System restart required ***

upgradeが動かない

一度稼働を始めるとなかなかバージョンアップできなくなるので、本番稼働前に執筆時点の最新となる3.0.0b3134にバージョンアップしようとしました。
そこでupgrade以下コマンドで上げてみようとしたところ…

$ sudo /opt/redash/current/bin/upgrade
Starting Redash upgrade:
Found version: 3.0.0
Current version: 2.0.0+b2990
* Before doing an upgrade, please make sure you have a backup.
* If you have any issues, please refer to the troubleshooting section in the upgrade guide:
  https://redash.io/help-onpremise/maintenance/how-to-upgrade-redash.html
* If the upgrade guide doesn't help, you can ask for help on the forum (https://discuss.redash.io).

Full CHANGELOG for this release: https://github.com/getredash/redash/blob/master/CHANGELOG.md
Continue with upgrade? (y/n): y ←ここでyを入力して実行
Downloading release tarball...
Unpacking to: redash.3.0.0.b3134...
Changing ownership to redash...
Linking .env file...
Installing new Python packages (if needed)...
Running migrations (if needed)...
Failed running: sudo -u redash bin/run ./manage.py db upgrade
Exit status: 1
Output:
(略)
AttributeError: 'module' object has no attribute 'SSL_ST_INIT'

$

_c_choju22_0013_s256_choju22_0013_9.jpgうーん。エラーが出てアップデートできないな。

ということで調査です。

原因調査

その1

エラーメッセージの中にAttributeError: 'module' object has no attribute 'SSL_ST_INIT'という文言がありました。これに注目して調べてみるとここに書かれているように、PyOpenSSLのバージョンアップをしてあげればよさそうです。

まずは現在のバージョンを確認します。

$ pip list --format=legacy | grep pyOpenSSL
pyOpenSSL (0.14)

今のイメージにはpyOpenSSL 0.14が入っているようです。では 3.0.0 ではどのバージョンにする必要があるのかをrequirements_all_ds.txtを見て調べます。
upgradeには失敗しましたが、ソースファイルは展開されているのでそれを利用します。

$ cd /opt/redash/redash.3.0.0.b3134
$ grep pyOpenSSL requirements*
requirements_all_ds.txt:pyOpenSSL==16.2.0
requirements_all_ds.txt:# other packages. To properly support it we probably need to switch from pyOpenSSL
$

現在入っている0.14ではなくて16.2以上が必要なようです。そこでpyOpenSSLをアップデートしましょう。

$ sudo pip install pyOpenSSL -U
(略)
Successfully installed cffi-1.11.2 cryptography-2.1.4 pyOpenSSL-17.5.0 six-1.11.0
$

これで改めてRedashをアップデートしてみます。

_c_chojuganso0009_s256_chojuganso0009_10.jpg他にエラーはないのでできるはず。

実行結果
$ sudo /opt/redash/current/bin/upgrade
Starting Redash upgrade:
Found version: 3.0.0
Current version: 2.0.0+b2990
* Before doing an upgrade, please make sure you have a backup.
* If you have any issues, please refer to the troubleshooting section in the upgrade guide:
  https://redash.io/help-onpremise/maintenance/how-to-upgrade-redash.html
* If the upgrade guide doesn't help, you can ask for help on the forum (https://discuss.redash.io).

Full CHANGELOG for this release: https://github.com/getredash/redash/blob/master/CHANGELOG.md
Continue with upgrade? (y/n): y ←yを入力
Downloading release tarball...
Unpacking to: redash.3.0.0.b3134...
Changing ownership to redash...
Linking .env file...
Installing new Python packages (if needed)...
Running migrations (if needed)...
Failed running: sudo -u redash bin/run ./manage.py db upgrade
Exit status: 1
Output:
[2017-12-13 09:13:04,419][PID:1545][INFO][root] Generating grammar tables from /usr/lib/python2.7/lib2to3/Grammar.txt
[2017-12-13 09:13:04,527][PID:1545][INFO][root] Generating grammar tables from /usr/lib/python2.7/lib2to3/PatternGrammar.txt
Traceback (most recent call last):
(略)
ImportError: /usr/lib/python2.7/lib-dynload/_sqlite3.x86_64-linux-gnu.so: failed to map segment from shared object

$

_c_choju27_0007_s256_choju27_0007_4.jpgダメだー
しかもエラーの内容を見ると、先程のようなライブラリのバージョンの問題ではなさそうです。

その2

_c_chojudaA0027_s256_chojudaA0027_5.jpgそういえばt2.micro使ったけどメモリどうなってるかな?

EC2インスタンスのタイプはみんな大好きt2.microを使ったのですが、このインスタンスにはメモリが1GBしかありません。
ということで、さっそくメモリの状態を見てみましょう。

$ free
              total        used        free      shared  buff/cache   available
Mem:        1014644      849896       74316        3168       90432       36728
Swap:             0           0           0
$

_c_choju29_0037_s256_choju29_0037_7.jpgうわ、freeが100MB以下!少な!

usedで80%以上使っていてfreeの値が小さすぎるので、メモリを増やしたほうがよさそうです。
ただ検証用のため速度は遅くても問題ないため、インスタンスサイズを上げずにswapを増やすことにしました。

ということで以下のようにして3GBのswapファイルを作成し、実メモリ1GBと合わせて合計4GBにしました。

swap追加
$ sudo dd if=/dev/zero of=/swapfile1 bs=1M count=3072
$ sudo chmod 600 /swapfile1
$ sudo mkswap /swapfile1
$ sudo swapon /swapfile1
swapができていることの確認
$ swapon -s
Filename    Type        Size    Used    Priority
/swapfile1      file        3145724 0   -1
$

改めてメモリの空きを見てみます。

swap追加後のfreeコマンド結果
$ free
              total        used        free      shared  buff/cache   available
Mem:        1014644      853484       77404        3168       83756       36460
Swap:       3145724           0     3145724
#

先程はSwapのtotalは0でしたが、今は3145724に増えています。
次にswapが自動マウントされるように/etc/fstabに以下のように追記します。(2行目を追記)
追記後にインスタンスをrebootしましょう。

$ sudo vi /etc/fstab
↓↓これを追記↓↓
/swapfile1  swap   swap    defaults   0 0

$ sudo reboot

改めてやってみます。

リトライ
$ sudo /opt/redash/current/bin/upgrade
Starting Redash upgrade:
Found version: 3.0.0
Current version: 2.0.0+b2990
* Before doing an upgrade, please make sure you have a backup.
* If you have any issues, please refer to the troubleshooting section in the upgrade guide:
  https://redash.io/help-onpremise/maintenance/how-to-upgrade-redash.html
* If the upgrade guide doesn't help, you can ask for help on the forum (https://discuss.redash.io).

Full CHANGELOG for this release: https://github.com/getredash/redash/blob/master/CHANGELOG.md
Continue with upgrade? (y/n): y
Downloading release tarball...
Unpacking to: redash.3.0.0.b3134...
Changing ownership to redash...
Linking .env file...
Installing new Python packages (if needed)...
Running migrations (if needed)...
Linking to current version...
Restarting...
Done! Enjoy.
$

_c_choju37_0023_s256_choju37_0023_0.jpgやったー!ようやくアップデートできたー!
ということで、無事アップデートすることができました。

今回Redashをはじめて触ったので気づかなかったのですが、今回利用したAMIはRedashを動かすのに必要なものが全て入っているので、そもそもt2.microのメモリ1GBでは足りなかったようです。

まとめ(得られた学び)

  • 公式が配布しているRedashサーバのAMIを利用する場合、t2.microだとメモリが1GBしかないので足りないこと
  • そのためt2.mediumくらいのインスタンスが望ましい。ただし規模による。
  • 検証用だったらswapファイルを利用する手もあるが、速度が遅くなるので本番サーバとしては利用はしない方が吉(一般論ですが)

おまけ (2018/05/08追記)

この時バージョンアップしたものをさらに4.0.1にupgradeしました。
先にapt-get upgradeしてからおこなったためか、何のエラーもなくバージョンアップ完了…

4.0.1へのupgrade
$ sudo /opt/redash/current/bin/upgrade
Starting Redash upgrade:
Found version: 4.0.1
Current version: 3.0.0+b3134
* Before doing an upgrade, please make sure you have a backup.
* If you have any issues, please refer to the troubleshooting section in the upgrade guide:
  https://redash.io/help/open-source/admin-guide/how-to-upgrade
* If the upgrade guide doesn't help, you can ask for help on the forum (https://discuss.redash.io).

Full CHANGELOG for this release: https://github.com/getredash/redash/blob/master/CHANGELOG.md
Continue with upgrade? (y/n): y ←yを入力
Downloading release tarball...
Unpacking to: redash.4.0.1.b4038...
Changing ownership to redash...
Linking .env file...
Installing new Python packages (if needed)...
Running migrations (if needed)...
Linking to current version...
Restarting... ←ここでしばらく待った
Done! Enjoy.
$

おわりに

当初はRedash導入直後に役立ちそうな小ネタを2,3書こうと思っていたのですが、upgradeの話だけで思っていたより長くなってしまったのでupgradeネタ1本にしました。

そして、イラストはこちらのものを利用させていただきました。この場を借りて御礼申し上げます。
http://www.chojugiga.com/2017/05/17/da2choju22_0013/

それでは、よいクリスマスを!

23
13
1

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
23
13