简体   繁体   English

是否可以在AWS EC2中从python运行Java命令行应用程序?

[英]Is it possible to run java command line app from python in AWS EC2?

I am working on some machine learning for chemical modelling in python. 我正在研究一些用于python中化学建模的机器学习。 I need to run a java app (from command line through python subprocess.call) and a python webserver. 我需要运行一个Java应用程序(从命令行通过python subprocess.call)和一个python网络服务器。 Is this possible on AWS EC2? 在AWS EC2上可能吗?

I currently have this setup running on my mac but I am curious on how to set it up on aws. 我目前在Mac上运行此设置,但对如何在AWS上设置感到好奇。

Thanks in advance! 提前致谢!

Since you're just making a command line call to the Java app, the path of least resistance would just be to make that call from another server using ssh. 由于您只是对Java应用程序进行命令行调用,因此阻力最小的方法就是使用ssh从另一台服务器进行该调用。 You can easily adapt the command you've been using with subprocess.call to use ssh -- more or less, subprocess.call(['ssh', '{user}@{server}', command]) (although have fun figuring out the quotation marks). 您可以轻松地将与subprocess.call一起使用的命令改编为使用ssh-或多或少, subprocess.call(['ssh', '{user}@{server}', command]) (尽管很有趣找出引号)。 As an aside on those lines, I usually find using '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' stabilizes scripted SSH calls in my environment. 顺便说一句,我通常会使用-o StrictHostKeyChecking = no -o UserKnownHostsFile = / dev / null在我的环境中稳定脚本化的SSH调用。

The more involved thing will be setting up the environments to properly run the components you need. 更复杂的事情是设置环境以正确运行所需的组件。 You'll need to set up ssh configs so that your django app can ssh over and set up -- probably with private key verification. 您需要设置ssh配置,以便您的django应用可以ssh并进行设置-可能使用私钥验证。 Then, you'll need to make sure that your EC2 security groups are set up to allow the ssh access to your java server on port 22, where sshd listens by default. 然后,您需要确保将EC2安全组设置为允许ssh访问端口22上的java服务器,默认情况下sshd侦听。

None of this is that hairy, but all the same, it might be stabler to just wrap your Java service in a HTTP server that your Django app can hit. 所有这些都不是那么繁琐,但是都一样,将Java服务包装在Django应用程序可以访问的HTTP服务器中可能会更稳定。 Anyway, hope this is helpful. 无论如何,希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM