VMware Photon OS 2.0 で PMD / pmd-cli を実行してみる。

VMware Photon OS 2.0 で PMD / pmd-cli を実行してみる。

Photon OS 2.0 から、PMD(Photon Management Daemon)と

その CLI である pmd-cli が導入されたので使用してみます。

Photon Management Daemon Command-line Interface (pmd-cli)

photon/pmd-cli.md at master · vmware/photon · GitHub

PMD のインストール。

pmd のパッケージをインストールして、pmd サービスを起動します。

root@photon-machine [ ~ ]# tdnf install -y pmd

Refreshing metadata for: 'VMware Photon Linux 2.0(x86_64)'

Refreshing metadata for: 'VMware Photon Linux 2.0(x86_64) Updates'

Refreshing metadata for: 'VMware Photon Extras 2.0(x86_64)'

photon-extras                              106    100%

Installing:

libgpg-error             x86_64       1.27-1.ph2       photon       118.88k 121733

cyrus-sasl               x86_64       2.1.26-13.ph2    photon       558.79k 572200

libgcrypt                x86_64       1.8.1-1.ph2      photon         1.18M 1235073

perl                     x86_64       5.24.1-4.ph2     photon        49.41M 51811861

libxml2                  x86_64       2.9.6-1.ph2      photon         7.30M 7651659

haveged                  x86_64       1.9.1-3.ph2      photon       186.28k 190753

openldap                 x86_64       2.4.44-3.ph2     photon         1.52M 1598869

iputils                  x86_64       20151218-4.ph2   photon       262.51k 268810

ntp                      x86_64       4.2.8p10-4.ph2   photon         6.28M 6581037

pcre                     x86_64       8.40-4.ph2       photon       699.09k 715866

pmd-libs                 x86_64       0.0.5-3.ph2      photon       330.13k 338056

lightwave-client-libs    x86_64       1.3.1-5.ph2      photon         2.20M 2308680

jansson                  x86_64       2.10-1.ph2       photon        76.67k 78510

copenapi                 x86_64       0.0.2-3.ph2      photon        62.80k 64304

likewise-open            x86_64       6.2.11.4-3.ph2   photon        11.52M 12078104

netmgmt                  x86_64       1.1.0-9.ph2      photon       149.77k 153360

c-rest-engine            x86_64       1.0.4-3.ph2      photon       107.93k 110520

pmd                      x86_64       0.0.5-3.ph2      photon       527.47k 540133

Total installed size:  82.42M 86419528

Downloading:

pmd                                     173185    100%

c-rest-engine                            49211    100%

netmgmt                                  72283    100%

likewise-open                          3899636    100%

copenapi                                 35650    100%

jansson                                  42100    100%

lightwave-client-libs                   737040    100%

pmd-libs                                 93441    100%

pcre                                    301344    100%

ntp                                    3637335    100%

iputils                                 129855    100%

openldap                                890618    100%

haveged                                  75010    100%

libxml2                                1589185    100%

perl                                  18290806    100%

libgcrypt                               510631    100%

cyrus-sasl                              298403    100%

libgpg-error                             61382    100%

Testing transaction

Running transaction

Installing/Updating: jansson-2.10-1.ph2.x86_64

Installing/Updating: copenapi-0.0.2-3.ph2.x86_64

Installing/Updating: libgpg-error-1.27-1.ph2.x86_64

Installing/Updating: libgcrypt-1.8.1-1.ph2.x86_64

Installing/Updating: iputils-20151218-4.ph2.x86_64

Installing/Updating: cyrus-sasl-2.1.26-13.ph2.x86_64

Installing/Updating: openldap-2.4.44-3.ph2.x86_64

Installing/Updating: perl-5.24.1-4.ph2.x86_64

Installing/Updating: ntp-4.2.8p10-4.ph2.x86_64

Installing/Updating: libxml2-2.9.6-1.ph2.x86_64

Installing/Updating: haveged-1.9.1-3.ph2.x86_64

Installing/Updating: likewise-open-6.2.11.4-3.ph2.x86_64

