PPT2ANY转换工具

PPT2ANY.vbs

Option Explicit

PPT2ANY "PATH_TO_INFILE\NEOHOPE.COM.IN.pptx","PATH_TO_INFILE\NEOHOPE.COM.OUT.pdf","PDF"
PPT2ANY "PATH_TO_INFILE\NEOHOPE.COM.IN.pptx","PATH_TO_INFILE\NEOHOPE.COM.OUT.png","PNG"

Sub PPT2ANY( inFile, outFile, outFormat)
	Dim objFSO, objPPT, objPresentation, pptFormat

	Const ppSaveAsAddIn                             =8
	Const ppSaveAsBMP                               =19
	Const ppSaveAsDefault                           =11
	Const ppSaveAsEMF                               =23
	Const ppSaveAsExternalConverter                 =64000
	Const ppSaveAsGIF                               =16
	Const ppSaveAsJPG                               =17
	Const ppSaveAsMetaFile                          =15
	Const ppSaveAsMP4                               =39
	Const ppSaveAsOpenDocumentPresentation          =35
	Const ppSaveAsOpenXMLAddin                      =30
	Const ppSaveAsOpenXMLPicturePresentation        =36
	Const ppSaveAsOpenXMLPresentation               =24
	Const ppSaveAsOpenXMLPresentationMacroEnabled   =25
	Const ppSaveAsOpenXMLShow                       =28
	Const ppSaveAsOpenXMLShowMacroEnabled           =29
	Const ppSaveAsOpenXMLTemplate                   =26
	Const ppSaveAsOpenXMLTemplateMacroEnabled       =27
	Const ppSaveAsOpenXMLTheme                      =31
	Const ppSaveAsPDF                               =32
	Const ppSaveAsPNG                               =18
	Const ppSaveAsPresentation                      =1
	Const ppSaveAsRTF                               =6
	Const ppSaveAsShow                              =7
	Const ppSaveAsStrictOpenXMLPresentation         =38
	Const ppSaveAsTemplate                          =5
	Const ppSaveAsTIF                               =21
	Const ppSaveAsWMV                               =37
	Const ppSaveAsXMLPresentation                   =34
	Const ppSaveAsXPS                               =33

	' Create a File System object
	Set objFSO = CreateObject( "Scripting.FileSystemObject" )

	' Create a PowerPoint object
	Set objPPT = CreateObject( "PowerPoint.Application" )

	With objPPT
		' True: make PowerPoint visible; False: invisible
		.Visible = True
 
		' Check if the PowerPoint document exists
		If not( objFSO.FileExists( inFile ) ) Then
			WScript.Echo "FILE OPEN ERROR: The file does not exist" & vbCrLf
			' Close PowerPoint
			.Quit
			Exit Sub
		End If
 
		' Open the PowerPoint document
		.Presentations.Open inFile
 
		' Make the opened file the active document
		Set objPresentation = .ActivePresentation
 
		If StrComp(Ucase( outFormat ),"PDF") = 0 then
			pptFormat = ppSaveAsPDF 
		ElseIf StrComp(Ucase( outFormat ),"XPS") = 0 then
			pptFormat = ppSaveAsXPS
		ElseIf StrComp(Ucase( outFormat ),"BMP") = 0 then
			pptFormat= ppSaveAsBMP
		ElseIf StrComp(Ucase( outFormat ),"PNG") = 0 then
			pptFormat= ppSaveAsPNG
		ElseIf StrComp(Ucase( outFormat ),"JPG") = 0 then
			pptFormat= ppSaveAsJPG
		ElseIf StrComp(Ucase( outFormat ),"GIF") = 0 then
			pptFormat= ppSaveAsGIF
		ElseIf StrComp(Ucase( outFormat ),"XML") = 0 then
			pptFormat= ppSaveAsOpenXMLPresentation
		ElseIf StrComp(Ucase( outFormat ),"RTF") = 0 then
			pptFormat= ppSaveAsRTF
		Else
			WScript.Echo "FILE FORTMART ERROR: Unknown file format" & vbCrLf
			' Close PowerPoint
			.Quit
			Exit Sub
		End If

		' Save in PDF/XPS format
		objPresentation.SaveAs outFile, pptFormat
 
		' Close the active document
		objPresentation.Close
 
		' Close PowerPoint
		.Quit
	End With
End Sub

Excel2ANY转换工具

Excel2ANY.vbs

Option Explicit

Excel2ANY "PATH_TO_INFILE\NEOHOPE.COM.IN.xlsx","PATH_TO_OUTFILE\NEOHOPE.COM.OUT.pdf","PDF"
Excel2ANY "PATH_TO_INFILE\NEOHOPE.COM.IN.xlsx","PATH_TO_OUTFILE\NEOHOPE.COM.OUT.xps","XPS"
Excel2ANY "PATH_TO_INFILE\NEOHOPE.COM.IN.xlsx","PATH_TO_OUTFILE\NEOHOPE.COM.OUT.csv","CSV"

Private Sub Excel2ANY(inFile, outFile, outFormat)
	Dim objFSO, objExcel, objWorkbook, objSheet, xlFormat, isSaveAs

	Const xlAddIn                           =18
	Const xlAddIn8                          =18
	Const xlCSV                             =6
	Const xlCSVMac                          =22
	Const xlCSVMSDOS                        =24
	Const xlCSVWindows                      =23
	Const xlCurrentPlatformText             =-4158
	Const xlDBF2                            =7
	Const xlDBF3                            =8
	Const xlDBF4                            =11
	Const xlDIF                             =9
	Const xlExcel12                         =50
	Const xlExcel2                          =16
	Const xlExcel2FarEast                   =27
	Const xlExcel3                          =29
	Const xlExcel4                          =33
	Const xlExcel4Workbook                  =35
	Const xlExcel5                          =39
	Const xlExcel7                          =39
	Const xlExcel8                          =56
	Const xlExcel9795                       =43
	Const xlHtml                            =44
	Const xlIntlAddIn                       =26
	Const xlIntlMacro                       =25
	Const xlOpenDocumentSpreadsheet         =60
	Const xlOpenXMLAddIn                    =55
	Const xlOpenXMLStrictWorkbook           =61 
	Const xlOpenXMLTemplate                 =54
	Const xlOpenXMLTemplateMacroEnabled     =53
	Const xlOpenXMLWorkbook                 =51
	Const xlOpenXMLWorkbookMacroEnabled     =52
	Const xlSYLK                            =2
	Const xlTemplate                        =17
	Const xlTemplate8                       =17
	Const xlTextMac                         =19
	Const xlTextMSDOS                       =21
	Const xlTextPrinter                     =36
	Const xlTextWindows                     =20
	Const xlUnicodeText                     =42
	Const xlWebArchive                      =45
	Const xlWJ2WD1                          =14
	Const xlWJ3                             =40
	Const xlWJ3FJ3                          =41
	Const xlWK1                             =5
	Const xlWK1ALL                          =31
	Const xlWK1FMT                          =30
	Const xlWK3                             =15
	Const xlWK3FM3                          =32
	Const xlWK4                             =38
	Const xlWKS                             =4
	Const xlWorkbookDefault                 =51
	Const xlWorkbookNormal                  =-4143
	Const xlWorks2FarEast                   =28
	Const xlWQ1                             =34
	Const xlXMLSpreadsheet                  =46
	Const XlFixedFormatType_xlTypePDF       =0
	Const XlFixedFormatType_xlTypeXPS       =1

	' Create a File System object
	Set objFSO = CreateObject( "Scripting.FileSystemObject" )

	' Create a Excell object
	Set objExcel = CreateObject("Excel.Application")

	With objExcel
		' True: make Excell visible; False: invisible
		.Visible = True
 
		' Check if the Excell document exists
		If not( objFSO.FileExists( inFile ) ) Then
			WScript.Echo "FILE OPEN ERROR: The file does not exist" & vbCrLf
			' Close Excell
			.Quit
			Exit Sub
		End If
 
		' Open the Excell document
		.Workbooks.Open inFile
 
		' Make the opened file the active document
		Set objWorkbook = .ActiveWorkbook
		Set objSheet = .ActiveSheet

 		isSaveAs = True
		If StrComp(Ucase( outFormat ),"PDF") = 0 then
			isSaveAs = False
		ElseIf StrComp(Ucase( outFormat ),"XPS") = 0 then
			isSaveAs = False
		ElseIf StrComp(Ucase( outFormat ),"CSV") = 0 then
			xlFormat= xlCSV
		ElseIf StrComp(Ucase( outFormat ),"HTML") = 0 then
			xlFormat= xlHtml
		ElseIf StrComp(Ucase( outFormat ),"XML") = 0 then
			xlFormat= xlXMLSpreadsheet
		ElseIf StrComp(Ucase( outFormat ),"TXT") = 0 then
			xlFormat= xlTextWindows
		Else
			WScript.Echo "FILE FORTMART ERROR: Unknown file format" & vbCrLf
			' Close Excell
			.Quit
			Exit Sub
		End If

		' Save in PDF/XPS format
		If isSaveAs then
			objSheet.SaveAs outFile, xlFormat
		ElseIf StrComp(Ucase( outFormat ),"PDF") = 0 then
			objSheet.ExportAsFixedFormat XlFixedFormatType_xlTypePDF, outFile
		ElseIf StrComp(Ucase( outFormat ),"XPS") = 0 then
			objSheet.ExportAsFixedFormat XlFixedFormatType_xlTypeXPS, outFile
		End If
 
		' Close the active document
		objWorkbook.Close
 
		' Close Excell
		.Quit
	End With
End Sub

Word2ANY转换工具

Word2ANY.vbs

Option Explicit

Word2ANY "PATH_TO_INFILE\NEOHOPE.COM.IN.docx","PATH_TO_OUTFILE\NEOHOPE.COM.OUT.xps","XPS"
Word2ANY "PATH_TO_INFILE\NEOHOPE.COM.IN.docx","PATH_TO_OUTFILE\NEOHOPE.COM.OUT.PDF","PDF"
Word2ANY "PATH_TO_INFILE\NEOHOPE.COM.IN.docx","PATH_TO_OUTFILE\NEOHOPE.COM.OUT.HTML","HTML"
Word2ANY "PATH_TO_INFILE\NEOHOPE.COM.IN.docx","PATH_TO_OUTFILE\NEOHOPE.COM.OUT.XML","XML"
Word2ANY "PATH_TO_INFILE\NEOHOPE.COM.IN.docx","PATH_TO_OUTFILE\NEOHOPE.COM.OUT.RTF","RTF"
Word2ANY "PATH_TO_INFILE\NEOHOPE.COM.IN.docx","PATH_TO_OUTFILE\NEOHOPE.COM.OUT.TXT","TEXT"

Sub Word2ANY( inFile, outFile, outFormat)
	Dim objFSO, objWord, objDoc, wdFormat

	Const wdFormatDocument                    =  0
	Const wdFormatDocument97                  =  0
	Const wdFormatDocumentDefault             = 16
	Const wdFormatDOSText                     =  4
	Const wdFormatDOSTextLineBreaks           =  5
	Const wdFormatEncodedText                 =  7
	Const wdFormatFilteredHTML                = 10
	Const wdFormatFlatXML                     = 19
	Const wdFormatFlatXMLMacroEnabled         = 20
	Const wdFormatFlatXMLTemplate             = 21
	Const wdFormatFlatXMLTemplateMacroEnabled = 22
	Const wdFormatHTML                        =  8
	Const wdFormatPDF                         = 17
	Const wdFormatRTF                         =  6
	Const wdFormatTemplate                    =  1
	Const wdFormatTemplate97                  =  1
	Const wdFormatText                        =  2
	Const wdFormatTextLineBreaks              =  3
	Const wdFormatUnicodeText                 =  7
	Const wdFormatWebArchive                  =  9
	Const wdFormatXML                         = 11
	Const wdFormatXMLDocument                 = 12
	Const wdFormatXMLDocumentMacroEnabled     = 13
	Const wdFormatXMLTemplate                 = 14
	Const wdFormatXMLTemplateMacroEnabled     = 15
	Const wdFormatXPS                         = 18

	' Create a File System object
	Set objFSO = CreateObject( "Scripting.FileSystemObject" )

	' Create a Word object
	Set objWord = CreateObject( "Word.Application" )

	With objWord
		' True: make Word visible; False: invisible
		.Visible = True
 
		' Check if the Word document exists
		If not( objFSO.FileExists( inFile ) ) Then
			WScript.Echo "FILE OPEN ERROR: The file does not exist" & vbCrLf
			' Close Word
			.Quit
			Exit Sub
		End If
 
		' Open the Word document
		.Documents.Open inFile
 
		' Make the opened file the active document
		Set objDoc = .ActiveDocument
 
		If StrComp(Ucase( outFormat ),"PDF") = 0 then
			wdFormat = wdFormatPDF 
		ElseIf StrComp(Ucase( outFormat ),"XPS") = 0 then
			wdFormat = wdFormatXPS
		ElseIf StrComp(Ucase( outFormat ),"TXT") = 0 then
			wdFormat= wdFormatTEXT
		ElseIf StrComp(Ucase( outFormat ),"HTML") = 0 then
			wdFormat= wdFormatHTML
		ElseIf StrComp(Ucase( outFormat ),"XML") = 0 then
			wdFormat= wdFormatXML
		ElseIf StrComp(Ucase( outFormat ),"RTF") = 0 then
			wdFormat= wdFormatXML
		Else
			WScript.Echo "FILE FORTMART ERROR: Unknown file format" & vbCrLf
			' Close Word
			.Quit
			Exit Sub
		End If

		' Save in PDF/XPS format
		objDoc.SaveAs outFile, wdFormat
 
		' Close the active document
		objDoc.Close
 
		' Close Word
		.Quit
	End With
End Sub

从Scratch开始建立Docker镜像(一)

最近尝试了从Scratch开始建立Docker镜像,整体来说并不难,就是从现在运行良好的linux机器上,把需要的文件放到Docker镜像里就好了。正确的做法是,使用工具直接生成你需要的镜像,尽量不要自己折腾。但我是手工处理的,为了就是折腾。

第一部分的目标,就是实现Linux的基本功能。

1、新建文件夹neodeb01,把你想放到Docker中的文件放到这个目录下面,比如,我这边结构如下:

├── bin
│   ├── bash
│   ├── cat
│   ├── chmod
│   ├── chown
│   ├── cp
│   ├── date
│   ├── dd
│   ├── df
│   ├── dir
│   ├── echo
│   ├── egrep
│   ├── false
│   ├── grep
│   ├── hostname
│   ├── kill
│   ├── less
│   ├── ln
│   ├── login
│   ├── ls
│   ├── mkdir
│   ├── more
│   ├── mount
│   ├── mv
│   ├── ps
│   ├── pwd
│   ├── rm
│   ├── rmdir
│   ├── sed
│   ├── sh
│   ├── sleep
│   ├── su
│   ├── systemd
│   ├── touch
│   ├── true
│   ├── umount
│   ├── uname
│   └── which
├── boot
├── build.sh
├── dev
├── Dockerfile
├── etc
│   ├── bash.bashrc
│   ├── default
│   │   ├── cron
│   │   ├── locale
│   │   ├── networking
│   │   └── useradd
│   ├── group
│   ├── group-
│   ├── gshadow
│   ├── gshadow-
│   ├── hostname
│   ├── init
│   │   └── networking.conf
│   ├── init.d
│   │   ├── hostname.sh
│   │   └── networking
│   ├── login.defs
│   ├── nsswitch.conf
│   ├── pam.conf
│   ├── pam.d
│   │   ├── atd
│   │   ├── chfn
│   │   ├── chpasswd
│   │   ├── chsh
│   │   ├── common-account
│   │   ├── common-auth
│   │   ├── common-password
│   │   ├── common-session
│   │   ├── common-session-noninteractive
│   │   ├── cron
│   │   ├── gdm-autologin
│   │   ├── gdm-launch-environment
│   │   ├── gdm-password
│   │   ├── login
│   │   ├── newusers
│   │   ├── other
│   │   ├── passwd
│   │   ├── polkit-1
│   │   ├── ppp
│   │   ├── runuser
│   │   ├── runuser-l
│   │   ├── sshd
│   │   ├── su
│   │   ├── sudo
│   │   └── systemd-user
│   ├── passwd
│   ├── passwd-
│   ├── profile
│   ├── security
│   │   ├── access.conf
│   │   ├── group.conf
│   │   ├── limits.conf
│   │   ├── limits.d
│   │   ├── namespace.conf
│   │   ├── namespace.d
│   │   ├── namespace.init
│   │   ├── opasswd
│   │   ├── pam_env.conf
│   │   ├── pwquality.conf
│   │   ├── sepermit.conf
│   │   └── time.conf
│   ├── services
│   ├── shadow
│   ├── shadow-
│   ├── skel
│   ├── subgid
│   └── subuid
├── home
├── lib
│   ├── terminfo
│   │   └── l
│   │       └── linux
│   └── x86_64-linux-gnu
│       ├── libacl.so.1
│       ├── libattr.so.1
│       ├── libaudit.so.1
│       ├── libaudit.so.1.0.0
│       ├── libblkid.so.1
│       ├── libbz2.so.1
│       ├── libbz2.so.1.0
│       ├── libbz2.so.1.0.4
│       ├── libcap.so.2
│       ├── libcrypt-2.19.so
│       ├── libcryptsetup.so.4
│       ├── libcryptsetup.so.4.6.0
│       ├── libcrypt.so.1
│       ├── libc.so.6
│       ├── libdl-2.19.so
│       ├── libdl.so.2
│       ├── libkmod.so.2
│       ├── libkmod.so.2.2.8
│       ├── libmount.so.1
│       ├── libm.so.6
│       ├── libncurses.so.5
│       ├── libncurses.so.5.9
│       ├── libnsl-2.19.so
│       ├── libnsl.so.1
│       ├── libnss_compat-2.19.so
│       ├── libnss_compat.so.2
│       ├── libpamc.so.0
│       ├── libpamc.so.0.82.1
│       ├── libpam_misc.so.0
│       ├── libpam_misc.so.0.82.0
│       ├── libpam.so.0
│       ├── libpam.so.0.83.1
│       ├── libpcre.so.3
│       ├── libprocps.so.3
│       ├── libpthread.so.0
│       ├── libreadline.so.6
│       ├── libreadline.so.6.3
│       ├── librt.so.1
│       ├── libselinux.so.1
│       ├── libsepol.so.1
│       ├── libtinfo.so.5
│       ├── libuuid.so.1
│       ├── libz.so.1
│       └── libz.so.1.2.8
├── lib64
│   └── ld-linux-x86-64.so.2
├── lost+found
├── media
├── mnt
├── opt
├── proc
├── root
├── run
├── sbin
├── srv
├── sys
├── tmp
├── usr
│   ├── bin
│   │   ├── awk
│   │   ├── basename
│   │   ├── clear
│   │   ├── diff
│   │   ├── diff3
│   │   ├── du
│   │   ├── env
│   │   ├── find
│   │   ├── gawk
│   │   ├── id
│   │   ├── passwd
│   │   ├── size
│   │   ├── sort
│   │   ├── time
│   │   ├── vi
│   │   ├── which
│   │   ├── who
│   │   └── whoami
│   ├── lib
│   │   ├── libbfd-2.25-system.so
│   │   └── x86_64-linux-gnu
│   │       ├── libgmp.so.10
│   │       ├── libgmp.so.10.2.0
│   │       ├── libmpfr.so.4
│   │       ├── libmpfr.so.4.1.2
│   │       ├── libsemanage.so.1
│   │       ├── libsigsegv.so.2
│   │       ├── libsigsegv.so.2.0.3
│   │       └── libustr-1.0.so.1
│   └── sbin
│       ├── chgpasswd
│       ├── chpasswd
│       ├── chroot
│       ├── groupadd
│       ├── groupdel
│       ├── groupmod
│       ├── service
│       ├── useradd
│       ├── userdel
│       └── usermod
└── var

2、Dockerfile文件

From	scratch 
ENV	PATH /bin:/sbin:/usr/bin:/usr/sbin:$PATH
COPY	.	/
RUN	/bin/ln -s lib64/ld-linux-x86-64.so.2	lib/x86_64-linux-gnu/
CMD	/bin/bash

3、build.sh文件

#/bin/sh
sudo docker build -t neodeb01 .

4、.dockerignore文件

Dockerfile
build.sh
*.swp

5、新建镜像并运行

sudo docker build -t neodeb01 .
sudo docker run -it neodeb01

PS:
一定要先把ld-linux-x86-64.so.2放到镜像中,否则无论你执行什么命令,镜像系统都告诉你

System error: no such file or directory

我在这个上面浪费了不少时间,学艺不精啊

PS1:
如果遇到I have no name的错误,一般是因为etc下的几个配置文件错误导致的,shadow gshadow group passwd。
但精简掉libnss_compat后,也会报同样的错误。

PS2:
如果遇到unknown terminal type的问题,要修改两个地方。一个是在.bashrc中

export TERM=linux

另一个是,要把文件夹/lib/terminfo中需要的内容,一起拷贝过去。

RMI简单示例

1、接口定义

package com.neohope.rmi.test;

import java.rmi.Remote;
import java.rmi.RemoteException;

/**
 * Created by Hansen
 */
public interface ITest extends Remote {
    /**
     * 返回“Hi XXX"字符串,必须声明抛出RemoteException异常
     * @return 返回“Hi XXX"字符串
     * @throws java.rmi.RemoteException
     */
    public String sayHiTo(String user) throws RemoteException;

    /**
     * 加法,必须声明抛出RemoteException异常
     * @param a
     * @parma b
     * @return a+b
     * @throws java.rmi.RemoteException
     */
    public int add(int a, int b) throws RemoteException;
}

2、服务端实现

package com.neohope.rmi.test;

import java.io.IOException;
import java.io.Serializable;
import java.net.MalformedURLException;
import java.rmi.AlreadyBoundException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;

/**
 * Created by Hansen
 */
public class TestServer implements ITest, Serializable {

