Forked from happypeter/get_linode_ready_for_rails.sh
Last active
December 19, 2015 23:28
-
-
Save luckyyang/6034707 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################# | |
# | |
# 本清单基于 ubuntu 12.04, | |
# 下个 ubuntu 的 LTS | |
# 发出来后,会相应更新这里的内容。我的目标是按步执行可以零错误完成安装。 | |
# 注意,本文件只是一个清单,不是一个可以安全执行的脚本 | |
# | |
################################# | |
# create a linode,login as root, and create a common user for all the tasks | |
ssh root@the_ip_of_this_linode | |
adduser peter --ingroup sudo | |
su peter | |
cd # go to /home/peter | |
################################# | |
# | |
# PART 1: 这一部分,和我在本地开发机器上搭建开发环境采用的步骤是完全一样的 | |
# 我的开发机器也是 ubuntu 1204,一般我都喜欢保证本地开发环境和 server | |
# 上部署环境的高度一致。 | |
# | |
################################# | |
echo "install ruby...." | |
sudo apt-get -y install git-core curl | |
# nice to add ~/.gitconfig before you run the rbenv-installer | |
# since the installer going to feach from git repos, without the config, | |
# trouble can happen. | |
curl -k https://gist.githubusercontent.com/luckyyang/6034718/raw/20798cadefb228166e51ec92190cb73cdf626ad6/gitconfig >>~/.gitconfig | |
echo "now install rbenv..." # https://github.com/fesplugas/rbenv-installer | |
curl https://raw.githubusercontent.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bash | |
# add the block to the end of ~/.profile | |
export RBENV_ROOT="${HOME}/.rbenv" | |
if [ -d "${RBENV_ROOT}" ]; then | |
export PATH="${RBENV_ROOT}/bin:${PATH}" | |
eval "$(rbenv init -)" | |
fi | |
source ~/.profile | |
# I see libxslt1.1 libxml things installed here too, | |
# that's why gems like nokogiri will produce no error installing | |
# If you are installing rbenv in Ubuntu you'll probably need to install some required packages. You can use the provided bootstrap scripts. | |
rbenv bootstrap-ubuntu-12-04 # this may require password | |
rbenv install 1.9.3-p125 # ruby的版本会影响后面/etc/apache2/http.conf中passenger的设置, | |
rbenv global 1.9.3-p125 # 而且不同的ruby版本所用的gem也不一样,因此要注意。 | |
# 如果切换了ruby版本,apache配置文件(/etc/apache2/http.conf) | |
# 要更改,bundle install要重新做。 | |
echo "install bundler..." | |
gem install bundler --no-ri --no-rdoc #这样安装的gem是全局的,gemfile中安装的gem是为某个具体的项目使用的 | |
rbenv rehash #gem安装完之后要做一下rehash | |
echo "install rails ..." | |
gem install rails -v 3.2.8 # this is safer to put in a project's Gemfile | |
################################# | |
# | |
# PART 2: 下面是 onestep 项目部署的具体内容 | |
# 但是本部分的内容依然是服务器和开发机上步骤完全一样 | |
# | |
################################# | |
# https://help.github.com/articles/generating-ssh-keys | |
# add ssh key to github, so that you can get a read-write happycasts repo clone | |
ssh-keygen -t rsa -C "[email protected]" | |
git clone [email protected]:happypeter/onestep.git | |
sudo apt-get install -y apache2 mysql-client mysql-server | |
sudo apt-get install -y libmysqlclient-dev # for mysql2 gem | |
sudo apt-get install -y nodejs # so that I dont need to install therubyracer | |
cd onestep/ | |
bundle | |
# for passenger | |
sudo apt-get install -y apache2-prefork-dev libcurl4-openssl-dev libaprutil1-dev | |
gem install passenger #安装全局的passenger | |
rbenv rehash | |
passenger-install-apache2-module #安装成功后会有一些提示,类似这样: | |
================================ | |
The Apache 2 module was successfully installed. | |
Please edit your Apache configuration file, and add these lines: | |
LoadModule passenger_module /home/ljy/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/passenger-4.0.10/buildout/apache2/mod_passenger.so | |
PassengerRoot /home/ljy/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/passenger-4.0.10 | |
PassengerDefaultRuby /home/ljy/.rbenv/versions/1.9.3-p125/bin/ruby | |
=============================== | |
把LoadModule开始的那3行放到下面的文件中的最上面(参考https://gist.github.com/luckyyang/6034797): | |
sudo vim /etc/apache2/http.conf | |
# then add passenger lines and a virtualhost to http.conf(参考https://gist.github.com/luckyyang/6034797) | |
上面这2步做完了文件就类似于这样: | |
LoadModule passenger_module /home/ljy/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/passenger-4.0.10/buildout/apache2/mod_passenger.so | |
PassengerRoot /home/ljy/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/passenger-4.0.10 | |
PassengerDefaultRuby /home/ljy/.rbenv/versions/1.9.3-p125/bin/ruby | |
<VirtualHost *:80> | |
ServerName ok.com | |
DocumentRoot /home/ljy/workspace/coursetimeline/public/ | |
RailsEnv development | |
<Directory /home/ljy/workspace/coursetimeline/public/ > | |
AllowOverride all | |
Options -MultiViews | |
</Directory> | |
</VirtualHost> | |
<VirtualHost *:80> | |
ServerName onestep.com | |
DocumentRoot /home/ljy/workspace/onestep/public/ | |
RailsEnv development | |
<Directory /home/ljy/workspace/onestep/public/ > | |
AllowOverride all | |
Options -MultiViews | |
</Directory> | |
</VirtualHost> | |
然后修改/etc/hosts与上面的ServerName对应起来: | |
sudo vi /etc/hosts, 添加下面两行: | |
127.0.1.1 ok.com | |
127.0.1.1 onestep.com | |
然后重启apache: | |
sudo apachectl graceful | |
# 如果之後你的Rails有任何修改要重新載入,但是並不想把Apache重開, | |
# 請在你的Rails應用程式目錄下執行touch tmp/restart.txt即可, | |
# 這樣Passenger就會知道要重新載入Rails, | |
# 而不需要重開Apache。(http://ihower.tw/rails3/deployment.html) | |
################################# | |
# | |
# PART 3: 产品环境下的一些具体操作 | |
# 和本地开发机器上有较大不同 | |
# | |
################################# | |
cd config | |
cp database.example.yml database.yml # 并在其中添加数据库密码 | |
bundle exec rake db:create RAILS_ENV=production # 这步为我们创建数据库,名为 onestep_production | |
touch tmp/restart.txt # need to create this for the first time, since tmp/ is in .gitignore | |
################################# | |
# | |
# PART 4: 这一部分的内容一般我会放到一个脚本中,放在本地做一键部署 | |
# https://gist.github.com/happypeter/3634487 | |
# | |
################################# | |
bundle exec rake db:migrate RAILS_ENV=production | |
bundle exec rake assets:precompile | |
mysql -uroot happycasts_production<happycasts_production.sql | |
################################# | |
# | |
# PART 5: 完成了上面几步,happycasts 就已经可以在浏览器中运行了 | |
# 但是一般我还会装一下一些工具 | |
# | |
################################# | |
sudo apt-get install ffmpeg # happycasts need this to get the video duration | |
sudo apt-get install tig tree ack-grep # make using git,vim things more comfortable on production server |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment