新手问题 mina 部署时 setup 出错,试了各种办法还是不行,请帮忙看看。-_-!!

gxlonline · 2016年11月29日 · 最后由 mingyuan0715 回复于 2016年11月30日 · 3974 次阅读

提示如下(使用 root 结果一样)

➜  XXX git:(master) ✗ mina setup -v                                                                        
[email protected]'s password:                                                                               
-----> Setting up /home/deploy/XXX.com                                                                   
       $ mkdir -p "/home/deploy/XXX.com"                                                                 
       $ mkdir -p "/home/deploy/XXX.com/releases"  
       $ mkdir -p "/home/deploy/XXX.com/shared"                                                          
       $ cd /home/deploy/XXX.com/shared                                                                  
       $ mkdir -p "vendor/bundle"                                                                             
       $ mkdir -p "log"                                                                                       
       $ mkdir -p "tmp/cache"                                                                                 
       $ mkdir -p "public/assets"                                                                             
       $ mkdir -p "log"                                                                                       
       $ mkdir -p "config"                                                                                    
       $ mkdir -p "config"                                                                                    
       $ if [ -x "$(command -v tree)" ]; then tree -d -L 2 "/home/deploy/XXX.com"; else ls -al "/home/dep
loy/XXX.com"; fi                                                                                         
       total 16                                                                                               
       drwxr-xr-x 4 deploy root 4096 Nov 29 12:56 .                                                           
       drwxr-xr-x 6 deploy root 4096 Nov 29 12:56 ..                                                          
       drwxr-xr-x 2 deploy root 4096 Nov 29 12:56 releases                                                    
       drwxr-xr-x 7 deploy root 4096 Nov 29 12:56 shared                                                      
       $ if ! ssh-keygen -H -F github.com &>/dev/null; then                                                   
         ssh-keyscan -t rsa -p 22 -H github.com >> ~/.ssh/known_hosts                                         
       fi                                                                                                     
       Connection to 115.28.150.205 closed.                                                                   

       Elapsed time: 5.72 seconds                        

config/deploy.rb

require 'mina/rails'
require 'mina/git'
require 'mina/rvm'    # for rvm support. (https://rvm.io)

set :user, 'deploy'
set :domain, '115.28.150.205'
set :deploy_to, '/home/deploy/XXX.com'
set :repository, '[email protected]:XXX/daquan.git'
set :branch, 'master'
set :rvm_path, '/usr/local/rvm/scripts/rvm'

set :shared_dirs, fetch(:shared_dirs, []).push('log')
set :shared_files, fetch(:shared_files, []).push('config/database.yml', 'config/secrets.yml')

task :environment do
  invoke :'rvm:use', 'ruby-2.3.3@default'
end

task :setup do
  # command %{rbenv install 2.3.0}
end

desc "Deploys the current version to the server."
task :deploy do
  deploy do
    invoke :'git:clone'
    invoke :'deploy:link_shared_paths'
    invoke :'bundle:install'
    #数据库已经migrate
    #invoke :'rails:db_migrate'
    invoke :'rails:assets_precompile'
    invoke :'deploy:cleanup'

    on :launch do
      in_path(fetch(:current_path)) do
        command %{mkdir -p tmp/}
        command %{touch tmp/restart.txt}
      end
    end
  end

end


一直找不出是哪的问题,服务器已经安装相应软件。

deploy@iZm5ej37sq84m7zum1fn7hZ:~$ ruby -v                                                                     
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux]        

deploy@iZm5ej37sq84m7zum1fn7hZ:~$ rvm -v                                                                      
rvm 1.27.0 (latest) by Wayne E. Seguin <[email protected]>, Michal Papis <[email protected]> [https://rvm.
io/]        

deploy@iZm5ej37sq84m7zum1fn7hZ:~$ git --version                                                               
git version 1.9.1                                                          

/opt/nginx/conf/nginx.conf

user   deploy;                                                                                                
worker_processes 1;                                                                                           

pid       /var/run/nginx.pid;                                                                                 

events {                                                                                                      
    worker_connections  1024;                                                                                 
}                                                                                                             

