王筝的博客
ruby学习
chmod +x analyse_log copy_log

 

(1)拷贝脚本到本地

脚本内容如下:

#!/usr/bin/env bash

LOG_PATH=/opt/logs
LOCAL_LOG_PATH=~/Documents/logs/8-15
PROJECTS=(m-cms-for-tudou-tv m-cms-for-tv)

if [[ $1 == "--debug" ]]; then
  set -x
fi

# Create local directories
for project in ${projects[@]}; do
  mkdir -p $SAVE_TO/$project
done

# Copy m-cms-for-tv
project=m-cms-for-tv
remote_log_dir=$LOG_PATH/$project

for server in {13..15}; do
  for port in {5200..5207}; do
    server_ip="10.xxx.32.$server"
    local_log_dir=$LOCAL_LOG_PATH/$project/$server_ip
    log_file="thin server (0.0.0.0:$port)_2015-08-15.log"

    if [[ ! -e $local_log_dir/"$log_file" ]]; then
      mkdir -p $local_log_dir
      scp $server_ip:$remote_log_dir/"'$log_file'" $local_log_dir/$port.log
    fi
  done
done

# Copy m-cms-for-todou-tv
project=m-cms-for-tudou-tv
remote_log_dir=$LOG_PATH/$project

for server in {13..15}; do
  for port in {3201..3208}; do
    server_ip="10.xxx.32.$server"
    local_log_dir=$LOCAL_LOG_PATH/$project/$server_ip
    log_file="thin server (0.0.0.0:$port)_2015-08-15.log"

    if [[ ! -e $local_log_dir/"$log_file" ]]; then
      mkdir -p $local_log_dir
      scp $server_ip:$remote_log_dir/"'$log_file'" $local_log_dir/$port.log
    fi
  done
done

project=ott-client-cms
remote_log_dir=/opt/app/ruby/$project/current/log

for server in {13..15}; do
  server_ip="10.xxx.32.$server"
  local_log_dir=$LOCAL_LOG_PATH/$project/$server_ip
  log_file="nginx.access.20150815.log"

  if [[ ! -e $local_log_dir/"$log_file" ]]; then
    mkdir -p $local_log_dir
    scp $server_ip:$remote_log_dir/$log_file $local_log_dir/$log_file
  fi
done

执行:

$./copy_log

执行后拷贝的日志如下

thin server (0.0.0.0:5200)_2015-08-15.log                                                                           100%   37MB   4.1MB/s   00:09    
thin server (0.0.0.0:5201)_2015-08-15.log                                                                           100%   37MB   4.6MB/s   00:08    
thin server (0.0.0.0:5202)_2015-08-15.log                                                                           100%   37MB   4.6MB/s   00:08    
thin server (0.0.0.0:5203)_2015-08-15.log                                                                           100%   37MB   3.7MB/s   00:10    
thin server (0.0.0.0:5204)_2015-08-15.log                                                                           100%   37MB   4.6MB/s   00:08    
thin server (0.0.0.0:5205)_2015-08-15.log                                                                           100%   37MB   4.6MB/s   00:08    
thin server (0.0.0.0:5206)_2015-08-15.log                                                                           100%   37MB   2.6MB/s   00:14    
thin server (0.0.0.0:5207)_2015-08-15.log                                                                           100%   37MB   3.7MB/s   00:10    
thin server (0.0.0.0:5200)_2015-08-15.log                                                                           100%   37MB   6.2MB/s   00:06    
thin server (0.0.0.0:5201)_2015-08-15.log                                                                           100%   37MB   4.1MB/s   00:09    
thin server (0.0.0.0:5202)_2015-08-15.log                                                                           100%   37MB   3.7MB/s   00:10    
thin server (0.0.0.0:5203)_2015-08-15.log                                                                           100%   37MB   3.1MB/s   00:12    
thin server (0.0.0.0:5204)_2015-08-15.log                                                                           100%   37MB   3.4MB/s   00:11    
thin server (0.0.0.0:5205)_2015-08-15.log                                                                           100%   37MB   3.4MB/s   00:11    
thin server (0.0.0.0:5206)_2015-08-15.log                                                                           100%   37MB   2.7MB/s   00:14    
thin server (0.0.0.0:5207)_2015-08-15.log                                                                           100%   37MB   2.7MB/s   00:14    
thin server (0.0.0.0:5200)_2015-08-15.log                                                                           100%   37MB   3.4MB/s   00:11    
thin server (0.0.0.0:5201)_2015-08-15.log                                                                           100%   37MB   4.6MB/s   00:08    
thin server (0.0.0.0:5202)_2015-08-15.log                                                                           100%   37MB   4.6MB/s   00:08    
thin server (0.0.0.0:5203)_2015-08-15.log                                                                           100%   37MB   6.2MB/s   00:06    
thin server (0.0.0.0:5204)_2015-08-15.log                                                                           100%   37MB   3.1MB/s   00:12    
thin server (0.0.0.0:5205)_2015-08-15.log                                                                           100%   37MB   3.4MB/s   00:11    
thin server (0.0.0.0:5206)_2015-08-15.log                                                                           100%   37MB   4.7MB/s   00:08    
thin server (0.0.0.0:5207)_2015-08-15.log                                                                           100%   37MB   3.7MB/s   00:10    
thin server (0.0.0.0:3201)_2015-08-15.log                                                                           100%   64KB  63.7KB/s   00:00    
thin server (0.0.0.0:3202)_2015-08-15.log                                                                           100%   63KB  63.2KB/s   00:00    
thin server (0.0.0.0:3203)_2015-08-15.log                                                                           100%   69KB  68.9KB/s   00:00    
thin server (0.0.0.0:3204)_2015-08-15.log                                                                           100%   67KB  66.9KB/s   00:00    
thin server (0.0.0.0:3205)_2015-08-15.log                                                                           100%   55KB  55.5KB/s   00:00    
thin server (0.0.0.0:3206)_2015-08-15.log                                                                           100%   63KB  63.0KB/s   00:00    
thin server (0.0.0.0:3207)_2015-08-15.log                                                                           100%   57KB  56.7KB/s   00:00    
thin server (0.0.0.0:3208)_2015-08-15.log                                                                           100%   60KB  60.4KB/s   00:00    
scp: /opt/logs/m-cms-for-tudou-tv/thin server (0.0.0.0:3201)_2015-08-15.log: No such file or directory
thin server (0.0.0.0:3202)_2015-08-15.log                                                                           100%   51KB  50.7KB/s   00:00    
thin server (0.0.0.0:3203)_2015-08-15.log                                                                           100%   51KB  50.6KB/s   00:00    
thin server (0.0.0.0:3204)_2015-08-15.log                                                                           100%   52KB  52.5KB/s   00:00    
thin server (0.0.0.0:3205)_2015-08-15.log                                                                           100%   52KB  52.0KB/s   00:00    
thin server (0.0.0.0:3206)_2015-08-15.log                                                                           100%   49KB  49.1KB/s   00:00    
thin server (0.0.0.0:3207)_2015-08-15.log                                                                           100%   52KB  52.3KB/s   00:00    
thin server (0.0.0.0:3208)_2015-08-15.log                                                                           100%   52KB  52.4KB/s   00:00    
thin server (0.0.0.0:3201)_2015-08-15.log                                                                           100%   45KB  44.9KB/s   00:00    
thin server (0.0.0.0:3202)_2015-08-15.log                                                                           100%   44KB  43.7KB/s   00:00    
thin server (0.0.0.0:3203)_2015-08-15.log                                                                           100%   46KB  45.6KB/s   00:00    
thin server (0.0.0.0:3204)_2015-08-15.log                                                                           100%   46KB  46.1KB/s   00:00    
thin server (0.0.0.0:3205)_2015-08-15.log                                                                           100%   43KB  43.4KB/s   00:00    
thin server (0.0.0.0:3206)_2015-08-15.log                                                                           100%   46KB  45.7KB/s   00:00    
thin server (0.0.0.0:3207)_2015-08-15.log                                                                           100%   44KB  44.5KB/s   00:00    
thin server (0.0.0.0:3208)_2015-08-15.log                                                                           100%   44KB  43.6KB/s   00:00    
nginx.access.20150815.log                                                                                           100%   81MB   4.3MB/s   00:19    
nginx.access.20150815.log                                                                                           100%   81MB   4.1MB/s   00:20    
nginx.access.20150815.log                                                                                           100%   81MB   2.7MB/s   00:30

 

 

