20180208

2018年02月08日

肖威工作总结

微信公众号支付开发中的坑(Ruby on Rails示例) http://evedreamer.com/2016/01/17/wechat-pay-with-jsapi-by-ruby-on-rails/

rails上使用微信支付(wx_pay gem),不是ping ++。 http://siwei.me/blog/posts/rails-wx_pay-gem-ping

微信支付总结 - Ruby on Rails 5 https://medium.com/@1003211008/%E5%BE%AE%E4%BF%A1%E6%94%AF%E4%BB%98%E6%80%BB%E7%BB%93-ruby-on-rails-5-c1b43ad37888

分享 Rails开发微信支付的一些总结 https://ruby-china.org/topics/27592

支付宝 / doc /quick_start_cn.md https://github.com/chloerei/alipay/blob/master/doc/quick_start_cn.md

Rails布署最佳实践 介绍 Rails 项目在 Ubuntu 下使用 nginx + puma + mina 布署方案

  1. 准备工作

购买域名:http://name.com/ 购买一台云服务器, 提供商: 阿里云,AWS 域名绑定IP为服务器IP地址 本文介绍的内容为:服务器 ubuntu16.04, Rails项目,mina 发布

  1. 安装rails环境

使用 root 账号登录服务器,创建一个没有root权限的账号。 $ adduser newuser 设置新用户密码

2.1 配置 ssh

在本地生成 SSH KEY (如果已经有了,可以忽略这步。)

打开终端

用你自己的邮箱地址替换下面的命令,并执行

$ ssh-keygen -t rsa -b 4096 -C "[email protected]" 执行这条命令时,系统会提示你输入要保存密钥的文件位置及安全passphrase,请按Enter键就行了。 生成完之后,在 ~/.ssh/ 目录下会添加两个文件,默认情况下一个私钥 id_rsa, 一个公钥 id_rsa.pub.

2.2 配置无密码登录服务器

这一步是为了给mina发布提供方便,因为mina发布需要无密登录服务器,执行发布命令。

将公钥 id_rsa.pub 文件上传到服务器上, 并添加到 authorized_keys $ scp ~/.ssh/id_rsa.pub [email protected]:~/.ssh/

$ ssh [email protected]

$ cd ~/.ssh/

$ cat id_rsa.pub >> authorized_keys

$ rm id_rsa.pub 重新开一个终端, 登录服务器,如果无需输入密码登录成功,那上面的配置就成功了。 $ ssh [email protected] 以上是配置 root 用户无密码登录, 同样给 newuser 用户配置成无密码登录。

登录 root 账号,将服务器上的 ssh 配置关掉密码登录 $ vi /etc/ssh/sshd_config

更新:

PasswordAuthentication no 2.3 安装 Node.js 和 Yarn 的系统依赖

为了确保能顺利安装Rails,先要安装 Node.js 和 Yarn 的系统依赖

以下操作使用 root 账号执行

$ curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - $ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - $ echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

$ sudo apt-get update $ sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev nodejs yarn 2.4 安装 rbenv

以下操作使用 newuser 账号执行

$ cd $ git clone https://github.com/rbenv/rbenv.git ~/.rbenv $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc $ echo 'eval "$(rbenv init -)"' >> ~/.bashrc $ exec $SHELL

$ git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build $ echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc $ exec $SHELL

$ rbenv install 2.4.3 $ rbenv global 2.4.3 $ ruby -v $ gem install bundler $ rbenv rehash 2.5 配置git账号

以下操作使用 newuser 账号执行

用你的github账号信息,替换下面的用户名和邮箱,并执行 $ git config --global color.ui true $ git config --global user.name "YOUR NAME" $ git config --global user.email "[email protected]" $ ssh-keygen -t rsa -b 4096 -C "[email protected]" 在服务器上生成了ssh key后, 将下面命令输出的内容,复制后粘贴到你github账号SSH and GPG keys下:https://github.com/settings/keys

