- 浏览: 849890 次
- 性别:
- 来自: lanzhou
文章分类
最新评论
-
liu346435400:
楼主讲了实话啊,中国程序员的现状,也是只见中国程序员拼死拼活的 ...
中国的程序员为什么这么辛苦 -
qw8226718:
国内ASP.NET下功能比较完善,优化比较好的Spacebui ...
国内外开源sns源码大全 -
dotjar:
敢问兰州的大哥,Prism 现在在12.04LTS上可用么?我 ...
最佳 Ubuntu 下 WebQQ 聊天体验 -
coralsea:
兄弟,卫星通信不是这么简单的,单向接收卫星广播信号不需要太大的 ...
Google 上网 -
txin0814:
我成功安装chrome frame后 在IE地址栏前加上cf: ...
IE中使用Google Chrome Frame运行HTML 5
Step 1. Initial server setup
You’ll need an Ubuntu box to get started. After the basic install you’ll need to run a few commands to get the box ready.
Log into your server via ssh & change your root password
ssh root@123.123.123.123 passwd
Change 123.123.123.123 with the IP of your server everywhere you see it.
Add a new user called rails and give it a password
adduser rails
Give it sudo permissions
visudo
And add this below “root ALL=(ALL) ALL”
rails ALL=(ALL) ALL
On your local machine:
ls ~/.ssh/
If it shows you id_rsa.pub, skip this next step (which generates the ssh):
ssh-keygen
Next, we’re going to copy your public key to your server so you can securely connect to it without having to enter your password. Again on your local machine, run:
scp ~/.ssh/id_rsa.pub rails@123.123.123.123:/home/rails/
Now on your server, run this:
mkdir /home/rails/.ssh mv /home/rails/id_rsa.pub /home/rails/.ssh/authorized_keys chown -R rails:rails /home/rails/.ssh chmod 700 /home/rails/.ssh chmod 600 /home/rails/.ssh/authorized_keys
It’s a good practice to change the SSH port for your machine so that’s what we’re going to do next:
nano /etc/ssh/sshd_config
Change “Port 22” to “Port 2222” or a different number
Save your file and close it (Ctrl+X, then Y and finally press enter-key)
Okay, now it’s time to setup IP Table Rules.
nano /etc/iptables.test.rules
In this file, enter your iptable rules. Here’s a decent I got fromhttp://articles.slicehost.com/assets/2007/9/4/iptables.txt. IPTables are like your firewall so all info is provided without warrantee. It’s your responsibility to use it wisely.
*filter # Allows all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0 -A INPUT -i lo -j ACCEPT -A INPUT -i ! lo -d 127.0.0.0/8 -j REJECT # Accepts all established inbound connections -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT # Allows all outbound traffic # You can modify this to only allow certain traffic -A OUTPUT -j ACCEPT # Allows HTTP and HTTPS connections from anywhere (the normal ports for websites) -A INPUT -p tcp --dport 80 -j ACCEPT -A INPUT -p tcp --dport 443 -j ACCEPT # Allows SSH connections # # THE -dport NUMBER IS THE SAME ONE YOU SET UP IN THE SSHD_CONFIG FILE # -A INPUT -p tcp -m state --state NEW --dport 2222 -j ACCEPT # Allow ping -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT # log iptables denied calls -A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7 # Reject all other inbound - default deny unless explicitly allowed policy -A INPUT -j REJECT -A FORWARD -j REJECT COMMIT
Save that file and close it. Then run this:
iptables-restore < /etc/iptables.test.rules iptables-save > /etc/iptables.up.rules
Now to make this info stay when you restart the server, run:
nano /etc/network/interfaces
And enter a line below the “iface lo inet loopback” line, as shown below:
... auto lo iface lo inet loopback pre-up iptables-restore < /etc/iptables.up.rules # The primary network interface ...
Save & close that file and then run:
/etc/init.d/ssh reload
Now it’s time to do some stuff on your local machine to make it easy to connect with your server.
On your local machine, open ~/.ssh/config file with textmate or your fav text editor:
mate ~/.ssh/config
and add your info using the template below:
Host blackbox Hostname 123.123.123.123 User rails Port 2222
Don’t forget to change your port number & IP as well as pick a name for your server that makes sense.
Save & close that file. Now you should be able to connect to your server by just typing:
ssh blackbox
Okay, we’ve got one final thing we need to get your initial server setup. That’s getting your server access to your github account (which you don’t need but most people have it so you should probably get one, even if it’s just to contribute to open source stuff.)
Once you’ve ssh’d into your server using the above command, generate your ssh key similar to how to you did it on your local machine:
ssh-keygen
It will ask you if you want to give it a password. I usually don’t give it one and I don’t know if that’s a good/bad thing. In anycase, when you’re done, you want to output the public key it generates by running this:
cat /home/rails/.ssh/id_rsa.pub
Copy the key that is outputted and enter it into your github account which you can usually do at:https://github.com/account
Alright, you’ve now completed step 1, which was getting the initial server ready.
Step 2 – Adding moonshine to your project & configuring it.
In this step, you’ll add the moonshine plugin to your project & configure it properly so it knows what you want it to do on your server.
On your local machine, go to your rails project directory and add the plugin:
ruby script/plugin install git://github.com/railsmachine/moonshine.git
Add all the gems your project needs to your environment.rb file.
Next, run the moonshine generator to create the necessary files:
ruby script/generate moonshine
This should make an output like this:
After the Moonshine generator finishes don't forget to: - Edit config/moonshine.yml Use this file to manage configuration related to deploying and running the app: domain name, git repos, package dependencies for gems, and more. - Edit app/manifests/application_manifest.rb Use this to manage the configuration of everything else on the server: define the server 'stack', cron jobs, mail aliases, configuration files create app/manifests create app/manifests/templates create app/manifests/application_manifest.rb exists app/manifests/templates create app/manifests/templates/README exists config create config/moonshine.yml create config/gems.yml
As the output suggests, the next thing you should do is edit config/moonshine.yml
Edit config/moonshine.yml
First give your app a name (such as your_app_name), pick where the files of your app will reside (by setting deploy_to) & tell moonshine where to grab your application from (by setting repository)
:application: your_app_name :deploy_to: /srv/your_app_name :repository: git@github.com:username/your_app_name.git
Next, if your app has directories in the public directory that need to stay persistent, uncomment this:
:app_symlinks: - uploads
If you don’t, the files will be removed every time you deploy since it gets the files from your git repo and it won’t be there.
You’ll also probably want to uncomment the local_config section, which will upload your local copy of /config/database.yml to the server, while bypassing your git repo.
:local_config: - config/database.yml
You probably want to leave the next section (:shared_children:) alone. It basically keeps everything the same.
Now save your file and from your terminal/command-line, run this command to generate a /config/gems.yml file, which will contain a list of gems that your app needs (based on what you specified in config/environment.rb)
rake moonshine:gems
Like the comments say, if your gems depend on native packages, you need to specify it next with :apt_gems. For example:
:apt_gems: :paperclip: - imagemagick
Next, change Passenger & MySQL settings to suit your app & hardware. For example, on a 256MB ram box, you might lower the max_pool_size to 2 or increase it to 8 for 1GB ram server.
Finally, if your app uses SSL, you’ll need to set your ssl properties with something like this:
:ssl: :ip: :certificate_file: :certificate_key_file: :certificate_chain_file: :vhost_extra: nly:
Set the nly: to true if your entire site should be ssl protected. If you are self-signing, can you can use:self_signed: true like this:
:ssl: :self_signed: true
When all is done, you might have a file that looks like this:
:ruby: ree :application: yourapp :user: rails :group: rails :ssl: :self_signed: true :deploy_to: /srv/yourapp :domain: yourapp.com :repository: git@github.com:username/reponame.git :app_symlinks: - assets :local_config: - config/database.yml :shared_children: - system - log - pids - config :apt_gems: :paperclip: - imagemagick :passenger: :max_pool_size: 3 :use_global_queue: true :mysql: :innodb_buffer_pool_size: 128M
Edit app/manifests/application_manifest.rb
In the application_manifest.rb, you’ll specify a few things:
- Which recipe(s) you want to use
- Packages you haven’t already specified
- Any rake commands you want run the first time
Recipes
The file that is generated uses the default_stack recipe. What this means is it will install Apache, Passenger, MySQL, Rails, NTP, Cron & Postfix. Checkout vendor/plugins/moonshine/lib/moonshine/manifest/rails.rb to see the actual method. For many apps, the default will work fine.
TODO: Add instructions for what to have in place of the default_stack if I want to use sqlite as my database (if my app is really small).
Additional Packages
If your app needs to have a package installed that hasn’t been specified yet, this is the place to add it. For example, if your app uses BackgroundRB, you’d specify it here.
TODO: Add example of how backgroundrb might be installed.
Run rake commands
You might need to run a rake command after your app has been deployed to initial things. This might be the place to add it.
TODO: Add example. Something I might want to do is do a mysql dump before I move forward… but this is just hypothetical.
Capify your project
Once you’ve got your app configured, capify your app by running the following code while inside your rails app directory:
capify .
Now open config/deploy.rb and replace it’s content with this:
server "blackbox", :app, :web, :db, :primary => true
Replace blackbox with the name you give your server in your ~/.ssh/config file.Next, store the files to your repo and push it to your git repo:
git add . && git commit -am "added moonshine" && git push
Step 3 – Deploy
Once all the configuration is done, you’ll see all your hard work pay off.
First thing you’ll do is setup the server. From your rails app root, run this:
cap deploy:setup
Once that is done, run this:
cap deploy
At this point, you should be done and your app should be live.
Step 3.5 – Add SSL
If your site uses SSL, this next section will get you setup with it. After you’ve deployed your app with the self-signed method as described above, ssh into your server and generate a new certificate request:
ssh blackbox sudo openssl req -new > mynewsite.csr
It will ask you to fill in a bunch of info that will need to match the info you provide your SSL provider (such as GoDaddy). The key one that you’ll want to pay attention to is Common Name. That needs to be your domain name (without the https://). For my app, i didn’t include the www and I’m not sure if that makes a difference. Next lets move these to a better location:
mkdir /home/rails/certs mv mynewsite.csr /home/rails/certs/mynewsite.csr mv privkey.pem /home/rails/certs/privkey.pem
Once done, output your certificate request by doing this:
cd /home/rails/certs/ cat mynewsite.csr
Copy that and enter it when your SSL provider asks for it.
Once your SSL provider approves your SSL, they’ll provide you with two files. One will be the certificate file and the second will be the certificate chain file. For godaddy, they provide a zip file that contains two files: yourdomain.com.crt & gd_bundle.crt. Save these two files in a directory called certs on your local machine. Change into that directory and copy the files to your server by running this on your local machine:
scp * blackbox:/home/rails/certs/
This should copy the files to /home/rails/certs/ on your server.
The final step is to update config/moonshine.yml, commit it to the git repo and deploy again. Open up config/moonshine.yml and replace:
:ssl: :self_signed: true
with
:ssl: :ip: 123.123.123.123 :certificate_file: /home/rails/certs/yourdomain.com.crt :certificate_key_file: /home/rails/certs/privkey.pem :certificate_chain_file: /home/rails/certs/gd_bundle.crt
Save & close this file. Next update your git repo.
git add config/moonshine.yml git commit -m "Updated moonshine config file with SSL info" git push
Now it’s time to deploy but we have one more tiny step. When you were creating the certificate request, it asked you to enter a password in. Apache will ask for that password every single time it wants to restart and moonshine won’t be able to enter this in for you. So we’re going to remove that password from the private key. (for more info) So log into your server & remove it by doing:
ssh blackbox cd certs cp privkey.pem privkey.pem.bak openssl rsa -in privkey.pem.bak -out privkey.pem
This will ask you to enter your password that you entered while generating the certificate request. When you’re done, you’re ready to deploy again:
cap deploy
That’s it! You should be good to go now. And if you’re in the market for managed hosting, particularly for your Rails apps, definitely check out RailsMachine, creators of moonshine!
PS: I originally wrote this guide as part of the moonshine wiki. Feel free to head out there and add to it. It’ll help everyone involved.
发表评论
-
Rails 3 Beta版本月将出 Merb融合带来选择
2010-01-11 09:48 1419Rails 3,目前流行Web开发框架Rails的一个升级版 ... -
MerbAdmin:Merb数据管理好帮手
2010-01-11 09:43 907Merb中要加入类似Django的Admin功能早有传闻,如今 ... -
rails cms
2009-12-28 20:29 1669Rails CMS alternatives ======= ... -
Generating Thousands of PDFs on EC2 with Ruby
2009-12-24 18:01 1038The Problem For about two mont ... -
Shrink your JavaScript with the Google Compiler Rails Plugin
2009-11-16 11:27 933Like it or not, JavaScript has ... -
Thank you, Rails
2009-11-06 18:21 567It’s fashionable, or perhaps in ... -
Top 50 Ruby on Rails Websites
2009-10-31 15:18 945We’re big fans of Ruby on Rails ... -
Let a human test your app, not (just) unit tests
2009-10-31 09:26 853I’m a big believer in unit test ... -
Heroku Gets Add-Ons: Serious Ruby Webapp Hosting Made Easy
2009-10-30 07:37 913Heroku is a Ruby webapp hosti ... -
Rails + Google Analytics = easy goal tracking
2009-10-29 20:38 892Google Analytics is an indis ... -
Integrating Flickr into your rails website
2009-10-29 20:37 1067In this post I’m going to show ... -
Ruby on Rails Roadshow in Austin Thursday
2009-10-29 14:25 809Justin Britten founded Prefine ... -
Ruby on Rails and the importance of being stupid
2009-10-21 08:13 806A tale of two servers… Server ... -
How a 1-Engineer Rails Site Scaled to 10 Million Requests Per Day
2009-10-20 14:49 775Ravelry is an online knitting ... -
Installing Rails on CentOS 5
2009-10-20 14:24 1191Note: Since this post origina ... -
CentOS配置lighttpd和rails
2009-10-20 14:22 1123lighttpd版本:1.4.18 fastcgi版本: ... -
Cells:将组件开发带入Ruby2.3
2009-10-20 09:17 1118cells "将使得面向组 ... -
High Quality Ruby on Rails Example Applications
2009-10-15 16:34 1461Sometimes to best way to get ... -
Install Passenger on Ubuntu
2009-10-07 10:17 806Phusion Passenger is one of the ... -
Installing Ruby on Rails with Apache on Ubuntu 9.04 (Jaunty)
2009-10-07 10:00 1015Installing Passenger and Depe ...
相关推荐
总结来说,这个"rails+grape+swagger+devise+capistrano"的简单融合示例展示了一个完整的、功能齐全的API项目架构。Rails作为基础框架,Grape负责API的构建,Swagger用于API的文档化,Devise处理用户认证,而...
这个“Ruby+Rails+社交+教程”显然旨在引导开发者如何利用Rails的灵活性和强大功能构建一个完整的社交平台。以下是教程可能涵盖的一些核心知识点: 1. **Ruby基础知识**:首先,你需要对Ruby编程语言有基本的理解,...
本教程“Ruby+Rails+社交+教程3”旨在帮助开发者掌握如何利用Ruby的强大功能和Rails的优雅设计来构建一个具有用户交互性的社交平台。 首先,让我们深入了解一下Ruby。Ruby是一种面向对象的编程语言,以其简洁、易读...
在本“Ruby+Rails+社交+进阶教程5”中,我们将深入探讨如何利用Ruby on Rails框架构建一个功能丰富的社交网络平台。Ruby on Rails(简称Rails)是一个基于Ruby语言的开源Web应用程序框架,它遵循MVC(模型-视图-控制...
Rails框架入门 MVC架构理解 数据库设计与迁移 ActiveRecord模型操作 Rails中的控制器编写 视图层HTML与ERB 路由系统详解 RESTful设计原则 Rails中的表单处理 Rails与JavaScript集成 Rails中的测试驱动开发 部署Rails...
在RHEL(Red Hat Enterprise Linux)系统上搭建Ruby on Rails(简称RoR)应用程序环境是一项技术性较强的任务,尤其当涉及到与其他服务如Nginx、Phusion Passenger、Ruby、Rails以及Oracle数据库集成时。以下是对这...
jax-on-rails Ruby on Rails实时博客+入门套件 入门 克隆存储库 $ git clone https://github.com/jacksonmccluskey/jax-on-rails.git ...$ rails server 建于 Pusher-与Pusher REST API交互的Ruby宝石
这是一个实验性游戏,可练习Ruby on Rails + Hotwire + Turbo的组合。 转到查看它正在运行。 邀请朋友一起玩。 游戏 两名玩家在五轮中回答简单的数学方程式,每轮有四个备选方案。 游戏仅接受第一个答案。 如果答案...
标题 "RailsAPI+React+Deviseの认证机能さんプル_Ruby_TypeScript.zip" 提供了一个项目概览,它是一个使用Rails API、React前端和Devise进行身份验证的示例应用。这个项目融合了Ruby on Rails后端开发框架、React...
### Ruby on Rails 在 Ping++ 平台实现支付 在当今数字化时代,支付接口的重要性不言而喻。无论是电商平台、在线服务还是任何涉及资金流转的应用,一个稳定且安全的支付系统都是其不可或缺的一部分。Ruby on Rails ...
标题 "CRA+RailsAPI+设计登录+ActiveAdmin样板_Ruby_JavaScript_下" 提供了关于项目的核心技术栈,其中包括Create React App (CRA)、Ruby on Rails API 和 ActiveAdmin,以及登录功能的设计。这是一份使用前端React...
入门项目-前端 Rails 5 API + Ember +语义UI演示/入门项目。 可以在找到后端项目。 命令历史 ember new starter-client ember install ember-simple-auth npm install ember g route login ...ember server --pro
3. 克隆或下载Rails 4.2.0项目的源代码,或者创建一个新的Rails项目,使用`rails new my_app -d sqlite3`命令,其中`my_app`是你的应用名,`-d sqlite3`指定使用SQLite数据库。 4. 进入项目目录,运行`bundle ...
标题 "Rails3+GithubOAuth2+设计示例应用程序" 提供了我们正在处理一个使用Rails 3框架构建的Web应用程序,该应用集成了Github的OAuth2授权机制。Rails是Ruby on Rails的简称,是一个流行的开源Web开发框架,以其DRY...
在Ruby on Rails框架中,与SQLServer 2000集成可能会比与其他常见的数据库系统(如MySQL或PostgreSQL)稍复杂一些,因为SQLServer 2000的兼容性问题和缺少官方支持。然而,通过一些第三方库和适当的配置,我们仍然...
Ruby On Rails系列从入门到精通实战教程 Ruby基础+Rails框架+网上商城项目实战
docker-rails-nginx-unicorn Docker Rails + Nginx + Unicorn(来自Ubuntu 16.04和Ruby 2.4.0) 易于使用的docker导轨。 较少的配置,负担得起的生产。 包括什么 独角兽,nginx,领班 mysql,PostgreSQL库 用法 在...
Prosopite能够以零误报/误报自动检测Rails N + 1查询。 Prosopite Prosopite能够自动检测零误报/误报的Rails N + 1查询。 已检测到N + 1个查询:从`users`的WHERE`users.`id` = 20 LIMIT 1中选择SELECT`users`。*从`...
这些是React on Rails 12的文档。要查看版本11文档,。新闻2020年10月14日: 。 2020年10月1日:请参阅示例存储库,以通过支持SSR的rails / webpacker gem进行webpack的简单配置。 2020年8月2日:请参阅的示例回购,...
#rails-vagrant-starter 您需要与Vagrant和Chef一起启动一个新的Rails / Nginx / Passenger / Mysql项目。 只需克隆这个 repo,改变原点并输入vagrant up ###我要安装什么(和厨师一起)? Ruby 2.2.0 (rbenv) ...