北京SEO

通过网络连接模拟处理器QEMU的monitor

2019/10/10/17:46:34  阅读:2110  来源:谷歌SEO算法  标签: 区块链

QEMU是一套开源的模拟处理器,在GNU/Linux平台上使用广泛,本文我们将通过网络连接QEMU的监控器monitor.

1.QEMU monitor支持远程telnet访问:

[root@kvm-host ~]# qemu-system-x86_64 -enable-kvm -smp 2 -m 1024 vm2.img -monitor telnet:10.1.77.82:4444,server,nowait

关于这里-monitor的选项,做如下说明:

  1. tcp–rawtcpsockets#下面第2点,我的举例是RAWTCPsocket
  2. telnet–thetelnetprotocolisusedinsteadofrawtcpsockets.ThisisthepreferredoptionovertcpasyoucanbreakoutofthemonitorusingCtrl-]thentypingquit.Youcan’tbreakoutofthemonitorlikethisafterconnectingwiththerawsocketoption
  3. 10.1.77.82–Listenonthishost/IPonly.Youcanuse127.0.0.1ifyouwanttoonlyallowconnectionslocally.Ifyouwanttolistenonanyipaddressontheserver,justleavethisblanksoyouendupwithtwoconsecutivecolonsie“::”.
  4. 4444–portnumbertolistenon.
  5. server–listeninginservermode
  6. nowait–qemuwillwaitforaclientsocketapplicationtoconnecttotheportbeforecontinuingunlessthisoptionisused.Inmostcasesyou’llwanttousethenowaitoption.

通过telnet连接到远程的QEMU monitor上,代码如下:

  1. jay@jay-linux:~$telnet10.1.77.824444
  2. Trying10.1.77.82...
  3. Connectedto10.1.77.82.
  4. Escapecharacteris'^]'.
  5. QEMU1.7.50monitor-type'help'formoreinformation
  6. (qemu)infokvm
  7. kvmsupport:enabled
  8. (qemu)infostatus
  9. VMstatus:running
  10. (qemu)helpmigrate
  11. migrate[-d][-b][-i]uri--migratetoURI(using-dtonotwaitforcompletion)
  12. -bformigrationwithoutsharedstoragewithfullcopyofdisk--phpfensi.com
  13. -iformigrationwithoutsharedstoragewithincrementalcopyofdisk(baseimagesharedbetweensrcanddestination)
  14. (qemu)ctrl+](断掉telnet连接)
  15. telnet>quit(退出telnet)
  16. Connectionclosed.

2.QEMU monitor支持RAW socket的远程访问,代码如下:

[root@kvm-host ~]# qemu-system-x86_64 -enable-kvm -smp 2 -m 1024 vm2.img -monitor tcp:10.1.77.82:4444,server,nowait

可以使用netcat去连接这个socket,代码如下:

  1. jay@jay-linux:~$nc10.1.77.824444
  2. QEMU1.7.50monitor-type'help'formoreinformation
  3. (qemu)infokvm
  4. infokvm
  5. kvmsupport:enabled
  6. (qemu)^C

自己写了个socket程序示例如连接monitor,效果如下:

  1. jay@jay-linux:~/workspace/c-cpp.git/c2013$./monitor_client
  2. sendingcommand'infokvm
  3. 'toremoteqemumonitor
  4. outputfromqemumonitor:QEMU1.7.50monitor-type'help'formoreinformation
  5. ??,?
  6. outputfromqemumonitor:(qemu)infokvm
  7. kvmsupport:enabled
  8. (qemu)

上面那个连接monitor的socket程序示例为:

https://github.com/smilejay/c-cpp/blob/master/c2013/socket_qemu_monitor_client.c

代码如下:

  1. /*socket_qemu_monitor_clinet.c
  2. *ConnecttoremoteQEMUmonitorsocketandsendingacommandtothemonitor.
  3. *author:Jay<smile665@gmail.com>
  4. */
  5. #include<sys/types.h>
  6. #include<sys/socket.h>
  7. #include<stdio.h>
  8. #include<netinet/in.h>
  9. #include<arpa/inet.h>
  10. #include<unistd.h>
  11. #include<stdlib.h>
  12. #include<string.h>
  13. intmain(intargc,char*argv[])
  14. {
  15. intsockfd;
  16. intlen;
  17. structsockaddr_inaddress;
  18. intresult;
  19. char*cmd="infokvmn";
  20. charoutput[200];
  21. /*Createasocketfortheclient.*/
  22. sockfd=socket(AF_INET,SOCK_STREAM,0);
  23. /*Namethesocket,asagreedwiththeserver.*/
  24. address.sin_family=AF_INET;
  25. address.sin_addr.s_addr=inet_addr("10.1.77.82");
  26. address.sin_port=htons(4444);
  27. len=sizeof(address);
  28. /*Nowconnectoursockettotheserver'ssocket.*/
  29. result=connect(sockfd,(structsockaddr*)&address,len);
  30. if(result==-1){
  31. perror("oops:socketconnetionfailed.");
  32. exit(1);//phpfensi.com
  33. }
  34. /*Wecannowread/writeviasockfd.*/
  35. printf("sendingcommand'%s'toremoteqemumonitorn",cmd);
  36. write(sockfd,cmd,strlen(cmd));
  37. read(sockfd,output,sizeof(output));
  38. printf("outputfromqemumonitor:%sn",output);
  39. read(sockfd,output,sizeof(output));
  40. printf("outputfromqemumonitor:%sn",output);
  41. close(sockfd);
  42. exit(0);
  43. }

广告内容

通过网络连接模拟处理器QEMU的monitor 通过网络连接模拟处理器QEMU的monitor 通过网络连接模拟处理器QEMU的monitor

相关阅读

热门评论

SEO探索者团队 SEO探索者团队

SEO服务&网站优化

总篇数182

精选文章

RMAN中catalog和nocatalog区别介绍 小技巧:为Linux下的文件分配多个权限 zimbra8.5.1安装第三方签名ssl证书的步骤 解决mysql不能远程连接数据库方法 windows服务器mysql增量备份批处理数据库 mysql中slow query log慢日志查询分析 JavaScript跨域问题总结 Linux下负载均衡软件LVS配置(VS/DR)教程 mysql中权限参数说明 MYSQL(错误1053)无法正常启动

SEO最新算法