这两天接到的任务是给 JAVA 开发项目组部署【JAVA+MySQL 主从+Redis 主从】运行环境。部署过程中大问题倒没有,小问题却不少,因此也涨了不少经验值。后续有时间我会一一整理记录下来,沉淀而不忘分享。
今天,装完一台 redis,并配置好 redis.conf 后,想偷懒直接用 scp 传到另一台 redis,省去全部重新编辑的麻烦。结果一执行就出现下面这个错误:
bash: scp: command not found
所有机器我都是最小化安装,所以很多组件没装也是情理之中,所以用 yum 装一下 scp:
yum -y install openssh-clients
装完后,继续执行之前的命令,结果出现如下错误:
[[email protected] etc]# scp redis.conf [email protected]:/usr/local/redis/etc/ [email protected]'s password: bash: scp: command not found lost connection [[email protected] etc]# whereis scp scp: /usr/bin/scp /usr/share/man/man1/scp.1.gz
我擦,这就诡异了!明明装了为毛提示不存在呢? 而且还提示输入密码了,用 whereis 也能找到 scp,没办法从 man 中找到一个 DEBUG 参数 -v,于是如下增加 -v 参数执行试试:
[[email protected] etc]# /usr/bin/scp -v redis.conf [email protected]:/usr/local/redis/etc/ Executing: program /usr/bin/ssh host 192.168.17.125, user root, command scp -v -t /usr/local/redis/etc/ OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013 debug1: Reading configuration data /etc/ssh/ssh_config debug1: Applying options for * ******此处省略数行****** [email protected]'s password: debug1: Authentication succeeded (password). debug1: channel 0: new [client-session] debug1: Requesting [email protected] debug1: Entering interactive session. debug1: Sending environment. debug1: Sending env LANG = en_US.UTF-8 #关键信息来了,这边将 scp 命令 send 到对方,对方提示 scp 没找到,原因水落石出! debug1: Sending command: scp -v -t /usr/local/redis/etc/ bash: scp: command not found debug1: client_input_channel_req: channel 0 rtype exit-status reply 0 debug1: client_input_channel_req: channel 0 rtype [email protected] reply 0 debug1: channel 0: free: client-session, nchannels 1 debug1: fd 0 clearing O_NONBLOCK debug1: fd 1 clearing O_NONBLOCK Transferred: sent 1624, received 2096 bytes, in 0.2 seconds Bytes per second: sent 9088.1, received 11729.5 debug1: Exit status 127 lost connection [[email protected] etc]#
原来是因为目标主机也没装 scp,倒是我大意了!登陆后再次执行如下命令安装 scp:
yum -y install openssh-clients
回到之前的服务器上,执行最初的命令,果然毫无意外成功了:
[[email protected] etc]# /usr/bin/scp redis.conf [email protected]:/usr/local/redis/etc/ [email protected]'s password: redis.conf 100% 35KB 35.3KB/s 00:00 [[email protected] etc]#
网站搜索这个故障,大部分经验都是告知要安装 scp,然后给出一个 yum 在线安装 scp 的命令。实际上,明明已经提示要输入密码了,说明 scp 是正常安装的!还继续报找不到命令,我们就只能从 scp 的执行过程来分析了,因此就借助到了 scp 的 debug 参数(-v),很清楚的看到了整个执行过程,从而得知真正的原因是对方主机没有安装 scp,而且还可以清楚的看到 scp 的工作流程。
中午时间有限,就写这么多了,希望遇到这个问题的人,看到此文能少走点弯路。
方法不错。
支持一下!
交换友链 http://huanglv.me/p 消灭星星