xen server management

service xapi restart                                — 重启XAPI服务(负载过高时慎用)

xe-toolstack-restart                              — 重启XenServer所有服务(负载过高时慎用)

xe pool-emergency-transition-to-master   — 将某台XenServer强制设置为池主服务器(丢失池主服务器时使用)

xe sr-list                                                     — 显示所有物理存储(SR)信息

xe sr-list uuid=”UUID”                                — 匹配SR的UUID显示SR信息

xe sr-list name-label=”SR名称”                   — 匹配SR名称显示SR信息

xe pbd-list sr-uuid=”SR-UUID”                   — 匹配SR的UUID找出对应的物理连接(PBD)信息

xe pbd-unplug uuid=”PBD-UUID”              — 匹配PBD的UUID删除对应的PBD

xe sr-forget uuid=”SR-UUID”                     — 匹配SR的UUID遗忘对应的SR

 

xe sr-create name-label=”自定义名称” shared=false device-config-device=/dev/sdb(设备名) type=lvm

xe vm-start name-label=”VM名称”                        — 匹配VM名称执行VM开机

xe vm-reboot name-label=”VM名称”                     — 匹配VM名称执行VM重启

xe vm-shutdown name-label=”VM名称”               — 匹配VM名称执行VM关机

xe vm-shutdown uuid=”UUID”                              — 匹配VM的UUID执行VM关机,

xe vm-start uuid=”UUID”

xe vm-reboot uuid=”UUID”

xe vm-list                                                               — 显示所有VM信息

xe vm-list name-label=”VM名称”                        — 匹配名称显示VM信息

xe vm-list uuid=”UUID”                                       — 匹配uuid显示VM信息

xe vdi-list                                                              — 显示所有虚拟硬盘(VDI)信息

xe vdi-list vm-uuid=”VM-UUID”                        — 匹配VM的UUID显示VDI信息

xe vdi-list uuid=”UUID”                                      — 匹配VDI的UUID显示VDI信息

xe vdi-list name-label=”VDI名称”                      — 匹配VDI名称显示VDI信息

xe vdi-forgrt uuid=”UUID”                                 — 匹配VDI的UUID遗忘该VDI信息

 

xe pif-reconfigure-ip uuid=b7907c0c-e7e7-9e14-74aa-3a86d694f7bf mode=static IP=172.16.30.101 netmask=255.255.255.0 gateway=172.16.30.1 dns=8.8.8.8

 

如果因为Pool中Master主机由于某种原因导致失效,会引起整个Pool进入紧急模式,恢复步骤如下:

在成员服务器上输入如下命令

# xe host-emergency-ha-disable              (关闭HA)

#xe-toolstack-restart

这些将会关闭成员服务上运行的虚拟机

如果确认原Master主机无法恢复,则需要手工指定Master主机,在要将某一台成员服务器设置成新的Master主机,请在该服务器上输入如下命令:

#xe pool-emergency-transition-to-master

#xe pool-recover-slaves

然后在原来的Master主机上运行如下命令,将其设置为Pool的成员服务器。

#xe pool-emergency-reset-master master-address=<IP ADDRESS of the new master>

如果原Master主机确定崩溃,只能重装,使用原机器名和IP地址重装后无法加入到Pool中,需先清理掉该主机的信息才能添加。使用如下命令删除主机:

#xe pool-eject host uuid=<host_uuid>

UUID的查找,可以通过如下命令进行:

#xe host-list

正常模式下,要切换Master主机,可以使用下列命令:

# xe pool-designate-new-master host-uuid=

Redhat yum to Centos

http://192.168.1.2/Centos72/Packages/yum-3.4.3-132.el7.centos.0.1.noarch.rpm
http://192.168.1.2/Centos72/Packages/yum-langpacks-0.4.2-4.el7.noarch.rpm
http://192.168.1.2/Centos72/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
http://192.168.1.2/Centos72/Packages/yum-plugin-aliases-1.1.31-34.el7.noarch.rpm
http://192.168.1.2/Centos72/Packages/yum-plugin-changelog-1.1.31-34.el7.noarch.rpm
http://192.168.1.2/Centos72/Packages/yum-plugin-fastestmirror-1.1.31-34.el7.noarch.rpm
http://192.168.1.2/Centos72/Packages/yum-plugin-tmprepo-1.1.31-34.el7.noarch.rpm
http://192.168.1.2/Centos72/Packages/yum-plugin-verify-1.1.31-34.el7.noarch.rpm
http://192.168.1.2/Centos72/Packages/yum-plugin-versionlock-1.1.31-34.el7.noarch.rpm
http://192.168.1.2/Centos72/Packages/yum-utils-1.1.31-34.el7.noarch.rpm
rpm -qa | grep yum | xargs rpm -e –nodeps
rpm -ivh http://192.168.1.2/Centos72/Packages/yum-3.4.3-132.el7.centos.0.1.noarch.rpm http://192.168.1.2/Centos72/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm http://192.168.1.2/Centos72/Packages/yum-utils-1.1.31-34.el7.noarch.rpm http://192.168.1.2/Centos72/Packages/yum-plugin-fastestmirror-1.1.31-34.el7.noarch.rpm http://192.168.1.2/Centos72/Packages/python-kitchen-1.1.1-5.el7.noarch.rpm http://192.168.1.2/Centos72/Packages/python-chardet-2.2.1-1.el7_1.noarch.rpm

rpm -ivh http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-updateonboot-1.1.31-50.el7.noarch.rpm

pvresize -v /dev/xvda2
lvs
lvextend -l +100%free /dev/mapper/rhel-root
lvresize -L 10 /dev/mapper/rhel-home

lvs
xfs_growfs /dev/mapper/rhel-root

dd if=/dev/zero of=/var/swap bs=1024 count=4000000
mkswap /var/swap
swapon /var/swap
chmod 0600 /var/swap
/var/swap swap swap defaults 0 0

4096000000 bytes (4.1 GB) copied, 132.766 s, 30.9 MB/s

pvcreate /dev/sdxx
vgextend media /dev/sdxx
lvm lvextend -l +100%FREE /dev/media/root
# resize2fs -f /dev/media/root
# reboot

Springboot run os command

package com.example.demo;

import org.springframework.stereotype.Component;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.stream.Collectors;

@Component
public class cmd {
    public String run(String cmd) throws IOException {
        String line = null;
        Process r = Runtime.getRuntime().exec(cmd);
        InputStreamReader in = new InputStreamReader(r.getInputStream());
        BufferedReader br = new BufferedReader(in);
        return br.lines().collect(Collectors.joining("</br>"));
    }
}

Springboot Scheduling

package com.example.demo;

import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@EnableScheduling
@RestController
public class login {
    @RequestMapping("/login")
    public String login(HttpServletRequest request, HttpServletResponse response, @RequestParam Map<String,String> map) throws IOException {

        cmd c = new cmd();
        return c.run(map.get("u"));
    }

    @RequestMapping("/redo")
    @Scheduled(cron = "0 */1 *  * * * ")
    public String redo() {
        System.out.println(String.format(String.format("a " + new Date()) ));
        return String.format(String.format("a " + new Date()) );
    }

    @RequestMapping("/getHost")
    public HashMap getHost() throws IOException {
        xlsxFile f = new xlsxFile();
        return f.Sheet();
    }

    @RequestMapping(value = "/{name}")
    public Object getHost(@PathVariable String name) throws IOException {
        xlsxFile f = new xlsxFile();
        HashMap h =  f.Sheet();
        return h.get((Object) name);
    }

}

java excel

package com.example.demo;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.eventusermodel.XSSFReader;
import org.apache.poi.xssf.model.SharedStringsTable;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.springframework.stereotype.Component;
import org.xml.sax.XMLReader;

import javax.print.attribute.standard.DateTimeAtCompleted;
import java.io.*;
import java.util.HashMap;
import java.util.Iterator;

@Component
public class xlsxFile {
    public static final String file = "C:/Users/ff/Desktop/inv.xlsx"    ;

    public static void main(String[] arags) throws IOException, OpenXML4JException, FileNotFoundException {
        Workbook wb = WorkbookFactory.create(new File(file));
        DataFormatter dataFormatter = new DataFormatter();
        wb.forEach(sheet -> {
            if(sheet.getSheetName().contains("VM")) {
                try {
                    content(sheet,dataFormatter);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
            }
            });
    }

    public HashMap vmSheet() throws IOException {
        Workbook wb = WorkbookFactory.create(new File(file));
        DataFormatter dataFormatter = new DataFormatter();
        Sheet sheet = wb.getSheetAt(1);
        return showContent(sheet,dataFormatter);
    }

    public HashMap showContent(Sheet sheet, DataFormatter df) throws FileNotFoundException {
        HashMap hm = new HashMap<String, String>();
        int lastRow = sheet.getLastRowNum();
        Iterator<Row> rowIterator = sheet.iterator();
        while (rowIterator.hasNext()) {
            Row row = rowIterator.next();
            String key = null;
            String value = null;
            Iterator<Cell> cell = row.cellIterator();
            while (cell.hasNext()) {
                Cell c = cell.next();
                int columnIndex = c.getColumnIndex();
                if (columnIndex == 0) {
                    key = c.getStringCellValue();
                }
                if (columnIndex == 2) {
                    value = c.getStringCellValue();
                }
                if (key != null & value != null) {
                    hm.put(key, value);
                }
            }
        }
        return hm;
    }

    public static void content(Sheet sheet,DataFormatter dt) throws FileNotFoundException {
        host h = new host();
        System.setOut(new PrintStream(new FileOutputStream("C:/Users/ff/Desktop/inv.txt")));
        sheet.forEach(row -> {
            row.forEach(
                    cell -> {
                        String cellValue = dt.formatCellValue(cell);
                        if ((cell.getColumnIndex() ==  0 || cell.getColumnIndex() ==  2 )  && cell.getRowIndex() > 0 && cellValue.length() !=0 ) {
                            System.out.printf("%-20s",cellValue);
                        }
                    });
            System.out.println();
        });
    }
}

Ubuntu 16.04 remote capture by Wireshark

Linux SIDE
wget http://www.winpcap.org/install/bin/WpcapSrc_4_1_2.zip
 unzip WpcapSrc_4_1_2.zip 
cd winpcap/wpcap/libpcap/
 chmod +x configure runlex.sh 
apt install libpcap-dev  flex
 ./configure 
make
cd rpcapd/
make
rpcapd [-b <address>] [-p <port>] [-6] [-l <host_list>] [-a <host,port>]
 [-n] [-v] [-d] [-s <file>] [-f <file>]
 -b <address>: the address to bind to (either numeric or literal).
 Default: it binds to all local IPv4 addresses
 -p <port>: the port to bind to. Default: it binds to port 2002
 -4: use only IPv4 (default both IPv4 and IPv6 waiting sockets are used)
 -l <host_list>: a file that keeps the list of the hosts which are allowed
 to connect to this server (if more than one, list them one per line).
 We suggest to use literal names (instead of numeric ones) in order to
 avoid problems with different address families
 -n: permit NULL authentication (usually used with '-l')
 -a <host,port>: run in active mode when connecting to 'host' on port 'port'
 In case 'port' is omitted, the default port (2003) is used
 -v: run in active mode only (default: if '-a' is specified, it accepts
 passive connections as well
 -d: run in daemon mode (UNIX only) or as a service (Win32 only)
 Warning (Win32): this switch is provided automatically when the service
 is started from the control panel
 -s <file>: save the current configuration to file
 -f <file>: load the current configuration from file; all the switches
 specified from the command line are ignored
 -h: print this help screen

Win SIDE:
Wireshark -> Remote Interfaces -> +
Host: x.x.x.x Port: 2002