    /**
     * 构造函数,必须声明抛出RemoteException异常
     *
     * @throws RemoteException
     */
    public TestServer() throws RemoteException {
    }

    /**
     * 返回“Hi XXX"字符串
     * @return 返回“Hi XXX"字符串
     * @throws java.rmi.RemoteException
     */
    @Override
    public String sayHiTo(String user) throws RemoteException {
        return "Hi " + user;
    }

    /**
     * 加法
     * @param a
     * @parma b
     * @return a+b
     * @throws java.rmi.RemoteException
     */
    @Override
    public int add(int a, int b) throws RemoteException {
        return a+b;
    }

    public static void main(String[] args) throws IOException, AlreadyBoundException {
        //创建一个远程对象
        ITest server = new TestServer();
        //注册端口
        LocateRegistry.createRegistry(1234);
        //绑定对象
        Naming.bind("rmi://localhost:1234/RemoteTest", server);

        System.in.read();
    }
}

3、客户端实现

package com.neohope.rmi.test;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

/**
 * Created by Hansen
 */
public class TestClient {
    public static void main(String args[]) throws RemoteException, NotBoundException, MalformedURLException {
        //查找服务,并调用方法
        ITest rservice = (ITest) Naming.lookup("rmi://localhost:1234/RemoteTest");
        System.out.println(rservice.sayHiTo("neohope"));
        System.out.println(rservice.add(1,2));
    }
}

XMLRPC简单示例

1、客户端实现

package com.neohope.xmlrpc.test;

import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Vector;

/**
 * Created by Hansen
 */
public class TestClient {
    public static void main(String[] args) throws MalformedURLException, XmlRpcException {
        //设置服务地址
        XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
        config.setServerURL(new URL("http://localhost:8080/XmlRpcTest"));
        //config.setServerURL(new URL("http://localhost:1234/xmlrpc"));
        XmlRpcClient client = new XmlRpcClient();
        client.setConfig(config);

        //调用方法
        Vector<String> params1 = new Vector<String>();
        params1.addElement("neohope");
        String result1 = (String) client.execute("ITest.sayHiTo", params1);
        System.out.println(result1);

        Vector<Integer> params2 = new Vector<Integer>();
        params2.addElement(1);
        params2.addElement(2);
        int result2 = (int) client.execute("ITest.add", params2);
        System.out.println(result2);
    }
}

2、服务端接口定义

package com.neohope.xmlrpc.test;

/**
 * Created by Hansen
 */
public interface ITest{
    /**
     * 返回“Hi XXX"字符串,必须声明抛出RemoteException异常
     * @return 返回“Hi XXX"字符串
     */
    public String sayHiTo(String user);

    /**
     * 加法,必须声明抛出RemoteException异常
     * @param a
     * @parma b
     * @return a+b
     */
    public int add(int a, int b);
}

3、基于WebServer的服务端实现

package com.neohope.xmlrpc.test;

import org.apache.xmlrpc.server.PropertyHandlerMapping;
import org.apache.xmlrpc.server.XmlRpcServer;
import org.apache.xmlrpc.server.XmlRpcServerConfigImpl;
import org.apache.xmlrpc.webserver.WebServer;

/**
 * Created by Hansen
 */
public class TestServer implements ITest {
    /**
     * 返回“Hi XXX"字符串
     * @return 返回“Hi XXX"字符串
     * @throws java.rmi.RemoteException
     */
    @Override
    public String sayHiTo(String user) {
        return "Hi " + user;
    }

    /**
     * 加法
     * @param a
     * @parma b
     * @return a+b
     * @throws java.rmi.RemoteException
     */
    @Override
    public int add(int a, int b) {
        return a+b;
    }


    public static void main(String [] args) throws Exception {
        WebServer webServer = new WebServer(1234);
        XmlRpcServer xmlRpcServer = webServer.getXmlRpcServer();
        PropertyHandlerMapping phm = new PropertyHandlerMapping();
        phm.addHandler("ITest", TestServer.class);
        xmlRpcServer.setHandlerMapping(phm);

        XmlRpcServerConfigImpl serverConfig = (XmlRpcServerConfigImpl)xmlRpcServer.getConfig();
        serverConfig.setEnabledForExtensions(true);
        serverConfig.setContentLengthOptional(false);
        webServer.start();

    }
}

4、基于Servlet的服务端实现

package com.neohope.xmlrpc.test;

import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.server.PropertyHandlerMapping;
import org.apache.xmlrpc.server.XmlRpcServerConfigImpl;
import org.apache.xmlrpc.webserver.XmlRpcServletServer;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by Hansen
 */
