STEP1.安装必备的gem包
- gem install –include-dependencies mongrel
- gem install –include-dependencies mongrel_cluster
STEP2.配置
Mongre_cluster的设置比较简单,进入Rails应用的根目录,执行
- cd /var/www/demo
- mongrel_rails cluster::configure -e production -p 8000 -a 127.0.0.1 -N 5 -c /var/www/demo
其中
-e 指定运行环境,有production(生产)、development(开发)、test(测试)三个选项。
-p 指定监听端口
-a 127.0.0.1 指定Mongrel在localhost下监听
-N 5 启动两个Mongrel进程,端口从8000~8004
执行以上命令后,会在/var/www/demo/config目录产生mongrel_cluster.yml文件
- ---
- cwd: /var/www/demo
- log_file: log/mongrel.log
- port: "8000"
- environment: production
- address: 127.0.0.1
- pid_file: tmp/pids/mongrel.pid
- servers: 5
至于mongrel_rails cluster::configure 命令的详细用法,可以mongrel_rails cluster::configure --help查看
- Usage: mongrel_rails <command> [options]
- -e, --environment ENV Rails environment to run as
- -p, --port PORT Starting port to bind to
- -a, --address ADDR Address to bind to
- -l, --log FILE Where to write log messages
- -P, --pid FILE Where to write the PID
- -c, --chdir PATH Change to dir before starting (will be expanded)
- -o, --timeout TIME Time to wait (in seconds) before killing a stalled thread
- -t, --throttle TIME Time to pause (in hundredths of a second) between accepting clients
- -m, --mime PATH A YAML file that lists additional MIME types
- -r, --root PATH Set the document root (default 'public')
- -n, --num-procs INT Number of processor threads to use
- -B, --debug Enable debugging mode
- -S, --script PATH Load the given file as an extra config script.
- -N, --num-servers INT Number of Mongrel servers
- -C, --config PATH Path to cluster configuration file
- --user USER
- User to run as
- --group GROUP
- Group to run as
- --prefix PREFIX
- Rails prefix to use
- -h, --help Show this message
- --version Show version
STEP3. 启动
在终端下输入以下命令启动Mongrel:
mongrel_rails cluster::start
STEP4.停止
mongrel_rails cluster::stop