웹사이트 검색

Rocky Linux 8에서 Nginx Reverse Proxy와 함께 WildFly Java 애플리케이션 서버 설치


이 페이지에서

  1. 전제 조건
  2. 자바 설치
  3. Wildfly 설치
  4. Wildfly 관리 사용자 추가
  5. 방화벽 및 SELinux 구성\n
  6. Wildfly 관리 콘솔에 액세스
  7. Nginx를 Wildfly용 리버스 프록시로 구성\n
  8. 결론

WildFly는 RedHat에서 개발한 오픈 소스 및 크로스 플랫폼 애플리케이션 서버입니다. Java로 작성되었으며 Java 응용 프로그램 개발에 사용됩니다. 간단하고 유연하며 가벼우며 요구 사항에 따라 추가하거나 제거할 수 있는 플러그형 하위 시스템을 기반으로 합니다. 간단하고 사용자 친화적인 대시보드와 함께 제공되며 사용자에게 빠르고 안정적인 Java 런타임 환경을 제공하는 것을 목표로 합니다.

이 튜토리얼에서는 Rocky Linux 8에서 리버스 프록시로 Nginx와 함께 Wildfly를 설치하는 방법을 보여줍니다. 동일한 단계가 AlmaLinux 8 및 CentOS 8에서도 작동합니다.

전제 조건

  • Rocky Linux 8/AlmaLinux 8 또는 centOS 8을 실행하는 서버.\n
  • 루트 암호는 서버에 구성됩니다.\n

자바 설치

Wildfly는 자바 기반 애플리케이션이므로 서버에 자바가 설치되어 있어야 합니다. 설치되어 있지 않은 경우 다음 명령으로 설치할 수 있습니다.

dnf install java-11-openjdk-devel -y

Java를 설치한 후 다음 명령을 사용하여 설치된 Java 버전을 확인할 수 있습니다.

java --version

다음 출력이 표시되어야 합니다.

openjdk 11.0.8 2020-07-14 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.8+10-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.8+10-LTS, mixed mode, sharing)

Wildfly 설치

Wildfly를 설치하기 전에 Wildfly를 실행하려면 별도의 사용자와 그룹을 만들어야 합니다. 다음 명령으로 생성할 수 있습니다.

groupadd --system wildfly
useradd -s /sbin/nologin --system -d /opt/wildfly -g wildfly wildfly

다음으로 Wildfly의 공식 웹사이트에서 최신 버전을 다운로드해야 합니다. 이 튜토리얼을 작성할 당시 Wildfly의 최신 버전은 20.0.1입니다. 다음 명령으로 다운로드할 수 있습니다.

wget https://download.jboss.org/wildfly/20.0.1.Final/wildfly-20.0.1.Final.tar.gz

다운로드가 완료되면 다음 명령을 사용하여 다운로드한 파일의 압축을 풉니다.

tar -xvzf /root/wildfly-20.0.1.Final.tar.gz

그런 다음 다음 명령을 사용하여 추출된 디렉터리를 /opt에 복사합니다.

mv wildfly-20.0.1.Final /opt/wildfly

다음으로 Wildfly 구성 파일을 저장할 디렉터리를 만듭니다.

mkdir /etc/wildfly

그런 다음 다음 명령을 사용하여 필요한 모든 파일을 원하는 위치에 복사합니다.

cp /opt/wildfly/docs/contrib/scripts/systemd/wildfly.conf /etc/wildfly/
cp /opt/wildfly/docs/contrib/scripts/systemd/wildfly.service /etc/systemd/system/
cp /opt/wildfly/docs/contrib/scripts/systemd/launch.sh /opt/wildfly/bin/

다음으로 다음 명령을 사용하여 wildfly 디렉터리 및 파일에 적절한 소유권과 권한을 부여합니다.

chmod +x /opt/wildfly/bin/launch.sh
chown -R wildfly:wildfly /opt/wildfly
chmod -R +x /opt/wildfly/

다음으로 다음 명령을 사용하여 systemd 데몬을 다시 로드합니다.

systemctl daemon-reload

그런 다음 Wildfly 서비스를 시작하고 다음 명령을 사용하여 부팅 시 시작되도록 활성화합니다.

systemctl start wildfly
systemctl enable wildfly

이제 다음 명령을 사용하여 Wildfly 서비스 상태를 확인할 수 있습니다.

systemctl status wildfly

다음 출력이 표시되어야 합니다.

? wildfly.service - The WildFly Application Server
   Loaded: loaded (/etc/systemd/system/wildfly.service; disabled; vendor preset: disabled)
   Active: active (running) since Sun 2020-09-13 05:57:22 EDT; 16s ago
 Main PID: 31834 (launch.sh)
    Tasks: 123 (limit: 12527)
   Memory: 304.1M
   CGroup: /system.slice/wildfly.service
           ??31834 /bin/bash /opt/wildfly/bin/launch.sh standalone standalone.xml 0.0.0.0
           ??31835 /bin/sh /opt/wildfly/bin/standalone.sh -c standalone.xml -b 0.0.0.0
           ??31925 java -D[Standalone] -server -Xms64m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=tru>

Sep 13 05:57:22 centos8 systemd[1]: Started The WildFly Application Server.

이 시점에서 Wildfly가 설치되고 시작됩니다. 기본적으로 wildfly 애플리케이션 서버는 포트 8080에서 수신 대기합니다. 다음 명령으로 확인할 수 있습니다.

ss -tunelp | grep 8080

다음 출력이 표시되어야 합니다.

tcp    LISTEN   0        128               0.0.0.0:8080           0.0.0.0:*      users:(("java",pid=31925,fd=478)) uid:989 ino:59014 sk:9

Wildfly 관리 콘솔은 포트 9990에서 수신 대기 중입니다. 다음 명령으로 확인할 수 있습니다.

ss -tunelp | grep 9990

다음 출력이 표시되어야 합니다.

tcp    LISTEN   0        50              127.0.0.1:9990           0.0.0.0:*      users:(("java",pid=31925,fd=138)) uid:989 ino:59017 sk:7

Wildfly 관리 사용자 추가

WildFly 관리 콘솔에 액세스하려면 Wildfly에 대한 관리 사용자를 생성해야 합니다. 다음 명령으로 만들 수 있습니다.

/opt/wildfly/bin/add-user.sh

아래와 같이 추가할 사용자 유형을 선택하라는 메시지가 표시됩니다.

What type of user do you wish to add? 
 a) Management User (mgmt-users.properties) 
 b) Application User (application-users.properties)
(a): a           

관리 사용자에 대해 a를 입력하고 Enter 키를 누릅니다. 다음 출력이 표시되어야 합니다.

Enter the details of the new user to add.
Using realm 'ManagementRealm' as discovered from the existing property files.
Username : wildflyadmin

원하는 사용자 이름을 제공하고 Enter를 누르십시오. 다음 출력이 표시되어야 합니다.

Password recommendations are listed below. To modify these restrictions edit the add-user.properties configuration file.
 - The password should be different from the username
 - The password should not be one of the following restricted values {root, admin, administrator}
 - The password should contain at least 8 characters, 1 alphabetic character(s), 1 digit(s), 1 non-alphanumeric symbol(s)
Password : 
Re-enter Password : 

비밀번호를 입력하고 Enter를 누르십시오. 다음 출력이 표시되어야 합니다.

What groups do you want this user to belong to? (Please enter a comma separated list, or leave blank for none)[  ]: 
About to add user 'wildflyadmin' for realm 'ManagementRealm'
Is this correct yes/no? yes
Added user 'wildflyadmin' to file '/opt/wildfly/standalone/configuration/mgmt-users.properties'
Added user 'wildflyadmin' to file '/opt/wildfly/domain/configuration/mgmt-users.properties'
Added user 'wildflyadmin' with groups  to file '/opt/wildfly/standalone/configuration/mgmt-groups.properties'
Added user 'wildflyadmin' with groups  to file '/opt/wildfly/domain/configuration/mgmt-groups.properties'
Is this new user going to be used for one AS process to connect to another AS process? 
e.g. for a slave host controller connecting to the master or for a Remoting connection for server to server EJB calls.
yes/no? yes
To represent the user add the following to the server-identities definition 

이 시점에서 Wildfly 관리 사용자가 생성됩니다. 다음 단계로 진행할 수 있습니다.

방화벽 및 SELinux 구성

기본적으로 SELinux는 Rocky Linux 8에서 활성화되어 있습니다. 따라서 Wildfly에 대해 SELinux를 구성해야 합니다. 다음 명령으로 수행할 수 있습니다.

semanage fcontext -a -t bin_t "/opt/wildfly/bin(/.*)?"
restorecon -Rv /opt/wildfly/bin/
setsebool -P httpd_can_network_connect 1

다음으로 방화벽을 통해 포트 8080, 9990 및 80을 허용해야 합니다. 다음 명령으로 수행할 수 있습니다.

firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --permanent --add-port=9990/tcp
firewall-cmd --permanent --add-port=80/tcp

다음으로 방화벽을 다시 로드하여 변경 사항을 적용합니다.

firewall-cmd --reload

완료되면 다음 단계로 진행할 수 있습니다.

Wildfly 관리 콘솔에 액세스

기본적으로 Wildfly 관리 콘솔은 localhost에서만 액세스할 수 있습니다. 외부 액세스를 위해 /opt/wildfly/bin/launch.sh를 편집하고 일부 변경해야 합니다.

nano /opt/wildfly/bin/launch.sh

다음 줄을 찾으십시오.

    $WILDFLY_HOME/bin/standalone.sh -c $2 -b $3

그리고 다음 줄로 바꿉니다.

    $WILDFLY_HOME/bin/standalone.sh -c $2 -b $3 -bmanagement=0.0.0.0

파일을 저장하고 닫은 다음 Wildfly 서비스를 다시 시작하여 변경 사항을 적용합니다.

systemctl restart wildfly

이제 웹 브라우저를 열고 URL http://your-server-ip:9990을 사용하여 Wildfly 관리 콘솔에 액세스하십시오. 아래와 같이 사용자 이름과 비밀번호를 입력하라는 메시지가 표시됩니다.

Wildfly 관리자 사용자 이름과 비밀번호를 제공하고 로그인 버튼을 클릭합니다. 로그인하면 다음 화면에 Wildfly 관리 대시보드가 표시됩니다.

Nginx를 Wildfly용 리버스 프록시로 구성

기본적으로 Wildfly 애플리케이션은 포트 8080에서 액세스할 수 있습니다. 따라서 포트 80을 사용하여 액세스할 수 있도록 Nginx를 역방향 프록시로 구성하는 것이 좋습니다.

먼저 다음 명령을 사용하여 Nginx 웹 서버를 설치합니다.

dnf install nginx -y

설치가 완료되면 다음 명령을 사용하여 새 Wildfly 구성 파일을 만듭니다.

nano /etc/nginx/conf.d/wildfly.conf

다음 줄을 추가합니다.

upstream wildfly {
  server 127.0.0.1:8080 weight=100 max_fails=5 fail_timeout=5;
}

server {
  listen          80;
  server_name     your-server-ip;

  location / {
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://wildfly/;
  }
}

파일을 저장하고 닫은 후 다음 명령을 사용하여 구성 오류가 있는지 Nginx를 확인합니다.

nginx -t

모든 것이 정상이면 다음과 같은 결과가 표시됩니다.

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

그런 다음 Nginx를 시작하고 다음 명령을 사용하여 시스템 재부팅 시 시작되도록 활성화합니다.

systemctl start nginx
systemctl enable nginx

다음 명령을 사용하여 Nginx 서비스의 상태를 확인할 수도 있습니다.

systemctl status nginx

다음 출력이 표시되어야 합니다.

? nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
  Drop-In: /usr/lib/systemd/system/nginx.service.d
           ??php-fpm.conf
   Active: active (running) since Sun 2020-09-13 06:03:37 EDT; 5s ago
  Process: 1775 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 1773 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 1771 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 1776 (nginx)
    Tasks: 3 (limit: 12527)
   Memory: 5.4M
   CGroup: /system.slice/nginx.service
           ??1776 nginx: master process /usr/sbin/nginx
           ??1777 nginx: worker process
           ??1778 nginx: worker process

Sep 13 06:03:37 centos8 systemd[1]: Stopped The nginx HTTP and reverse proxy server.
Sep 13 06:03:37 centos8 systemd[1]: Starting The nginx HTTP and reverse proxy server...
Sep 13 06:03:37 centos8 nginx[1773]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Sep 13 06:03:37 centos8 nginx[1773]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Sep 13 06:03:37 centos8 systemd[1]: Started The nginx HTTP and reverse proxy server.

이 시점에서 Wildfly 애플리케이션을 제공하도록 Nginx가 설치되고 구성됩니다. 이제 URL http://your-server-ip를 사용하여 Wildfly 애플리케이션에 액세스할 수 있습니다. 다음 화면이 표시됩니다.

결론

이 가이드에서는 Rocky Linux 8에서 Wildfly를 설치하고 원격 액세스를 활성화하는 방법을 배웠습니다. 또한 포트 80을 통해 Wildfly에 액세스하기 위해 Nginx를 리버스 프록시로 구성했습니다. 이제 Java 애플리케이션 빌드를 시작하고 다음에서 관리할 수 있습니다. Widfly 관리 콘솔.