繁体   English   中英

bsh脚本中的ssh“端口22:无主机路由”错误

[英]ssh “port 22: no route to host” error in bash script

我编写了一个scipt来执行一些与apache storm有关的ssh远程命令。 当我执行脚本时,它说:

ssh: connect to host XXX.XXX.XXX.XXX port 22: No route to host
ssh: connect to host XXX.XXX.XXX.XXX port 22: No route to host
ssh: connect to host XXX.XXX.XXX.XXX port 22: No route to host
ssh: connect to host XXX.XXX.XXX.XXX port 22: Connection refused

如果我手动执行命令,它可以正常工作,我可以ping机器。 所以这段代码必须有问题:

while [ $i -le $numVM ]

do
    if [ $i -eq 1 ];then
        ssh -i file root@IP1 './zookeeper-3.4.6/bin/zkServer.sh start' 
    else
        ssh -i file root@IP2 'sed -i '"'"'s/#\ storm.zookeeper.servers.*/storm.zookeeper.servers:/'"'"' /root/apache-storm-0.9.3/conf/storm.yaml'
        ssh -i file root@IP2 'sed -i '"'"'0,/^#[[:space:]]*-[[:space:]]*\"server1\".*/s//"      - \"'${IParray[1]}'\""/'"'"' /root/apache-storm-0.9.3/conf/storm.yaml'
        ssh -i file root@IP2 'sed -i '"'"'s/#\ nimbus.host:.*/"nimbus.host: \"'${IParray[2]}'\""/'"'"' /root/apache-storm-0.9.3/conf/storm.yaml'
        ssh -i file root@IP2 './zookeeper-3.4.6/bin/zkCli.sh -server ${IParray[1]} &'
        sleep 10
        ssh -i file root@IP2 './apache-storm-0.9.3/bin/storm nimbus &' &
        sleep 10
        ssh -i file root@IP2 './apache-storm-0.9.3/bin/storm ui &' & 
        sleep 10
        ssh -i file root@IP2 './apache-storm-0.9.3/bin/storm supervisor &' &
    fi  
    ((i++))
done

我在两个从同一图像部署的虚拟机上启动了几个进程,因此它们通常是相同的。 令人困惑的部分是,第一个ssh命令(zkServer.sh start)运行良好,但如果我脚本试图执行三个“sed”-ssh命令,我会收到上面的错误消息。 但后来最后四个ssh命令再次运行良好。 这对我没有任何意义......

我能想到的几件事:

  • 大多数sshd守护进程不允许root访问。 哎呀,许多版本的Unix / Linux不再允许root登录。 如果您需要root访问权限,则需要使用sudo
  • 远程计算机上的sshd守护程序未运行。 虽然很少见,但有些网站可能永远不会设置它,或故意将其关闭作为安全问题。
  • 你的ssh命令本身是不正确的。

不要在shell脚本中执行ssh命令,而是修改shell脚本以打印出您尝试执行的内容。 然后,查看是否可以在shell脚本之外执行命令。 这样您就可以确定问题是否是shell脚本,或者问题是ssh命令本身。

如果您的ssh命令在命令行之外不起作用,则可以简化它们并查看是否可以确定问题所在。 你有ssh -i file root@IP2 这假设是ssh -i $file root@$IP2 (也就是说,你错过了主要的印记)。

$ ssh -i file root@$IP2 ls   # Can't get simpler than this...
$ ssh -i file root@IPS       # See if you can remotely log on...
$ ssh root@IP2               # Try it without an 'identity file'
$ ssh bob@IP2                # Try it as a user other than 'root'
$ telnet IP2 22              # Is port 22 even open on the remote machine?

如果这些不起作用,那么您在设置远程机器的sshd命令时会遇到一些非常基本的问题。

暂无
暂无

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

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