(2)分析日志

分析日志的脚本如下:

#!/usr/bin/env bash

if [[ $1 == "--debug" ]]; then
  set -x
fi

LOG_PATH=~/Documents/logs/8-15
TMP_FILE=/tmp/analyse_cat.log

tv() {
  project=$1
  log_files=$LOG_PATH/$project/**/*.log

  for hour in {15..16}; do
    for min in {0..5}; do
      if [[ $hour -lt 10  ]]; then
        str="2015-08-15 0$hour:$min"
      else
        str="2015-08-15 $hour:$min"
      fi  

      request_count=$(grep "$str" $log_files | wc -l)
      response_count=$(grep "^$hour:$min" $log_files | grep Completed | wc -l)
      grep "^$hour:$min" $log_files | grep Completed > $TMP_FILE

      echo "------- $str 时总请求数: $request_count,响应数:$response_count"
      echo '响应码:'
      cut -d ' ' -f4 $TMP_FILE | sort -n | uniq -c
      # echo '响应时间:'
      # cut -d ' ' -f7 $TMP_FILE | sort -n | uniq -c | sort -nr
    done
  done
}

echo '*** Youku TV ***'
tv m-cms-for-tv

echo '*** Tubou TV ***'
tv m-cms-for-tudou-tv

执行

$ ./analyse_log

执行后的结果

~/Desktop:$ ./analyse_log 
*** Youku TV ***
------- 2015-08-15 15:0 时总请求数: 10934,响应数:10934
响应码:
  10934 200
------- 2015-08-15 15:1 时总请求数: 10908,响应数:10908
响应码:
  10908 200
------- 2015-08-15 15:2 时总请求数: 10903,响应数:10903
响应码:
  10903 200
------- 2015-08-15 15:3 时总请求数: 7184,响应数:7160
响应码:
   7160 200
------- 2015-08-15 15:4 时总请求数: 552,响应数:0
响应码:
------- 2015-08-15 15:5 时总请求数: 194063,响应数:193978
响应码:
 193978 200
------- 2015-08-15 16:0 时总请求数: 142234,响应数:142233
响应码:
 142233 200
------- 2015-08-15 16:1 时总请求数: 195244,响应数:195244
响应码:
 195244 200
------- 2015-08-15 16:2 时总请求数: 233320,响应数:233342
响应码:
 233342 200
------- 2015-08-15 16:3 时总请求数: 12787,响应数:12788
响应码:
  12788 200
------- 2015-08-15 16:4 时总请求数: 11341,响应数:11341
响应码:
  11341 200
------- 2015-08-15 16:5 时总请求数: 12470,响应数:12470
响应码:
  12470 200
*** Tubou TV ***
------- 2015-08-15 15:0 时总请求数: 5,响应数:5
响应码:
      5 200
------- 2015-08-15 15:1 时总请求数: 3,响应数:3
响应码:
      3 200
------- 2015-08-15 15:2 时总请求数: 39,响应数:39
响应码:
     39 200
------- 2015-08-15 15:3 时总请求数: 11,响应数:3
响应码:
      3 200
------- 2015-08-15 15:4 时总请求数: 31,响应数:0
响应码:
------- 2015-08-15 15:5 时总请求数: 1315,响应数:1288
响应码:
   1288 200
------- 2015-08-15 16:0 时总请求数: 9,响应数:9
响应码:
      9 200
------- 2015-08-15 16:1 时总请求数: 2,响应数:2
响应码:
      2 200
------- 2015-08-15 16:2 时总请求数: 39,响应数:39
响应码:
     39 200
------- 2015-08-15 16:3 时总请求数: 10,响应数:10
响应码:
     10 200
------- 2015-08-15 16:4 时总请求数: 2,响应数:2
响应码:
      2 200
------- 2015-08-15 16:5 时总请求数: 15,响应数:15
响应码:
     15 200

 

部署完的新机器报错

App 12595 stderr: PG::ConnectionBad (FATAL:  Peer authentication failed for user "dbuser"
App 12595 stderr: ):

上网查了一下,很多帖子上都在说要修改/etc/postgresql/9.4/main/pg_hba.conf这个文件,然而并没有什么用

回忆一下整个数据库搭建过程

(1)创建数据库用户dbuser,并指定其为超级用户

