Skip to the content.

< Home

📕 Linux 개발 환경 구축 (WSL2)

WSL2 환경 구축

  1. Window 버전 Update

    image

  2. Ubuntu 설치(Microsoft Store: 최신 LTS - 20.04 사용을 권장함)
  3. WSL2 설치 및 버전 변환: https://www.lesstif.com/software-architect/wsl-2-windows-subsystem-for-linux-2-89555812.html



VSCode 개발 환경 세팅

  1. ‘Remote – WSL’ 확장 프로그램을 설치
  2. WSL: Ubuntu에 연결(Status bar 좌측 초록색 버튼)
  3. WSL: Ubuntu에 “Node Extension Pack” 확장 프로그램을 설치

실행

  1. 빌드 스크립트 실행

    make build-dev
    
  2. 새 터미널 열고 run-console 스크립트 실행

    make run-console
    
  3. HyperCloud 페이지 https://{이름}.tmaxcloud.org/ 접속 (호스트명은 서버 담당자에게 문의)

발생할 수 있는 에러 유형 및 해결법


WSL2 외부 네트워크로 연결

  1. PowerShell 관리자 모드로 열기
  2. wsl 접속

    image

  3. 접속한 wsl의 아무 위치나 상관 없이 wsl-networks.ps1 파일 생성 (찾기 쉬운 위치로 지정하는 것 추천)

    포트 변경시 $ports=@(80,443,9000, 9001); 이 줄에 추가

    $remoteport = bash.exe -c "ifconfig eth0 | grep 'inet '"
    $found = $remoteport -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
    
    if( $found ){
      $remoteport = $matches[0];
    } else{
      echo "The Script Exited, the ip address of WSL 2 cannot be found";
      exit;
    }
    
    #[Ports]
    
    #All the ports you want to forward separated by coma
    $ports=@(80,443,9000, 9001);
    
    #[Static ip]
    #You can change the addr to your ip config to listen to a specific address
    $addr='0.0.0.0';
    $ports_a = $ports -join ",";
    
    #Remove Firewall Exception Rules
    iex "Remove-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' ";
    
    #adding Exception Rules for inbound and outbound Rules
    iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Outbound -LocalPort $ports_a -Action Allow -Protocol TCP";
    iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Inbound -LocalPort $ports_a -Action Allow -Protocol TCP";
    
    for( $i = 0; $i -lt $ports.length; $i++ ){
      $port = $ports[$i];
      iex "netsh interface portproxy delete v4tov4 listenport=$port listenaddress=$addr";
      iex "netsh interface portproxy add v4tov4 listenport=$port listenaddress=$addr connectport=$port connectaddress=$remoteport";
    }
    
  4. PowerShell.exe -ExecutionPolicy ByPass -File ./wsl-networks.ps1 명령 실행

    image

    이 에러는 무시해도 괜찮음. 다음 실행부터는 안남…

    • PowerShell.exe가 없다는 에러 발생시

      image

      powershell.exe가 있는 폴더를 찾아 들어가서 직접 실행해주면 됨 (TODO: alias 설정)

      /mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe

      image

  5. 완료! 외부에서 로컬IP:PORT 로 접근 가능 (ex. https://192.168.8.21:9000)

☝ 위와 같이 했는데 외부접속이 안된다면..



etc