public class TestServlet extends HttpServlet {
    private XmlRpcServletServer rpcserver;

    public void init(ServletConfig pConfig) throws ServletException {

        super.init(pConfig);

        try {
            rpcserver = new XmlRpcServletServer();
            PropertyHandlerMapping phm = new PropertyHandlerMapping();
            phm.addHandler("ITest", TestServer.class);
            rpcserver.setHandlerMapping(phm);

            XmlRpcServerConfigImpl serverConfig = (XmlRpcServerConfigImpl)rpcserver.getConfig();
            serverConfig.setEnabledForExtensions(true);
            serverConfig.setContentLengthOptional(false);

        } catch (XmlRpcException ex) {
            ex.printStackTrace();
        }
    }

    @Override
    public void doPost(HttpServletRequest pRequest, HttpServletResponse pResponse) throws IOException, ServletException {
        rpcserver.execute(pRequest, pResponse);
    }

    @Override
    public void doGet(HttpServletRequest pRequest, HttpServletResponse pResponse) throws IOException, ServletException {
        pResponse.getOutputStream().print("It is working.");
    }
}

4、基于Servlet的服务端配置

    <servlet>
        <servlet-name>XmlRpcTest</servlet-name>
        <servlet-class>com.neohope.xmlrpc.test.TestServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>XmlRpcTest</servlet-name>
        <url-pattern>/XmlRpcTest</url-pattern>
    </servlet-mapping>

Docker原理03

最后,咱们聊一下,Docker是如何实现虚拟化的。

1、先说一下Docker镜像
Docker多层文件系统
从图上可以看出,每一个镜像由一系列的层(layers)组成(Debian,Add Emacs,Add Apache,writable,但不包括内核,内核是与宿主机公用的)。

可如下复现:下载Debian镜像(200m),添加Emacs(20m)后,生成一个新的镜像,然后添加Apache(80m)后,生成了下一个新的镜像,然后运行时,挂在了一个可读写曾,供应用软件写数据。
如果不用分层式架构,那Debian镜像为200m,Emacs镜像为220m,Apache镜像为300m,你的硬盘一共需要720m。而分层后,各层只需要存储与原来不同的文件,所以结果为Debian镜像为200m,Emacs镜像为20m,Apache镜像为80m,你的硬盘一共需要300m。
分层的另外一个好处是,如果你希望新建一个Jetty(60m)镜像,同样可以从Debian镜像进行,这样相互之间就可以很好的复用已有镜像了。同样的,镜像升级的时候,也只需要更新自己所在的层,重新打包一个镜像,就可以升级完毕了。

那分层镜像架构,在运行时,是如何挂载到一起的呢?
答案是联合文件系统(UnionFS)。Union文件系统允许独立文件系统中的文件和文件夹(称之为分支)被透明覆盖,形成一个单独连贯的文件系统,所以可以方便的将这些层联合到一个镜像中。

2、再说一下容器是实现隔离的呢?
容器主要作用是隔离工作空间,虚拟机之间相互隔离,虚拟机与宿主机之间也相互隔离。当容器运行的时候,Docker就需要为该容器创建一个命名空间集合,每一个应用在它们自己的命名空间中运行而且不会访问到命名空间之外。
现在常用的容器有:Linux的LXC,BSD的Jails,Solaris的Zone等。

Docker使用到的命名空间有:
pid命名空间: 使用在进程隔离(PID: Process ID)。
net命名空间: 使用在管理网络接口(NET: Networking)。
ipc命名空间: 使用在管理进程间通信资源 (IPC: InterProcess Communication)。
mnt命名空间: 使用在管理挂载点 (MNT: Mount)。
uts命名空间: 使用在隔离内核和版本标识 (UTS: Unix Timesharing System)。

3、容器是如何管理硬件资源的呢?
答案是群组控制。
群组控制允许Docker分享或者限制容器使用硬件资源。
Docker使用了cgroups技术来管理群组。

Docker原理02

然后,咱们聊一下,Docker是如何运行的。

Docker整体架构如下(假设你比较熟悉VMWare或VirtualBox):
Docker Architecture
Docker Client:与Docker Deamon交互,告诉Docker Deamon要做什么,可以理解为一个远程执行Docker相关各种指令的工具
Docker Host:Docker Deamon的运行环境,就是宿主机
Docker Deamon:Docker服务,管理容器的创建,运行,停止等,是核心服务
Docker Images:Docker镜像,可以先理解为存放GuestOS所需二进制文件的只读光盘(这个不准确的,其实有分层结构),比如你可以把Ubuntu的可运行环境,经过定制后,做成一个镜像(不需要内核,不需要自己重头开始建立)
Docker Containers:Docker容器,通过某个镜像来创建,可以理解为一个虚拟机的实例
Docker Registry:Docker仓库,用来存放大家做好的镜像文件,可以方便的查询和下载

