通过 Web 界面使用 Python/Django 执行系统管理任务
我刚刚开始学习Django,我的主要目标是建立一个公司内网网站我可以在其中执行系统管理操作,例如备份、恢复等。
我找到了有关一般网站的各种 Django 教程,但我找不到任何教程/链接,其中有些人考虑通过 Web 界面执行系统管理操作。
如何使用模型/视图并与 Python 函数集成?
I have just started learning Django and my main aim is to build a company intranet website where I can do system administration things like backups, restore, etc.
I have found various Django tutorials about general web sites, but I could not find any tutorials / links where some have thought about doing system administration things via a web interface.
How can I use models / views and integrate with Python functions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您只想执行管理任务,那么我建议使用 webmin。如果您只是想这样做来学习 Django/Python 然后随意使用 webmin 的功能作为指导。考虑一下备份、移动文件和其他管理任务所涉及的所有步骤。这应该可以帮助您更好地理解问题并将其分解为可管理的块。
请记住,Django 实际上只是底层的 Python,它可以是一个非常强大的工具。尝试查看一些用于系统管理的 Python 脚本。也许您可以将它们改编为网络界面。
If all you want is to do administration tasks then I suggest using webmin. If you just want to do this to learn Django/Python then feel free to use the functionality of webmin as a guide. Think about all the steps involved in taking backups, moving files around and other administration tasks. This should help you understand the problem better and break it into manageable chunks.
Remember that Django is really just Python underneath, and it can be a vastly powerful tool. Try looking at some of your Python scripts that you use for systems administration. Maybe you can adapt those as a web interface.
Ansible 执行您所描述的操作。
Ansible does what you describe.
正如 Devin M 所说,Django 在后端“只是 Python”(即你的视图调用的函数),所以如果你真的想要,你可以使用像 Fabric 来调用系统管理操作,而不需要您的 Web 服务器直接访问基础设施。
As Devin M says, Django is 'just Python' in the backend (that is, the functions your views call), so if you really wanted to, you could use a library like Fabric to invoke system administration actions without needing your web server to have direct access to the infrastructure.
您可以使用 Python (Django) + SSH 来执行所有系统管理任务。在我的地方,我们建立了一个具有系统管理功能的网络自定义计算机监控系统。
您所需要的基本上就是为每台服务器设置无密码 SSH 连接。我们选择使用 SSH 密钥方法。所有系统管理任务均使用 SSH 执行,例如
ssh user@server1 'sh backupall.sh'
。剩下的就是创建一个执行所有这些 SSH 命令的 Python (Django) 应用程序。You can use Python (Django) + SSH for doing all the system administration tasks. At my place, we built a web custom computer monitoring system with a system administration capability.
All you need is basically setting up a password-less SSH connection for each server. We chose to use the SSH key method. All system administration tasks were executed using SSH, for example
ssh user@server1 'sh backupall.sh'
. All that was left was creating a Python (Django) application which executes all these SSH commands.