windows上部署linux集群应用
程序员文章站
2022-07-12 16:15:55
...
在独立开发一个跨云的集群应用的时候,突然发现以往使用的jekins、shell脚本完全不够用了,部署一个版本效率低下到要死要死了。于是觉得非常有必要手写一个bat脚本,去操作集群在linus上的jar应用,虽然忙乎了一个晚上,但是部署效率直线上升。
windows上传和操作应用使用到两个工具分别是pscp和plink
pscp,就像linux的scp命令指令如下,
plink就是linux的ssh,可以在window下远程执行linux的shell脚本,指令如下:
window的expect命令不像linux的那么好用,可能是我没掌握好,下载地址也很不好找,使用的时候也跟linux不一样;所以在执行pscp的时候,有个嵌入命令(yes/no),可以在执行pscp命令前加上 echo y| pscp .... ,这样居然也能达到linux expect命令的效果。
window的start命令,类似linux的nohup,异步执行命令,跟pscp、plink结合使用,这样就实行多线程传输应用和远程执行linux脚本
还是贴代码吧,部署代码如下
services.txt为服务器列表
格式如下:
windows上传和操作应用使用到两个工具分别是pscp和plink
pscp,就像linux的scp命令指令如下,
Usage: pscp [options] [user@]host:source target pscp [options] source [source...] [user@]host:target pscp [options] -ls [user@]host:filespec Options: -V print version information and exit -pgpfp print PGP key fingerprints and exit -p preserve file attributes -q quiet, don't show statistics -r copy directories recursively -v show verbose messages -load sessname Load settings from saved session -P port connect to specified port -l user connect with specified username -pw passw login with specified password -1 -2 force use of particular SSH protocol version -4 -6 force use of IPv4 or IPv6 -C enable compression -i key private key file for user authentication -noagent disable use of Pageant -agent enable use of Pageant -hostkey aa:bb:cc:... manually specify a host key (may be repeated) -batch disable all interactive prompts -no-sanitise-stderr don't strip control chars from standard error -proxycmd command use 'command' as local proxy -unsafe allow server-side wildcards (DANGEROUS) -sftp force use of SFTP protocol -scp force use of SCP protocol -sshlog file -sshrawlog file log protocol details to a file
plink就是linux的ssh,可以在window下远程执行linux的shell脚本,指令如下:
Usage: pscp [options] [user@]host:source target pscp [options] source [source...] [user@]host:target pscp [options] -ls [user@]host:filespec Options: -V print version information and exit -pgpfp print PGP key fingerprints and exit -p preserve file attributes -q quiet, don't show statistics -r copy directories recursively -v show verbose messages -load sessname Load settings from saved session -P port connect to specified port -l user connect with specified username -pw passw login with specified password -1 -2 force use of particular SSH protocol version -4 -6 force use of IPv4 or IPv6 -C enable compression -i key private key file for user authentication -noagent disable use of Pageant -agent enable use of Pageant -hostkey aa:bb:cc:... manually specify a host key (may be repeated) -batch disable all interactive prompts -no-sanitise-stderr don't strip control chars from standard error -proxycmd command use 'command' as local proxy -unsafe allow server-side wildcards (DANGEROUS) -sftp force use of SFTP protocol -scp force use of SCP protocol -sshlog file -sshrawlog file log protocol details to a file C:\Users\Administrator>D:\tool\seo_deploy\plink Plink: command-line connection utility Release 0.72 Usage: plink [options] [user@]host [command] ("host" can also be a PuTTY saved session name) Options: -V print version information and exit -pgpfp print PGP key fingerprints and exit -v show verbose messages -load sessname Load settings from saved session -ssh -telnet -rlogin -raw -serial force use of a particular protocol -P port connect to specified port -l user connect with specified username -batch disable all interactive prompts -proxycmd command use 'command' as local proxy -sercfg configuration-string (e.g. 19200,8,n,1,X) Specify the serial configuration (serial only) The following options only apply to SSH connections: -pw passw login with specified password -D [listen-IP:]listen-port Dynamic SOCKS-based port forwarding -L [listen-IP:]listen-port:host:port Forward local port to remote address -R [listen-IP:]listen-port:host:port Forward remote port to local address -X -x enable / disable X11 forwarding -A -a enable / disable agent forwarding -t -T enable / disable pty allocation -1 -2 force use of particular protocol version -4 -6 force use of IPv4 or IPv6 -C enable compression -i key private key file for user authentication -noagent disable use of Pageant -agent enable use of Pageant -noshare disable use of connection sharing -share enable use of connection sharing -hostkey aa:bb:cc:... manually specify a host key (may be repeated) -sanitise-stderr, -sanitise-stdout, -no-sanitise-stderr, -no-sanitise-stdout do/don't strip control chars from standard output/error -no-antispoof omit anti-spoofing prompt after authentication -m file read remote command(s) from file -s remote command is an SSH subsystem (SSH-2 only) -N don't start a shell/command (SSH-2 only) -nc host:port open tunnel in place of session (SSH-2 only) -sshlog file -sshrawlog file log protocol details to a file -shareexists test whether a connection-sharing upstream exists
window的expect命令不像linux的那么好用,可能是我没掌握好,下载地址也很不好找,使用的时候也跟linux不一样;所以在执行pscp的时候,有个嵌入命令(yes/no),可以在执行pscp命令前加上 echo y| pscp .... ,这样居然也能达到linux expect命令的效果。
window的start命令,类似linux的nohup,异步执行命令,跟pscp、plink结合使用,这样就实行多线程传输应用和远程执行linux脚本
还是贴代码吧,部署代码如下
@echo off for /f "eol=/delims=" %%s in (services.txt) do ( for /f "tokens=1,2,3,4 delims= " %%a in ('echo %%s') do ( start /b cmd /c "echo y|D:\tool\seo_deploy\pscp -scp -v -q -l %%c -pw %%d -P %%b E:\seo\seo \target\seo-0.0.1-SNAPSHOT.jar root@%%a:/opt/seo.jar & D:\tool\seo_deploy\plink -no-antispoof -l %%c -pw %%d -P %%b %%a ps -ef^|grep seo ^| awk '{if($0 ~/java/) print $2}' ^| xargs kill -9 ^| rm -rf ^/root^/seo.jar ^/root^/seo.log ^| mv ^/opt^/seo.jar ^/root^/ & D:\tool\seo_deploy\plink -no-antispoof -l %%c -pw %%d -P %%b %%a nohup java -DisProducer=true -Dshell='ifdown ppp0^,ifup ppp0' -DdesKey=^"AAAAA123^" -DipChannel=^"aaa^" - DredisHostName=^"127.0.0.1^" -Xms128m -Xmx640m -server -XX:^+UseParNewGC -XX:^+UseConcMarkSweepGC -XX:^ +CMSClassUnloadingEnabled -XX:^+CMSScavengeBeforeRemark -XX:^+DisableExplicitGC -Djava.awt.headless=true -jar seo.jar ^>^> seo.log 2^>^&1 ^&" echo ============我是分割线============ ) ) :cmd /k pause
services.txt为服务器列表
格式如下:
服务器ip1 22 root pwd 服务器ip2 22 root pwd
上一篇: 网页爬虫修改js文件
下一篇: windows上部署linux集群应用
推荐阅读
-
在Windows上使用putty远程登录Linux服务器的简单教程
-
自建windows服务器如何部署egg应用
-
浅谈Windows是如何把SQL Server迁移到Linux上的
-
如何在Windows系统上利用Telnet协议连接Linux服务器?
-
在Docker上开始部署Python应用的教程
-
.Net Core 在Linux服务器下部署程序--(1). Windows 连接 Linux服务器
-
mysql-8.0.13在windows上的部署
-
Linux上也有10个流行的Windows应用程序
-
Node.js环境在linux上的部署教程
-
CentOS+Linux部署.NET Core应用程序