sudo -u postgres createuser --superuser dbuser

(2)创建数据库uppers_staging, 并指定所有者为dbuser

sudo -u postgres createdb -O dbuser uppers_staging

 

(3)给dbuser设置登录密码(之前没设置密码的时候登录报这个错psql: fe_sendauth: no password supplied,设置了就ok了)

root@i-1lb6pxls:/home/ubuntu/campo/shared# sudo -u postgres psql
psql (9.4.4)
Type "help" for help.

postgres=# \password dbuser
Enter new password: 
Enter it again: 
postgres=# \q

(4)登录查看下数据库

root@i-1lb6pxls:/home/ubuntu/campo/current# psql -U dbuser -d uppers_staging -h 127.0.0.1 
Password for user dbuser: 
psql (9.4.4)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.

uppers_staging=> \l
                                      List of databases
        Name        |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
--------------------+----------+----------+-------------+-------------+-----------------------
 postgres           | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0          | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
                    |          |          |             |             | postgres=CTc/postgres
 template1          | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
                    |          |          |             |             | postgres=CTc/postgres
 uppers_development | root     | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 uppers_staging     | dbuser   | UTF8     | en_US.UTF-8 | en_US.UTF-8 |

dbuser的权限

uppers_staging=> \du
                             List of roles
 Role name |                   Attributes                   | Member of 
-----------+------------------------------------------------+-----------
 dbuser    |                                                | {}
 postgres  | Superuser, Create role, Create DB, Replication | {}
 root      | Superuser, Create role, Create DB              | {}

接下来需要讲数据库uppers_staging 的所有权限都赋给dbuser,否则dbuser只能登录控制台,没有操作数据库的权限

 GRANT ALL PRIVILEGES ON DATABASE uppers_staging to dbuser;

这时候再来看一下数据库列表

uppers_staging=> \l
                                      List of databases
        Name        |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
--------------------+----------+----------+-------------+-------------+-----------------------
 postgres           | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0          | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
                    |          |          |             |             | postgres=CTc/postgres
 template1          | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
                    |          |          |             |             | postgres=CTc/postgres
 uppers_development | root     | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 uppers_staging     | dbuser   | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/dbuser           +
                    |          |          |             |             | dbuser=CTc/dbuser

报错的原因其实就是没有授权 @_@

常见的数据库操作命令如下

\h:查看SQL命令的解释,比如\h select。
\?:查看psql命令列表。
\l:列出所有数据库。
\c [database_name]:连接其他数据库。
\d:列出当前数据库的所有表格。
\d [table_name]:列出某一张表格的结构。
\du:列出所有用户。
\e:打开文本编辑器。
\conninfo:列出当前数据库和连接的信息。

 

今天部署了新服务器发现cache目录没有权限,

App 26772 stderr: Started GET "/investors" for 103.238.226.130 at 2015-08-25 11:25:47 +0800
App 26772 stderr: Processing by InvestorsController#index as HTML
App 26772 stderr: Read fragment views/investors/1-20150825032428475102000/zh-CN/ba9ec9f1a927c00438fab3e53de969e8 (0.2ms)
App 26772 stderr: Write fragment views/investors/1-20150825032428475102000/zh-CN/ba9ec9f1a927c00438fab3e53de969e8 (0.8ms)
App 26772 stderr:   Rendered investors/_investor.html.slim (3.8ms)
App 26772 stderr:   Rendered investors/index.html.slim within layouts/application (10.1ms)
App 26772 stderr: Completed 500 Internal Server Error in 13ms
App 26772 stderr: 
App 26772 stderr: ActionView::Template::Error (Permission denied - /home/ubuntu/campo/releases/20150824101227/tmp/cache/84B):
App 26772 stderr:     1: - cache [investor, locale] do
App 26772 stderr:     2:   .investor-frame
App 26772 stderr:     3:     .investor  id="investor-#{investor.id}"
App 26772 stderr:     4:       .investor-content
App 26772 stderr:   app/views/investors/_investor.html.slim:1:in `_app_views_investors__investor_html_slim___4107010476464905044_55536860'
App 26772 stderr:   app/views/investors/index.html.slim:40:in `_app_views_investors_index_html_slim___256757312322326570_55623180'
App 26772 stderr:

