LoginSignup
4
2

More than 5 years have passed since last update.

メモリ不足でpuppetserverが起動しないときの対処法

Posted at

これは何

Dockerコンテナ上でpuppetserverを起動したら、メモリ不足で起動しなかったときの対処方法です。Docker Machineのメモリがデフォルト2GBですが、これだとデフォルト設定のpuppetserverが起動しなかったので。Dockerに限らず、動作確認用環境だとメモリ少ない場合があるので、参考になればと思います。

なお、Rubyで動いていた以前のpuppet masterとは無関係な内容で、JVMで動くpuppetserverについての内容です。

バージョン

確認した環境のバージョン情報です。

# cat /etc/centos-release
CentOS Linux release 7.1.1503 (Core)
# rpm -qa | grep puppetserver
puppetserver-2.2.1-1.el7.noarch

初期設定で起動できない

puppetserverをrpmでインストールして、初期設定のまま起動すると起動に失敗しました。

# systemctl start puppetserver 
Job for puppetserver.service failed. See 'systemctl status puppetserver.service' and 'journalctl -xn' for details.

puppetserverのログを見ると、Puppet Serverが2159MBのメモリ使おうとしているけど足りないみたいなエラーが出てています。

/var/log/puppetlabs/puppetserver/puppetserver.log
2016-01-31 03:10:56,948 ERROR [main] [p.t.internal] Error during service init!!!
java.lang.Error: Not enough available RAM (2002MB) to safely accommodate the configured JVM heap size of 1963MB.  Puppet Server requires at least 2159MB of available RAM given this heap size, computed as 1.1 * max heap (-Xmx).  Either increase available memory or decrease the configured heap size by reducing the -Xms and -Xmx values in JAVA_ARGS in /etc/sysconfig/puppetserver on EL systems or /etc/default/puppetserver on Debian systems.

設定変更する

上記エラーに、EL系なら/etc/sysyconfig/puppetserver、Debian系なら/etc/default/puppetserverのJAVA_ARGSの設定を変更してください、とあるので変更します。ちゃんとした環境用であれば、メモリ割り当てを増やすとかですが、ちょっとした動作確認用の環境なのでヒープサイズ設定(-Xmsと-Xmx)を小さくします。

ヒープサイズ設定

変更前の初期設定の抜粋です。初期設定だと2GBです。

/etc/sysconfig/puppetserver
# Modify this if you'd like to change the memory allocation, enable JMX, etc
JAVA_ARGS="-Xms2g -Xmx2g -XX:MaxPermSize=256m"

-Xms2g -Xmx2gの部分を-Xms512m -Xmx512mに変更します。性能影響あるのでちゃんとした環境だと足りないかもしれないですが、デモ用でも512MBはあった方がよいらしいのでぎりぎりまで減らします。

/etc/sysconfig/puppetserver
# Modify this if you'd like to change the memory allocation, enable JMX, etc
JAVA_ARGS="-Xms512m -Xmx512m -XX:MaxPermSize=256m"

max-active-instances設定

あと、max-active-instancesの設定が推奨ヒープサイズに関係する(後述)ようなので、max-active-intancesの設定も変えます。この設定は変えなくても起動はしますが、ヒープサイズを小さくしたのにインスタンスが多いと動作影響でるかもしれないので、念のため変えておきます。

変更前はコメントアウトされてます。

/etc/puppetlabs/puppetserver/conf.d/puppetserver.conf
    # (optional) maximum number of JRuby instances to allow
    #max-active-instances: 1

max-active-intancesを1にします。

/etc/puppetlabs/puppetserver/conf.d/puppetserver.conf
    # (optional) maximum number of JRuby instances to allow
    max-active-instances: 1

設定後起動できた

設定変更後、puppetserverを起動すると起動できました。

# systemctl start puppetserver

# systemctl status puppetserver
puppetserver.service - puppetserver Service
   Loaded: loaded (/usr/lib/systemd/system/puppetserver.service; disabled)
  Drop-In: /run/systemd/system/puppetserver.service.d
           └─00-docker.conf
   Active: active (running) since Sun 2016-01-31 04:18:13 UTC; 3min 45s ago
(省略)

参考までにメモリ容量とか。

# free -h                       
              total        used        free      shared  buff/cache   available
Mem:           2.0G        609M        736M        132M        657M        1.2G
Swap:          1.4G          0B        1.4G

ヒープサイズの求め方

puppetserverに設定するヒープサイズの求め方は、下記を参考にしてください。

デモ用なら512MBくらいでよいらしいです。

We’re working on some optimizations for really small installations (for testing, demos, etc.). Puppet Server should run fine with a value of 1 for max-active-instances and a heap size of 512MB, and we might be able to improve that further in the future.

もう少し読むと推奨は、512MB + max-active-instances * 512MBとのことです。

max-active-instancesの設定については下記参照。

デフォルト、cpu数 - 1(1から4)らしいです。ちなみチューニングガイドを読むと、クライアント数が多い場合は4だと少ないらしいので、逆にこの値を大きくして、ヒープサイズ、メモリを増やすとかになるかと。

max-active-instances: Optional. The maximum number of JRuby instances allowed. The default is ‘num-cpus - 1’, with a minimum value of 1 and a maximum value of 4.

4
2
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
4
2