我正在设置简单的capistrano 3部署脚本,以便为每个由aws autoscaler生成的新节点运行rc.local。
当我以root身份手动执行脚本时,一切运行正常,但是一旦我重新启动并查看rc.local执行日志,我就会得到以下信息:
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host 127.0.0.1: Authentication failed for user ubuntu@127.0.0.1
/var/lib/gems/1.9.1/gems/net-ssh-2.9.1/lib/net/ssh.rb:219:in `start'
/var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/connection_pool.rb:50:in `call'
/var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/connection_pool.rb:50:in `create_new_entry'
/var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/connection_pool.rb:22:in `checkout'
/var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:179:in `with_ssh'
/var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:131:in `block in _execute'
/var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `tap'
/var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `_execute'
/var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:66:in `execute'
/var/lib/gems/1.9.1/gems/capistrano-3.2.1/lib/capistrano/tasks/git.rake:17:in `block (3 levels) in <top (required)>'
/var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `run'
/var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/runners/parallel.rb:13:in `block (2 levels) in execute'
Net::SSH::AuthenticationFailed: Authentication failed for user ubuntu@127.0.0.1
/var/lib/gems/1.9.1/gems/net-ssh-2.9.1/lib/net/ssh.rb:219:in `start'
/var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/connection_pool.rb:50:in `call'
/var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/connection_pool.rb:50:in `create_new_entry'
/var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/connection_pool.rb:22:in `checkout'
/var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:179:in `with_ssh'
/var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:131:in `block in _execute'
/var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `tap'
/var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `_execute'
/var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:66:in `execute'
/var/lib/gems/1.9.1/gems/capistrano-3.2.1/lib/capistrano/tasks/git.rake:17:in `block (3 levels) in <top (required)>'
/var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `run'
/var/lib/gems/1.9.1/gems/sshkit-1.5.1/lib/sshkit/runners/parallel.rb:13:in `block (2 levels) in execute'
Tasks: TOP => git:check => git:wrapper
(See full trace by running task with --trace)
The deploy has failed with an error: #<SSHKit::Runner::ExecuteError: Exception while executing on host 127.0.0.1: Authentication failed for user ubuntu@127.0.0.1>
为了避免known_hosts问题,root用户有〜/ .ssh / config
Host 127.0.0.1
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
以root用户身份
ssh ubuntu@127.0.0.1
很顺利。
rc.local看起来像这样:
#!/bin/bash -ex
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
exec > >(tee /var/log/rc.local.log|logger -t rc.local -s 2>/dev/console) 2>&1
/home/ubuntu/deployment/local-deploy.sh
exit 0
如上所述以root用户身份运行/home/ubuntu/deployment/local-deploy.sh手动工作正常,但是当它在启动时运行时(来自rc.local)我得到上面的身份验证错误。
感谢您的帮助。
答案 0 :(得分:0)
我终于通过向ubuntu用户起诉然后执行命令解决了这个问题:
su ubuntu -c '...'