scp在虚拟机操作系统之上的使用

操作系统:CentOS release 6.10 (Final)

主机1:192.168.12.28

主机2:192.168.12.29

虚拟机:VMware WorkStation

任务:将主机1的nginx服务脚本传送到主机2,同一脚本使用多处主机,重复使用效率高。

主机1操作:

[root@Nginx init.d]# scp nginx  root@192.168.12.129:/etc/init.d/

The authenticity of host '192.168.12.129 (192.168.12.129)' can't be established.

RSA key fingerprint is 7f:0e:90:ab:43:32:f4:43:43:fb:d5:ca:62:a7:d1:6a.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '192.168.12.129' (RSA) to the list of known hosts.

root@192.168.12.129's password: 

bash: scp: command not found

lost connection

[root@Nginx init.d]# which scp

/usr/bin/scp

主机2操作:

[root@Nginx init.d]# which scp

/usr/bin/which: no scp in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)

[root@Nginx init.d]# yum install openssh-clients

分析原因是主机2没有安装openssh-clients软件包

主机1操作:

[root@Nginx init.d]# scp nginx  root@192.168.12.129:/etc/init.d   #传送文件成功

root@192.168.12.129's password: 

nginx                                                   100%  571     0.6KB/s   00:00    

主机2操作:

[root@Nginx init.d]# chmod +x /etc/init.d/nginx 

[root@Nginx init.d]# chkconfig --add nginx 

[root@Nginx init.d]# chkconfig --level 2345 nginx on

nginx服务脚本如下:

[root@Nginx init.d]# cat nginx 

#!/bin/bash

#chkconfig: 35 85 15

DAEMON=/usr/local/nginx/sbin/nginx

case "$1" in

   start)

     echo "Starting nginx daemon..."

      $ DAEMOM && echo "SUCCESS"

    ;;

   stop)

      echo "Stopping nginx daemon..."

      $DAEMON  -s quit && echo "SUCCESS"

  ;;

   reload)

      echo "Reloading nginx daemon...."

      $DAEMON -s reload && echo "SUCCESS"

   ;;

    restart)

     echo "Restaring nginx daemon..."

     $DAEMON -s quit

     $DAEMON && echo "SUCESS"

    ;;

   *)

       echo "Usage:service nginx{start|stop|restart|reload}"

       exit 2

        ;;

     esac

实战小结:

1.服务器端、客户端,或者说传送文件两端必须安装openssh-clients软件包。

2.重用脚本有利于提升运维工作效率。

3.nginx脚本下载地址:http://down.51cto.com/data/2458026


相关文章

文章浏览阅读3.7k次,点赞2次,收藏5次。Nginx学习笔记一、N...
文章浏览阅读1.7w次,点赞14次,收藏61次。我们在使用容器的...
文章浏览阅读1.4k次。当用户在访问网站的过程中遇到404错误时...
文章浏览阅读2.7k次。docker 和 docker-compose 部署 nginx+...
文章浏览阅读1.3k次。5:再次启动nginx,可以正常启动,可以...
文章浏览阅读3.1w次,点赞105次,收藏182次。高性能:Nginx ...