简体   繁体   English

来自Jenkins的Rsync到Google Compute引擎实例

[英]Rsync to Google Compute engine Instance from Jenkins

I want to send files from Jenkins to to my instance in Google Compute engine instance I added a build in my config in jenkins : 我想将文件从Jenkins发送到我在Google Compute引擎实例中的实例我在jenkins的配置中添加了一个版本:

rsync -vrzhe "ssh -i /var/lib/jenkins/.ssh/google_compute_engine -o UserKnownHostsFile=/dev/null -o CheckHostIP=no -o StrictHostKeyChecking=no" . login@Host:/var/www

And I get this error : 我收到这个错误:

Checking out Revision 59cf9dd819fe2168c4c40f716707d58b2b99e251 (refs/remotes/origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 59cf9dd819fe2168c4c40f716707d58b2b99e251
> git rev-list 59cf9dd819fe2168c4c40f716707d58b2b99e251 # timeout=10
[Platform] $ /bin/sh -xe /tmp/hudson4502433356962914860.sh
+ rsync -vrzhe 'ssh -i /var/lib/jenkins/.ssh -o UserKnownHostsFile=/dev/null -o 

CheckHostIP=no -o StrictHostKeyChecking=no' . login@Host:/var/www
   StrictHostKeyChecking=no' . login@host:/var/www
   ssh: connect to host host port 22: Connection timed out
   rsync: connection unexpectedly closed (0 bytes received so far) [sender]
   rsync error: unexplained error (code 255) at io.c(601) [sender=3.0.7]
   Build step 'Exécuter un script shell' marked build as failure
   Finished: FAILURE

Any idea 任何想法

first configure .ssh config file by (assuming you installed gcloud sdk): 首先配置.ssh配置文件(假设你安装了gcloud sdk):

gcloud compute config-ssh

It will tell you that "now you can use ssh/scp with your instances by running 它会告诉你“现在你可以通过运行来使用ssh / scp和你的实例了

ssh your-instance

your-instance is in the form of "instance.zone.project", usually. 你的实例通常采用“instance.zone.project”的形式。

Now you can rsync: 现在你可以rsync:

rsync -ave ssh your-local-dir your-instance:~/your-destination

Done. 完成。

You can mention the user if you like so: 如果您愿意,可以提及用户:

rsync -ave ssh your-local-dir your-user@your-instance:~/your-destination

It worked for me. 它对我有用。 Juts do not forget to replace "your-instance" (and your-user) with the correct one. Juts不要忘记用正确的替换“你的实例”(和你的用户)。 You can get it through "gcloud compute config-ssh" or "gcloud compute config-ssh --dry-run" or go to your cloud.google.com then compute engine then vm instances then from connect choose view gcloud command. 您可以通过“gcloud compute config-ssh”或“gcloud compute config-ssh --dry-run”获取它,或者转到您的cloud.google.com然后计算引擎然后是vm实例然后从connect choose view gcloud命令。 All will show your instance name in the form of "instance.zone.project." All将以“instance.zone.project”的形式显示您的实例名称。

I hope it will help someone in future. 我希望它将来会帮助别人。 :) :)

Maybe a little late, but you can use the gcloud compute ssh command directly instead of finding the google ssh keys. 也许有点晚了,但你可以直接使用gcloud compute ssh命令而不是找到google ssh键。

First, you have to make a script that will hide the rsync ssh command args from gcloud: 首先,你必须创建一个脚本来隐藏来自gcloud的rsync ssh命令args:

cat >./gcloud-compute-ssh <<EOF
#! /bin/sh
host="$1"
shift
exec gcloud compute ssh "$host" -- "$@"
EOF

chmod a+x ./gcloud-compute-ssh

Then you can rsync -e to your heart's content: 然后你可以rsync -e到你的心脏的内容:

rsync -e ./gcloud-compute-ssh my-dir my-instance:/my-dir

Your rsync command above uses the -i option for ssh. 上面的rsync命令使用ssh的-i选项。 The argument to -i option should be path to ssh key file, not the directory where the key file is. -i选项的参数应该是ssh密钥文件的路径,而不是密钥文件所在的目录。

The problem was with my public key so to solve the problem you need to : 问题在于我的公钥,所以要解决你需要的问题:

1 - Setting up your ssh keys : run 1 - 设置ssh键:运行

gcloud compute ssh example-instance

2 - cp your .ssh/google_compute_engine.pub content into the GCE VM authorized_key 2 - 将您的.ssh / google_compute_engine.pub内容转换为GCE VM authorized_key

3 - restart VM instance 3 - 重启VM实例

Thanks for your help 谢谢你的帮助

As mentioned in " How to solve rsync error: error in rsync protocol data stream (code 12) at io.c(600) on windows ", check which ssh get to be actually used, and if that ssh version is compatible with with the one from rsync. 如“ 如何在Windows上的io.c(600)中解决rsync协议数据流(代码12)中的rsync错误:错误 ”中所述,检查实际使用的ssh,以及ssh版本是否与一个来自rsync。

Specifying an absolute path for the ssh executable can help: 指定ssh可执行文件的绝对路径可以提供帮助:

rsync -e /usr/bin/ssh .... 

This thread also suggests to purge ~/.ssh/know_hosts in case the server has changed and now has a different key. 该线程还建议在服务器已更改并且现在具有不同密钥的情况下清除~/.ssh/know_hosts

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM