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  [email protected]:/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.

[email protected]'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  [email protected]:/etc/init.d   #傳送文件成功

[email protected]'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 --add /etc/init.d/nginx  #建議採用此種方式添加nginx服務

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

[root@Nginx init.d]# chkconfig nginx on  #建議採用此種方式自動啓動nginx服務

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

4.解決下面兩個小問題:

問題1:

[root@Nginx init.d]# service nginx start

Starting nginx daemon...

/etc/init.d/nginx: line 7: $: command not found

$ DAEMOM 改成$DAEMOM 即可解決上述報錯問題

問題2:

nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)

[root@Nginx init.d]# /usr/local/nginx/sbin/nginx -c  /usr/local/nginx/conf/nginx.conf

#使用nginx -c的參數指定nginx.conf文件的位置

問題3:

chkconfig nginx on #實際上重新啓動系統,nginx服務並沒有自動啓動,不知道問題出現在哪?

[root@Nginx ~]# vim  /etc/rc.local  #目前先用這種方式解決自動啓動nginx服務

/usr/local/nginx/sbin/nginx

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章