fence vmware use vmware vSphere SDK for Perl

简介:
我们可以通过fence_vmware命令连接到vCenter来fence vCenter管理的虚拟机.
本文将简单的描述一下fence_vmware的使用, 以及/etc/cluster/cluster.conf的配置.
命令行帮助如下 :
[root@digoal_02 soft_bak]# fence_vmware --help
Usage:
        fence_vmware [options]
Options:
   -o, --action=<action>          Action: status, reboot (default), off or on
   -a, --ip=<ip>                  IP address or hostname of fencing device
   -l, --username=<name>          Login name
   -p, --password=<password>      Login password or passphrase
   -S, --password-script=<script> Script to run to retrieve password
   -n, --plug=<id>                Physical plug number on device or
                                        name of virtual machine
   -e, --exec=<command>           Command to execute
   -d, --vmware_type=<type>       Type of VMware to connect
   -x, --ssh                      Use ssh connection
   -k, --identity-file=<filename> Identity file (private key) for ssh 
   -s, --vmware-datacenter=<dc>   VMWare datacenter filter
   -v, --verbose                  Verbose mode
   -D, --debug-file=<debugfile>   Debugging to output file
   -V, --version                  Output version information and exit
   -h, --help                     Display this help and exit
   -C, --separator=<char>         Separator for CSV created by 'list' operation
   --power-timeout <seconds>      Test X seconds for status change after ON/OFF
   --shell-timeout <seconds>      Wait X seconds for cmd prompt after issuing command
   --login-timeout <seconds>      Wait X seconds for cmd prompt after login
   --power-wait <seconds>         Wait X seconds after issuing ON/OFF
   --delay <seconds>              Wait X seconds before fencing is started
   --retry-on <attempts>          Count of attempts to retry power on
[root@digoal_02 soft_bak]# fence_vmware_helper --help

Synopsis: /usr/sbin/fence_vmware_helper OPTIONS 


Command-specific options:
   --datacenter
      The name of the datacenter
   --operation (default 'list')
      The operation to perform (on,off,list,status). Operations on/off/status require name of the virtual machine
   --vmname
      The name of the virtual machine

Common VI options: 
   --config (variable VI_CONFIG)
      Location of the VI Perl configuration file
   --credstore (variable VI_CREDSTORE)
      Name of the credential store file defaults to <HOME>/.vmware/credstore/vicredentials.xml on Linux and <APPDATA>/VMware/credstore/vicredentials.xml on Windows
   --encoding (variable VI_ENCODING, default 'utf8')
      Encoding: utf8, cp936 (Simplified Chinese), iso-8859-1 (German), shiftjis (Japanese)
   --help
      Display usage information for the script
   --passthroughauth (variable VI_PASSTHROUGHAUTH)
      Attempt to use pass-through authentication
   --passthroughauthpackage (variable VI_PASSTHROUGHAUTHPACKAGE, default 'Negotiate')
      Pass-through authentication negotiation package
   --password (variable VI_PASSWORD)
      Password
   --portnumber (variable VI_PORTNUMBER)
      Port used to connect to server
   --protocol (variable VI_PROTOCOL, default 'https')
      Protocol used to connect to server
   --savesessionfile (variable VI_SAVESESSIONFILE)
      File to save session ID/cookie to utilize
   --server (variable VI_SERVER, default 'localhost')
      VI server to connect to. Required if url is not present
   --servicepath (variable VI_SERVICEPATH, default '/sdk/webService')
      Service path used to connect to server
   --sessionfile (variable VI_SESSIONFILE)
      File containing session ID/cookie to utilize
   --url (variable VI_URL)
      VI SDK URL to connect to. Required if server is not present
   --username (variable VI_USERNAME)
      Username
   --verbose (variable VI_VERBOSE)
      Display additional debugging information
   --version
      Display version information for the script

fence_vmware需要依赖vSphere提供的SDK. 
如果你还没有安装SDK, 使用fence_vmware时会报错如下 :
[root@digoal_01 vmware-vsphere-cli-distrib]# fence_vmware -a 10.10.10.155 -l OU\\digoal -p digoal_123321 -o list
fence_vmware_helper returned Please install VI Perl API package to use this tool!
Perl error: Can't locate VMware/VIRuntime.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at (eval 1) line 1.
BEGIN failed--compilation aborted at (eval 1) line 1.
Please use '-h' for usage