Waiting for lwreg startup.

ok

Installing settings from /opt/likewise/share/config/accounts.reg...

Installing settings from /opt/likewise/share/config/dcerpcd.reg...

Installing settings from /opt/likewise/share/config/eventlogd.reg...

Installing settings from /opt/likewise/share/config/lsassd.reg...

Installing settings from /opt/likewise/share/config/lwiod.reg...

Installing settings from /opt/likewise/share/config/lwreg.reg...

Installing settings from /opt/likewise/share/config/netlogond.reg...

Installing settings from /opt/likewise/share/config/privileges.reg...

Installing settings from /opt/likewise/share/config/rdr.reg...

Starting service dependency: netlogon

Starting service dependency: lwio

Starting service dependency: rdr

Starting service: lsass

Installing/Updating: lightwave-client-libs-1.3.1-5.ph2.x86_64

Installing/Updating: pmd-libs-0.0.5-3.ph2.x86_64

Installing/Updating: pcre-8.40-4.ph2.x86_64

Installing/Updating: netmgmt-1.1.0-9.ph2.x86_64

Installing/Updating: c-rest-engine-1.0.4-3.ph2.x86_64

Installing/Updating: pmd-0.0.5-3.ph2.x86_64

Generating a 2048 bit RSA private key

................................+++

..+++

writing new private key to '/etc/pmd/server.key'

-----

Generating RSA private key, 2048 bit long modulus

..........................................................+++

...............................................................................................+++

e is 65537 (0x10001)

writing RSA key

Complete!

root@photon-machine [ ~ ]#

pmd サービスを起動します。

root@photon-machine [ ~ ]# systemctl start pmd

root@photon-machine [ ~ ]# systemctl enable pmd

root@photon-machine [ ~ ]# systemctl status pmd

● pmd.service - photon management daemon

   Loaded: loaded (/lib/systemd/system/pmd.service; enabled; vendor preset: enabled)

   Active: active (running) since Fri 2017-11-03 17:45:40 UTC; 4s ago

Main PID: 715 (pmd)

    Tasks: 18 (limit: 4915)

   CGroup: /system.slice/pmd.service

           mq715 /usr/bin/pmd

Nov 03 17:45:40 photon-machine systemd[1]: Started photon management daemon.

なぜか pmd サービスが起動できないことがあるのですが、

その場合は restServer.log ファイルのパーミッションが下記になっているか

確認してみるとよいと思います。

root@photon-machine [ ~ ]# ls -l /var/log/pmd/restServer.log

-rw-r--r-- 1 pmd pmd 0 Nov  3 17:45 /var/log/pmd/restServer.log

pmd-cli のインストール。

pmd-cli の RPM をインストールします。

すでに pmd で依存 PRM がインストール済みとなっているため

pmd-cli だけがインストールされます。

root@photon-machine [ ~ ]# tdnf install -y pmd-cli

Installing:

pmd-cli                  x86_64       0.0.5-3.ph2      photon        58.79k 60200

Total installed size:  58.79k 60200

Downloading:

pmd-cli                                  33148    100%

Testing transaction

Running transaction

Installing/Updating: pmd-cli-0.0.5-3.ph2.x86_64

Complete!

root@photon-machine [ ~ ]#

pmd-cli がインストールされました。

オプションなしで実行すると、help が見られます。

ネットワーク(net)、RPM パッケージ(pkg)、ユーザ(usr)、firewall の

情報確認や設定ができるようです。

そして pmd が起動しているリモートサーバに実行することもできます。

root@photon-machine [ ~ ]# pmd-cli

These are the current registered components

'firewall' : firewall management

'net' : network management

'pkg' : package management

'usr' : user management

You need to specify a component and a command

usage: pmd-cli [connection/auth options] <component> <command> [command options]

For local connections, use: pmd-cli <component> <cmd> <options>.

Current logged in user permissions will apply when executing commands.

This is the same as specifying --servername localhost.

