远程部署到 .NET Box
多年来,我一直能够使用 Jenkins 等连续构建系统进行构建,然后远程部署我的应用程序到各种 Unix 服务器。我可以使用 ssh
和 scp
命令来执行我的命令。
现在,我正在构建 .NET。我已经使用 Jenkins 完成了构建,现在想部署到远程 .NET 服务器。我需要关闭应用程序,复制文件,然后重新启动应用程序。我需要能够通过命令行工具(无 GUI 工具)远程执行此操作。我在一系列被锁定的机器上,不能随意部署东西——尤其是生产机器。
是否有一种机制可以让我远程关闭服务器、部署一组新文件并重新启动应用程序?
额外问题
我知道 *.cab
文件有点类似于 Java *.jar
文件。也就是说,您可以将单个 *.cab
文件部署到服务器,服务器会将其视为目录中的一堆文件。
- 这是正确的吗?如果是这样,我想使用 cab 文件来部署东西。
- 我的构建中有一个
webapp.config
文件,该文件对于每个服务器都不同。我更愿意创建一个不包含webapp.config
文件的 cab 文件,这样,我的 cab 文件就可以部署到每台计算机上而无需更改它(仅 webapp.config 文件必须改变)。
谢谢
附录,
我只是无法获胜...
我在 machine02 上构建了一个版本,我需要部署到 machine06 上。 Machine06 位于 DMZ 中,因此我无法在其上添加域用户。我只能创建本地帐户。
通过 sc
,我可以访问远程系统,但我运行 sc
的帐户也需要存在于远程系统上。由于我无法在 machine06 上创建域帐户,并且无法将计算机本地帐户添加到另一个 Windows 系统(即,使 machine06\user 也成为 machine02 上的管理员),所以我无法使用 sc
。
我尝试了 Sysinternals 中的 lp 命令。这些允许我指定用户名和密码(我假设是用于其他系统的)。但是,我收到以下错误:
C:\Windows\system32>pslist \\machine02 -user remuser02 -password Swordfish
pslist v1.29 - Sysinternals PsList
Copyright (C) 2000-2009 Mark Russinovich
Sysinternals
Cannot connect to remote registry on MACHINE02:
Access is denied.
Failed to take process snapshot on MACHINE02.
Make sure that the Remote Registry service is running on the remote system,
that you havefirewall ports allow RPC access, and your account has read
access the following key on the remote system:
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Perflib
C:\Windows\system32>
由于该用户是 machine02 上的管理员,我确信该用户具有对 Windows 注册表项的读取访问权限,并且我验证了远程注册表访问已打开。
因此,sc
已退出,因为我无法指定要使用的帐户。我无法添加服务器上的 sshd
。
For years, I've been able to do a build using a continuous build system like Jenkins and then remotely deploying my apps to various Unix servers. I can use the ssh
and scp
commands to do my bidding.
Now, I have a .NET build I'm doing. I've done the build using Jenkins and would now like to deploy to a remote .NET server. I need to shutdown the application, copy the files over, and then restart the application. I need to be able to do this remotely and via command line tools (no GUI tools). I am on a series of machines that are locked down, and cannot deploy stuff willy-nilly -- especially to the production machines.
Is there a mechanism that will allow me to remotely shutdown the server, deploy a new set of files, and restart the application?
BONUS QUESTION
I understand that a *.cab
file is somewhat similar to a Java *.jar
file. That is, you can deploy a single *.cab
file to a server, and the server will treat it as if it's a bunch of files in a directory.
- Is this correct? If so, I'd like to deploy things using the cab file.
- There is a
webapp.config
file that's part of my build that's different for each and every server. I'd prefer to create a cab file that does not contain thewebapp.config
file, that way, the cab file I have can be deployed to every machine without changing it (only the webapp.config file has to be changed).
Thanks
Addendum
I just can't win...
I have a build on machine02 and I need to deploy to machine06. Machine06 is in a DMZ, so I can't add a domain user on it. I can only create local accounts.
With sc
, I can access remote systems, but the account I'm running sc
from also needs to exist on the remote system. Since I can't create a domain account on machine06, and I can't add a computer local account to another Windows system (i.e., make machine06\user an administrator on machine02 too)., I can't use sc
.
I tried the lp commands from Sysinternals. These allow me to specify a user name and password (which I assume is for the other system. However, I get the following error:
C:\Windows\system32>pslist \\machine02 -user remuser02 -password Swordfish
pslist v1.29 - Sysinternals PsList
Copyright (C) 2000-2009 Mark Russinovich
Sysinternals
Cannot connect to remote registry on MACHINE02:
Access is denied.
Failed to take process snapshot on MACHINE02.
Make sure that the Remote Registry service is running on the remote system,
that you havefirewall ports allow RPC access, and your account has read
access the following key on the remote system:
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Perflib
C:\Windows\system32>
Since that user is an admin on machine02, I am sure that user has read access to the Windows registry key, and I verified that Remote Registry Access is on. I suspect that the router is blocking RPC calls.
So, sc
is out since I can't specify an account to use. The Sysinternals PS tools are out. I can't add the sshd
on the server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在部署 Web 应用程序时,我之前使用过 vbscript 和 powershell 以及老式的 xcopy(尽管我同意 robocopy 可能是更好的副本替代品)。
因此,了解一下要求 - 我认为这是您想要做的事情(这应该通过 PowerShell 命令提示符完成):
我不会使用 *.cab 除非您想要压缩来传输文件,然后我会使用 *.zip 文件。我不认为两者之间有任何真正的区别,但通常 *.cab 文件用于 msi 部署。
就个人而言,除非您有人很好地理解 MSI 版本控制,否则我认为 MSI 不应该用于将文件部署到 Web 服务器。即使有人确实理解它,我仍然喜欢它只对跟踪安装的内容有用,可以通过多种方式实现,同时避免自动更新等...
由于它是 IIS,因此您可以在网站打开时删除临时 asp.net 文件向下。
我(根据标签)假设这是一个 Web 应用程序,因此在代码中使用 iisadmin。这同样适用于任何服务。
哈特哈,
马特
When deploying web applications before I've used vbscript and powershell plus good old fashioned xcopy (though I'd agree robocopy is probably a better copy replacement).
So going through the requirements - I think this is the sort of thing you want to do (this should be done form a PowerShell command prompt):
I wouldn't use *.cab unless you wanted compression for transferring the files then I'd use a *.zip file. I don't believe their is any real difference between the two but in general *.cab files are used in msi deployments.
Personally, unless you have someone how understands MSI versioning well, I don't think MSI should be used to deploy files to a web server. And even if someone did understand it I still like it's only useful for tracking what's installed where which can be achieved many ways whilst avoiding autoupdate etc...
As it's IIS you may what to remove the temporary asp.net files whilst the web site is down.
I've made the assumption (from the tags) that this is a web application, hence iisadmin in the code. This would equally work with any service.
HTH,
Matt
您可以使用 netsvc.exe 停止和启动远程计算机上的 IIS 服务
You could use netsvc.exe to stop and start the IIS service on the remote machine
我看到您已经接受了答案,但我想我会添加这个,因为也许对其他人有用:
您也可以使用 PsTools。它允许您远程执行命令、停止和启动服务、复制文件等(无需在目标主机上安装)。
I see you have already accepted an answer, but I thought I would add this, because maybe it is useful to someone else:
You could also use PsTools. It allows you to remotely execute commands, stop and start services, copy files etc. (No installation needed on the target host).
也许您想尝试 Windows 版本的 SSH 服务器?例如http://mobassh.mobatek.net/。与往常一样,免费版本的功能较少,但如果您能够远程执行命令,您也许能够执行部署任务。
Perhaps you want to try a Windows version of an SSH server? For example http://mobassh.mobatek.net/. As usual, the free version has fewer features, but if you are able to execute commands remotely, you might be able to do carry your deployment tasks.