thin+god搭建rails服务器集群
安装thin sudo gem install thin
安装god sudo gem install god
配置god
?
# configure variables list below
app_dir?????????? = "项目路径"
service??????????? = "项目名称"
num_servers? = 5 // 开启服务器的个数
port???????????? = 9000 // 端口号
#user???????????? = "rocket_finance"
#group??????????? = "rocket_finance"
pid_path???????? = "#{app_dir}/tmp/pids/thin.pid"? pid存放的路径
?
(0...num_servers).each do |i|
number = port + i
God.watch do |w|
? ? w.group = "thin-#{service}"
? ? w.name = w.group + "-#{number}"
? ? w.interval = 30.seconds
? ? #w.uid = user
? ? #w.gid = group
? ? ext = File.extname(pid_path)
? ? w.pid_file = pid_path.gsub(/#{ext}$/, ".#{number}#{ext}")
? ? w.start = "thin start -c #{app_dir} -p #{number} -o #{number}"
? ? w.start_grace = 10.seconds
? ? w.stop = "thin stop -c #{app_dir} -P #{w.pid_file}"
? ? w.stop_grace = 10.seconds
? ? w.restart = "thin restart -c #{app_dir} -p #{number} -o #{number} -P #{w.pid_file}"
? ? w.behavior(:clean_pid_file)
?
??? w.start_if do |start|end
运行 god -c config/thin.god? -D
OK
god status
thin-test-9000: up
thin-test-9001: up
thin-test-9002: up
thin-test-9003: up
thin-test-9004: up