解决以上报错, 首先要根据环境中vSphere的版本, 下载对应的sdk. 
例如5.5的for linux x86_64 sdk如下 : 
https://my.vmware.com/web/vmware/info/slug/datacenter_cloud_infrastructure/vmware_vsphere/5_5#drivers_tools
vSphere SDK for Perl - 64-bit Linux Installer
File size: 26 MB
File type: gz
Download Now Download Manager Name: VMware-vSphere-Perl-SDK-5.5.0-2043780.x86_64.tar.gz 
Release Date: 2014-09-09
Build Number: 2043780
vSphere SDK for Perl - 64-bit Linux Installer 
Download an SDK for 64-bit Linux environments that allows to create Perl scripts to automate vSphere management.
MD5SUM: acf30529e00783f4a06ff5ce3ec9545c 
SHA1SUM: 909a64950f4310ed36ec435f8922e110f8abd097

执行vmware-install.pl安装SDK :
[root@digoal_01 soft_bak]# tar -zxvf VMware-vSphere-Perl-SDK-5.5.0-2043780.x86_64.tar.gz
[root@digoal_01 soft_bak]# cd vmware-vsphere-cli-distrib/
[root@digoal_01 vmware-vsphere-cli-distrib]# ll
total 280
drwxr-xr-x 10 root root   4096 Aug 13 23:54 apps
drwxr-xr-x  2 root root   4096 Aug 13 23:54 bin
drwxr-xr-x  3 root root   4096 Aug 13 23:54 doc
drwxr-xr-x  2 root root   4096 Aug 13 23:54 etc
-r--r--r--  1 root root 253803 Aug 13 23:54 FILES
drwxr-xr-x 29 root root   4096 Aug 13 23:54 lib
-r--r--r--  1 root root   3340 Aug 13 23:54 Makefile.PL
drwxr-xr-x  2 root root   4096 Aug 13 23:54 man
drwxr-xr-x  2 root root   4096 Aug 13 23:54 resources
lrwxrwxrwx  1 root root     35 Sep 25 09:41 vmware-install.pl -> bin/vmware-uninstall-vSphere-CLI.pl

[root@digoal_01 vmware-vsphere-cli-distrib]# ./vmware-install.pl 
Creating a new vSphere CLI installer database using the tar4 format.

Installing vSphere CLI 5.5.0 build-2043780 for Linux.
..............................
Do you accept? (yes/no) yes         

Thank you.

This vSphere CLI installer includes precompiled Perl modules for RHEL.
Answering yes will install the precompiled modules, and answering no will 
install from CPAN.
Do you want to install precompiled Perl modules for RHEL?
[yes] 

In which directory do you want to install the executable files? 
[/usr/bin]          

Please wait while copying vSphere CLI files...

The installation of vSphere CLI 5.5.0 build-2043780 for Linux completed 
successfully. You can decide to remove this software from your system at any 
time by invoking the following command: 
"/usr/bin/vmware-uninstall-vSphere-CLI.pl".

This installer has successfully installed both vSphere CLI and the vSphere SDK 
for Perl.

The following Perl modules were found on the system but may be too old to work 
with vSphere CLI:

version 0.78 or newer 

Enjoy,

--the VMware team

现在就可以使用fence_vmware来列出账号授权的虚拟机.
10.10.10.155 是vCenter的地址
OU\\digoal 是账号(这里假设vCenter的认证是通过AD域来管理的, 需要加前缀, 两个反斜线来转义) 
digoal_123321 是域账号OU\digoal的密码
-o list 列出用户授权的虚拟机(这里列出的虚拟机名称要被fence_vmware用于开关机)
-v 输出明细数据
[root@digoal_01 ~]# fence_vmware -a 10.10.10.155 -l OU\\digoal -p digoal_123321 -o list -v
fence_vmware_helper --server 'digoal_01' --username 'OU\digoal' --password 'digoal_123321' --operation list
digoal_02:[FOR-VC] digoal_02/digoal_02.vmx:poweredOn:connected
digoal_01:[FOR-VC] digoal_01/digoal_01.vmx:poweredOn:connected
digoal_02,
digoal_01,

