17.4 CLI
CLI 실행 방법이나 조작 방법에 대해 설명한다.
CLI 실행 방법
CLI는 서버(스탠드얼론 서버 또는 도메인 컨트롤러)가 시작된 상태에서 실행하여 대상 서버 에 접속해 각종 관리 명령을 실행한다.
CLI 시작
CLI의 실행은 $JBOSS_HOME/bin 폴더에서 jboss-cli.sh의 스크립트를 실행하면 된다.
아래와 같은 명령을 실행하면 CLI의 파라미터 목록이 표시된다.
$./jboss-cli.sh --help
Usage: jboss-cli.sh/jboss-cli.bat [--help] [--version] [--controller=host:port]
……
jboss-cli.sh 주요 옵션들은 다음과 같다.
| 옵션 | 설명 |
|---|---|
--help(-h) | jboss-cli 도움말 표시한다. |
--version | OS, JVM, JBoss의 버전 정보와 환경 변수를 표시한다. |
--controller | --connect의 명령으로 접속할 호스트명과 포트 번호를 지정한다. --controller=IP주소:포트 형식으로 입력한다. 생략시 localhost:9999가 사용된다. |
--connect(-c) | CLI를 시작하면 바로 서버에 접속한다. |
--gui | GUI 모드로 시작한다. |
--file | 배치 모드로 실행할 경우, 명령어와 오퍼레이션을 포함한 파일 경로를 지정한다. |
--command | 실행할 명령어 또는 오퍼레이션을 지정한다. |
--commands | 실행할 여러 개의 명령어 또는 오퍼레이션을 컴마로 구분하여 지정한다. |
--user | JBoss 관리자 아이디 |
--password | JBoss 관리자 패스워드 |
서버 접속
CLI를 시작한 후 connect 명령어를 실행하면 서버(기본값 localhost:9999)에 접속한다.
$ ./jboss-cli.sh
You are disconnected at the moment. Type 'connect' to connect to the server or 'help' for the list of supported commands.
[disconnected /] connect
[standalone@localhost:9999 /]
또, jboss-cli.sh 스크립트를 실행할 때 ‘--connect’ 나 ‘-c’ 옵션을 사용하여 CLI를 시작하면 곧바로 관리 서버에 접속하는 것도 가능하다. 특정 컨트롤러에 접속하려면 jboss-cli.sh 시작 시 --connect 옵션의 뒤에 --controller=[host][:port]를 지정한다.
$ ./jboss-cli.sh --connect --controller=localhost:9999
[standalone@localhost:9999 /]
connect 명령의 파라미터로 접속할 서버의 IP주소와 포트 번호를 지정하여 접속할 수 있다.
$ ./jboss-cli.sh
You are disconnected at the moment. Type 'connect' to connect to the server or 'help' for the list of supported commands.
[disconnected /] connect localhost:9999
[standalone@localhost:9999 /]
CLI 실행 모드
jboss-cli.sh 스크립트의 실행 모드는 일반적인 쉘(Shell)과 같이 프롬프트에 명령을 입력하면 실행 결과를 출력하는 대화형 모드와 jboss-cli.sh의 파라미터로 명령을 직접 지정해 실행하는 비대화형 모드가 있다.
-
대화형 모드
$ ./jboss-cli.shYou are disconnected at the moment. Type 'connect' to connect to the server or 'help' for the list of supported commands.[disconnected /] connect[standalone@localhost:9999 /] cd /core-service=management[standalone@localhost:9999 core-service=management] lsldap-connection management-interface security-realm[standalone@localhost:9999 core-service=management]
비대화형 모드는 접속할 때 사용하는 --connect(-c) 옵션과 실행할 명령을 지정하는 --command, --commands 나 --file 옵션을 사용한다.
다음은 비대화형 모드 실행 예로 cd 명령으로 /core-service=management 노드로 이동하여, ls명령으로 하위 자원이나 속성들을 표시하는 예제이다. 그런데 비대화형 모드의 --command는 하나의 명령만 지정할 수 있기 때문에 cd명령어를 사용하지 않고 루트 디렉터리에서 ls 명령을 실행하였다.
-
비대화형 모드
-
--command 옵션(ls명령만 실행)
$ ./jboss-cli.sh -c command="ls"core-servicedeploymentdeployment-overlayextensioninterfacepath… 생략 …$
-
-
--commands 옵션
$ ./jboss-cli.sh -c --commands="cd /core-service=management, ls"ldap-connectionmanagement-interfacesecurity-realm[jboss@rhel63pc bin]$ -
--file 옵션
다음과 같이 sample.cli 파일을 작성한다.
$ vi sample.clicd /core-service=managementls작성한 파일을 CLI에서 --file 옵션에 지정하여 실행한다.
$ ./jboss-cli.sh -c --file=sample.clildap-connectionmanagement-interfacesecurity-realm
CLI 인증
JBoss 매니지먼트에는 보안 Realm으로 ManagementRealm이 적용되어 로컬 호스트 이외의 원격접근에는 관리자 아이디와 패스워드를 입력해야 한다.
-
로컬 호스트 인증
로컬 호스트에서 접근은 ManagementRealm 설정에 있는 local 이 설정되어 있어 인증없이 접근할 수 있다. 이 인증 기능을 사일런트 인증이라 하며, 로컬 호스트에서의 접근도 ManagementRealm을 적용하여 인증하도록 설정하는 것도 가능하다. 사일런트 인증을 사용하지 않으려면 아래와 같이 실행하여 local 설정을 제거하면 된다.
[standalone@localhost:9999 /] /core-service=management/security-realm=ManagementRealm/authentication=local:remove{"outcome" => "success","response-headers" => {"operation-requires-reload" => true,"process-state" => "reload-required"}}[standalone@localhost:9999 /] :reload{"outcome" => "success"}
CLI 종료
CLI를 종료하려면 Ctrl+D 나 quit(혹은 q)를 입력한다.
비대화형 모드에서는 지정된 명령을 실행한 후 자동으로 종료한다.
CLI 명령어
CLI의 명령은 크게 관리 자원의 오퍼레이션 실행과 그 외의 일반 명령으로 나눌 수 있다. 관리 자원의 오퍼레이션 실행 명령과 보조 명령어로 cd, ls, pwn(pwd)등 일반 명령어가 있다.
CLI 명령어 사용법
CLI로 입력할 수 있는 명령어는 CLI 공통 명령어와 관리 대상 서버에 따라 사용할 수 있는 명령이 다른 명령어가 있다. 사용할 수 있는 명령의 목록은 관리 대상 서버(스탠드얼론 또는 도메인 컨트롤러)에 접속한 상태에서 help 명령을 실행하면 명령어에 대한 도움말이 출력된다.
$ ./jboss-cli.sh -c
[standalone@localhost:9999 /] help
Usage:
jboss-cli.sh/jboss-cli.bat [--help] [--version] [--controller=host:port]
{empty}[--connect] [--file=file_path]
{empty}[--commands=command_or_operation1,command_or_operation2...]
{empty}[--command=command_or_operation]
{empty}[--user=username --password=password]
{empty}[--timeout=timeout]
--help (-h) - prints (this) basic description of the command line utility.
--version - prints the version info of the JBoss AS release, JVM and system environment.
--controller - the default controller host and port to connect to when --connect option (described below) is specified or when the connect command is issued w/o the arguments. The default controller host is localhost and the port is 9999.
--connect (-c) - instructs the CLI to connect to the controller on start-up (to avoid issuing a
separate connect command later).
--gui - GUI built on top of the CLI, the only difference is that it brings up a GUI instead
of a command line. In this mode, the CLI will automatically connect during start-up.
You can optionally specify --controller, if necessary.
--file - specifies a path to a file which contains commands and operations (one per line) that
should be executed (in a non-interactive mode). The CLI will terminate the session
immediately after the last command has been executed or if some command
or operation failed.
… 생략 …
각각의 명령에 대해 명령어 파라미터에 '--help’를 지정하면 상세 정보가 표시된다.
[standalone@localhost:9999 /] command --help
SYNOPSIS
command [add --node-type=node_path_to_the_type
[--property-id=identifying_property]
--command-name=name_for_the_command |
remove --command_name=command_to_remove |
list]
DESCRIPTION
Allows to add new, remove and list existing generic type commands.
A generic type command is a command that is assigned to a specific node type
and which allows to perform any operation available for an instance of that
type and/or modify any of the properties exposed by the type on any existing
instance of that type.
For example, suppose there is a generic type command assigned to type
… 생략 …
다음은 CLI의 기본 명령어들은 다음과 같은 것이 있다.
| 명령어 | 설명 |
|---|---|
| batch | 배치 모드 시작 |
| cn (or cd) | 노드 경로를 입력하여 위치를 변경(디렉터리 변경과 유사) |
| connect | 서버 인스턴스에 접속 |
| command | 일반 명령의 추가, 삭제 |
| deploy | 애플리케이션 배포 |
| help (or h) | 도움말 표시 |
| history | 명령어 히스토리를 표시 |
| ls | 현재 노드의 자원 목록을 표시한다. 파라미터 ‘-l’을 사용하면 attribute와 child 자원이 표시된다. |
| pwn (or pwd) | 현재 노드 위치를 표시 |
| quit (or q) | CLI를 종료한다. |
| read-attribute | 노드의 속성 정보를 표시한다. |
| read-operation | 오퍼레이션의 설명 및 목록을 표시한다. |
| deploy | 애플리케이션을 배포한다. |
| version | 버전 정보를 표시한다. |
탭 자동완성
CLI 명령어 입력시 Linux의 쉘과 같이 탭 자동완성(Tab-completion)을 사용할 수 있다. 대화형 모드로 명령어나 노드 경로, 오퍼레이션, 명령어나 오퍼레이션의 파라미터 등 모든 입력에 대해서 동작한다. 대상 후보가 하나일 경우엔 자동으로 입력 문자가 채워지고, 대상 후보가 여러 개일 경우엔 리스트로 표시한다.
명령어 히스토리
Linux 쉘과 마찬가지로 CLI 는 실행한 명령어에 대한 히스토리(history) 기능을 제공한다. 대화형 모드에서 위, 아래 화살표 키를 눌러 사용한 명령어 히스토리의 전/후를 확인하고 다시 실행하거나 편집하여 실행할 수 있다. 명령어 히스토리는 메모리와 파일에 보관하여 있어 CLI를 재 시작하더라도 명령어 히스토리를 참조할 수 있다. 히스토리가 저장되는 파일명은 사용자 홈디렉터리에 있는 ‘.jboss-cli-history’파일이다. 히스토리 기능을 변경하려면 history 명령어를 사용한다. 파라미터 없이 실행하면, 메모리상에 보관하고 있는 모든 히스토리(최댓값 500개)이 출력된다.
[standalone@localhost:9999 /] history
connect 192.168.0.11:10099
connect localhost:9999
connect
cd /core-service=management
ls
exit
command --help
history
(The history is currently enabled)
[standalone@localhost:9999 /]
history 명령어는 아래와 같은 3개의 파라미터를 사용할 수 있다.
- disable : 히스토리를 사용하지 않는다. 기존의 히스토리도 삭제한다.
- enabled : 히스토리의 기록을 사용한다.
- clear : 메모리상의 히스토리를 삭제한다. 파일의 히스토리는 삭제하지 않는다.