For remote servers, use one of 3 methods mentioned below. Password is never sent out to the remote in any of the below auth scenarios.

When --user is specified, you will be prompted for password.

1. System user.

   pmd-cli --servername <server> --user <user>

2. Lightwave user (pmd server must be joined or should be part of embedded lightwave)

   pmd-cli --servername <server> --user <user> --domain <lightwave domain>

3. Kerberos spn (client must successfully run kinit before using this method)

   pmd-cli --servername <server> --spn <service principal name>

Error(805) : Unknown error

root@photon-machine [ ~ ]#

pmd-cli を実行してみる。

pmd-cli は、途中までのコマンドラインを実行することで下記のようにヘルプを見ながら操作できます。

root@photon-machine [ ~ ]# pmd-cli net

Unknown command net

Usage: netmgr command <command options ...>

For help: netmgr -h or netmgr --help

For version: netmgr -v or netmgr --version

List of commands:

link_info        get or set interface mac address, mtu, link state, or link mode

ip4_address      get or set interface IPv4 address and optionally default gateway

ip6_address      add or delete IPv6 address(es) and optionally default gateway for interface

ip_route         add or delete static IP route for the interface

dns_servers      get or set DNS mode, list of DNS servers

dns_domains      get or set list of DNS domains

dhcp_duid        get or set DHCP DUID, optionally per interface

if_iaid          get or set interface IAID

ntp_servers      get or set NTP servers list

hostname         get or set system hostname

wait_for_link    wait for the interface to come up

wait_for_ip      wait for the interface to acquire a valid IP address

error_info       get error information from error code

net_info         get or set network configuration parameters

set_duid         This is deprecated, will be removed in the future. Please use 'dhcp_duid --set'

set_iaid         This is deprecated, will be removed in the future. Please use 'if_iaid --set'

get_dns_servers  This is deprecated, will be removed in the future. Please use 'dns_servers --get'

Error(33) : Unknown error

root@photon-machine [ ~ ]#

root@photon-machine [ ~ ]# pmd-cli net ip4_address

Usage:

ip4_address --get --interface <ifame>

ip4_address --set --interface <ifname> --mode dhcp|static|none --addr <IPv4Address/prefix> --gateway <Gateway Address>

Error(33) : Unknown error

root@photon-machine [ ~ ]#

IP アドレスの設定情報を表示してみました。

root@photon-machine [ ~ ]# pmd-cli net ip4_address --get --interface eth0

IPv4 Address Mode: dhcp

IPv4 Address=192.168.12.207/24

IPv4 Gateway=192.168.12.1

root@photon-machine [ ~ ]#

たとえば、RPM のインストールもできます。

ためしに jq コマンドの RPM をインストールしてみました。

root@photon-machine [ ~ ]# pmd-cli pkg install -y jq

Installing:

jq                       x86_64       1.5-3.ph2        photon       340.52k 348689

Total installed size: 340.52k 348689

Downloading:

Complete!

root@photon-machine [ ~ ]#

root@photon-machine [ ~ ]# rpm -q jq

jq-1.5-3.ph2.x86_64

そして、pmd が起動している別の Photon OS にも jq をインストールしてみます。

これまでの pmd-cli の結果にあるように、このサーバは 192.168.12.207 ですが、

そこからリモート(192.168.12.208)の Photon に pmd-cli を実行してみます。

リモート(192.168.12.208)の Photon でも pmd を起動してあります。

root@photon-machine [ ~ ]# ssh root@192.168.12.208 "cat /etc/photon-release;systemctl is-active pmd"

Password:

VMware Photon OS 2.0

PHOTON_BUILD_NUMBER=304b817

active

root@photon-machine [ ~ ]#

ただ、これだけだと pmd-cli では接続できないようです。

root@photon-machine [ ~ ]# pmd-cli --servername 192.168.12.208 --user root pkg install -y jq

Password:

Error(382312513) : (null)

Error(382312513) : Failed to connect to the remote host, reason = rpc_s_connect_timed_out (0x16c9a041).

root@photon-machine [ ~ ]#

たまたまうちにあった Log Insight で NSX 分散ファイアウォールのログを取得できるので見てみると、

pmd-cli をリモート実行したタイミングで TCP 2016 番ポート宛のアクセスがあるようでした。

vrli-pmd-port.png

宛先 Photon 側(192.168.12.208)で見てみると、

たしかに pmd が TCP 2016番ポートをリスニングしています。

※さりげなくここで lsof と pmd-cli をインストールしています。

root@photon-machine [ ~ ]# ip a | grep 192

    inet 192.168.12.208/24 brd 192.168.12.255 scope global dynamic eth0

root@photon-machine [ ~ ]# tdnf install -y --quiet lsof pmd-cli

root@photon-machine [ ~ ]# lsof -i -P | grep pmd

pmd       690             pmd    4u  IPv4   8867      0t0  TCP *:2081 (LISTEN)

pmd       690             pmd    5u  IPv6   8868      0t0  TCP *:2081 (LISTEN)

pmd       690             pmd   10u  IPv4   8886      0t0  TCP *:2016 (LISTEN)

pmd       690             pmd   11u  IPv6   8888      0t0  TCP *:2016 (LISTEN)

Photon の iptables でそのポートは解放されていないので、

今回は pmd-cli firewall ~ のローカル実行でポートを開放してしまいます。

pmd は TCP 2081 番もリスニングしていますが、ファイアウォールのログでは通信がなかったので

今回は 2016 番だけ解放してみました。

root@photon-machine [ ~ ]# pmd-cli net ip4_address --get --interface eth0

IPv4 Address Mode: dhcp

IPv4 Address=192.168.12.208/24

IPv4 Gateway=192.168.12.1

root@photon-machine [ ~ ]# pmd-cli firewall rules --chain INPUT --add "-p tcp -m tcp --dport 2016 -j ACCEPT"

root@photon-machine [ ~ ]#

iptables のポートを開放すると、192.168.12.207 から pmd-cli をリモート実行できました。

root@photon-machine [ ~ ]# pmd-cli net ip4_address --get --interface eth0

IPv4 Address Mode: dhcp

IPv4 Address=192.168.12.207/24

IPv4 Gateway=192.168.12.1

root@photon-machine [ ~ ]# pmd-cli --servername 192.168.12.208 --user root pkg install -y jq

Password:

Installing:

jq                       x86_64       1.5-3.ph2        photon       340.52k 348689

Total installed size: 340.52k 348689

Downloading:

Complete!

root@photon-machine [ ~ ]#

root@photon-machine [ ~ ]# ssh root@192.168.12.208 jq -V

Password:

jq-1.5

root@photon-machine [ ~ ]#

エラーメッセージを見ると rpc とあるので 2016 版ポートの解放でしたが、

設定ファイルをみると REST でのアクセスの場合は 2081 の解放が必要かもしれません。

root@photon-machine [ ~ ]# cat /etc/pmd/pmd.conf

[main]

#not an rpmostree server

servertype=0

apisecurity=/etc/pmd/api_sddl.conf

roledir=/etc/javelin.roles.d

rolepluginsdir=/etc/javelin.roles.plugins.d

[rest-server]

enabled=1

port=2081

apispec=/etc/pmd/restapispec.json

[rpc-server]

enabled=1

port=2016

[privsep]

pubkey=/etc/pmd/privsep_pub.key

privkey=/etc/pmd/privsep_priv.key

簡単にまとめると、pmd-cli の実行には・・・

  • pmd サービスが起動している必要がある。
  • リモート実行の場合は、iptables の TCP 2016 番ポートの解放が必要。
    (もしくは systemctl stop iptables)

ちなみに、pmd-cli net ~ のリモード実行はなぜかうまくいかないようです。

ひきつづき Photon OS 2.0 で いろいろと試してみたいと思います。

以上、PMD / pmd-cli を使用してみる話でした。

Version history
Revision #:
1 of 1
Last update:
‎11-03-2017 01:03 PM
Updated by: