- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我编写java项目时,我发现无法使用libvirt正确创建域。它抛出一个异常“qemu-system-x86_64:无法在‘127.0.0.1:4101’上启动VNC服务器:无法绑定(bind)套接字:地址已在使用中”,但我不使用“4101”端口。
系统信息:
# system centos7
$ uname -a
Linux bogon 3.10.0-957.27.2.el7.x86_64 #1 SMP Mon Jul 29 17:46:05 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
$ rpm -ql libvirt-java
/usr/share/doc/libvirt-java-0.4.9
/usr/share/doc/libvirt-java-0.4.9/AUTHORS
/usr/share/doc/libvirt-java-0.4.9/INSTALL
/usr/share/doc/libvirt-java-0.4.9/LICENCE
/usr/share/doc/libvirt-java-0.4.9/NEWS
/usr/share/doc/libvirt-java-0.4.9/README
/usr/share/java/libvirt-0.4.9.jar
/usr/share/java/libvirt.jar
$ java -version
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)
异常消息:
libvirt: QEMU Driver 错误 : 内部错误:process exited while connecting to monitor:
(process:5178): GLib-WARNING **: 08:32:41.803: gmem.c:489: custom memory allocation vtable not supported
2019-09-12T00:32:41.839117Z qemu-system-x86_64: Failed to start VNC server on `127.0.0.1:4101': Failed to bind socket: Address already in use
Exception in thread "main" org.libvirt.LibvirtException: 内部错误:process exited while connecting to monitor:
(process:5178): GLib-WARNING **: 08:32:41.803: gmem.c:489: custom memory allocation vtable not supported
2019-09-12T00:32:41.839117Z qemu-system-x86_64: Failed to start VNC server on `127.0.0.1:4101': Failed to bind socket: Address already in use
at org.libvirt.ErrorHandler.processError(Unknown Source)
at org.libvirt.Connect.processError(Unknown Source)
at org.libvirt.Connect.domainCreateXML(Unknown Source)
at open.main(open.java:20)
测试代码:
public class VirConnector {
static Connect connect;
public static Connect getConnection() {
try {
connect = new Connect("qemu:///system");
} catch ( LibvirtException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return connect;
}
}
public class VirtualManageService {
Connect connect = null;
//创建,加载镜像也是这个函数只是cfg不同而已
public boolean domainCreate(String cfg) throws LibvirtException {
//创建一个domain
boolean status = false;
try {
connect = VirConnector.getConnection();
connect.domainCreateXML(cfg,0);
status = true;
} catch (LibvirtException e) {
e.printStackTrace();
}
return status;
}
public boolean domainActive(String name) throws LibvirtException {
//创建一个domain
boolean status = false;
try {
connect = VirConnector.getConnection();
Domain domain = connect.domainLookupByName(name);
int num = domain.isActive();
if (num == 0){
domain.create();
status = true;
}else {
status = true;
}
} catch (LibvirtException e) {
e.printStackTrace();
}
return status;
}
//删除
public boolean domainDelete(String name) throws LibvirtException {
try {
connect = VirConnector.getConnection();
Domain domain = connect.domainLookupByName(name);
domain.destroy();
} finally {
}
return true;
}
//创建存储池
public boolean storagePoolCreate(String cfg) {
boolean status = false;
StoragePool storagePool = null;
try {
//创建存储池
connect = VirConnector.getConnection();
storagePool = connect.storagePoolDefineXML(cfg,0);
//激活
storagePool.create(0);
//设置自动启动
storagePool.setAutostart(0);
status = true;
} catch (LibvirtException e) {
e.printStackTrace();
}
return status;
}
//销毁存储池
public boolean storagePoolDelete(String name) throws LibvirtException {
boolean status = false;
StoragePool storagePool = null;
try {
//查找存储池
connect = VirConnector.getConnection();
storagePool = connect.storagePoolLookupByName(name);
//销毁对象
storagePool.destroy();
//清除定义
storagePool.undefine();
status = true;
} catch (LibvirtException e) {
e.printStackTrace();
}
return status;
}
//创建分卷
public boolean volumeCreate(String poolName,String cfg){
boolean status = false;
StoragePool storagePool = null;
StorageVol storageVol = null;
try {
//查找存储池
connect = VirConnector.getConnection();
storagePool = connect.storagePoolLookupByName(poolName);
//创建分卷
storagePool.storageVolCreateXML(cfg,0);
status = true;
} catch (LibvirtException e) {
e.printStackTrace();
}
return status;
}
//删除分卷
public boolean volumeDelete(String poolName,String volName){
boolean status = false;
StoragePool storagePool = null;
StorageVol storageVol = null;
try {
//查找存储池
connect = VirConnector.getConnection();
storagePool = connect.storagePoolLookupByName(poolName);
//查找分卷
storageVol = storagePool.storageVolLookupByName(volName);
//清空分卷数据
storageVol.wipe();
//删除分卷
storageVol.delete(0);
status = true;
} catch (LibvirtException e) {
e.printStackTrace();
}
return status;
}
//分卷迁移
public boolean volumeMove(String poolNameSrc,String volNameSrc,String poolNameDesc,String cfg) throws LibvirtException {
boolean status = false;
StoragePool storagePoolSrc = null;
StoragePool storagePoolDesc = null;
StorageVol storageVolSrc = null;
try {
//查找存储池
connect = VirConnector.getConnection();
storagePoolSrc = connect.storagePoolLookupByName(poolNameSrc);
//查找待迁移的分卷
storageVolSrc = storagePoolSrc.storageVolLookupByName(volNameSrc);
//查找目的存储池
if (poolNameDesc != poolNameSrc){
storagePoolDesc = connect.storagePoolLookupByName(poolNameDesc);
//将待迁移的分卷按照cfg的策略进行迁移
storagePoolDesc.storageVolCreateXMLFrom(cfg,storageVolSrc,0);
}else{
storagePoolSrc.storageVolCreateXMLFrom(cfg,storageVolSrc,0);
}
status = true;
} catch (LibvirtException e) {
e.printStackTrace();
}
return status;
}
//创建网络配置
public boolean networkCreate(String cfg){
boolean status = false;
Network network = null;
try {
connect = VirConnector.getConnection();
network = connect.networkDefineXML(cfg);
network.create();
network.getAutostart();
status = true;
} catch (LibvirtException e) {
e.printStackTrace();
}
return status;
}
//删除一个网络配置
public boolean networkDelete(String name){
boolean status = false;
Network network = null;
try {
connect = VirConnector.getConnection();
network = connect.networkLookupByName(name);
network.destroy();
network.undefine();
status = true;
} catch (LibvirtException e) {
e.printStackTrace();
}
return status;
}
}
@Controller
public class VirController {
//老师
@RequestMapping("/openExpVir.do")
@ResponseBody
// public String openVirtualForTeacher(HttpServletRequest request) throws IOException, LibvirtException, DocumentException {
public String openVirtualForTeacher(String coursename, String teacherID) throws IOException, LibvirtException {
//获取当前用户及其课程的信息
int[] port = new int[2];
// HttpSession session = request.getSession();
String link = "null";
//账号就是teacherDomain的主键
// String teacherID = (String) session.getAttribute("teacherID");
// String courseName = (String) session.getAttribute("coursename");
String courseName = coursename;
InquireDao inquireDao = new InquireDao();
port = inquireDao.inquireTeacherDomain(teacherID, courseName);
if (port[0] != 0 & port[1] != 0) {
boolean active = new VirtualManageService().domainActive(teacherID+courseName);
//1.传递参数
String shell = "bash " + "/shell/run.sh " + port[0] + " " + port[1];
//2.启动脚本
Process process = Runtime.getRuntime().exec(shell);
//创建连接,写入数据库意味着websocket创建成功,镜像创建成功。故直接访问link
link = "http://localhost:" + port[1] + "/vnc_lite.html";
} else {
//等待创建镜像和创建websocket
//创建镜像
VirtualManageService virtualManageService = new VirtualManageService();
//对镜像进行克隆
String volNameDesc = teacherID + courseName;
//配置文件
String pathVolMove = "/config/vol/defaultMove.xml";
XmlAlterService xmlVolMove = new XmlAlterService(pathVolMove);
xmlVolMove.xmlAlterName(volNameDesc);
String volDescCfg = xmlVolMove.xmlAlterVolPath("/home/chenyiguang/images/" + volNameDesc);
boolean isMove = virtualManageService.volumeMove("mypool", "sparse.img", "mypool", volDescCfg);
if (isMove) {
//成功
} else {
//失败
}
//获取配置文件 源配置文件
String path = "/config/dom/defaultDomain.xml";
XmlAlterService xmlDol = new XmlAlterService(path);
xmlDol.xmlAlterName(teacherID + courseName);
//自动选择端口
port = virtualManageService.selectPortForTeacher();
xmlDol.xmlAlterDomPort(port[0]);
String domainCfg = xmlDol.xmlAlterDomPath("/home/chenyiguang/images/" + volNameDesc);
boolean status = virtualManageService.domainCreate(domainCfg);
if (status == true) {
//创建成功
} else {
//创建失败
}
//写入数据库
AddDao addDao = new AddDao();
addDao.addTeacherDomain(teacherID, courseName, port[0], port[1]);
//创建websockify
//1.传递参数
String shell = "bash " + "/shell/run.sh " + port[0] + " " + port[1];
//2.启动脚本
Process process = Runtime.getRuntime().exec(shell);
link = "http://localhost:" + port[1] + "/vnc_lite.html";
}
return link;
}
配置文件
<?xml version="1.0" encoding="UTF-8"?>
<domain type="qemu">
<name>20050505云计算与大数据</name>
<memory unit="G">1</memory>
<vcpu>1</vcpu>
<os>
<type arch="x86_64" machine="pc">hvm</type>
<boot dev="hd"/>
</os>
<devices>
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<disk type="file" device="disk">
<source file="/home/chenyiguang/images/20050505云计算与大数据"/>
<target dev="hda"/>
</disk>
<interface type="network">
<source network="default"/>
</interface>
<input type="mouse" bus="ps2"/>
<graphics type="vnc" port="10001" listen="127.0.0.1"/>
</devices>
</domain>
$ virt-xml-validate error.xml
error.xml validates
最佳答案
It throws an exception that is "qemu-system-x86_64: Failed to start VNC server on `127.0.0.1:4101': Failed to bind socket: Address already in use", but I don't use the "4101" port.
这是一个稍微误导性的 QEMU 错误消息。
您的 XML 配置正在请求端口 10001:
<graphics type="vnc" port="10001" listen="127.0.0.1"/>
-vnc 的 QEMU 命令行参数不需要端口号,而是需要 VNC 显示号。要从端口号中获取 VNC 显示号,我们必须减去 5900。因此,您对端口 10001 的请求将变成 QEMU 命令行参数 -vnc 127.0.0.1:4101
。
QEMU 无法绑定(bind)到显示 4101/端口 10001,因为其他东西已经在监听它。
这里最简单的解决方案是根本不指定端口号,而是在 XML 配置中设置 autoport="yes"
,libvirt 会自动选择一个可用端口来使用。
关于java - 无法使用domainCreateXML或domainDefineXML函数在java中创建新域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57898378/
我需要将文本放在 中在一个 Div 中,在另一个 Div 中,在另一个 Div 中。所以这是它的样子: #document Change PIN
奇怪的事情发生了。 我有一个基本的 html 代码。 html,头部, body 。(因为我收到了一些反对票,这里是完整的代码) 这是我的CSS: html { backgroun
我正在尝试将 Assets 中的一组图像加载到 UICollectionview 中存在的 ImageView 中,但每当我运行应用程序时它都会显示错误。而且也没有显示图像。 我在ViewDidLoa
我需要根据带参数的 perl 脚本的输出更改一些环境变量。在 tcsh 中,我可以使用别名命令来评估 perl 脚本的输出。 tcsh: alias setsdk 'eval `/localhome/
我使用 Windows 身份验证创建了一个新的 Blazor(服务器端)应用程序,并使用 IIS Express 运行它。它将显示一条消息“Hello Domain\User!”来自右上方的以下 Ra
这是我的方法 void login(Event event);我想知道 Kotlin 中应该如何 最佳答案 在 Kotlin 中通配符运算符是 * 。它指示编译器它是未知的,但一旦知道,就不会有其他类
看下面的代码 for story in book if story.title.length < 140 - var story
我正在尝试用 C 语言学习字符串处理。我写了一个程序,它存储了一些音乐轨道,并帮助用户检查他/她想到的歌曲是否存在于存储的轨道中。这是通过要求用户输入一串字符来完成的。然后程序使用 strstr()
我正在学习 sscanf 并遇到如下格式字符串: sscanf("%[^:]:%[^*=]%*[*=]%n",a,b,&c); 我理解 %[^:] 部分意味着扫描直到遇到 ':' 并将其分配给 a。:
def char_check(x,y): if (str(x) in y or x.find(y) > -1) or (str(y) in x or y.find(x) > -1):
我有一种情况,我想将文本文件中的现有行包含到一个新 block 中。 line 1 line 2 line in block line 3 line 4 应该变成 line 1 line 2 line
我有一个新项目,我正在尝试设置 Django 调试工具栏。首先,我尝试了快速设置,它只涉及将 'debug_toolbar' 添加到我的已安装应用程序列表中。有了这个,当我转到我的根 URL 时,调试
在 Matlab 中,如果我有一个函数 f,例如签名是 f(a,b,c),我可以创建一个只有一个变量 b 的函数,它将使用固定的 a=a1 和 c=c1 调用 f: g = @(b) f(a1, b,
我不明白为什么 ForEach 中的元素之间有多余的垂直间距在 VStack 里面在 ScrollView 里面使用 GeometryReader 时渲染自定义水平分隔线。 Scrol
我想知道,是否有关于何时使用 session 和 cookie 的指南或最佳实践? 什么应该和什么不应该存储在其中?谢谢! 最佳答案 这些文档很好地了解了 session cookie 的安全问题以及
我在 scipy/numpy 中有一个 Nx3 矩阵,我想用它制作一个 3 维条形图,其中 X 轴和 Y 轴由矩阵的第一列和第二列的值、高度确定每个条形的 是矩阵中的第三列,条形的数量由 N 确定。
假设我用两种不同的方式初始化信号量 sem_init(&randomsem,0,1) sem_init(&randomsem,0,0) 现在, sem_wait(&randomsem) 在这两种情况下
我怀疑该值如何存储在“WORD”中,因为 PStr 包含实际输出。? 既然Pstr中存储的是小写到大写的字母,那么在printf中如何将其给出为“WORD”。有人可以吗?解释一下? #include
我有一个 3x3 数组: var my_array = [[0,1,2], [3,4,5], [6,7,8]]; 并想获得它的第一个 2
我意识到您可以使用如下方式轻松检查焦点: var hasFocus = true; $(window).blur(function(){ hasFocus = false; }); $(win
我是一名优秀的程序员,十分优秀!