使用-n 指定虚拟机, 查看状态.
[root@digoal_01 vmware-vsphere-cli-distrib]# fence_vmware -a 10.10.10.155 -l OU\\digoal -p digoal_123321 -n digoal_01 -o status  -v
fence_vmware_helper --server 'digoal_01' --username 'OU\digoal' --password 'digoal_123321' --operation status --vmname 'digoal_01'
digoal_01:[FOR-VC] digoal_01/digoal_01.vmx:poweredOn:connected
Status: ON


修改/etc/cluster/cluster.conf, 注意递增config_version版本.
[root@digoal_02 ~]# cat /etc/cluster/cluster.conf 
<cluster config_version="31" name="digoal001">
  <fence_daemon post_fail_delay="6" post_join_delay="30"/>
  <clusternodes>
    <clusternode name="10.10.10.154" nodeid="1">
      <fence>
        <method name="abc">
          <device action="off" port="digoal_01" name="fence_vc"/>   # port 是这个主机对应的vCenter里的虚拟机名
          <device action="on" port="digoal_01" name="fence_vc"/>
        </method>
      </fence>
    </clusternode>
    <clusternode name="10.10.10.221" nodeid="2">
      <fence>
        <method name="abc">
          <device action="off" port="digoal_02" name="fence_vc"/>
          <device action="on" port="digoal_02" name="fence_vc"/>
        </method>
      </fence>
    </clusternode>
  </clusternodes>
  <cman expected_votes="1" transport="udpu" two_node="1"/>
  <fencedevices>
    <fencedevice agent="fence_vmware" ipaddr="10.10.10.155" login="OU\digoal" name="fence_vc" passwd="digoal_123321"/>
  </fencedevices>
  <rm>
    <failoverdomains>
      <failoverdomain name="digoal001_fd" nofailback="1" ordered="1" restricted="1">
        <failoverdomainnode name="10.10.10.154" priority="1"/>
        <failoverdomainnode name="10.10.10.221" priority="1"/>
      </failoverdomain>
    </failoverdomains>
    <resources>
      <ip address="10.10.10.223" monitor_link="1"/>
      <script file="/usr/local/bin/pgctl.sh" name="pgctl">
        <action name="status" interval="10"/>
      </script>
    </resources>
    <service autostart="0" domain="digoal001_fd" name="digoal001_pg">
      <ip ref="10.10.10.223"/>
      <script ref="pgctl"/>
    </service>
  </rm>
  <logging/>
</cluster>

重启集群 :
clusvcadm -d service_name
umount gfs_dir
service clvmd stop
service rgmanager stop
service cman stop

service cman start
service rgmanager start
service clvmd start
mount gfs_dir
clusvcadm -e service_name


[参考]
1.  http://www.it165.net/os/html/201307/5698.html
6. 
# man fence_vmware
# man fence_vmware_helper
# man fence_vmware_soap
8. /usr/share/cluster/cluster.rng
      <!-- fence_vmware -->
      <group rha:name="fence_vmware" rha:description="Fence agent for VMWare">
        <optional>
          <attribute name="option"/> <!-- deprecated; for compatibility.  use "action" -->
        </optional>
        <optional>
          <attribute name="action" rha:description="Fencing Action" />
        </optional>
        <optional>
          <attribute name="ipaddr" rha:description="IP Address or Hostname" />
        </optional>
        <optional>
          <attribute name="login" rha:description="Login Name" />
        </optional>
        <optional>
          <attribute name="passwd" rha:description="Login password or passphrase" />
        </optional>
        <optional>
          <attribute name="passwd_script" rha:description="Script to retrieve password" />
        </optional>
        <optional>
          <attribute name="port" rha:description="Physical plug number or name of virtual machine" />
        </optional>
        <optional>
          <attribute name="exec" rha:description="Command to execute" />
        </optional>
        <optional>
          <attribute name="vmware_type" rha:description="Type of VMware to connect" />
        </optional>
        <optional>
          <attribute name="secure" rha:description="SSH connection" />
        </optional>
        <optional>
          <attribute name="identity_file" rha:description="Identity file for ssh" />
        </optional>
        <optional>
          <attribute name="vmware_datacenter" rha:description="Show only machines in specified datacenter" />
        </optional>
        <optional>
          <attribute name="verbose" rha:description="Verbose mode" />
        </optional>
        <optional>
          <attribute name="debug" rha:description="Write debug information to given file" />
        </optional>
        <optional>
          <attribute name="version" rha:description="Display version information and exit" />
        </optional>
        <optional>
          <attribute name="help" rha:description="Display help and exit" />
        </optional>
        <optional>
          <attribute name="separator" rha:description="Separator for CSV created by operation list" />
        </optional>
        <optional>
          <attribute name="power_timeout" rha:description="Test X seconds for status change after ON/OFF" />
        </optional>
        <optional>
          <attribute name="shell_timeout" rha:description="Wait X seconds for cmd prompt after issuing command" />
        </optional>
        <optional>
          <attribute name="login_timeout" rha:description="Wait X seconds for cmd prompt after login" />
        </optional>
        <optional>
          <attribute name="power_wait" rha:description="Wait X seconds after issuing ON/OFF" />
        </optional>
        <optional>
          <attribute name="delay" rha:description="Wait X seconds before fencing is started" />
        </optional>
        <optional>
          <attribute name="retry_on" rha:description="Count of attempts to retry power on" />
        </optional>
      </group>

