使用Paramiko穿越堡垒机连接服务器的方法
最编程
2024-02-10 08:45:29
...
paramiko 通过堡垒机连接服务器
#!/usr/bin/env python
# encoding: utf-8
import paramiko
import time
def get_inst_log(ip,command):
ssh=paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('test.lili.test','2222','xxxxx','123',timeout=10)
invoke=ssh.invoke_shell()
invoke.send(ip+'\r')
#time.sleep(2)
invoke.send('5\r')
#invoke.send('ll\r')
time.sleep(2)
invoke.send(command+'\r')
time.sleep(2)
a=invoke.recv(99999).decode()
print(a)
ssh.close()
if __name__=="__main__":
ip='127.0.0.1'
command=r'tail -f /AppHome/Logs/zf/all.8080.log'
get_inst_log(ip,command)
©著作权归作者所有,转载或内容合作请联系作者
推荐阅读
-
总结使用 OpenCv 连接海康威视摄像机回放视频片段的两种方法(演示)
-
如何在RDS SQL Server中使用链接服务器连接到互联网的方法
-
使用Python(paramiko库)连接Linux服务器的方法
-
使用Python 3的paramiko库连接本地SSH服务器指南
-
使用Python的Paramiko库实现远程SSH连接,执行nohup命令的方法
-
使用Paramiko穿越堡垒机连接服务器的方法
-
玩转Java底层:JMX详解 - jconsole与自定义MBean监控工具的实际应用与区别" 在日常JVM调优中,我们熟知的jconsole工具通过JMX包装的bean以图形化形式展示管理数据,而像jstat和jmap这类内建监控工具则由JVM直接支持。本文将以jconsole为例,深入讲解其实质——基于JMX的MBean功能,包括可视化界面上的bean属性查看和操作调用。 MBeans在jconsole中的体现是那些可观察的组件属性和方法,如上图所示,通过名为"Verbose"的属性能看到其值为false,同时还能直接操作该bean的方法,例如"closeJerryMBean"。 尽管jconsole给我们提供了直观的可视化界面,但请注意,这里的MBean并非固定不变,开发者可根据JMX提供的接口将自己的自定义bean展示到jconsole。以下步骤展示了如何创建并注册一个名为"StudyJavaMBean"的自定义MBean: 1. 首先定义接口`StudyJavaMBean`,接口需遵循MBean规范,即后缀为"MBean"且包含getter方法代表属性,如`getApplicationName`,和无返回值的setter方法代表操作,如`closeJerryMBean`。 ```java public interface StudyJavaMBean { String getApplicationName(); void closeJerryMBean(); } ``` 2. 编写接口的实现类`StudyJavaMBeanImpl`,实现接口中的方法: ```java public class StudyJavaMBeanImpl implements StudyJavaMBean { @Override public String getApplicationName() { return "每天学Java"; } @Override public void closeJerryMBean() { System.out.println("关闭Jerry应用"); } } ``` 3. 在代码中注册自定义MBean,涉及的关键步骤包括: - 获取平台MBeanServer - 定义ObjectName,指定唯一的MBean标识符 - 注册MBean到服务器 - 启动RMI连接器服务,以便jconsole能够访问 ```java public void registerMBean() throws Exception { // ... 具体实现省略 ... } ``` 实际运行注册后的MBean,您将在jconsole中发现并查看自定义bean的属性和调用相关方法。然而,这种方式相较于传统的属性/日志查看和HTTP接口,实用性相对有限,可能存在潜在的安全风险。但不可否认的是,JMX及其MBean机制对于获取操作系统信息、内存状态等关键性能指标仍然具有重要价值。例如: 1. **获取操作系统信息**:通过JMX MBean,可以直接获取到诸如CPU使用率、操作系统版本等系统级信息,这对于资源管理和优化工作具有显著帮助。
-
搭建本地rtmp直播服务器的方法,使用CentOS虚拟机