예: REST API 구성
이 예는 Junos OS 디바이스에서 REST API를 구성하는 방법을 보여줍니다.
요구 사항
-
지원되는 버전의 Junos OS를 실행하는 라우팅, 스위칭 또는 보안 디바이스가 필요합니다.
개요
이 예에서는 Junos OS 디바이스에서 REST API를 구성합니다. lighttpd 및 juise tracing이 활성화된 상태에서 HTTP 및 HTTPS 액세스를 모두 구성합니다.
| 동작 | 플랫폼 참고 사항 |
| REST API 구성 | 플랫폼별 동작이 없습니다. |
구성
CLI 빠른 구성
이 예를 빠르게 구성하려면, 아래 명령을 복사하여 텍스트 파일에 붙여 넣은 다음 모든 라인브레이크를 제거하고, 네트워크 구성을 일치하는 데 필요한 세부 사항을 변경하고, 계층 수준에서 [edit] 명령을 복사하여 CLI에 붙여 넣은 다음, 구성 모드에서 입력합니다 commit .
set system services rest control allowed-sources [192.0.2.0 198.51.100.0] set system services rest control connection-limit 100 set system services rest http port 3000 set system services rest http addresses [203.0.113.0 203.0.113.1] set system services rest https port 3443 set system services rest https addresses [203.0.113.2 203.0.113.3] set system services rest https server-certificate testcert set system services rest https cipher-list rsa-with-3des-ede-cbc-sha set system services rest https mutual-authentication certificate-authority testca set system services rest traceoptions flag all set system services rest enable-explorer
REST API 구성
단계별 절차
REST API를 구성하려면 다음을 수행합니다.
들어오는 HTTP 및 HTTPS 연결에 허용되는 IP 주소를 지정합니다.
[edit] user@R1# set system services rest control allowed-sources [192.0.2.0 198.51.100.0]
HTTP 및 HTTPS 모두에서 허용되는 최대 연결 수를 지정합니다.
[edit] user@R1# set system services rest control connection-limit 100
들어오는 HTTP 연결에 대한 TCP 포트를 설정합니다.
[edit] user@R1# set system services rest http port 3000
서버가 수신 HTTP 연결을 수신하는 주소를 설정합니다.
[edit] user@R1# set system services rest http addresses [203.0.113.0 203.0.113.1]
들어오는 HTTPS 연결에 대한 TCP 포트를 설정합니다.
[edit] user@R1# set system services rest https port 3443
서버가 들어오는 HTTPS 연결을 수신하는 주소를 설정합니다.
[edit] user@R1# set system services rest https addresses [203.0.113.2 203.0.113.3]
서버 인증서를 설정합니다.
[edit] user@R1# set system services rest https server-certificate testcert
서버가 암호화 및 복호화 기능을 수행하는 데 사용할 수 있는 암호 집합을 구성합니다.
[edit] user@R1# set system services rest https cipher-list rsa-with-3des-ede-cbc-sha
(선택 사항) 인증서를 사용하여 서버와 클라이언트 모두에서 TLS 상호 인증을 설정합니다.
[edit] user@R1# set system services rest https mutual-authentication certificate-authority testca
(선택 사항) lighttpd, juise 또는 둘 다에 대한 추적 옵션을 구성합니다.
[edit] user@R1# set system services rest traceoptions flag all
(선택 사항) REST API 탐색기를 활성화합니다.
[edit] user@R1# set system services rest enable-explorer
구성을 커밋합니다.
[edit] user@R1# commit and-quit
결과
system {
services {
rest {
control {
allowed-sources [ 192.0.2.0 198.51.100.0 ];
connection-limit 100;
}
enable-explorer;
http {
addresses [ 203.0.113.0 203.0.113.1 ];
port 3000;
}
https {
port 3443;
addresses [ 203.0.113.2 203.0.113.3 ];
server-certificate testcert;
cipher-list rsa-with-3des-ede-cbc-sha;
mutual-authentication {
certificate-authority testca;
}
}
traceoptions {
flag all;
}
}
}
}
REST API에 대해 traceoptions가 활성화되면 로그는 /var/chroot/rest-api/var/log/lighttpd에 저장됩니다.
이 로그 위치는 지원되는 Junos OS 플랫폼에 적용됩니다.
검증
REST API 구성 확인
목적
REST API 구성이 디바이스에서 제대로 작동하고 있는지 확인합니다.
작업
운영 모드 명령을 실행 show configuration system services rest 하여 REST API 구성을 표시합니다.
user@R1> show configuration system services rest
http {
port 3000;
addresses [ 203.0.113.0 203.0.113.1 ];
}
https {
port 3443;
addresses [ 203.0.113.2 203.0.113.3 ];
server-certificate testcert;
cipher-list rsa-with-3des-ede-cbc-sha;
mutual-authentication {
certificate-authority testca;
}
}
control {
allowed-sources [ 192.0.2.0 198.51.100.0 ];
connection-limit 100;
}
traceoptions {
flag all;
}
enable-explorer;
의미
이 예에서는 디바이스에서 HTTP 및 HTTPS 액세스를 모두 구성했습니다. HTTP 액세스의 경우, 디바이스는 포트 3000에서 수신하고 IP 주소 192.0.2.0, 198.51.100.0, 203.0.113.0 및 203.0.113.1의 트래픽을 허용합니다. 보다 안전한 연결을 위해 HTTPS 액세스는 포트 3443을 사용하고 192.0.2.0, 198.51.100.0, 203.0.113.2 및 203.0.113.3의 IP 주소를 허용하는 상호 인증로 구성되었습니다. HTTP 및 HTTPS 모두에 대해 100의 연결 제한이 구성되었으며 juise 및 lighttpd 추적이 모두 활성화되었습니다. 기본적으로 REST API 탐색기는 비활성화되어 있습니다( 예: REST API 탐색기 사용 참조).