相关文章
|
开发工具 数据中心 虚拟化
使用VMware VSphere WebService SDK进行开发 (七)——获取数据中心、集群、主机、虚拟机的目录结构
在实际应用中,需要显示出数据中心(Datacenter)、集群(ClusterComputeResource)、主机(HostSystem)、虚拟机(VirtualMachine)之间的目录关系。
2104 0
|
开发工具 虚拟化 监控
使用VMware VSphere WebService SDK进行开发 (二)——获取虚拟机cpu的使用情况
本文通过代码举例虚拟机cpu的使用情况来演示如何遍历搜寻VirtualMachine的对象,以及根据这个对象进行性能指标的见识。希望可以取到举一反三的效果。 首先下面先罗列出如何更具虚拟机的名称获得VirtualMachine的ManagedObjectReference对象。
1791 0
|
开发工具 虚拟化
使用VMware VSphere WebService SDK进行开发 (三)——获取主机(HostSystem)的基本信息
通过前面两篇文章的了解,详细应该很快掌握的code路数,这里首先罗列如何获取主机(接下去也会成为HostSystem)的对象。 private static TraversalSpec getHostSystemTraversalSpec() { SelectionSpec ss = new SelectionSpec(); ss.
1826 0
|
开发工具 虚拟化 存储
使用VMware VSphere WebService SDK进行开发 (六)——检测告警信息
获取告警信息相对而言比较简单点,这里先陈述告警信息的pojo类,作为存储告警信息的源头(省略getter和setter方法): public class AlarmItem { //对象 private String ObjectName; //状态 private Manag...
1455 0
|
3天前
|
JavaScript Java Maven
云效产品使用常见问题之android sdk 构建出aar后,上传到私有maven仓库失败如何解决
云效作为一款全面覆盖研发全生命周期管理的云端效能平台,致力于帮助企业实现高效协同、敏捷研发和持续交付。本合集收集整理了用户在使用云效过程中遇到的常见问题,问题涉及项目创建与管理、需求规划与迭代、代码托管与版本控制、自动化测试、持续集成与发布等方面。
|
3天前
|
安全 开发工具 Android开发
几个Flutter常见诊断错误与解决Android toolchain - develop for Android devices X Unable to locate Android SDK
几个Flutter常见诊断错误与解决Android toolchain - develop for Android devices X Unable to locate Android SDK
467 0
|
7月前
|
API 开发工具 Android开发
解决 Android App 上架 Google play后 ,签名变更,第三方sdk无法登录
解决 Android App 上架 Google play后 ,签名变更,第三方sdk无法登录
153 0
|
1天前
|
Java 开发工具 Maven
Android SDK开发的那些事(1),已整理成文档
Android SDK开发的那些事(1),已整理成文档
|
3天前
|
开发工具 Android开发
Android获取SDK的版本信息
Android获取SDK的版本信息
46 0
|
5月前
|
编解码 Java 开发工具
Android端接入视频生产 Java SDK
Android端接入视频生产 Java SDK
43 1

热门文章

最新文章