自动化部署Liunx服务器脚本(解放双手)

100 阅读1分钟

sheel脚本

前言

why?
持续更新代码,需要手动部署到服务器上,那么写一个自动化脚本很重要!!

拷贝文件到服务器

scp -r filename 账号@服务器地址:目录
命令参数 -r 递归文件夹
可选: 目录,默认是根目录

scp -r prototype.zip root@127.0.0.1:/data/wwwroot/prototype

连接服务器并执行命令

  1. 连接服务器执行批量命令
ssh root@127.0.0.1  << remotessh   //连接服务器    << remotessh是自定义名字
cd /data/wwwroot/prototype  
exit  
remotessh //结束服务器里面的脚本
  1. 连接服务器执行简单命令
ssh root@127.0.0.1 "cd /data; ls -l"

连接服务器绕过手动输入密码

  1. 连接服务器安全密钥key
  2. 使用sshpass免密码登陆