那当你运行下面指令时,究竟发生了什么呢?

# 利用基础镜像为ubuntu创建一个容器,采用交互模式运行(-it),并在容器中执行命令/bin/bash,
docker run -it ubuntu /bin/bash

1、查找并获取镜像文件:Docker检查本地是否有ubuntu镜像,如果本地没有该镜像,Docker会从Docker Hub下载。
2、创建容器:如果镜像已经存在或镜像下载后,Docker会使用它来创建新的容器。
3、分配文件系统并且挂载一个可读写的层。
4、分配网络/桥接接口: 创建一个允许容器与本地主机通信的网络接口。
5、设置一个IP地址: 从池中寻找一个可用的IP地址并且服加到容器上。
6、运行你指定的程序:按上面的命令,应该为/bin/bash
7、捕获并且提供应用输出: 连接并且记录标准输出、输入和错误让你可以看到你的程序是如何运行的。

那大家看下来,步骤1、6、7没有什么难理解的,但2、3、4、5究竟在做什么呢?

Docker原理01

首先聊一下虚拟化技术。

虚拟化离我们很近,平时我们接触的虚拟化技术种类很多,比如硬件虚拟化(超线程技术),虚拟设备(虚拟光驱、虚拟软件、WinMount)、虚拟网络(VPN),桌面虚拟化(虚拟桌面、远程桌面),虚拟内存(利用交换文件或交换分区扩展系统可用内存),存储虚拟化(硬盘分区,网络硬盘映射),各类游戏机模拟器等。有些技术用的是如此普遍,你并不一定觉得它应该归类到虚拟化技术之中。但是,一旦提到虚拟化技术,你一定会想到其中一个,那就是虚拟机。

虚拟机技术按实现方式,分为纯硬件虚拟化、纯软件虚拟化及基于硬件辅助的软件虚拟化。其中纯硬件虚拟化,一般在大型机上实现的比较多,操作系统比较单一(其实支持该硬件架构的操作系统就可以,但多数情况下同一型号大型机操作系统的确比较单一),硬件架构复杂。纯软件虚拟化,其实现技术比较复杂,一般通过hypervisor提供硬件虚拟层,支持多种操作系统。时至今日,很多设备都提供了硬件辅助虚拟化的功能,这大大降低了虚拟机管理软件的实现难度,并增强了虚拟机的执行效率,所以现在一般的虚拟化软件都支持基于硬件辅助的软件虚拟化。

虚拟机技术按虚拟化程度分为三种,第一种是完全虚拟化,第二种准虚拟化,第三种是操作系统级层虚拟化。其中,
完全虚拟化,直接用软件/硬件辅助方式,不修改Guest,模拟虚拟机的全部硬件的技术,一般支持多种操作系统,但效率一般不高;
准虚拟化,直接用软件/硬件辅助方式,并同时通过修改Guest,对其进行一定程度的“欺骗”,实现与hypervisor相配合,实现虚拟化的技术,一般支持多种操作系统,运行效率比较高;
操作系统层虚拟化,是利用操作系统特性,利用一个操作系统内核,模拟多台虚拟设备的方式,由于一般需要共享操作系统内核,一般只支持一类操作系统;

还有一类特殊的虚拟机软件,叫跨平台虚拟化,允许针对特定CPU或者操作系统的软件,不做修改就能运行在其他平台上。如Wine(在Linux上模拟Windows应用),还有我们用的各类游戏模拟器(在Windows/Linux上模拟红白机FC、Projetc64、PSP)等。

那我们回过头来看下Docker的虚拟化方式与普通虚拟化方式的区别:
A、Dcoker虚拟化
Dcoker虚拟化
B、VMware VirtualBox虚拟化
VMware VirtualBox虚拟化

比较下来就很清楚了:

项目 Docker VMware VirtualBox
虚拟化技术 纯软件虚拟化 纯软件虚拟化+基于硬件辅助的软件虚拟化
虚拟化程度 操作系统级层虚拟化 完全虚拟化+准虚拟化
硬件抽象层 不需要 hypervisor
运行效率 安装插件前,效率较低;安装插件后,效率较高
支持系统 Linxu各发行版 硬件架构支持即可安装
需要安装Guest系统 共享内核,应用软件需要安装 完全安装