Ruby on Rails - 使用puma部署Rails项目
Puma是一个基于Ruby的Web Server服务器,主要基于多线程,所以内存占用较少
使用Puma方法如下:
1. 在Gemfile中添加:
gem 'puma'
2. 配置config/puma.rb文件,当前具体配置如下
其中端口以及sock名字需要对应更改
module Railsclass << selfdef rootFile.expand_path("../..", __FILE__)endend
end
# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches the default thread size of Active Record.
#
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
# threads threads_count, threads_count# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
port ENV.fetch("PORT") { 3040 }# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch("RAILS_ENV") { "development" }# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked webserver processes. If using threads and workers together
# the concurrency of the application would be max `threads` * `workers`.
# Workers do not work on JRuby or Windows (both of which do not support
# processes).
rails_env = ENV.fetch("RAILS_ENV") || "development"# 计算机核数
if rails_env == "development"workers ENV.fetch("WEB_CONCURRENCY") { 2 }
elseworkers 2
end# Use the `preload_app!` method when specifying a `workers` number.
# This directive tells Puma to first boot the application and load code
# before forking the application. This takes advantage of Copy On Write
# process behavior so workers use less memory. If you use this option
# you need to make sure to reconnect any threads in the `on_worker_boot`
# block.
#
pidfile "#{Rails.root}/tmp/pids/puma.pid"
state_path "#{Rails.root}/tmp/pids/puma.state"
stdout_redirect "#{Rails.root}/log/puma.stdout.log", "#{Rails.root}/log/puma.stderr.log", true
bind "unix://#{Rails.root}/tmp/navy_monitor.sock"
daemonize
threads 0,4
preload_app!# If you are preloading your application and using Active Record, it's
# recommended that you close any connections to the database before workers
# are forked to prevent connection leakage.
#
# before_fork do
# ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)
# end# The code in the `on_worker_boot` will be called if you are using
# clustered mode by specifying a number of `workers`. After each worker
# process is booted, this block will be run. If you are using the `preload_app!`
# option, you will want to use this block to reconnect to any threads
# or connections that may have been created at application boot, as Ruby
# cannot share connections between processes.
#
# on_worker_boot do
# ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
# end
#
# on_worker_boot do
# ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
# endbefore_fork doActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)# PumaWorkerKiller.config do |config|# config.ram = 16*1024 # mb 服务器内存# # config.frequency = 5 # seconds# config.percent_usage = 0.7 # 内存使用上限# config.rolling_restart_frequency = 12 * 3600 # 12 hours in seconds# end# PumaWorkerKiller.start
end
# Allow puma to be restarted by `rails restart` command.
# plugin :tmp_restart
3. 添加start.sh以及restart.sh
start.sh文件
rails s puma -e development -b 0.0.0.0 -p 8088
restart.sh文件
kill -s USR2 `cat ./tmp/pids/puma.pid`
保存以后即可直接运行
4. 执行启动以及重启操作
如需启动项目,执行./start.sh即可
./start.sh
在执行操作后,提示以下错误:
bash: ./start.sh: Permission denied
对当前文件进行赋值即可
chmod 777 *.sh
接下来启动项目成功
Ruby on Rails - 使用puma部署Rails项目相关推荐
- 视频教程-Ruby on Rails打造企业级RESTful API项目实战我的云音乐-Ruby/Rails
Ruby on Rails打造企业级RESTful API项目实战我的云音乐 任苹蜻,爱学啊创始人 & CEO,曾就职于某二车手公司担任Android工程师后离职创办爱学啊,我们的宗旨是:人生 ...
- Rails 的自动化部署工具Cap(Capistrano)和mina
项目的自动化部署工具.cap 整合了与rails 相关的自动化部署命令 项目经过多次部署后,服务器会生成一个这样项目的目录 current 是指当前版本, link 到 release 下的指定版本目 ...
- aws v2.2.exe_如何在AWS Elastic Beanstalk上部署Rails 5.2 PostgreSQL应用
aws v2.2.exe by Evrim Persembe 通过埃夫里姆·佩塞姆贝 如何在AWS Elastic Beanstalk上部署Rails 5.2 PostgreSQL应用 (How to ...
- apache服务器安装以及使用passenger插件部署rails应用,基于ubuntu 12.04 LTS
小例子可以部署在rails自带的WEBrick上,逐渐往后走还得上Apache. 安装apache服务器 命令是sudo apt-get install apache2 安装passenger插件 安 ...
- Nginx+mongrel部署Rails应用
安装nginx 下载地址 http://nginx.org/en/download.html 我下载的版本是 nginx-0.8.40.tar.gz 解压安装 tar -zxvf nginx-0.8. ...
- rails 创建_使用Rails和Icecast创建在线流媒体广播
rails 创建 Hello and welcome to this article! Today I would like to talk about creating an online stre ...
- 从零学习Jenkins部署SpringBoot项目
前言 之前项目中虽然使用过 Jenkins,但是都只是使用,没有自己搭建过,完整部署一个项目.既然工作中没有独立部署过,那么就只能自己动手实操一番,技多不压身嘛. 一开始是在本机上下载安装 Jenki ...
- Mac 使用 Valet 部署 PHP 项目
先安装valet 1.安装 Homebrew 软件包管理工具,如果已经安装,可以跳过此步骤 /usr/bin/ruby -e "$(curl -fsSL https://raw.githu ...
- Docker 部署 SpringBoot 项目整合 Redis 镜像做访问计数Demo
Docker 部署SpringBoot项目整合 Redis 镜像做访问计数Demo 最终效果如下 大概就几个步骤 1.安装 Docker CE 2.运行 Redis 镜像 3.Java 环境准备 4. ...
最新文章
- Python+selenium 自动化-模拟键盘输入、点击操作,如何查看所支持的全部键位名称
- 文件不混淆_Android Studio配置反混淆
- awk文本工具按列计算和
- java 创建线程的三种方法_java 创建线程的几种方式
- IE6PNG8PNG24test
- 信息学奥赛一本通(1070:人口增长)
- Kaggle新上比赛-鲸鱼图像识别-总奖池17.4万人民币
- css实现居中的各种方法
- Webpack4 学习笔记六 多页面配置和devtool
- paip.js input onclick失灵不起作用无反应的解决.txt
- 索尼android 怎么截屏快捷键,索尼z5怎么截屏 sony z5截图方法教程
- java正则表达式 用户名_java之正则表达式
- js获取当前url路径
- 【进销存管理系统——开题报告 分享(仅供参考呀)】
- 八数码 (Astar)
- 由于您的系统没有安装html help,win10遇到“您未安装FLASH控件”的提示怎么办
- 深入浅出Meta Learning - 让机器学会如何去学习
- java 内存模型书籍_《深入理解 Java 内存模型》读书笔记
- 自定义对象转换接口实现JDBC的封装
- c语言合并wav文件,如何将两个WAV文件合并/合并为一个WAV文件?