查一下文件夹目录的权限

# namei -om /home/ubuntu/campo/releases/20150824101227/tmp/cache
f: /home/ubuntu/campo/releases/20150824101227/tmp/cache
 drwxr-xr-x root   root   /
 drwxr-xr-x root   root   home
 drwxr-xr-x ubuntu ubuntu ubuntu
 drwxr-xr-x root   root   campo
 drwxr-xr-x root   root   releases
 drwxr-xr-x root   root   20150824101227
 drwxr-xr-x root   root   tmp
 lrwxrwxrwx root   root   cache -> /home/ubuntu/campo/shared/tmp/cache
   drwxr-xr-x root   root   /
   drwxr-xr-x root   root   home
   drwxr-xr-x ubuntu ubuntu ubuntu
   drwxr-xr-x root   root   campo
   drwxr-xr-x root   root   shared
   drwxr-xr-x root   root   tmp
   drwxr-xr-x root   root   cache

网上看了一下没有太好的方法,只能先修改下权限了

# chmod 777 /home/ubuntu/campo/shared/tmp/cache/

 

 

部署新服务器之后发现,服务器上没有console命令了

root@i-1lb6pxls:/home/ubuntu/campo/current# bundle exec rails c
Usage:
  rails new APP_PATH [options]

Options:
  -r, [--ruby=PATH]                                      # Path to the Ruby binary of your choice
                                                         # Default: /usr/local/rvm/rubies/ruby-2.0.0-p643/bin/ruby
  -m, [--template=TEMPLATE]                              # Path to some application template (can be a filesystem path or URL)
      [--skip-gemfile], [--no-skip-gemfile]              # Don't create a Gemfile
  -B, [--skip-bundle], [--no-skip-bundle]                # Don't run bundle install
  -G, [--skip-git], [--no-skip-git]                      # Skip .gitignore file
      [--skip-keeps], [--no-skip-keeps]                  # Skip source control .keep files
  -O, [--skip-active-record], [--no-skip-active-record]  # Skip Active Record files
  -V, [--skip-action-view], [--no-skip-action-view]      # Skip Action View files
  -S, [--skip-sprockets], [--no-skip-sprockets]          # Skip Sprockets files
      [--skip-spring], [--no-skip-spring]                # Don't install Spring application preloader
  -d, [--database=DATABASE]                              # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)
                                                         # Default: sqlite3
  -j, [--javascript=JAVASCRIPT]                          # Preconfigure for selected JavaScript library
                                                         # Default: jquery
  -J, [--skip-javascript], [--no-skip-javascript]        # Skip JavaScript files
      [--dev], [--no-dev]                                # Setup the application with Gemfile pointing to your Rails checkout
      [--edge], [--no-edge]                              # Setup the application with Gemfile pointing to Rails repository
  -T, [--skip-test-unit], [--no-skip-test-unit]          # Skip Test::Unit files
      [--rc=RC]                                          # Path to file containing extra configuration options for rails command
      [--no-rc], [--no-no-rc]                            # Skip loading of extra configuration options from .railsrc file

Runtime options:
  -f, [--force]                    # Overwrite files that already exist
  -p, [--pretend], [--no-pretend]  # Run but do not make any changes
  -q, [--quiet], [--no-quiet]      # Suppress status output
  -s, [--skip], [--no-skip]        # Skip files that already exist

Rails options:
  -h, [--help], [--no-help]        # Show this help message and quit
  -v, [--version], [--no-version]  # Show Rails version number and quit

Description:
    The 'rails new' command creates a new Rails application with a default
    directory structure and configuration at the path you specify.

    You can specify extra command-line arguments to be used every time
    'rails new' runs in the .railsrc configuration file in your home directory.

    Note that the arguments specified in the .railsrc file don't affect the
    defaults values shown above in this help message.

Example:
    rails new ~/Code/Ruby/weblog

    This generates a skeletal Rails installation in ~/Code/Ruby/weblog.
    See the README in the newly created application to get going.

看了一下文件发现bin目录有个软链接,