http {                                                                                                        
    passenger_root /usr/local/rvm/gems/ruby-2.3.3/gems/passenger-5.0.30;                                      
    passenger_ruby /usr/local/rvm/gems/ruby-2.3.3/wrappers/ruby;                                              

    include       mime.types;                                                                                 
    default_type  application/octet-stream;                                                                                                            

    access_log  /var/log/nginx/access.log;                                                                    
    error_log   /var/log/nginx/error.log;                                                                     

    sendfile        on;                                                                                                                                                                             

    #keepalive_timeout  0;                                                                                    
    keepalive_timeout  65;          

    gzip  on;                                                                                                 

    server {                                                                                                  
        listen       80;                                                                                      
        server_name  www.XXX.com;                                                                        
        rails_env    production;                                                                              
        root         /home/deploy/XXX.com/current/public;                                                

        passenger_enabled on;                                                                                                                                                                                                 

    location ~ ^(/assets) {                                                                                   
      access_log        off;                                                                                                                                                    
      expires           max;                                                                                  
    }      
   ...
set :forward_agent, true

maybe help

@flowerwrong 谢谢回答,不过还是同样的错误

直接运行 mina deploy 结果如下

➜  XXX git:(master) ✗ mina deploy  -v                                                                                                                                 
[email protected]'s password:                                                                                                                                        
-----> Creating a temporary build path                                                                                                                                   
       $ touch "deploy.lock"                                                                                                                                             
       $ mkdir -p "$build_path"                                                                                                                                          
       $ cd "$build_path"                                                                                                                                                
-----> Using RVM environment "ruby-2.3.3@default"                                                                                                                        
       $ if [[ ! -s "/usr/local/rvm/scripts/rvm" ]]; then                                                                                                                
           echo "! Ruby Version Manager not found"                                                                                                                       
           echo "! If RVM is installed, check your :rvm_use_path setting."                                                                                               
           exit 1                                                                                                                                                        
         fi                                                                                                                                                              
       $ source /usr/local/rvm/scripts/rvm                                                                                                                               
       $ rvm use "ruby-2.3.3@default" --create                                                                                                                           
       Using /usr/local/rvm/gems/ruby-2.3.3       
-----> Cloning the Git repository                                                                                                                                        
       $ git clone "[email protected]:XXX/daquan.git" "/home/deploy/XXX.com/scm" --bare                                                                          
       Cloning into bare repository '/home/deploy/XXX.com/scm'...                                                                                                   
       Warning: Permanently added the RSA host key for IP address '192.30.253.113' to the list of known hosts.                                                           
       Permission denied (publickey).                                                                                                                                    
       fatal: Could not read from remote repository.                                                                                                                     

       Please make sure you have the correct access rights                                                                                                               
       and the repository exists.                                                                                                                                        
 !     ERROR: Deploy failed.                                                                                                                             
-----> Cleaning up build                                                                                                                                                 
       $ rm -rf "$build_path"                                                                                                                                            
       Unlinking current                                                                                                                                                 
       $ rm -f "deploy.lock"                                                                                                                                             
       OK                                                                                                                                                                
       Connection to 115.28.150.205 closed.                                                                                                                              

 !     Run Error                          

我觉得 1 楼的可以解决问题。不然你就麻烦一点,登陆到服务器,然后确保可以 clone from github. 也 ok。

加上也不工作那就是墙了。加代理。

Could not read from remote repository. 是这个原因吗?

你试试

ssh-add -l

看看有没有内容,没有内容再

ssh-add

试试。 再部署试试。

应该是 ssh 的原因 @xiaohesong

ssh-add 
Could not open a connection to your authentication agent. 

目前直接跳过 mina setup 直接 mina deploy,然后在 config/deploy.rb 做了如下修改

set :term_mode, nil
# 不使用ssh,直接使用https方式clone
#set :repository, '[email protected]:XXX/daquan.git'
set :repository, 'https://github.com/XXX/daquan'

然后手动把 database.yml 和 secrets.yml 复制到服务器上。 曲线救国总算可以用了。

最可能的问题是配置问题。

使用 GitHub 的 git 协议要求你 clone 仓库时用户的公钥在你的 GitHub 账号中。就是说只有 GitHub 的用户才能用 git 协议。部署工具自动 clone 时怎么证明是 GItHub 的用户?要么你服务器上的部署用户的 .ssh/id_rsa.pub 在某个 GitHub 账号的 SSH keys 中,要么你本地用户的 .ssh/id_rsa.pub 在某个账号的 SSH keys 中且设置了 set :forward_agent, true

SSH 相关设置

通过 ssh 连接至服务器

  • 将你本机~/.ssh/id_rsa.pub文件添加到服务器~/.ssh/authorized_keys

设置 ssh 代理连接,即让服务器可以通过 ssh 连接以你的 ssh 配置使用 git 等服务

  • 配置本机 ssh, 配置文件为 ~/.ssh/config, 如果没有则新建这个文件,配置内容如下;
Host 123.123.123.123 114.114.114.114
  ForwardAgent yes

其中,Host 是你允许使用你本机 ssh 连接的服务器,如果有多个,用空格隔开

  • 确保你本机的 ssh-agent 服务已经启动
echo $SSH_AUTH_SOCK
  • 允许 ssh-agent 使用你的 ssh key
ssh-add ~/.ssh/id_rsa # 临时, 在mac中, 重启之后就失效了
ssh-add -K ~/.ssh/id_rsa # 永久, for mac
ssh-add -l # 检测是否添加成功

远程服务器,test

  • 登陆到服务器,测试 ssh 连接,这一步很重要,否则将无法正常使用 ssh agent,这步将会将你测试的地址添加到服务器的 known_hosts 文件中
ssh -T [email protected]

参考资料

SSH agent forward

根据我的经验,你是这一步没做:远程服务器, test,这一步很坑。其他的 mina 的配置,楼上已经说了。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号