操作系统: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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。