现在我一直在努力让monit监视我的瘦群。 我正在使用3个瘦实例。 这些是我的monit和瘦configuration文件:
/etc/thin/vocab.yml: pid: tmp/pids/thin.pid log: log/thin.log port: 3000 max_conns: 1024 timeout: 30 chdir: /home/tenjack/apps/Vocab/current max_persistent_conns: 512 environment: production servers: 3 address: 0.0.0.0 daemonize: true require: [] thin.monitrc: check process thin0 with pidfile tmp/pid/thin.3000.pid start program = "/etc/init.d/thin start" stop program = "/etc/init.d/thin stop" if totalmem > 50.0 MB for 5 cycles then restart if failed port 3000 then restart if cpu usage > 95% for 3 cycles then restart if 5 restarts within 5 cycles then timeout group thin
我也尝试将thin.monitrc文件中的pidpath与许多其他变体一起指向tmp / pids / thin.pid,但是它们都不起作用。 有人有主意吗?
不知道如果你已经解决了这个问题,我会回复。 =)
你做这件事的方式有几件事情。
首先你要监视一个“集群”,所以你需要分别监视每个节点。
其次,您需要重新启动相应的瘦节点,而不是在/etc/init.d中。
它会看起来像这样:
check process thin-81 with pidfile /yourapphere/tmp/pids/thin.81.pid start program = "/usr/bin/thin -d -e production start -p 81" stop program = "/usr/bin/thin stop -Ptmp/pids/thin.81.pid" if 3 restarts within 5 cycles then timeout if totalmem is greater than 150.0 MB for 2 cycles then restart if cpu is greater than 80% for 2 cycles then restart if failed port 81 protocol http with timeout 30 seconds for 2 cycles then restart group thin check process thin-82 with pidfile /yourapphere/tmp/pids/thin.82.pid start program = "/usr/bin/thin start -d -e production -p 82" stop program = "/usr/bin/thin stop -Ptmp/pids/thin.82.pid" if 3 restarts within 5 cycles then timeout if totalmem is greater than 150.0 MB for 2 cycles then restart if cpu is greater than 80% for 2 cycles then restart if failed port 82 protocol http with timeout 30 seconds for 2 cycles then restart group thin
沿着这些线路的东西,取决于你如何设置你的瘦“集群”
以下是我如何处理Monit观看我的瘦服务器集群:
对我来说关键是使用Monit的一个更新的“匹配”function。 这是在Monit 5.2中引入的(使用'monit -V'检查你的monit版本)。 您可以编写一个Monit节来监视一个进程名称的正则expression式,而不是看单个的PID文件。 由于你的集群对集群中的每个节点都有一个进程,所以这实际上是在监视是否没有匹配的进程。
例如,我的Monit节是:
check process thin matching "thin server" start program = "/bin/su - myapp -c 'cd /home/myapp/www/current; bundle exec thin start -C config/thin.yml'" stop program = "/bin/su - myapp -c 'cd /home/myapp/www/current; bundle exec thin stop -C config/thin.yml'" group thin
现在,如果没有进程匹配“瘦服务器”,Monit会根据我的项目目录下的config / thin.yml文件重启整个集群。 开始/停止例程也被编码为用户“myapp”
我发现这个方法比为每个进程的每个PID文件编写一段更为优雅,特别是当我的集群使用yml文件进行configuration时。
补充笔记:
要在先前安装的版本上安装最新版本的Monit(具有“匹配”function),您可以从源代码安装。 对于Ubuntu:
apt-get install libpam-dev apt-get install monit cd /tmp wget http://mmonit.com/monit/dist/monit-5.3.2.tar.gz gunzip monit-5.3.2.tar.gz tar -xvf monit-5.3.2.tar cd /tmp/monit-5.3.2 ./configure --prefix=/usr/sbin --bindir=/usr/sbin --sysconfdir=/etc/monit/ make sudo make install
注意configure上的额外标志。 我需要这些来确保我的“make install”会覆盖使用apt-get安装的以前版本的Monit。 你的path可能有所不同