root@i-1lb6pxls:/home/ubuntu/campo/current# ls -al
total 136
drwxr-xr-x 12 root root  4096 Aug 24 18:12 .
drwxr-xr-x  7 root root  4096 Aug 24 18:12 ..
drwxrwxr-x 10 root root  4096 Aug 18 16:23 app
-rw-r--r--  1 root root 26401 Aug 24 18:12 assets_manifest_backup
lrwxrwxrwx  1 root root    29 Aug 24 18:12 bin -> /home/ubuntu/campo/shared/bin
drwxrwxr-x  2 root root  4096 Aug 24 18:12 .bundle
-rw-rw-r--  1 root root   386 Aug 18 16:23 Capfile
-rw-rw-r--  1 root root   337 Aug 18 16:23 CHANGELOG.md
drwxrwxr-x  5 root root  4096 Aug 24 18:12 config
-rw-rw-r--  1 root root   154 Aug 18 16:23 config.ru
drwxrwxr-x  3 root root  4096 Aug 18 16:23 db
-rw-rw-r--  1 root root  2988 Aug 18 16:23 Gemfile
-rw-rw-r--  1 root root  9758 Aug 18 16:23 Gemfile.lock
-rw-rw-r--  1 root root   727 Aug 18 16:23 .gitignore
-rw-rw-r--  1 root root   459 Aug 18 16:23 Guardfile
drwxrwxr-x  4 root root  4096 Aug 18 16:23 lib
-rw-rw-r--  1 root root  1128 Aug 18 16:23 LICENSE.md
lrwxrwxrwx  1 root root    29 Aug 24 18:12 log -> /home/ubuntu/campo/shared/log
drwxrwxr-x  2 root root  4096 Aug 24 18:12 public
-rw-rw-r--  1 root root   249 Aug 18 16:23 Rakefile
-rw-rw-r--  1 root root   258 Aug 18 16:23 README.md
-rw-rw-r--  1 root root    11 Aug 18 16:23 .ruby-version
drwxrwxr-x  2 root root  4096 Aug 18 16:23 script
drwxrwxr-x 11 root root  4096 Aug 18 16:23 test
drwxr-xr-x  2 root root  4096 Aug 24 18:12 tmp
-rw-rw-r--  1 root root   438 Aug 18 16:23 .travis.yml
-rw-rw-r--  1 root root   615 Aug 18 16:23 Vagrantfile
drwxrwxr-x  3 root root  4096 Aug 24 18:12 vendor

先删除了链接

# rm bin

然后再新建个文件夹重新生成一下目录的内容就ok啦

root@i-1lb6pxls:/home/ubuntu/campo/current# mkdir bin
root@i-1lb6pxls:/home/ubuntu/campo/current# rake rails:update:bin
       exist  bin
      create  bin/bundle
      create  bin/rails
      create  bin/rake

如果记不清rake命令了可以查一下

root@i-1lb6pxls:/home/ubuntu/campo/current# rake -T
rake about                              # List versions of all Rails frameworks and the environment
rake assets:clean[keep]                 # Remove old compiled assets
rake assets:clobber                     # Remove compiled assets
rake assets:environment                 # Load asset compile environment
rake assets:precompile                  # Compile all the assets named in config.assets.precompile
rake cache_digests:dependencies         # Lookup first-level dependencies for TEMPLATE (like messages/show or comments/_comment.html)
rake cache_digests:nested_dependencies  # Lookup nested dependencies for TEMPLATE (like messages/show or comments/_comment.html)
rake db:create                          # Creates the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:create:...
rake db:drop                            # Drops the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:drop:all ...
rake db:fixtures:load                   # Load fixtures into the current environment's database
rake db:migrate                         # Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)
rake db:migrate:status                  # Display status of migrations
rake db:populate                        # Fill database with sample data
rake db:rollback                        # Rolls the schema back to the previous version (specify steps w/ STEP=n)
rake db:schema:cache:clear              # Clear a db/schema_cache.dump file
rake db:schema:cache:dump               # Create a db/schema_cache.dump file
rake db:schema:dump                     # Create a db/schema.rb file that is portable against any DB supported by AR
rake db:schema:load                     # Load a schema.rb file into the database
rake db:seed                            # Load the seed data from db/seeds.rb
rake db:send_invitations                # send_invitations_to_all
rake db:setup                           # Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the ...
rake db:structure:dump                  # Dump the database structure to db/structure.sql
rake db:version                         # Retrieves the current schema version number
rake doc:app                            # Generate docs for the app -- also available doc:rails, doc:guides (options: TEMPLATE=/rdoc-template.rb,...
rake elasticsearch:import:all           # Import all indices from `app/models` (or use DIR environment variable)
rake elasticsearch:import:model         # Import data from your model (pass name as CLASS environment variable)
rake log:clear                          # Truncates all *.log files in log/ to zero bytes (specify which logs with LOGS=test,development)
rake middleware                         # Prints out your Rack middleware stack
rake notes                              # Enumerate all annotations (use notes:optimize, :fixme, :todo for focus)
rake notes:custom                       # Enumerate a custom annotation, specify with ANNOTATION=CUSTOM
rake rails:template                     # Applies the template supplied by LOCATION=(/path/to/template) or URL
rake rails:update                       # Update configs and some other initially generated files (or use just update:configs or update:bin)
rake rails_admin:install                # Install rails_admin
rake rails_admin:prepare_ci_env         # CI env for Travis
rake rails_admin:uninstall              # Uninstall rails_admin
rake resque:failures:sort               # Sort the 'failed' queue for the redis_multi_queue failure backend
rake resque:work                        # Start a Resque worker
rake resque:workers                     # Start multiple Resque workers
rake routes                             # Print out all defined routes in match order, with names
rake secret                             # Generate a cryptographically secure secret key (this is typically used to generate a secret for cookie ...
rake stats                              # Report code statistics (KLOCs, etc) from the application
rake test                               # Runs test:units, test:functionals, test:generators, test:integration together
rake test:all                           # Run tests quickly by merging all types and not resetting db
rake test:all:db                        # Run tests quickly, but also reset db
rake time:zones:all                     # Displays all time zones, also available: time:zones:us, time:zones:local -- filter with OFFSET paramete...
rake tmp:clear                          # Clear session, cache, and socket files from tmp/ (narrow w/ tmp:sessions:clear, tmp:cache:clear, tmp:so...
rake tmp:create                         # Creates tmp directories for sessions, cache, sockets, and pids

接下来就可以运行console啦

RAILS_ENV=staging bundle exec rails c

 

# gem install json -v ‘1.8.3’
Building native extensions. This could take a while…
ERROR: Error installing json:
ERROR: Failed to build gem native extension.

/usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file — mkmf (LoadError)
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require’
from extconf.rb:1:in `<main>’
Gem files will remain installed in /var/lib/gems/1.9.1/gems/json-1.8.3 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/json-1.8.3/ext/json/ext/generator/gem_make.out
解决问题的方法是

# sudo apt-get install ruby-dev

or

#yum install ruby-devel

== 测试服务器是:  test132 
== 正式服务器是:  133, 134 
== which server do you want to deploy to? (test132/133/134/83)? 134
== password for 10.xxx.xx.134 is: 
    triggering start callbacks for `deploy'
  * executing `rbenv:setup_default_environment'
  * executing "echo \"$HOME/.rbenv\""
    servers: ["10.100.27.134"]
connection failed for: 10.xxx.xx.134 (ArgumentError: invalid byte sequence in US-ASCII)

 

网上写的解决方法主要有两种,我是用第一种方法解决的

(1)修改本机的语言设置

export LANG="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"

楼主只用以上两句解决了问题,发现有的网站还补充了一句,我没执行下面这句就已经能部署了

export  LANGUAGE=en_US.UTF-8

 

(2)修改Gemfile, put this into your Gemfile , 楼主没有用这个方法,有足够探索未知世界的好奇宝宝们可以撸袖子试试

if RUBY_VERSION =~ /1.9/
  Encoding.default_external = Encoding::UTF_8
  Encoding.default_internal = Encoding::UTF_8
end

 

https://github.com/sstephenson/rbenv

  • Check out rbenv into ~/.rbenv.
    $ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
  • Add ~/.rbenv/bin to your $PATH for access to the rbenv command-line utility.
    $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile

    Ubuntu Desktop note: Modify your ~/.bashrc instead of ~/.bash_profile.

    Zsh note: Modify your ~/.zshrc file instead of ~/.bash_profile.

  • Add rbenv init to your shell to enable shims and autocompletion.
    $ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile

    Same as in previous step, use ~/.bashrc on Ubuntu, or ~/.zshrc for Zsh.

  • Restart your shell so that PATH changes take effect. (Opening a new terminal tab will usually do it.) Now check if rbenv was set up:
    $ type rbenv
    #=> "rbenv is a function"
  • (Optional) Install ruby-build, which provides the rbenv install command that simplifies the process ofinstalling new Ruby versions.

 

Upgrading

If you’ve installed rbenv manually using git, you can upgrade your installation to the cutting-edge version at any time.

$ cd ~/.rbenv
$ git pull

To use a specific release of rbenv, check out the corresponding tag:

$ cd ~/.rbenv
$ git fetch
$ git checkout v0.3.0
--------------------------------------------

$rbenv install –list     如果发现没有自己想要装的版本
$cd ~/.rbenv
$git pull
$cd plugins
$cd ruby-build
$git pull
$rbenv install –list
$rbenv install 2.1.2

==========如果这时候下载不了====

查看https://github.com/sstephenson/ruby-build#readme

Package download caching

You can instruct ruby-build to keep a local cache of downloaded package files by setting theRUBY_BUILD_CACHE_PATH environment variable. When set, package files will be kept in this directory after the first successful download and reused by subsequent invocations of ruby-build and rbenv install.

The rbenv install command defaults this path to ~/.rbenv/cache, so in most cases you can enable download caching simply by creating that directory.

新建个cache文件夹,手动下载安装包

2001 cd ~/.rbenv/
2002 ll
2003 mkdir cache
2004 cd cha
2005 cd cache/
2006 wget http://ruby.taobao.org/mirrors/ruby/ruby-2.2.2.tar.gz
2007 cd
2008 rbenv install 2.2.2 -v

=====================
$ruby -v
$rbenv global 2.1.2
$rbenv versions
还有一种方式是
$export RBENV_VERSION=2.1.2
但是这种方式只在当前终端窗口有效
$gem install rails
这时候会发现速度超级慢,
$gem list
$gem source -l
来到网页看一下吧 ruby.taobao.org,接着按照网页提示操作
$gem sources –remove http://rubygems.org/
….

$gem install bundler -V

新装的ruby里是没有bundler,rails这些gem,需要先安装一下

$bundle -V

这样就会自动安装项目里所有需要安装的gem

 

<%= f.datetime_select :updated_at %> 可以对时间和日期进行修改

存一个8月5号,总会自动保存成5月8,于是做了限制

s = “08/20/2015 3:31 PM”
dt = DateTime.strptime s, “%m/%d/%Y %H:%M %p”

参考文档:http://ruby-doc.org/stdlib-2.2.2/libdoc/date/rdoc /Date.html#method-c-strptime
http://ruby-doc.org/stdlib-2.2.2/libdoc/date/rdoc/Date.html#method-i-strftime

$ RAILS_ENV=production bundle exec rails c
There is a version mismatch between the spring client and the server.
You should restart the server and make sure to use the same version.

CLIENT: 1.3.6, SERVER: 1.3.5

 

$ spring status
Spring is running:

17284 spring server | new_uppers | started 22 hours ago
Warning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.html
 6291 spring app    | new_uppers | started 8 mins ago | development mode

 

$ spring stop
Spring stopped.

重新启动

$ spring
Version: 1.3.6

 

 

https://github.com/shadowsocks/shadowsocks

https://github.com/shadowsocks/shadowsocks/wiki/Configuration-via-Config-File

A fast tunnel proxy that helps you bypass firewalls

(1)楼主用的是CentOS服务器,所以安装及配置如下

yum install python-setuptools && easy_install pip
pip install shadowsocks

接下来在服务器上配置下To run in the background:

sudo ssserver -p 8761 -k password -m aes-256-cfb --user nobody -d start

想停止的时候在服务器执行以下命令To stop:

sudo ssserver -d stop

(2)到自己的本地电脑上增加一些配置:

vim /home/wangz/.ss_config.json
{
  "server":"1xx.xxx.xx.xx",  #这里填写服务器地址
  "server_port":8761,   #这个端口就是刚才配置的端口
  "local_port":1080,
  "password":"password", #这里的password就刚才配置的-k后面的内容
  "timeout":600,
  "method":"aes-256-cfb"    #这个就是刚才-m后面配置的内容
}

本地启动下

sslocal -c /home/wangz/.ss_config.json -d start