博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
阿里云裸机部署rails运用
阅读量:6144 次
发布时间:2019-06-21

本文共 3205 字,大约阅读时间需要 10 分钟。

登录阿里云后首先

sudo apt-get update


apt-get install git curl clang make nodejs openssl libssl-dev libreadline6-dev zlib1g-dev libyaml-dev libxml2-dev libxslt1-dev libpq-dev libmysqlclient-dev libsqlite3-dev libcurl4-openssl-dev unzip


———————————————

安装rvm


$ curl -L https://get.rvm.io | bash -s stable

$ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"' >>~/.bashrc

$ source ~/.bashrc

$ rvm -v


reboot重启rvm groop分组权限

-----

# rvm如果安装失败参考命令

curl -sSL https://get.rvm.io | bash -s stable 

#或者 

curl -L https://rvm.io | bash -s stable 



安装RVM依赖等

$ rvm requirements

$ rvm pkg install readline

$ rvm pkg install openssl


$ rvm install 2.3.1

$ rvm use 2.3.1 --default

rvm gemset create 3color244


----------


安装MySQL

$ sudo apt-get install mysql-server


# 加数据库驱动

# mysql client is missing. You may need to 'apt-get install libmysqlclient-dev'

apt-get install libmysqlclient-dev


--------


在使用Ubuntu的时候发现不管是终端输入中文还是终端显示中文,都会出现中文显示为问号的问题。 .解决办法如下:

sudo locale-gen zh_CN.UTF-8 即可完成中文字符集的添加,之后中文就显示正常了。



出现上面问题的原因是rails生产环境没有配置secret_key_base变量,解决方法:

$ cd project

$ bundle exec rake secret # rails 4.2.6还需要bundle exec,请根据rails版本自行匹配



跑起来项目:

git clone your project 项目拉下来。

这样代码就下载到服务器上了,然后安装gem

$ cd project

$ bundle install

创建生产环境数据库并执行迁移

$ RAILS_ENV=production rake db:create

$ RAILS_ENV=production rake db:migrate

否则最终网站页面会显示(之前heroku部署时也经常遇到)

We're sorry, but something went wrong

重新compile assets,这样所有的图片,CSS,scripts才会加载

$ RAILS_ENV=production rake assets:precompile

版权声明:本文由  
整理编辑!本文章来源于网络,如有侵权,请联系云栖社区,欢迎分享本文,转载请保留出处!

---------


Step6: 安装Passenger for Nginx (注意内存必须大于1g)

Nginx是HTTP服务器,运行nginx类似于本地开启rails server,才能实现网站的访问,首先安装passenger:

$ gem install passenger

然后通过source编译的方式安装Nginx

$ rvmsudo passenger-install-nginx-module



Step6: 安装Passenger for Nginx


rvmsudo passenger-install-nginx-module



一路回车即可,在这里选择1回车:


Automatically download and install Nginx?Nginx doesn't support loadable modules such as some other web servers do, so in order to install Nginx with Passenger support, it must be recompiled.Do you want this installer to download, compile and install Nginx for you?

1. Yes: download, compile and install Nginx for me. (recommended) The easiest way to get started. A stock Nginx 1.4.4 with Passenger support, but with no other additional third party modules, will be installed for you to a directory of your choice.

2. No: I want to customize my Nginx installation. (for advanced users) Choose this if you want to compile Nginx with more third party modules besides Passenger, or if you need to pass additional options to Nginx's 'configure' script. This installer will 1) ask you for the location of the Nginx source code, 2) run the 'configure' script according to your instructions, and 3) run 'make install'.

Whichever you choose, if you already have an existing Nginx configuration file, then it will be preserved.Enter your choice (1 or 2) or press Ctrl-C to abort:1[ENTER]


最后看到这句话即安装成功

Nginx with Passenger support was successfully installed.



http {

...

passenger_root /usr/local/rvm/gems/ruby-2.3.1@3color244/gems/passenger-5.0.30;

passenger_ruby /usr/local/rvm/gems/ruby-2.3.1@3color244/wrappers/ruby;

...

}



启动linux


ps auxw | grep nginx


sudo /opt/nginx/sbin/nginx


/opt/nginx/sbin/nginx -s reload 

你可能感兴趣的文章
Office WORD如何取消开始工作右侧栏
查看>>
Android Jni调用浅述
查看>>
CodeCombat森林关卡Python代码
查看>>
第一个应用程序HelloWorld
查看>>
(二)Spring Boot 起步入门(翻译自Spring Boot官方教程文档)1.5.9.RELEASE
查看>>
Java并发编程73道面试题及答案
查看>>
企业级负载平衡简介(转)
查看>>
ICCV2017 论文浏览记录
查看>>
科技巨头的交通争夺战
查看>>
当中兴安卓手机遇上农行音频通用K宝 -- 卡在“正在通讯”,一直加载中
查看>>
Shell基础之-正则表达式
查看>>
JavaScript异步之Generator、async、await
查看>>
讲讲吸顶效果与react-sticky
查看>>
c++面向对象的一些问题1 0
查看>>
直播视频流技术名词
查看>>
企业级java springboot b2bc商城系统开源源码二次开发-hystrix参数详解(八)
查看>>
java B2B2C 多租户电子商城系统- 整合企业架构的技术点
查看>>
IOC —— AOP
查看>>
比特币现金将出新招,推动比特币现金使用
查看>>
数据库的这些性能优化,你做了吗?
查看>>