阿里云裸机部署rails运用

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS MySQL,高可用系列 2核4GB
简介:
登录阿里云后首先
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
版权声明:本文由 数控等离子切割机  http://www.hycsk.com 整理编辑!本文章来源于网络,如有侵权,请联系云栖社区,欢迎分享本文,转载请保留出处!
---------

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 
相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
8月前
|
边缘计算 Kubernetes Devops
KubeSphere平台安装系列之二【Linux单节点部署KubeSphere】(2/3)
KubeSphere平台安装系列之二【Linux单节点部署KubeSphere】(2/3)
151 3
|
8月前
|
安全 测试技术 数据安全/隐私保护
【好用的个人工具】Docker环境下部署FileDrop文件共享工具
【2月更文挑战第13天】Docker环境下部署FileDrop文件共享工具
223 2
|
Kubernetes 数据库 C++
.netcore应用在WSL中的容器化部署
前面,我们讲解了如何在wsl中安装数据库,.netcore运行时,以及如何发布一个.netcore应用,为了构成一个完整的小系列,本节,我们来学习一下,如何将.netcore应用在WSL中容器化。
|
8月前
|
边缘计算 Kubernetes Linux
KubeSphere平台安装系列之三【Linux多节点部署KubeSphere】(3/3)
KubeSphere平台安装系列之三【Linux多节点部署KubeSphere】(3/3)
138 1
|
程序员 网络安全 Ruby
利用vagrant快速搭建rails开发环境
利用vagrant快速搭建rails开发环境
92 0
|
JavaScript 前端开发 Java
基于Docker在Win10平台搭建Ruby on Rails 6.0框架开发环境
2023年,“非著名Web框架”--Ruby on Rails已经18岁了。在今年,Rails 6.0趋于完善,除了拿掉讨厌的Jquery,Webpacker 也成为默认前端打包方案,Sprockets 开始软着陆,未来很可能会和Jquery一样被彻底废弃,这就是历史的进程。
基于Docker在Win10平台搭建Ruby on Rails 6.0框架开发环境
|
NoSQL 关系型数据库 MySQL
使用 Rainbond 搭建本地开发环境
在开发之前,你需要在本地安装各种开发工具和服务,比如:Mysql、Redis、Nacos 等等,我们都知道在个人电脑上安装这些服务相当的繁琐,可能会遇到很多问题,环境问题、依赖问题等等。
|
SQL 安全 关系型数据库
云环境下快速搭建LAMP环境
云起冬季实战营第一期:从零到一上手玩转云服务器。参加学习一下,教程很好,记录一下。并在一些自己不太清楚的地方简单注解。
226 1
云环境下快速搭建LAMP环境
|
JavaScript Ubuntu 前端开发
在vagrant部署的Ubuntu系统搭建ruby on rails环境
#准备工作,更新源,安装依赖包等
137 0
|
监控 NoSQL 关系型数据库
《Rails 程序部署之道》—— 可靠的重复式部署和配置
《Rails 程序部署之道》讲述可靠的重复式部署和配置方法。
159 0
《Rails 程序部署之道》—— 可靠的重复式部署和配置