$ cat ~/.ssh/id_rsa.pub 测试github配置是否成功 $ ssh -T [email protected] 如果成功会输出以下信息:

Hi xxxx! You've successfully authenticated, but GitHub does not provide shell access. 2.6 安装 Rails

使用 newuser 账号执行以下命令 $ gem install rails -v 5.1.4

$ rbenv rehash

$ rails -v

Rails 5.1.4

2.7 安装 MySQL

使用 root 账号执行以下命令 $ sudo apt-get install mysql-server mysql-client libmysqlclient-dev 2.8 安装 PostgreSQL

使用 root 账号执行以下命令 $ sudo sh -c "echo 'deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main' > /etc/apt/sources.list.d/pgdg.list" $ wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add - $ sudo apt-get update $ sudo apt-get install postgresql-common $ sudo apt-get install postgresql-9.5 libpq-dev postgres安装不会为你设置一个用户,所以你需要按照以下步骤创建一个有权创建数据库的用户。 随意用你的用户名替换 chris。

$ sudo -u postgres createuser chris -s

If you would like to set a password for the user, you can do the following

$ sudo -u postgres psql $ postgres=# \password chris

  1. 配置nginx

使用 root 账号登录服务器

将 home/newuser/xxx, xxx 的目录改成你发布项目的目录,将 example.com 改成你的域名。

upstream RBlog { server unix:///home/newuser/xxx/shared/tmp/sockets/puma.sock fail_timeout=0; }

server { listen 80; server_name example.com; root /home/newuser/xxx/current/public;

location ^~ /assets/ { gzip_static on; expires max; add_header Cache-Control public; }

location /cable { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://xxx; }

location ~ ^/(uploads)/ { expires max; break; }

try_files $uri/index.html $uri @RBlog; location @xxx { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_redirect off; proxy_pass http://xxx; }

error_page 500 502 503 504 /500.html; client_max_body_size 20M; keepalive_timeout 10; } 将以上更换后的配置信息,保存到 /etc/nginx/conf.d/ 目录下,命令为 xxx.conf xxx 用你想要的命名替换。

测试配置信息是否OK

$ nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

重新加载 nginx $ nginx -s reload

  1. 发布Rails项目

如果你是用这个 模板 创建的Rails项目, 以下配置信息都已经添加了,只需要更新目录信息就行。

如果没有需要在Gemfile里添加这些gem包。

gem 'mina', '~>0.3.8', require: false gem 'mina-puma', '~>0.3.2', require: false gem 'mina-multistage', '~> 1.0', '>= 1.0.2', require: false gem 'mina-sidekiq', '~> 0.3.1', require: false gem 'mina-logs', '>= 0.1.0', require: false gem 'whenever', :require => false 4.1 配置 puma

在你的Rails项目下配置 puma,config/puma.rb, 替换 /home/newuser/xxx 目录.

if ENV['RAILS_ENV'] == 'production' app_root = "/home/newuser/xxx/shared" pidfile "#{app_root}/tmp/pids/puma.pid" state_path "#{app_root}/tmp/pids/puma.state" bind "unix://#{app_root}/tmp/sockets/puma.sock" activate_control_app "unix://#{app_root}/tmp/sockets/pumactl.sock" daemonize true workers 4 threads 8, 16 preload_app!

on_worker_boot do ActiveSupport.on_load(:active_record) do ActiveRecord::Base.establish_connection end end

before_fork do ActiveRecord::Base.connection_pool.disconnect! end else plugin :tmp_restart end 4.2 配置config/deploy.rb

set :stages, %w(production) set :default_stage, 'production'

require 'mina/multistage' require 'mina/bundler' require 'mina/rails' require 'mina/git' require 'mina/rbenv' require 'mina/puma' require "mina_sidekiq/tasks" require 'mina/logs' require 'mina/whenever'

set :shared_paths, ['config/database.yml', 'config/newrelic.yml', 'config/application.yml', 'log', 'public/uploads']

task :environment do invoke :'rbenv:load' end

task :setup => :environment do queue! %[mkdir -p "#{deploy_to}/shared/tmp/sockets"] queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/tmp/sockets"]

queue! %[mkdir -p "#{deploy_to}/shared/pids"] queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/pids"]

queue! %[mkdir -p "#{deploy_to}/shared/tmp/pids"] queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/tmp/pids"]

queue! %[mkdir -p "#{deploy_to}/#{shared_path}/log"] queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/log"]

queue! %[mkdir -p "#{deploy_to}/#{shared_path}/public/uploads"] queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/public/uploads"]

queue! %[mkdir -p "#{deploy_to}/#{shared_path}/config"] queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/config"]

queue! %[touch "#{deploy_to}/#{shared_path}/config/application.yml"] queue %[echo "-----> Be sure to edit '#{deploy_to}/#{shared_path}/config/application.yml'"]

queue! %[touch "#{deploy_to}/#{shared_path}/config/database.yml"] queue %[echo "-----> Be sure to edit '#{deploy_to}/#{shared_path}/config/database.yml'"] end

desc "Deploys the current version to the server." task :deploy => :environment do queue %[echo "-----> Server: #{domain}"] queue %[echo "-----> Path: #{deploy_to}"] queue %[echo "-----> Branch: #{branch}"]

deploy do invoke :'sidekiq:quiet' invoke :'git:clone' invoke :'deploy:link_shared_paths' invoke :'bundle:install' invoke :'rails:db_migrate' invoke :'rails:assets_precompile' invoke :'deploy:cleanup'

to :launch do
  invoke :'puma:hard_restart'
  invoke :'sidekiq:restart'
  invoke :'whenever:update'
end

end end

desc "Deploys the current version to the server." task :first_deploy => :environment do queue %[echo "-----> Server: #{domain}"] queue %[echo "-----> Path: #{deploy_to}"] queue %[echo "-----> Branch: #{branch}"]

deploy do invoke :'git:clone' invoke :'deploy:link_shared_paths' invoke :'bundle:install' invoke :'deploy:cleanup'

to :launch do
  invoke :'rails:db_create'
end

end end 4.3 配置 config/deploy/production.rb

将domain, deploy_to, repository, branch, user替换成你自己的信息。

set :domain, 'your.domain.com' set :deploy_to, '/home/newuser/xxx' set :repository, '[email protected]:xxx/xxx.git' set :branch, 'master' set :user, 'newuser' set :puma_config, ->{ "#{deploy_to}/#{current_path}/config/puma/production.rb" } 这些配置信息更新好之后,提交到github

4.4 首次发布

$ mina setup $ mina first_deploy 4.5 后续发布

$ mina deploy 4.6 本地查看生产环境日志

$ mina log 4.7 本地登录生产环境数据库控制台

$ mina console 4.8 本地登录服务器

$ mina ssh

  1. 参考文档

Ubuntu 安装 Rails 环境: https://gorails.com/setup/ubuntu/16.04

Mina 配置: https://github.com/80percent/rails-template

个人简历的样板

个人信息

刘祯 / 女 / rina.liuzhen#gmail.com

深圳 / 中南林业科技大学(本科) / 5 年工作经验 / 个人博客

个人简介

Rails 全栈工程师一枚, 独立做过 Goda, ECS 创业项目, 是 CoFund 项目的主要负责人. 现在专注于前端开发. 利用 Vue.js 实现了一个 v2ex 的克隆版本. 近期又利用 React 实现了一个 RubyChina 的克隆版本.

个人擅长:

前端: HTML5, CSS, Javascript, ReacJS, Vue.js, AngularJS, Bootstrap, Foundation, UIkit

后端: Rails

主要个人作品

V2EX - vue.js 项目

V2EX 是一个利用 vue.js 和 v2ex api 实现的 V2EX 社区克隆项目, 主要目的是为了熟悉 vue.js.

这是一个前后端分离项目, 前端主要是 vue.js 和 vue-router, css 框架使用了 uikit. 后端利用 v2ex 开放的 api. 支持响应式布局. 目前已有 307+ star 数.

GitHub: https://github.com/liuzhenangel/v2ex_frontend

核心技术框架

vue.js uikit lodash vue-paginate vue-router RubyChina - React 项目

react-ruby-china 项目是一个利用 react, react-dom, react-redux, react-router, redux, es6 和 redux-thunk 实现的 RubyChina 社区克隆项目, 主要目的是为了熟悉 react.js.

这是一个前后端分离项目, 前端主要是 react, react-dom, react-redux, react-router, redux, es6, redux-thunk, css 框架使用了 bootstrap. 后端利用 ruby-china 开放的 api. 支持响应式布局. 目前已有 245+ star 数.

Github: https://github.com/liuzhenangel/react-ruby-china

核心技术框架

react react-dom react-router redux redux-thunk react-md-editor isomorphic-fetch react-paginate react-redux marked es6-promise classnames ECS - 一个发现,创造与分享城市一切美好事物的公益平台

这是为朋友做的一个公益平台项目, 主要用于发布活动信息, 核心功能: 搜索, 点赞, 分享, 评论, 后台管理等功能 前端使用了 Bootstrap, jquery, SASS, Coffee 技术栈. 后端使用了 Rails. 代码在 github 开源: https://github.com/liuzhenangel/ecssz 个人博客系统

具备博客后台管理, 数据统计, 文章管理, 相册管理, 简历在线编辑等现代网站所有特性. 前端使用了bootstrap 4, turn.js, vertical-timeline, sb-admin, startbootstrap-clean-blog技术栈. 后端使用了Ruby on Rails 5.1.4. 代码在 github 开源: https://github.com/liuzhenangel/RBlog 工作经历

大疆 - Web前端研发工程师 (2016.11 ~ 现在)

独立负责无人机培训考试系统开发。 优融网络科技 - Rails 高级工程师 (2015.09 ~ 2016.06)

UBOSS 商城, 是一个专注本地化的电商系统 主要负责 后端逻辑 及 前端UI 工作 主要开发功能: 运费模板, 单个或多个商品运费计算, 运费满减, 订单评价, 退款/退货售后, 团购管理(店铺管理/验证管理/前台用户&商家模块/收益管理/评价管理/商品管理) 等等 深信服科技 - 测试开发工程师 (2013.03 ~ 2015.03)

作为测试开发工程师, 与团队一起负责测试资源管理平台的开发及维护. 负责自动化框架的开发与维护. 完成一些内部工具的开发如: 企业内部搜索引擎的技术选型与开发. 项目经历

君投天地 Co.Fund

纽约的一个股权众筹的创业项目, 我作为主程负责开发了相关功能: 线上融资流程, 用户充值取现系统, 授权认证等. 前端使用了 AngularJS1.x, Foundation5 和 font-awesome, underscore, SASS 技术栈. 后端使用了 Rails. 收获了很多: https 布署, 全站 CDN 加速, 前后端分离的实践. GODA

GODA 是一站式高端人才招聘的创业项目, 我负责了前期所有前后端开发及部署上线工作. 前端使用了 Bootstrap, turbolinks, font-awesome, query-cookie, SASS, Coffee 技术栈. 后端使用了 Rails. 核心功能: 简历拍卖, 面试邀请, 后台审核, 接受/拒绝邀请, 邮件通知等. 收获: mina + unicorn + nignx 环境部署, RJS 前端交互. 关键字

Vue.js | ReactJS | AngularJS | Bootstrap | Foundation | UIkit | jQuery | HTML | CSS | Ruby | Ruby On Rails | Git | Vim | Slim | JavaScript(Coffee) | SVN | PostgreSQL | MySQL

技能特长

熟悉: Vue.js, ReactJS, AngularJS, Bootstrap, Foundation, UIkit, Ruby, Ruby on Rails

results matching ""

    No results matching ""