ssh 执行远程命令卡住问题解决

问题现象

我这边执行的pc-ctl命令,这个是tidb的pd命令行工具
命令本地会自行的结果如下:

[root@centos7 ~]# /root/pd-ctl -u 10.226.157.132:2900 region
{
  "count": 1,
  "regions": [
    {
      "id": 2,
      "start_key": "",
      "end_key": "",
      "epoch": {
        "conf_ver": 128,
        "version": 9
      },
      "peers": [
        {
          "id": 65,
          "store_id": 28
        },
        {
          "id": 66,
          "store_id": 11
        },
        {
          "id": 70,
          "store_id": 31
        },
        {
          "id": 71,
          "store_id": 4
        },
        {
          "id": 75,
          "store_id": 6
        }
      ],
      "leader": {
        "id": 70,
        "store_id": 31
      },
      "approximate_size": 4986
    }
  ]
}

[root@centos7 ~]#

但是通过ssh远程执行pd-ctl会卡住

[root@centos7 ~]# ssh root@127.0.0.1 "/root/pd-ctl -u 10.226.157.132:2900 region"
The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established.
ECDSA key fingerprint is SHA256:yWPZSs92gAknt9ycN17tNs9NBZGIF/RA0PSn9evBx7o.
ECDSA key fingerprint is MD5:00:74:b3:d5:bc:2f:14:dc:8a:e6:88:03:12:9f:7f:67.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '127.0.0.1' (ECDSA) to the list of known hosts.
root@127.0.0.1's password: #输入密码后卡住了



^CKilled by signal 2. #通过ctrl + c停止
[root@centos7 ~]#

解决方法

是用ssh -t 就可以了

[root@centos7 ~]# ssh -t root@127.0.0.1 "/root/pd-ctl -u 10.226.157.132:2900 region"
root@127.0.0.1's password:
{
  "count": 1,
  "regions": [
    {
      "id": 2,
      "start_key": "",
      "end_key": "",
      "epoch": {
        "conf_ver": 128,
        "version": 9
      },
      "peers": [
        {
          "id": 65,
          "store_id": 28
        },
        {
          "id": 66,
          "store_id": 11
        },
        {
          "id": 70,
          "store_id": 31
        },
        {
          "id": 71,
          "store_id": 4
        },
        {
          "id": 75,
          "store_id": 6
        }
      ],
      "leader": {
        "id": 70,
        "store_id": 31
      },
      "approximate_size": 4986
    }
  ]
}

Connection to 127.0.0.1 closed.
[root@centos7 ~]#

man ssh 查看-t参数的含义如下:

     -t      Force pseudo-terminal allocation.  This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful,
             e.g. when implementing menu services.  Multiple -t options force tty allocation, even if ssh has no local tty.

#强制伪终端分配。 这可用于在远程机器上执行任意基于屏幕的程序,这非常有用,例如 实现菜单服务时。 多个 -t 选项强制分配 tty,即使 ssh 没有本地 tty。
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值